diff options
author | Justus Winter <justus@gnupg.org> | 2016-04-18 21:53:28 +0200 |
---|---|---|
committer | Justus Winter <justus@gnupg.org> | 2016-05-19 22:27:37 +0200 |
commit | 13efe6721a370c38b65e0da3d33f310f42cfa05f (patch) | |
tree | 5c05409d7e27b9cb0842af4bbe7bf242b7659ab7 /libfshelp | |
parent | 3416078aa58b095566e559b7dbd9c9da4d1fc5d5 (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 'libfshelp')
-rw-r--r-- | libfshelp/fetch-root.c | 40 | ||||
-rw-r--r-- | libfshelp/fshelp.h | 16 |
2 files changed, 56 insertions, 0 deletions
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 <assert.h> #include <hurd/fsys.h> +#include <hurd/paths.h> #include <hurd/ports.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -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; +} diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h index d04c0561..ecd9335d 100644 --- a/libfshelp/fshelp.h +++ b/libfshelp/fshelp.h @@ -148,6 +148,22 @@ typedef error_t (*fshelp_fetch_root_callback1_t) (void *cookie1, void *cookie2, uid_t *uid, gid_t *gid, char **argz, size_t *argz_len); +/* A cookie for fshelp_short_circuited_callback1. Such a structure + must be passed to the call to fshelp_fetch_root. */ +struct fshelp_stat_cookie2 +{ + io_statbuf_t *statp; + mode_t *modep; + void *next; +}; + +/* 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); + + /* This routine is called by fshelp_fetch_root to fetch more information. Return an unauthenticated node for the file itself in *UNDERLYING and *UNDERLYING_TYPE (opened with FLAGS). COOKIE1 is the cookie passed in |