diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-07-30 11:59:14 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2013-09-15 23:16:22 +0200 |
commit | f18f06ea2fbde9d5ab2d6bbd30e4cdeebb186c87 (patch) | |
tree | 185130a52d38b17542b0aa63c0a43279cb37cec1 | |
parent | 9df906ee4f34cf54c9ba253d44abb74b0ef63fe1 (diff) |
libdiskfs: add fsys_get_children
Keep track of active translators and handle fsys_get_children
requests.
* libdiskfs/Makefile (FSYSSRCS): Add fsys-get-children.c.
* libdiskfs/dead-name.c (ports_dead_name): Remove dead translators.
* libdiskfs/file-set-trans.c (diskfs_S_file_set_translator): Register
active translators.
* libdiskfs/fsys-get-children.c: New file.
-rw-r--r-- | libdiskfs/Makefile | 3 | ||||
-rw-r--r-- | libdiskfs/dead-name.c | 4 | ||||
-rw-r--r-- | libdiskfs/file-set-trans.c | 19 | ||||
-rw-r--r-- | libdiskfs/fsys-get-children.c | 99 |
4 files changed, 122 insertions, 3 deletions
diff --git a/libdiskfs/Makefile b/libdiskfs/Makefile index 3c8de4c8..1a0edd00 100644 --- a/libdiskfs/Makefile +++ b/libdiskfs/Makefile @@ -34,7 +34,8 @@ IOSRCS= io-async-icky.c io-async.c io-duplicate.c io-get-conch.c io-revoke.c \ io-reauthenticate.c io-rel-conch.c io-restrict-auth.c io-seek.c \ io-select.c io-stat.c io-stubs.c io-write.c io-version.c io-sigio.c FSYSSRCS=fsys-getroot.c fsys-goaway.c fsys-startup.c fsys-getfile.c \ - fsys-options.c fsys-syncfs.c fsys-forward.c + fsys-options.c fsys-syncfs.c fsys-forward.c \ + fsys-get-children.c IFSOCKSRCS=ifsock.c OTHERSRCS = conch-fetch.c conch-set.c dir-clear.c dir-init.c dir-renamed.c \ extern-inline.c \ diff --git a/libdiskfs/dead-name.c b/libdiskfs/dead-name.c index 760b36ff..6ca208e4 100644 --- a/libdiskfs/dead-name.c +++ b/libdiskfs/dead-name.c @@ -40,6 +40,8 @@ ports_dead_name (void *notify, mach_port_t dead_name) else pthread_mutex_unlock (&np->lock); } - + + fshelp_remove_active_translator (dead_name); + ports_interrupt_notified_rpcs (notify, dead_name, MACH_NOTIFY_DEAD_NAME); } diff --git a/libdiskfs/file-set-trans.c b/libdiskfs/file-set-trans.c index 49303e7c..8de2e641 100644 --- a/libdiskfs/file-set-trans.c +++ b/libdiskfs/file-set-trans.c @@ -1,5 +1,6 @@ /* libdiskfs implementation of fs.defs: file_set_translator - Copyright (C) 1992,93,94,95,96,99,2001,02 Free Software Foundation, Inc. + Copyright (C) 1992,93,94,95,96,99,2001,02,13 + 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 @@ -206,5 +207,21 @@ diskfs_S_file_set_translator (struct protid *cred, } pthread_mutex_unlock (&np->lock); + + if (! error && cred->po->path) + error = fshelp_set_active_translator (cred->po->path, active); + + if (! error && active != MACH_PORT_NULL) + { + mach_port_t old; + error = mach_port_request_notification (mach_task_self (), active, + MACH_NOTIFY_DEAD_NAME, 0, + cred->pi.port_right, + MACH_MSG_TYPE_MAKE_SEND_ONCE, + &old); + if (old != MACH_PORT_NULL) + mach_port_deallocate (mach_task_self (), old); + } + return error; } diff --git a/libdiskfs/fsys-get-children.c b/libdiskfs/fsys-get-children.c new file mode 100644 index 00000000..69c9963e --- /dev/null +++ b/libdiskfs/fsys-get-children.c @@ -0,0 +1,99 @@ +/* fsys_get_children + + Copyright (C) 2013 Free Software Foundation, Inc. + + Written by Justus Winter <4winter@informatik.uni-hamburg.de> + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */ + +#include "priv.h" +#include "fsys_S.h" + +#include <argz.h> + +/* Return any active translators bound to nodes of the receiving + filesystem. CHILDREN is an argz vector containing file names + relative to the root of the receiving translator. */ +error_t +diskfs_S_fsys_get_children (fsys_t server, + mach_port_t reply, + mach_msg_type_name_t replyPoly, + char **children, + mach_msg_type_number_t *children_len) +{ + error_t err; + + struct protid *cred = ports_lookup_port (diskfs_port_bucket, + server, + diskfs_protid_class); + if (! cred) + return EOPNOTSUPP; + + /* check_access performs the same permission check as is normally + done, i.e. it checks that all but the last path components are + executable by the requesting user and that the last component is + readable. */ + error_t check_access (const char *path) + { + error_t err; + char *elements = NULL; + size_t elements_len = 0; + + err = argz_create_sep (path, '/', &elements, &elements_len); + if (err) + return err; + + struct node *dp = diskfs_root_node; + + for (char *entry = elements; + entry; + entry = argz_next (elements, elements_len, entry)) + { + struct node *next; + err = diskfs_lookup (dp, entry, LOOKUP, &next, NULL, cred); + + if (dp != diskfs_root_node) + diskfs_nput (dp); + + if (err) + return err; + + dp = next; + } + + err = fshelp_access (&dp->dn_stat, S_IRUSR, cred->user); + diskfs_nput (dp); + return err; + } + + + char *c = NULL; + size_t c_len = 0; + + err = fshelp_get_active_translators (&c, &c_len, check_access); + if (err) + goto errout; + + err = iohelp_return_malloced_buffer (c, c_len, children, children_len); + if (err) + goto errout; + + c = NULL; /* c was freed by iohelp_return_malloced_buffer. */ + + errout: + free (c); + return err; +} |