summaryrefslogtreecommitdiff
path: root/libnetfs
diff options
context:
space:
mode:
authorJustus Winter <justus@gnupg.org>2016-04-18 21:53:28 +0200
committerJustus Winter <justus@gnupg.org>2016-05-19 22:27:37 +0200
commit13efe6721a370c38b65e0da3d33f310f42cfa05f (patch)
tree5c05409d7e27b9cb0842af4bbe7bf242b7659ab7 /libnetfs
parent3416078aa58b095566e559b7dbd9c9da4d1fc5d5 (diff)
Unify the short-circuit translator logic
* libdiskfs/dir-lookup.c (short_circuited_callback1): Move function to libfshelp. (diskfs_S_dir_lookup): Use the function from libfshelp instead. * libdiskfs/fsys-getroot.c (diskfs_S_fsys_getroot): Adapt accordingly. * libdiskfs/trans-callback.c (_diskfs_translator_callback2_fn): Likewise. * libfshelp/fetch-root.c (fshelp_short_circuited_callback1): New function. * libfshelp/fshelp.h (struct fshelp_stat_cookie): New definition. (fshelp_short_circuited_callback1): New prototype. * libnetfs/dir-lookup.c (short_circuited_callback1): Drop function. (netfs_S_dir_lookup): Use the function from libfshelp instead. * libnetfs/fsys-getroot.c (netfs_S_fsys_getroot): Adapt accordingly. * libnetfs/trans-callback.c (_netfs_translator_callback2_fn): Likewise.
Diffstat (limited to 'libnetfs')
-rw-r--r--libnetfs/dir-lookup.c53
-rw-r--r--libnetfs/fsys-getroot.c7
-rw-r--r--libnetfs/trans-callback.c4
3 files changed, 18 insertions, 46 deletions
diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c
index caeb1516..3bcc745e 100644
--- a/libnetfs/dir-lookup.c
+++ b/libnetfs/dir-lookup.c
@@ -207,48 +207,6 @@ netfs_S_dir_lookup (struct protid *dircred,
{
mach_port_t dirport;
- /* A callback function for short-circuited translators.
- S_ISLNK and S_IFSOCK are handled elsewhere. */
- error_t short_circuited_callback1 (void *cookie1, void *cookie2,
- uid_t *uid, gid_t *gid,
- char **argz, size_t *argz_len)
- {
- struct node *np = cookie1;
- error_t err;
-
- err = netfs_validate_stat (np, dircred->user);
- if (err)
- return err;
-
- switch (np->nn_translated & S_IFMT)
- {
- case S_IFCHR:
- case S_IFBLK:
- if (asprintf (argz, "%s%c%d%c%d",
- (S_ISCHR (np->nn_translated)
- ? _HURD_CHRDEV : _HURD_BLKDEV),
- 0, major (np->nn_stat.st_rdev),
- 0, minor (np->nn_stat.st_rdev)) < 0)
- return ENOMEM;
- *argz_len = strlen (*argz) + 1;
- *argz_len += strlen (*argz + *argz_len) + 1;
- *argz_len += strlen (*argz + *argz_len) + 1;
- break;
- case S_IFIFO:
- if (asprintf (argz, "%s", _HURD_FIFO) < 0)
- return ENOMEM;
- *argz_len = strlen (*argz) + 1;
- break;
- default:
- return ENOENT;
- }
-
- *uid = np->nn_stat.st_uid;
- *gid = np->nn_stat.st_gid;
-
- return 0;
- }
-
/* Create an unauthenticated port for DNP, and then
unlock it. */
err = iohelp_create_empty_iouser (&user);
@@ -267,6 +225,12 @@ netfs_S_dir_lookup (struct protid *dircred,
boolean_t register_translator = 0;
if (! err)
{
+ struct fshelp_stat_cookie2 cookie = {
+ .statp = &np->nn_stat,
+ .modep = &np->nn_translated,
+ .next = dircred->po,
+ };
+
dirport = ports_get_send_right (newpi);
/* Check if an active translator is currently running. If
@@ -275,13 +239,14 @@ netfs_S_dir_lookup (struct protid *dircred,
translators. */
register_translator = np->transbox.active == MACH_PORT_NULL;
- err = fshelp_fetch_root (&np->transbox, dircred->po,
+ err = fshelp_fetch_root (&np->transbox,
+ &cookie,
dirport,
dircred->user,
lastcomp ? flags : 0,
((np->nn_translated & S_IPTRANS)
? _netfs_translator_callback1
- : short_circuited_callback1),
+ : fshelp_short_circuited_callback1),
_netfs_translator_callback2,
do_retry, retry_name, retry_port);
/* fetch_root copies DIRPORT for success, so we always should
diff --git a/libnetfs/fsys-getroot.c b/libnetfs/fsys-getroot.c
index 2d02120e..d9191105 100644
--- a/libnetfs/fsys-getroot.c
+++ b/libnetfs/fsys-getroot.c
@@ -23,6 +23,7 @@
#include "misc.h"
#include "callbacks.h"
#include <fcntl.h>
+#include <hurd/fshelp.h>
error_t
netfs_S_fsys_getroot (struct netfs_control *pt,
@@ -67,8 +68,12 @@ netfs_S_fsys_getroot (struct netfs_control *pt,
|| fshelp_translated (&netfs_root_node->transbox))
&& !(flags & O_NOTRANS))
{
+ struct fshelp_stat_cookie2 cookie = {
+ .next = &peropen_context,
+ };
+
err = fshelp_fetch_root (&netfs_root_node->transbox,
- &peropen_context, dotdot, cred, flags,
+ &cookie, dotdot, cred, flags,
_netfs_translator_callback1,
_netfs_translator_callback2,
do_retry, retry_name, retry_port);
diff --git a/libnetfs/trans-callback.c b/libnetfs/trans-callback.c
index ed21aa2a..99f4dc05 100644
--- a/libnetfs/trans-callback.c
+++ b/libnetfs/trans-callback.c
@@ -20,6 +20,7 @@
#include "priv.h"
#include <fcntl.h>
+#include <hurd/fshelp.h>
/* Callback function needed for calls to fshelp_fetch_root. See
<hurd/fshelp.h> for the interface description. */
@@ -57,6 +58,7 @@ _netfs_translator_callback2_fn (void *cookie1, void *cookie2, int flags,
error_t err;
struct protid *cred;
struct node *node = cookie1;
+ struct fshelp_stat_cookie2 *statc = cookie2;
struct iouser *user;
struct peropen *po;
@@ -65,7 +67,7 @@ _netfs_translator_callback2_fn (void *cookie1, void *cookie2, int flags,
if (err)
return err;
- po = netfs_make_peropen (node, flags, cookie2);
+ po = netfs_make_peropen (node, flags, statc->next);
if (! po)
{
err = errno;