Hi,
Although Roland wasn't sure of the usefulness of the this patch. This patch changes both libnetfs and libdiskfs to have make_node return an error_t. 2002-04-06 James A. Morrison <[EMAIL PROTECTED]> libnetfs: * make-node.c (netfs_make_node): Now returns an error_t and sets the node in the new *NNP parameter. * netfs.h (netfs_make_node): Likewise. libdiskfs: * diskfs.h (diskfs_make_node): Now returns error_t and takes a pointer to a node as a new argument. Fixed a typo. * node-make.c (diskfs_make_node): Likewise. ext2fs: * inode.c (diskfs_cached_lookup): Check return value of diskfs_make_node using its new semantics. ftpfs: * fs.c (ftpfs_create): Check return value of netfs_make_node using its new semantics. * node.c (ftpfs_create_node): Likewise. hostmux: * leaf.c (create_host_node): Check return value of netfs_make_node using its new semantics. * hostmux.c (main): Likewise. isofs: * inode.c (diskfs_cached_lookup): Check return value of diskfs_make_node using its new semantics. (load_inode): Likewise. nfs: * nfs.c (xdr_decode_fhandle): Check return value of lookup_fhandle and assert_perror on the error. * cache.c (lookup_fhandle): Now returns error_t instead of void. Check return value of netfs_make_node using its new semantics. * nfs.h (lookup_fhandle): Now returns error_t instead of void. tmpfs: * node.c (diskfs_cached_lookup): Check return value of diskfs_make_node using its new semantics. ufs: * inode.c (diskfs_cached_lookup): Check return value of diskfs_make_node using its new semantics. Check the return value of malloc for DN. usermux: * usermux.c (main): Check the return value of netfs_make_node using its new semantics. * leaf.c (create_user_node): Likewise. Index: libnetfs/make-node.c =================================================================== RCS file: /cvsroot/hurd/hurd/libnetfs/make-node.c,v retrieving revision 1.5 diff -u -p -r1.5 make-node.c --- libnetfs/make-node.c 30 Dec 2000 18:22:28 -0000 1.5 +++ libnetfs/make-node.c 7 Apr 2002 20:16:45 -0000 @@ -1,5 +1,5 @@ /* - Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 2000, 2002 Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -21,12 +21,12 @@ #include "netfs.h" #include <hurd/fshelp.h> -struct node * -netfs_make_node (struct netnode *nn) +error_t +netfs_make_node (struct netnode *nn, struct node **nnp) { - struct node *np = malloc (sizeof (struct node)); + struct node *np = *nnp = malloc (sizeof (struct node)); if (! np) - return NULL; + return ENOMEM; np->nn = nn; @@ -38,5 +38,5 @@ netfs_make_node (struct netnode *nn) fshelp_transbox_init (&np->transbox, &np->lock, np); fshelp_lock_init (&np->userlock); - return np; + return 0; } Index: libnetfs/netfs.h =================================================================== RCS file: /cvsroot/hurd/hurd/libnetfs/netfs.h,v retrieving revision 1.29 diff -u -p -r1.29 netfs.h --- libnetfs/netfs.h 30 Jan 2001 00:50:25 -0000 1.29 +++ libnetfs/netfs.h 7 Apr 2002 20:16:45 -0000 @@ -341,9 +336,9 @@ extern int netfs_maxsymlinks; /* Definitions provided by netfs. */ /* Given a netnode created by the user program, wraps it in a node - structure. The new node is not locked and has a single reference. - If an error occurs, NULL is returned. */ -struct node *netfs_make_node (struct netnode *); + structure, *NNP. The new node is not locked and has a single reference. + If an error occurs, the error value is returned. */ +error_t netfs_make_node (struct netnode *nn, struct node **nnp); /* Whenever node->references is to be touched, this lock must be held. Cf. netfs_nrele, netfs_nput, netfs_nref and netfs_drop_node. */ Index: libdiskfs/diskfs.h =================================================================== RCS file: /cvsroot/hurd/hurd/libdiskfs/diskfs.h,v retrieving revision 1.94 diff -u -p -r1.94 diskfs.h --- libdiskfs/diskfs.h 26 Mar 2002 14:59:52 -0000 1.94 +++ libdiskfs/diskfs.h 7 Apr 2002 20:16:43 -0000 @@ -652,9 +652,9 @@ void diskfs_notice_filechange (struct node *np, enum file_changed_type type, off_t start, off_t end); -/* Create a new node structure with DS as its physical disknode. +/* Create a new node structure with DN as its physical disknode. The new node will have one hard reference and no light references. */ -struct node *diskfs_make_node (struct disknode *dn); +error_t diskfs_make_node (struct disknode *dn, struct node **nnp); /* The library also exports the following functions; they are not generally Index: libdiskfs/node-make.c =================================================================== RCS file: /cvsroot/hurd/hurd/libdiskfs/node-make.c,v retrieving revision 1.15 diff -u -p -r1.15 node-make.c --- libdiskfs/node-make.c 10 Aug 1998 17:42:39 -0000 1.15 +++ libdiskfs/node-make.c 7 Apr 2002 20:16:43 -0000 @@ -1,5 +1,5 @@ /* - Copyright (C) 1994, 1995, 1996 Free Software Foundation + Copyright (C) 1994, 1995, 1996, 2002 Free Software Foundation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -21,11 +21,14 @@ /* Create a and return new node structure with DN as its physical disknode. The node will have one hard reference and no light references. */ -struct node * -diskfs_make_node (struct disknode *dn) +error_t +diskfs_make_node (struct disknode *dn, struct node **nnp) { - struct node *np = malloc (sizeof (struct node)); - + struct node *np = *nnp = malloc (sizeof (struct node)); + + if (! np) + return ENOMEM; + np->dn = dn; np->dn_set_ctime = 0; np->dn_set_atime = 0; @@ -45,6 +48,5 @@ diskfs_make_node (struct disknode *dn) iohelp_initialize_conch (&np->conch, &np->lock); fshelp_lock_init (&np->userlock); - - return np; + return 0; } Index: ext2fs/inode.c =================================================================== RCS file: /cvsroot/hurd/hurd/ext2fs/inode.c,v retrieving revision 1.60 diff -u -p -r1.60 inode.c --- ext2fs/inode.c 4 Jan 2002 01:39:33 -0000 1.60 +++ ext2fs/inode.c 7 Apr 2002 20:16:41 -0000 @@ -94,7 +94,13 @@ diskfs_cached_lookup (int inum, struct n pokel_init (&dn->indir_pokel, diskfs_disk_pager, disk_image); /* Create the new node. */ - np = diskfs_make_node (dn); + err = diskfs_make_node (dn, &np); + if (err) + { + spin_unlock (&diskfs_node_refcnt_lock); + return err; + } + np->cache_id = inum; mutex_lock (&np->lock); Index: ftpfs/fs.c =================================================================== RCS file: /cvsroot/hurd/hurd/ftpfs/fs.c,v retrieving revision 1.4 diff -u -p -r1.4 fs.c --- ftpfs/fs.c 29 Dec 2001 00:19:39 -0000 1.4 +++ ftpfs/fs.c 7 Apr 2002 20:16:41 -0000 @@ -1,6 +1,6 @@ /* Fs operations - Copyright (C) 1997,2001 Free Software Foundation, Inc. + Copyright (C) 1997,2001,2002 Free Software Foundation, Inc. Written by Miles Bader <[EMAIL PROTECTED]> This file is part of the GNU Hurd. @@ -64,21 +64,26 @@ ftpfs_create (char *rmt_path, int fsid, if (! err) { - super_root = netfs_make_node (0); - if (! super_root) - err = ENOMEM; - else + err = netfs_make_node (0, &super_root); + if (err) + goto out; + + err = ftpfs_dir_create (new, super_root, rmt_path, &super_root_dir); + if (err) { - err = ftpfs_dir_create (new, super_root, rmt_path, &super_root_dir); - if (! err) - err = ftpfs_dir_null_lookup (super_root_dir, &new->root); + netfs_node_norefs (super_root); + goto out; } + err = ftpfs_dir_null_lookup (super_root_dir, &new->root); + if (err) + ftpfs_dir_free (super_root_dir); } - if (err) - free (new); - else + if (! err) *fs = new; + else +out: + free (new); return err; } Index: ftpfs/node.c =================================================================== RCS file: /cvsroot/hurd/hurd/ftpfs/node.c,v retrieving revision 1.1 diff -u -p -r1.1 node.c --- ftpfs/node.c 6 Aug 1997 22:08:35 -0000 1.1 +++ ftpfs/node.c 7 Apr 2002 20:16:41 -0000 @@ -1,6 +1,6 @@ /* General fs node functions - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997, 2002 Free Software Foundation, Inc. Written by Miles Bader <[EMAIL PROTECTED]> This file is part of the GNU Hurd. @@ -37,6 +37,7 @@ error_t ftpfs_create_node (struct ftpfs_dir_entry *e, const char *rmt_path, struct node **node) { + error_t err; struct node *new; struct netnode *nn = malloc (sizeof (struct netnode)); @@ -50,11 +51,11 @@ ftpfs_create_node (struct ftpfs_dir_entr nn->rmt_path = strdup (rmt_path); nn->ncache_next = nn->ncache_prev = 0; - new = netfs_make_node (nn); - if (! new) + err = netfs_make_node (nn, &new); + if (err) { free (nn); - return ENOMEM; + return err; } fshelp_touch (&new->nn_stat, TOUCH_ATIME|TOUCH_MTIME|TOUCH_CTIME, Index: hostmux/hostmux.c =================================================================== RCS file: /cvsroot/hurd/hurd/hostmux/hostmux.c,v retrieving revision 1.6 diff -u -p -r1.6 hostmux.c --- hostmux/hostmux.c 12 Feb 2001 22:18:55 -0000 1.6 +++ hostmux/hostmux.c 7 Apr 2002 20:16:41 -0000 @@ -1,6 +1,6 @@ /* Multiplexing filesystems by host - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997, 2002 Free Software Foundation, Inc. Written by Miles Bader <[EMAIL PROTECTED]> This file is part of the GNU Hurd. @@ -115,9 +115,9 @@ main (int argc, char **argv) netfs_init (); /* Create the root node (some attributes initialized below). */ - netfs_root_node = netfs_make_node (&root_nn); - if (! netfs_root_node) - error (5, ENOMEM, "Cannot create root node"); + err = netfs_make_node (&root_nn, &netfs_root_node); + if (err) + error (5, err, "Cannot create root node"); err = maptime_map (0, 0, &hostmux_maptime); if (err) Index: hostmux/leaf.c =================================================================== RCS file: /cvsroot/hurd/hurd/hostmux/leaf.c,v retrieving revision 1.2 diff -u -p -r1.2 leaf.c --- hostmux/leaf.c 20 Jun 1997 05:38:01 -0000 1.2 +++ hostmux/leaf.c 7 Apr 2002 20:16:42 -0000 @@ -1,6 +1,6 @@ /* Hostmux leaf node functions - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997, 2002 Free Software Foundation, Inc. Written by Miles Bader <[EMAIL PROTECTED]> This file is part of the GNU Hurd. @@ -80,6 +80,7 @@ error_t create_host_node (struct hostmux *mux, struct hostmux_name *name, struct node **node) { + error_t err; struct node *new; struct netnode *nn = malloc (sizeof (struct netnode)); @@ -89,11 +90,11 @@ create_host_node (struct hostmux *mux, s nn->mux = mux; nn->name = name; - new = netfs_make_node (nn); - if (! new) + err = netfs_make_node (nn, &new); + if (err) { free (nn); - return ENOMEM; + return err; } new->nn_stat = mux->stat_template; Index: isofs/inode.c =================================================================== RCS file: /cvsroot/hurd/hurd/isofs/inode.c,v retrieving revision 1.14 diff -u -p -r1.14 inode.c --- isofs/inode.c 20 Feb 2001 19:37:28 -0000 1.14 +++ isofs/inode.c 7 Apr 2002 20:16:42 -0000 @@ -1,5 +1,5 @@ /* - Copyright (C) 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 2002 Free Software Foundation, Inc. Written by Thomas Bushnell, n/BSG. This file is part of the GNU Hurd. @@ -198,13 +198,13 @@ diskfs_cached_lookup (int id, struct nod dn->fileinfo = 0; dn->dr = c->dr; dn->file_start = c->file_start; - np = diskfs_make_node (dn); - if (!np) + err = diskfs_make_node (dn, &np); + if (err) { free (dn); spin_unlock (&diskfs_node_refcnt_lock); release_rrip (&rr); - return ENOMEM; + return err; } np->cache_id = id + 1; /* see above for rationale for increment */ mutex_lock (&np->lock); @@ -357,12 +357,12 @@ load_inode (struct node **npp, struct di dn->dr = record; dn->file_start = file_start; - np = diskfs_make_node (dn); - if (!np) + err = diskfs_make_node (dn, &np); + if (err) { free (dn); spin_unlock (&diskfs_node_refcnt_lock); - return ENOMEM; + return err; } mutex_lock (&np->lock); Index: nfs/cache.c =================================================================== RCS file: /cvsroot/hurd/hurd/nfs/cache.c,v retrieving revision 1.15 diff -u -p -r1.15 cache.c --- nfs/cache.c 30 Jan 2001 00:38:45 -0000 1.15 +++ nfs/cache.c 7 Apr 2002 20:16:47 -0000 @@ -1,5 +1,5 @@ /* Node cache management for NFS client implementation - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -49,11 +49,12 @@ hash (int *data, size_t len) hash table. Whichever course, a new reference is generated and the node is returned in *NPP; the lock on the node, (*NPP)->LOCK, is held. */ -void +error_t lookup_fhandle (void *p, size_t len, struct node **npp) { struct node *np; struct netnode *nn; + error_t err; int h; h = hash (p, len); @@ -69,12 +70,13 @@ lookup_fhandle (void *p, size_t len, str spin_unlock (&netfs_node_refcnt_lock); mutex_lock (&np->lock); *npp = np; - return; + return 0; } /* Could not find it */ nn = malloc (sizeof (struct netnode)); - assert (nn); + if (! nn) + return ENOMEM; nn->handle.size = len; memcpy (nn->handle.data, p, len); @@ -83,17 +85,20 @@ lookup_fhandle (void *p, size_t len, str nn->dead_dir = 0; nn->dead_name = 0; - np = netfs_make_node (nn); - mutex_lock (&np->lock); - nn->hnext = nodehash[h]; - if (nn->hnext) - nn->hnext->nn->hprevp = &nn->hnext; - nn->hprevp = &nodehash[h]; - nodehash[h] = np; - + err = netfs_make_node (nn, npp); + if (! err) + { + np = *npp; + mutex_lock (&np->lock); + nn->hnext = nodehash[h]; + if (nn->hnext) + nn->hnext->nn->hprevp = &nn->hnext; + nn->hprevp = &nodehash[h]; + nodehash[h] = np; + } spin_unlock (&netfs_node_refcnt_lock); - *npp = np; + return err; } /* Package holding args to forked_node_delete. */ Index: nfs/nfs.c =================================================================== RCS file: /cvsroot/hurd/hurd/nfs/nfs.c,v retrieving revision 1.26 diff -u -p -r1.26 nfs.c --- nfs/nfs.c 30 Jan 2001 00:38:45 -0000 1.26 +++ nfs/nfs.c 7 Apr 2002 20:16:47 -0000 @@ -1,5 +1,5 @@ /* XDR frobbing and lower level routines for NFS client - Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1999, 2002 Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -23,6 +23,7 @@ #include <string.h> #include <netinet/in.h> #include <stdio.h> +#include <error.h> /* Convert an NFS mode (TYPE and MODE) to a Hurd mode and return it. */ mode_t @@ -376,11 +377,13 @@ xdr_decode_64bit (int *p, long long *n) int * xdr_decode_fhandle (int *p, struct node **npp) { + error_t err; size_t len; len = protocol_version == 2 ? NFS2_FHSIZE : ntohl (*p++); /* Enter into cache */ - lookup_fhandle (p, len, npp); + err = lookup_fhandle (p, len, npp); + assert_perror(err); return p + len / sizeof (int); } Index: nfs/nfs.h =================================================================== RCS file: /cvsroot/hurd/hurd/nfs/nfs.h,v retrieving revision 1.18 diff -u -p -r1.18 nfs.h --- nfs/nfs.h 29 Dec 2001 00:40:09 -0000 1.18 +++ nfs/nfs.h 7 Apr 2002 20:16:47 -0000 @@ -1,5 +1,5 @@ /* Data structures and global variables for NFS client - Copyright (C) 1994,95,96,97,99,2001 Free Software Foundation, Inc. + Copyright (C) 1994,95,96,97,99,2001,2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -24,6 +24,7 @@ #include <sys/mman.h> #include "nfs-spec.h" #include <hurd/netfs.h> +#include <error.h> /* A file handle */ struct fhandle @@ -191,7 +192,7 @@ void timeout_service_thread (void); void rpc_receive_thread (void); /* cache.c */ -void lookup_fhandle (void *, size_t, struct node **); +error_t lookup_fhandle (void *, size_t, struct node **); int *recache_handle (int *, struct node *); /* name-cache.c */ Index: tmpfs/node.c =================================================================== RCS file: /cvsroot/hurd/hurd/tmpfs/node.c,v retrieving revision 1.10 diff -u -p -r1.10 node.c --- tmpfs/node.c 24 Mar 2002 01:14:54 -0000 1.10 +++ tmpfs/node.c 7 Apr 2002 20:16:55 -0000 @@ -156,6 +156,7 @@ recompute_blocks (struct node *np) error_t diskfs_cached_lookup (int inum, struct node **npp) { + error_t err; struct disknode *dn = (void *) inum; struct node *np; @@ -174,7 +175,9 @@ diskfs_cached_lookup (int inum, struct n { struct stat *st; - np = diskfs_make_node (dn); + err = diskfs_make_node (dn, &np); + if (err) + return err; np->cache_id = (ino_t) dn; spin_lock (&diskfs_node_refcnt_lock); Index: ufs/inode.c =================================================================== RCS file: /cvsroot/hurd/hurd/ufs/inode.c,v retrieving revision 1.58 diff -u -p -r1.58 inode.c --- ufs/inode.c 21 Nov 2001 22:08:48 -0000 1.58 +++ ufs/inode.c 7 Apr 2002 20:16:56 -0000 @@ -1,5 +1,5 @@ /* Inode management routines - Copyright (C) 1994,95,96,97,98,2000,01 Free Software Foundation, Inc. + Copyright (C) 1994,95,96,97,98,2000,01,02 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -67,7 +67,11 @@ diskfs_cached_lookup (int inum, struct n } dn = malloc (sizeof (struct disknode)); - + if (! dn) + { + spin_unlock (&diskfs_node_refcnt_lock); + return ENOMEM; + } dn->number = inum; dn->dirents = 0; dn->dir_idx = 0; @@ -76,7 +80,12 @@ diskfs_cached_lookup (int inum, struct n dn->dirty = 0; dn->fileinfo = 0; - np = diskfs_make_node (dn); + err = diskfs_make_node (dn, &np); + if (err) + { + spin_unlock (&diskfs_node_refcnt_lock); + return err; + } np->cache_id = inum; mutex_lock (&np->lock); Index: usermux/leaf.c =================================================================== RCS file: /cvsroot/hurd/hurd/usermux/leaf.c,v retrieving revision 1.1 diff -u -p -r1.1 leaf.c --- usermux/leaf.c 23 Jul 1997 13:47:25 -0000 1.1 +++ usermux/leaf.c 7 Apr 2002 20:16:56 -0000 @@ -1,6 +1,6 @@ /* Usermux leaf node functions - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997, 2002 Free Software Foundation, Inc. Written by Miles Bader <[EMAIL PROTECTED]> This file is part of the GNU Hurd. @@ -76,11 +76,11 @@ create_user_node (struct usermux *mux, s nn->mux = mux; nn->name = name; - new = netfs_make_node (nn); - if (! new) + err = netfs_make_node (nn, &new); + if (err) { free (nn); - return ENOMEM; + return err; } new->nn_stat = mux->stat_template; Index: usermux/usermux.c =================================================================== RCS file: /cvsroot/hurd/hurd/usermux/usermux.c,v retrieving revision 1.3 diff -u -p -r1.3 usermux.c --- usermux/usermux.c 12 Feb 2001 22:18:55 -0000 1.3 +++ usermux/usermux.c 7 Apr 2002 20:16:56 -0000 @@ -1,6 +1,6 @@ /* Multiplexing filesystems by user - Copyright (C) 1997, 2000 Free Software Foundation, Inc. + Copyright (C) 1997, 2000, 2002 Free Software Foundation, Inc. Written by Miles Bader <[EMAIL PROTECTED]> This file is part of the GNU Hurd. @@ -107,9 +107,9 @@ main (int argc, char **argv) netfs_init (); /* Create the root node (some attributes initialized below). */ - netfs_root_node = netfs_make_node (&root_nn); - if (! netfs_root_node) - error (5, ENOMEM, "Cannot create root node"); + err = netfs_make_node (&root_nn, &netfs_root_node); + if (err) + error (5, err, "Cannot create root node"); err = maptime_map (0, 0, &usermux_maptime); if (err) _______________________________________________ Bug-hurd mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-hurd