From 13efe6721a370c38b65e0da3d33f310f42cfa05f Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 18 Apr 2016 21:53:28 +0200 Subject: 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. --- libfshelp/fetch-root.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'libfshelp/fetch-root.c') diff --git a/libfshelp/fetch-root.c b/libfshelp/fetch-root.c index eb0f3152..75aa2d37 100644 --- a/libfshelp/fetch-root.c +++ b/libfshelp/fetch-root.c @@ -20,7 +20,9 @@ #include #include +#include #include +#include #include #include #include @@ -197,3 +199,41 @@ fshelp_fetch_root (struct transbox *box, void *cookie, return err; } + +/* A callback function for short-circuited translators. S_ISLNK and + S_IFSOCK must be handled elsewhere. */ +error_t +fshelp_short_circuited_callback1 (void *cookie1, void *cookie2, + uid_t *uid, gid_t *gid, + char **argz, size_t *argz_len) +{ + struct fshelp_stat_cookie2 *statc = cookie2; + + switch (*statc->modep & S_IFMT) + { + case S_IFCHR: + case S_IFBLK: + if (asprintf (argz, "%s%c%d%c%d", + (S_ISCHR (*statc->modep) + ? _HURD_CHRDEV : _HURD_BLKDEV), + 0, major (statc->statp->st_rdev), + 0, minor (statc->statp->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 = statc->statp->st_uid; + *gid = statc->statp->st_gid; + + return 0; +} -- cgit v1.2.3