[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
error checking in libnetfs
From: |
James A Morrison |
Subject: |
error checking in libnetfs |
Date: |
Fri, 29 Mar 2002 01:42:30 -0500 (EST) |
Hi,
Here is my patch to increase the error checking within libnetfs.
I've also included error.h in a couple of files that I noticed had compiler
warnings. There aren't any functions that return pointers to struct's
left in libnetfs.
Apparently the copyright wasn't updated in console-run.c during the last
set of checkins.
Just a reminder, there are outstanding documentation patches for hurd.texi.
2002-03-28 James A. Morrison <ja2morri@uwaterloo.ca>
daemons:
* console-run.c: Updated copyright.
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.
libnetfs:
* netfs.h: Changed to signatures of netfs_make_node,
netfs_make_peropen, and netfs_make_protid to return an error_t and
take an extra parameter to replace the old return value.
Removed old netfs_make_user function signature.
* make-node.c (netfs_make_node): Instead of returning the node, return
an error_t and set the node in the new *NNP parameter.
* make-peropen.c (netfs_make_peropen): Instead of returning the
peropen, return an error_t and set the peropen in the new
parameter *PPO.
* make-protid.c (netfs_make_protid): Instead of returning the protid,
return an error_t and set the protid in the new parameter *PI.
* dir-lookup.c (netfs_S_dir_lookup): Check the return values of
netfs_make_peropen netfs_make_protid using the new semantics.
* dir-mkfile.c (netfs_S_dir_mkfile): Likewise.
* file-reparent.c (netfs_S_file_reparent): Likewise
* file-exec.c (netfs_S_file_exec): Likewise
* io-duplicate.c (netfs_S_io_duplicate): Likewise.
* io-reauthenticate.c (netfs_S_io_reauthenticate): Likewise.
* io-restrict-auth.c (netfs_S_io_restrict_auth): Likewise.
* trans-callback.c (_netfs_translator_callback2_fn): Likewise.
* fsys-getroot.c (netfs_S_fsys_getroot): Likwise. Removed superflous
error state check.
nfs:
* nfs.c (xdr_decode_fhandle): Check return value of lookup_fhandle
and assert_perror on the error.
* cache.c (lookup_fhandle): Function now returns an error_t instead of
void. Check return value of netfs_make_node using its new semantics.
* nfs.h: Changed lookup_fhandle to return an error_t instead of void.
nfsd:
* fsys.c: Include error.h, so that the error function is explicitly
declared.
* main.c: Likewise.
sutils:
* halt.c: Include error.h, so that the error function is explicitly
declared.
* reboot.c: Likewise.
* update.c: Likewise.
usermux:
* usermux.c (main): Check the return value of netfs_make_node using
its new semantics.
* leaf.c (create_user_node): Likewise.
utils:
* shd.c: Include error.h, so that the error function is explicitly
declared.
Index: daemons/console-run.c
===================================================================
RCS file: /cvsroot/hurd/hurd/daemons/console-run.c,v
retrieving revision 1.5
diff -u -p -r1.5 console-run.c
--- daemons/console-run.c 26 Mar 2002 18:59:31 -0000 1.5
+++ daemons/console-run.c 29 Mar 2002 06:12:03 -0000
@@ -1,5 +1,5 @@
/* Run a program on the console, trying hard to get the console open.
- Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2001, 02 Free Software Foundation, Inc.
This file is part of the GNU Hurd.
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 29 Mar 2002 06:12:05 -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 <miles@gnu.org>
This file is part of the GNU Hurd.
@@ -64,10 +64,8 @@ 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)
{
err = ftpfs_dir_create (new, super_root, rmt_path, &super_root_dir);
if (! 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 29 Mar 2002 06:12:05 -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 <miles@gnu.ai.mit.edu>
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 29 Mar 2002 06:12:05 -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 <miles@gnu.ai.mit.edu>
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 29 Mar 2002 06:12:05 -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 <miles@gnu.ai.mit.edu>
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: libnetfs/dir-lookup.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/dir-lookup.c,v
retrieving revision 1.22
diff -u -p -r1.22 dir-lookup.c
--- libnetfs/dir-lookup.c 9 Sep 2001 17:32:03 -0000 1.22
+++ libnetfs/dir-lookup.c 29 Mar 2002 06:12:07 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1995,96,97,98,99,2000,01 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,97,98,99,2000,01,02 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -47,6 +47,7 @@ netfs_S_dir_lookup (struct protid *dirus
struct node *dnp, *np;
char *nextname;
error_t error;
+ struct peropen *newpo;
struct protid *newpi;
struct iouser *user;
@@ -239,14 +240,15 @@ netfs_S_dir_lookup (struct protid *dirus
error = iohelp_create_empty_iouser (&user);
if (! error)
{
- newpi = netfs_make_protid (netfs_make_peropen (dnp, 0,
- diruser->po),
- user);
- if (! newpi)
- {
- error = errno;
- iohelp_free_iouser (user);
+ error = netfs_make_peropen (dnp, 0, diruser->po, &newpo);
+ if (! error)
+ {
+ error = netfs_make_protid (newpo, user, &newpi);
+ if (error)
+ netfs_release_peropen (newpo);
}
+ if (error)
+ iohelp_free_iouser (user);
}
if (! error)
@@ -381,12 +383,17 @@ netfs_S_dir_lookup (struct protid *dirus
if (error)
goto out;
- newpi = netfs_make_protid (netfs_make_peropen (np, flags, diruser->po),
- user);
- if (! newpi)
+ error = netfs_make_peropen (np, flags, diruser->po, &newpo);
+ if (! error)
+ {
+ error = netfs_make_protid (newpo, user, &newpi);
+ if (error)
+ netfs_release_peropen (newpo);
+ }
+
+ if (error)
{
iohelp_free_iouser (user);
- error = errno;
goto out;
}
Index: libnetfs/dir-mkfile.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/dir-mkfile.c,v
retrieving revision 1.8
diff -u -p -r1.8 dir-mkfile.c
--- libnetfs/dir-mkfile.c 9 Sep 2001 17:32:03 -0000 1.8
+++ libnetfs/dir-mkfile.c 29 Mar 2002 06:12:07 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1995,96,97,2001 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,97,2001,2002 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -29,6 +29,7 @@ netfs_S_dir_mkfile (struct protid *dirus
error_t err;
struct node *np;
struct iouser *user;
+ struct peropen *newpo;
struct protid *newpi;
mutex_lock (&diruser->po->np->lock);
@@ -41,20 +42,22 @@ netfs_S_dir_mkfile (struct protid *dirus
err = iohelp_dup_iouser (&user, diruser->user);
if (! err)
{
- newpi = netfs_make_protid (netfs_make_peropen (np, flags,
- diruser->po),
- user);
- if (newpi)
+ err = netfs_make_peropen (np, flags, diruser->po, &newpo);
+ if (! err)
+ {
+ err = netfs_make_protid (newpo, user, &newpi);
+ if (err)
+ netfs_release_peropen (newpo);
+ }
+
+ if (! err)
{
*newfile = ports_get_right (newpi);
*newfiletype = MACH_MSG_TYPE_MAKE_SEND;
ports_port_deref (newpi);
}
else
- {
- err = errno;
- iohelp_free_iouser (user);
- }
+ iohelp_free_iouser (user);
}
netfs_nput (np);
}
Index: libnetfs/file-exec.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/file-exec.c,v
retrieving revision 1.9
diff -u -p -r1.9 file-exec.c
--- libnetfs/file-exec.c 9 Sep 2001 17:32:03 -0000 1.9
+++ libnetfs/file-exec.c 29 Mar 2002 06:12:07 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1996,97,2000,01 Free Software Foundation, Inc.
+ Copyright (C) 1996,97,2000,01,02 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -123,14 +123,21 @@ netfs_S_file_exec (struct protid *cred,
if (! err)
{
struct iouser *user;
+ struct peropen *newpo;
struct protid *newpi;
err = iohelp_dup_iouser (&user, cred->user);
if (! err)
{
- newpi = netfs_make_protid (netfs_make_peropen (np, O_READ, cred->po),
- user);
- if (newpi)
+ err = netfs_make_peropen (np, O_READ, cred->po, &newpo);
+ if (! err)
+ {
+ err = netfs_make_protid (newpo, user, &newpi);
+ if (err)
+ netfs_release_peropen (newpo);
+ }
+
+ if (! err)
{
right = ports_get_send_right (newpi);
err = exec_exec (_netfs_exec,
@@ -145,10 +152,7 @@ netfs_S_file_exec (struct protid *cred,
ports_port_deref (newpi);
}
else
- {
- err = errno;
- iohelp_free_iouser (user);
- }
+ iohelp_free_iouser (user);
}
}
Index: libnetfs/file-reparent.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/file-reparent.c,v
retrieving revision 1.4
diff -u -p -r1.4 file-reparent.c
--- libnetfs/file-reparent.c 16 Jun 2001 20:23:29 -0000 1.4
+++ libnetfs/file-reparent.c 29 Mar 2002 06:12:07 -0000
@@ -1,6 +1,6 @@
/* Reparent a file
- Copyright (C) 1997, 2001 Free Software Foundation
+ Copyright (C) 1997, 2001, 2002 Free Software Foundation
Written by Miles Bader <miles@gnu.org>
@@ -28,6 +28,7 @@ netfs_S_file_reparent (struct protid *cr
{
error_t err;
struct node *node;
+ struct peropen *newpo;
struct protid *new_cred;
struct iouser *user;
@@ -42,12 +43,17 @@ netfs_S_file_reparent (struct protid *cr
mutex_lock (&node->lock);
- new_cred =
- netfs_make_protid (netfs_make_peropen (node, cred->po->openstat, cred->po),
- user);
+ err = netfs_make_peropen (node, cred->po->openstat, cred->po, &newpo);
+ if (! err)
+ {
+ err = netfs_make_protid (newpo, user, &new_cred);
+ if (err)
+ netfs_release_peropen (newpo);
+ }
+
mutex_unlock (&node->lock);
- if (new_cred)
+ if (! err)
{
/* Remove old shadow root state. */
if (new_cred->po->shadow_root && new_cred->po->shadow_root != node)
@@ -70,5 +76,5 @@ netfs_S_file_reparent (struct protid *cr
return 0;
}
else
- return errno;
+ return err;
}
Index: libnetfs/fsys-getroot.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/fsys-getroot.c,v
retrieving revision 1.10
diff -u -p -r1.10 fsys-getroot.c
--- libnetfs/fsys-getroot.c 16 Jun 2001 20:23:29 -0000 1.10
+++ libnetfs/fsys-getroot.c 29 Mar 2002 06:12:07 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1996, 1997, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 2001, 2002 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -41,6 +41,7 @@ netfs_S_fsys_getroot (mach_port_t cntl,
netfs_control_class);
struct iouser *cred;
error_t err;
+ struct peropen *newpo;
struct protid *newpi;
mode_t type;
struct peropen peropen_context = { root_parent: dotdot };
@@ -127,20 +128,28 @@ netfs_S_fsys_getroot (mach_port_t cntl,
flags &= ~OPENONLY_STATE_MODES;
- newpi = netfs_make_protid (netfs_make_peropen (netfs_root_node, flags,
- &peropen_context),
- cred);
- mach_port_deallocate (mach_task_self (), dotdot);
-
- *do_retry = FS_RETRY_NORMAL;
- *retry_port = ports_get_right (newpi);
- *retry_port_type = MACH_MSG_TYPE_MAKE_SEND;
- retry_name[0] = '\0';
- ports_port_deref (newpi);
-
+ err = netfs_make_peropen (netfs_root_node, flags, &peropen_context, &newpo);
+ if (! err)
+ {
+ err = netfs_make_protid (newpo, cred, &newpi);
+ if (err)
+ netfs_release_peropen (newpo);
+ }
+
+ if (! err)
+ {
+ mach_port_deallocate (mach_task_self (), dotdot);
+
+ *do_retry = FS_RETRY_NORMAL;
+ *retry_port = ports_get_right (newpi);
+ *retry_port_type = MACH_MSG_TYPE_MAKE_SEND;
+ retry_name[0] = '\0';
+ ports_port_deref (newpi);
+ }
+ else
out:
- if (err)
iohelp_free_iouser (cred);
+
mutex_unlock (&netfs_root_node->lock);
return err;
}
Index: libnetfs/io-duplicate.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/io-duplicate.c,v
retrieving revision 1.3
diff -u -p -r1.3 io-duplicate.c
--- libnetfs/io-duplicate.c 16 Jun 2001 20:23:29 -0000 1.3
+++ libnetfs/io-duplicate.c 29 Mar 2002 06:12:07 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1995,96,2001 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,2001, 2002 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -35,10 +35,15 @@ netfs_S_io_duplicate (struct protid *use
return err;
mutex_lock (&user->po->np->lock);
- newpi = netfs_make_protid (user->po, clone);
- *newport = ports_get_right (newpi);
- mutex_unlock (&user->po->np->lock);
- *newporttp = MACH_MSG_TYPE_MAKE_SEND;
- ports_port_deref (newpi);
- return 0;
+ err = netfs_make_protid (user->po, clone, &newpi);
+ if (! err)
+ {
+ *newport = ports_get_right (newpi);
+ mutex_unlock (&user->po->np->lock);
+ *newporttp = MACH_MSG_TYPE_MAKE_SEND;
+ ports_port_deref (newpi);
+ return 0;
+ }
+ else
+ return err;
}
Index: libnetfs/io-reauthenticate.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/io-reauthenticate.c,v
retrieving revision 1.10
diff -u -p -r1.10 io-reauthenticate.c
--- libnetfs/io-reauthenticate.c 16 Jun 2001 20:23:29 -0000 1.10
+++ libnetfs/io-reauthenticate.c 29 Mar 2002 06:12:07 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1995,96,2000,01 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,2000,01,02 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -32,22 +32,28 @@ netfs_S_io_reauthenticate (struct protid
return EOPNOTSUPP;
mutex_lock (&user->po->np->lock);
- newpi = netfs_make_protid (user->po, 0);
+ err = netfs_make_protid (user->po, 0, &newpi);
- newright = ports_get_send_right (newpi);
- assert (newright != MACH_PORT_NULL);
+ if (! err)
+ {
- err = iohelp_reauth (&newpi->user, netfs_auth_server_port, rend_port,
- newright, 1);
-
- mach_port_deallocate (mach_task_self (), rend_port);
- mach_port_deallocate (mach_task_self (), newright);
-
- mach_port_move_member (mach_task_self (), newpi->pi.port_right,
- netfs_port_bucket->portset);
-
- mutex_unlock (&user->po->np->lock);
- ports_port_deref (newpi);
-
- return err;
+ newright = ports_get_send_right (newpi);
+ assert (newright != MACH_PORT_NULL);
+
+ err = iohelp_reauth (&newpi->user, netfs_auth_server_port, rend_port,
+ newright, 1);
+
+ mach_port_deallocate (mach_task_self (), rend_port);
+ mach_port_deallocate (mach_task_self (), newright);
+
+ mach_port_move_member (mach_task_self (), newpi->pi.port_right,
+ netfs_port_bucket->portset);
+
+ mutex_unlock (&user->po->np->lock);
+ ports_port_deref (newpi);
+
+ return err;
+ }
+ else
+ return err;
}
Index: libnetfs/io-restrict-auth.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/io-restrict-auth.c,v
retrieving revision 1.4
diff -u -p -r1.4 io-restrict-auth.c
--- libnetfs/io-restrict-auth.c 16 Jun 2001 20:37:39 -0000 1.4
+++ libnetfs/io-restrict-auth.c 29 Mar 2002 06:12:07 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1995,96,2001 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,2001,2002 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -96,21 +96,17 @@ netfs_S_io_restrict_auth (struct protid
}
mutex_lock (&user->po->np->lock);
- newpi = netfs_make_protid (user->po, new_user);
- if (newpi)
+ err = netfs_make_protid (user->po, new_user, &newpi);
+ if (! err)
{
*newport = ports_get_right (newpi);
- mutex_unlock (&user->po->np->lock);
*newporttype = MACH_MSG_TYPE_MAKE_SEND;
+ ports_port_deref (newpi);
}
- else
- {
- mutex_unlock (&user->po->np->lock);
- iohelp_free_iouser (new_user);
- err = ENOMEM;
- }
-
- ports_port_deref (newpi);
+ mutex_unlock (&user->po->np->lock);
+
+ iohelp_free_iouser (new_user);
return err;
+
}
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 29 Mar 2002 06:12:07 -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/make-peropen.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/make-peropen.c,v
retrieving revision 1.3
diff -u -p -r1.3 make-peropen.c
--- libnetfs/make-peropen.c 2 Mar 1997 21:12:03 -0000 1.3
+++ libnetfs/make-peropen.c 29 Mar 2002 06:12:07 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1997, 2002 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -21,11 +21,15 @@
#include "netfs.h"
#include <sys/file.h>
-struct peropen *
-netfs_make_peropen (struct node *np, int flags, struct peropen *context)
+error_t
+netfs_make_peropen (struct node *np, int flags, struct peropen *context,
+ struct peropen **ppo)
{
- struct peropen *po = malloc (sizeof (struct peropen));
-
+ struct peropen *po = *ppo = malloc (sizeof (struct peropen));
+
+ if (! po)
+ return ENOMEM;
+
po->filepointer = 0;
po->lock_status = LOCK_UN;
po->refcnt = 0;
@@ -51,6 +55,6 @@ netfs_make_peropen (struct node *np, int
netfs_nref (np);
- return po;
+ return 0;
}
Index: libnetfs/make-protid.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/make-protid.c,v
retrieving revision 1.6
diff -u -p -r1.6 make-protid.c
--- libnetfs/make-protid.c 18 Nov 1996 23:51:10 -0000 1.6
+++ libnetfs/make-protid.c 29 Mar 2002 06:12:07 -0000
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 2002 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -20,26 +20,26 @@
#include "netfs.h"
-struct protid *
-netfs_make_protid (struct peropen *po, struct iouser *cred)
+error_t
+netfs_make_protid (struct peropen *po, struct iouser *cred, struct protid **pi)
{
- struct protid *pi;
+ error_t err;
if (cred)
- errno = ports_create_port (netfs_protid_class, netfs_port_bucket,
- sizeof (struct protid), &pi);
+ err = ports_create_port (netfs_protid_class, netfs_port_bucket,
+ sizeof (struct protid), pi);
else
- errno = ports_create_port_noinstall (netfs_protid_class,
- netfs_port_bucket,
- sizeof (struct protid), &pi);
+ err = ports_create_port_noinstall (netfs_protid_class,
+ netfs_port_bucket,
+ sizeof (struct protid), pi);
- if (errno)
- return 0;
+ if (err)
+ return err;
po->refcnt++;
- pi->po = po;
- pi->user = cred;
- pi->shared_object = MACH_PORT_NULL;
- pi->mapped = 0;
- return pi;
+ (*pi)->po = po;
+ (*pi)->user = cred;
+ (*pi)->shared_object = MACH_PORT_NULL;
+ (*pi)->mapped = 0;
+ 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 29 Mar 2002 06:12:08 -0000
@@ -1,6 +1,6 @@
/*
- Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000 Free Software Foundation
+ Copyright (C) 1994,95,96,97,99,2000,02 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
@@ -263,11 +263,6 @@ error_t netfs_attempt_write (struct ious
error_t netfs_report_access (struct iouser *cred, struct node *np,
int *types);
-/* The user must define this function. Create a new user from the
- specified UID and GID arrays. */
-struct iouser *netfs_make_user (uid_t *uids, int nuids,
- uid_t *gids, int ngids);
-
/* The user must define this function. Node NP has no more references;
free all its associated storage. */
void netfs_node_norefs (struct node *np);
@@ -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. */
@@ -363,15 +358,16 @@ mach_port_t netfs_startup (mach_port_t b
void netfs_server_loop (void);
/* Creates a new credential from USER which can be NULL on the peropen
- PO. Returns NULL and sets errno on error. */
-struct protid *netfs_make_protid (struct peropen *po, struct iouser *user);
+ PO. Returns the error value. */
+error_t netfs_make_protid (struct peropen *po, struct iouser *user,
+ struct protid **pi);
-/* Create and return a new peropen structure on node NP with open
+/* Create a new peropen structure, *ppo, on node NP with open
flags FLAGS. The initial values for the root_parent, shadow_root,
and shadow_root_parent fields are copied from CONTEXT if it's
- non-zero, otherwise zeroed. */
-struct peropen *netfs_make_peropen (struct node *, int,
- struct peropen *context);
+ non-zero, otherwise zeroed. Returns the error value. */
+error_t netfs_make_peropen (struct node *np, int, struct peropen *context,
+ struct peropen **ppo);
/* Add a reference to node NP. Unless you already hold a reference,
NP must be locked. */
Index: libnetfs/trans-callback.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/trans-callback.c,v
retrieving revision 1.2
diff -u -p -r1.2 trans-callback.c
--- libnetfs/trans-callback.c 16 Jun 2001 20:23:29 -0000 1.2
+++ libnetfs/trans-callback.c 29 Mar 2002 06:12:08 -0000
@@ -1,6 +1,6 @@
/* Callback functions for starting translators
- Copyright (C) 1995,96,97,2001 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,97,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU Hurd.
@@ -52,6 +52,7 @@ _netfs_translator_callback2_fn (void *co
mach_msg_type_name_t *underlying_type)
{
error_t err;
+ struct peropen *newpo;
struct protid *cred;
struct node *node = cookie1;
struct iouser *user;
@@ -60,10 +61,16 @@ _netfs_translator_callback2_fn (void *co
node->nn_stat.st_gid);
if (err)
return err;
+
+ err = netfs_make_peropen (node, flags, cookie2, &newpo);
+ if (! err)
+ {
+ err = netfs_make_protid (newpo, user, &cred);
+ if (err)
+ netfs_release_peropen (newpo);
+ }
- cred = netfs_make_protid (netfs_make_peropen (node, flags, cookie2),
- user);
- if (cred)
+ if (! err)
{
*underlying = ports_get_right (cred);
*underlying_type = MACH_MSG_TYPE_MAKE_SEND;
@@ -71,7 +78,7 @@ _netfs_translator_callback2_fn (void *co
return 0;
}
else
- return errno;
+ return err;
}
fshelp_fetch_root_callback1_t _netfs_translator_callback1 =
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 29 Mar 2002 06:12:10 -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 29 Mar 2002 06:12:10 -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 29 Mar 2002 06:12:10 -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: nfsd/fsys.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfsd/fsys.c,v
retrieving revision 1.3
diff -u -p -r1.3 fsys.c
--- nfsd/fsys.c 26 Mar 2002 19:09:34 -0000 1.3
+++ nfsd/fsys.c 29 Mar 2002 06:12:11 -0000
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <errno.h>
+#include <error.h>
#include <hurd.h>
#include <fcntl.h>
#include <string.h>
Index: nfsd/main.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfsd/main.c,v
retrieving revision 1.5
diff -u -p -r1.5 main.c
--- nfsd/main.c 26 Mar 2002 19:09:34 -0000 1.5
+++ nfsd/main.c 29 Mar 2002 06:12:13 -0000
@@ -1,5 +1,5 @@
/* Main NFS server program
- Copyright (C) 1996 Free Software Foundation, Inc.
+ Copyright (C) 1996, 2002 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -24,6 +24,7 @@
#include <rpc/pmap_prot.h>
#include <maptime.h>
#include <hurd.h>
+#include <error.h>
int main_udp_socket, pmap_udp_socket;
struct sockaddr_in main_address, pmap_address;
Index: sutils/halt.c
===================================================================
RCS file: /cvsroot/hurd/hurd/sutils/halt.c,v
retrieving revision 1.7
diff -u -p -r1.7 halt.c
--- sutils/halt.c 26 Mar 2002 19:10:17 -0000 1.7
+++ sutils/halt.c 29 Mar 2002 06:12:16 -0000
@@ -25,6 +25,8 @@
#include <argp.h>
#include <hurd.h>
#include <version.h>
+#include <errno.h>
+#include <error.h>
const char *argp_program_version = STANDARD_HURD_VERSION (halt);
Index: sutils/reboot.c
===================================================================
RCS file: /cvsroot/hurd/hurd/sutils/reboot.c,v
retrieving revision 1.7
diff -u -p -r1.7 reboot.c
--- sutils/reboot.c 26 Mar 2002 19:10:17 -0000 1.7
+++ sutils/reboot.c 29 Mar 2002 06:12:16 -0000
@@ -25,6 +25,7 @@
#include <argp.h>
#include <hurd.h>
#include <version.h>
+#include <error.h>
const char *argp_program_version = STANDARD_HURD_VERSION (reboot);
Index: sutils/update.c
===================================================================
RCS file: /cvsroot/hurd/hurd/sutils/update.c,v
retrieving revision 1.5
diff -u -p -r1.5 update.c
--- sutils/update.c 26 Mar 2002 19:10:17 -0000 1.5
+++ sutils/update.c 29 Mar 2002 06:12:16 -0000
@@ -21,6 +21,7 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <error.h>
int
main (int argc, char **argv)
Index: trans/firmlink.c
===================================================================
RCS file: /cvsroot/hurd/hurd/trans/firmlink.c,v
retrieving revision 1.12
diff -u -p -r1.12 firmlink.c
--- trans/firmlink.c 26 Feb 2001 04:16:01 -0000 1.12
+++ trans/firmlink.c 29 Mar 2002 06:12:17 -0000
@@ -1,8 +1,9 @@
/* A translator for `firmlinks'
- Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
+ Extended by James A. Morrison <ja2morri@uwaterloo.ca>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -26,42 +27,91 @@
#include <fcntl.h>
#include <argp.h>
#include <error.h>
+#include <time.h>
#include <sys/mman.h>
#include <hurd/trivfs.h>
#include <version.h>
+#define TIME_MODE 0
+#define RANDOM_MODE 1
+#define SEQUENCE_MODE 2
+
const char *argp_program_version = STANDARD_HURD_VERSION (firmlink);
static const struct argp_option options[] =
{
+ {"randomized", 'r', NULL, 0, "Randomize selection of files, default" },
+ {"sequencial", 's', NULL, 0, "Choose files sequencially" },
+ {"format",'f',"DATE FORMAT", 0,
+ "Create files named file1/file2.DATE FORMAT"},
{ 0 }
};
-static const char args_doc[] = "TARGET";
-static const char doc[] = "A translator for firmlinks."
+static const char args_doc[] = "[file1 file2 ...]";
+static const char doc[] = "A translator for multiple firmlinks."
"\vA firmlink is sort of half-way between a symbolic link and a hard link:"
"\n"
"\nLike a symbolic link, it is `by name', and contains no actual reference to"
" the target. However, the lookup returns a node which will redirect parent"
" lookups so that attempts to find the cwd that go through the link will"
" reflect the link name, not the target name. The target referenced by the"
-" firmlink is looked up in the namespace of the translator, not the client.";
+" firmlink is looked up in the namespace of the translator, not the client."
+" A multiple firmlink can point to more than one file, and can also create"
+" files based on dates.";
/* Link parameters. */
-static char *target = 0; /* What we translate too. */
+
+struct arg_struct
+{
+ char **args;
+ char *date_format;
+ int type;
+ int flags;
+ unsigned long lastused;
+ unsigned long size;
+};
+
+struct arg_struct config;
/* Parse a single option/argument. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
- if (key == ARGP_KEY_ARG && state->arg_num == 0)
- target = arg;
- else if (key == ARGP_KEY_ARG || key == ARGP_KEY_NO_ARGS)
- argp_usage (state);
- else
- return ARGP_ERR_UNKNOWN;
+ struct arg_struct *arguments = state->input;
+
+ switch (key)
+ {
+ case 'r':
+ arguments->type = RANDOM_MODE;
+ arguments->flags = O_CREAT;
+ break;
+ case 's':
+ arguments->type = SEQUENCE_MODE;
+ arguments->flags = O_CREAT;
+ arguments->lastused = 0;
+ break;
+ case 'f':
+ arguments->type = TIME_MODE;
+ arguments->date_format = arg;
+ arguments->flags = 0;
+ break;
+ case ARGP_KEY_ARG:
+ arguments->args[arguments->size] = arg;
+ arguments->size++;
+ break;
+ case ARGP_KEY_END:
+ if ( arguments->type == TIME_MODE && arguments->size != 2 )
+ argp_usage (state);
+ break;
+ case ARGP_KEY_NO_ARGS:
+ argp_usage (state);
+ break;
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
return 0;
}
@@ -74,8 +124,16 @@ main (int argc, char **argv)
mach_port_t bootstrap;
struct trivfs_control *fsys;
+ config.size = 0;
+ config.type = RANDOM_MODE;
+ config.args = (char**) malloc (argc);
+ if (! config.args)
+ error (ENOMEM, 1, "Starting up");
+
/* Parse our options... */
- argp_parse (&argp, argc, argv, 0, 0, 0);
+ argp_parse (&argp, argc, argv, 0, 0, &config);
+ if ( config.type == RANDOM_MODE )
+ srand (time (NULL) );
task_get_bootstrap_port (mach_task_self (), &bootstrap);
if (bootstrap == MACH_PORT_NULL)
@@ -102,7 +160,26 @@ firmlink (mach_port_t parent, const char
{
error_t err;
file_t authed_link;
- file_t target = file_name_lookup (target_name, flags & ~O_CREAT, 0);
+ file_t target = file_name_lookup (target_name, flags & ~config.flags, 0);
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 29 Mar 2002 06:12:17 -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 <miles@gnu.ai.mit.edu>
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 29 Mar 2002 06:12:17 -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 <miles@gnu.ai.mit.edu>
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)
Index: utils/shd.c
===================================================================
RCS file: /cvsroot/hurd/hurd/utils/shd.c,v
retrieving revision 1.9
diff -u -p -r1.9 shd.c
--- utils/shd.c 26 Mar 2002 19:12:38 -0000 1.9
+++ utils/shd.c 29 Mar 2002 06:12:18 -0000
@@ -23,6 +23,7 @@
#include <device/device.h>
#include <unistd.h>
#include <errno.h>
+#include <error.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <stdlib.h>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- error checking in libnetfs,
James A Morrison <=