Hi,
This patch should sync the interfaces of libnetfs and libdiskfs wrt the creation of peropens and protids. 2002-04-05 James A. Morrison <[EMAIL PROTECTED]> libnetfs: 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-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. 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 7 Apr 2002 20:16:45 -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,18 @@ 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); + iohelp_free_iouser (user); + } } + else + iohelp_free_iouser (user); } if (! error) @@ -381,12 +386,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 7 Apr 2002 20:16:45 -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 7 Apr 2002 20:16:45 -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 7 Apr 2002 20:16:45 -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 <[EMAIL PROTECTED]> @@ -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) @@ -69,6 +75,7 @@ netfs_S_file_reparent (struct protid *cr return 0; } - else - return errno; + + iohelp_free_iouser (user); + 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 7 Apr 2002 20:16:45 -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); + 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); + } + 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); - + if (! err) + { + *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 7 Apr 2002 20:16:45 -0000 @@ -1,5 +1,5 @@ /* - Copyright (C) 1995,96,2001 Free Software Foundation, Inc. + Copyright (C) 1995,96,2001,02 Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -35,10 +35,17 @@ 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); + 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; + } + mutex_unlock (&user->po->np->lock); - *newporttp = MACH_MSG_TYPE_MAKE_SEND; - ports_port_deref (newpi); - return 0; + iohelp_free_iouser (clone); + 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 7 Apr 2002 20:16:45 -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,29 @@ 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); + 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); - 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); + return err; + } mutex_unlock (&user->po->np->lock); - ports_port_deref (newpi); - 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 7 Apr 2002 20:16:45 -0000 @@ -1,5 +1,5 @@ /* - Copyright (C) 1995,96,2001 Free Software Foundation, Inc. + Copyright (C) 1995,96,2001,02 Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -96,21 +96,19 @@ 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); + iohelp_free_iouser (new_user); + + mutex_unlock (&user->po->np->lock); + return err; + } 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 7 Apr 2002 20:16:45 -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 7 Apr 2002 20:16:45 -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 7 Apr 2002 20:16:45 -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); @@ -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 7 Apr 2002 20:16:45 -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,26 +52,34 @@ _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; err = iohelp_create_simple_iouser (&user, node->nn_stat.st_uid, - node->nn_stat.st_gid); + 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; ports_port_deref (cred); return 0; } - else - return errno; + + iohelp_free_iouser (user); + return err; } fshelp_fetch_root_callback1_t _netfs_translator_callback1 = _______________________________________________ Bug-hurd mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-hurd