>From 973b0a6fd08d132306ddf40293062f3583f2980f Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov <unlimitedscol...@gmail.com> Date: Thu, 16 Jul 2009 21:24:57 +0000 Subject: [PATCH 4/4] Supply the port to the real underlying node to the mountee.
* mount.c (unionmount_proxy): Remove variable. (start_mountee): Remove parameter np. Remove variable underlying_port. Create unauth_dir as a port to the root node of unionfs. (open_port): Return the port to the real underlying node. * mount.h (unionmount_proxy): Remove variable. (start_mountee): Remove parameter np. --- mount.c | 62 ++++++++++++++------------------------------------------------ mount.h | 11 +++-------- 2 files changed, 17 insertions(+), 56 deletions(-) diff --git a/mount.c b/mount.c index 4d0a0d4..d0b9907 100644 --- a/mount.c +++ b/mount.c @@ -29,14 +29,12 @@ #include "mount.h" #include "lib.h" #include "ulfs.h" +#include "unionfs.h" /* The command line for starting the mountee. */ char * mountee_argz; size_t mountee_argz_len; -/* The node the mountee is sitting on. */ -node_t * unionmount_proxy; - mach_port_t mountee_port; mach_port_t mountee_control = MACH_PORT_NULL; @@ -53,15 +51,12 @@ int shutting_down = 0; mountee. */ mach_port_t mountee_listen_port; -/* Starts the mountee (given by `argz` and `argz_len`), sets it on - node `np` and opens a port `port` to with `flags`. `port` is not - modified when an error occurs. */ +/* Starts the mountee (given by `argz` and `argz_len`) and opens a + port `port` to it with `flags`. */ error_t -start_mountee (node_t * np, char * argz, size_t argz_len, int flags, - mach_port_t * port) +start_mountee (char * argz, size_t argz_len, int flags, mach_port_t * port) { error_t err; - mach_port_t underlying_port; /* The intermediate container for the port to the root of the mountee. */ @@ -113,37 +108,16 @@ start_mountee (node_t * np, char * argz, size_t argz_len, int flags, ngids = getgroups (ngids, gids); assert (ngids > 0); - /* Opens the port on which to set the mountee. */ + /* Provides the mountee with a port to the unionfs's underlying + node. */ error_t open_port (int flags, mach_port_t * underlying, mach_msg_type_name_t * underlying_type, task_t task, void *cookie) { - err = 0; + *underlying = underlying_node; + *underlying_type = MACH_MSG_TYPE_COPY_SEND; - /* The user which has created this process. */ - struct iouser * user; - - /* Create an iouser instance basing on the obtained authority - information. */ - err = iohelp_create_complex_iouser (&user, uids, nuids, gids, ngids); - if (err) - return err; - - /* Create a port to `np`. */ - newpi = netfs_make_protid - (netfs_make_peropen (np, flags, NULL), user); - if (!newpi) - { - iohelp_free_iouser (user); - return errno; - } - - *underlying = underlying_port = ports_get_send_right (newpi); - *underlying_type = MACH_MSG_TYPE_COPY_SEND; - - ports_port_deref (newpi); - - return err; + return 0; } /*open_port */ /* Create a completely unprivileged user. */ @@ -151,9 +125,10 @@ start_mountee (node_t * np, char * argz, size_t argz_len, int flags, if(err) return err; - /* Create a port to `np` for the unprivileged user. */ + /* Create a port to the root node of unionfs for the unprivileged + user. */ newpi = netfs_make_protid - (netfs_make_peropen (np, flags, NULL), nobody); + (netfs_make_peropen (netfs_root_node, flags, NULL), nobody); if (!newpi) { iohelp_free_iouser (nobody); @@ -226,23 +201,14 @@ setup_unionmount (void) { error_t err = 0; - /* The proxy node on which the mountee will be sitting must be able - to forward some of the RPCs coming from the mountee to the - underlying filesystem. That is why we create this proxy node as - a clone of the root node: the mountee will feel as if there is no - unionfs under itself. */ - unionmount_proxy = netfs_make_node (netfs_root_node->nn); - if (!unionmount_proxy) - return ENOMEM; + /* Start the mountee. - /* Set the mountee on the proxy node. Note that the O_READ flag does not actually limit access to the mountee's filesystem considerably. Whenever a client looks up a node which is not a directory, unionfs will give off a port to the node itself, withouth proxying it. Proxying happens only for directory nodes. */ - err = start_mountee (unionmount_proxy, mountee_argz, - mountee_argz_len, O_READ, &mountee_port); + err = start_mountee (mountee_argz, mountee_argz_len, O_READ, &mountee_port); if (err) return err; diff --git a/mount.h b/mount.h index ebbfa93..94f13a6 100644 --- a/mount.h +++ b/mount.h @@ -33,9 +33,6 @@ extern char * mountee_argz; extern size_t mountee_argz_len; -/* The node the mountee is sitting on. */ -extern node_t * unionmount_proxy; - extern mach_port_t mountee_port; extern mach_port_t mountee_control; @@ -48,12 +45,10 @@ extern int transparent_mount; /* Shows whether unionmount is shutting down. */ extern int shutting_down; -/* Starts the mountee (given by `argz` and `argz_len`), sets it on - node `np` and opens a port `port` to with `flags`. `port` is not - modified when an error occurs. */ +/* Starts the mountee (given by `argz` and `argz_len`) and opens a + port `port` to it with `flags`. */ error_t -start_mountee (node_t * np, char * argz, size_t argz_len, int flags, - mach_port_t * port); +start_mountee (char * argz, size_t argz_len, int flags, mach_port_t * port); /* Sets up a proxy node, sets the translator on it, and registers the filesystem published by the translator in the list of merged -- 1.6.3.3