bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 06/17] libdiskfs: add fsys_get_children


From: Justus Winter
Subject: [PATCH 06/17] libdiskfs: add fsys_get_children
Date: Fri, 19 Jul 2013 17:25:08 +0200

---
 libdiskfs/Makefile            |    3 +-
 libdiskfs/dead-name.c         |    4 +-
 libdiskfs/file-set-trans.c    |   15 +++++++
 libdiskfs/fsys-get-children.c |  100 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 120 insertions(+), 2 deletions(-)
 create mode 100644 libdiskfs/fsys-get-children.c

diff --git a/libdiskfs/Makefile b/libdiskfs/Makefile
index 3c8de4c..1a0edd0 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 760b36f..6ca208e 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 49303e7..df5db3b 100644
--- a/libdiskfs/file-set-trans.c
+++ b/libdiskfs/file-set-trans.c
@@ -18,6 +18,7 @@
 #include "priv.h"
 #include "fs_S.h"
 #include <hurd/paths.h>
+#include <hurd/fshelp.h>
 #include <hurd/fsys.h>
 
 /* Implement file_set_translator as described in <hurd/fs.defs>. */
@@ -206,5 +207,19 @@ 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);
+    }
+
   return error;
 }
diff --git a/libdiskfs/fsys-get-children.c b/libdiskfs/fsys-get-children.c
new file mode 100644
index 0000000..fcb8f99
--- /dev/null
+++ b/libdiskfs/fsys-get-children.c
@@ -0,0 +1,100 @@
+/* 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; see the file COPYING.  If not, write to
+   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+#include "priv.h"
+#include "fsys_S.h"
+
+#include <argz.h>
+
+/* Return any passive and active translators bound to nodes of the
+   receiving filesystem. children is a 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;
+}
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]