Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame^] | 1 | From 4e41a05de1f34ba00a68ca4f20fb49c4d1cbd2d0 Mon Sep 17 00:00:00 2001 |
| 2 | From: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 3 | Date: Wed, 6 Nov 2019 12:17:46 +0000 |
| 4 | Subject: [PATCH] Add statx glibc/syscall support |
| 5 | |
| 6 | Modern distros (e.g. fedora30) are starting to use the new statx() syscall through |
| 7 | the newly exposed glibc wrapper function in software like coreutils (e.g. the ls |
| 8 | command). Add support to intercept this to pseudo. |
| 9 | |
| 10 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 11 | Upstream-Status: Submitted [Emailed to seebs] |
| 12 | --- |
| 13 | ports/linux/guts/statx.c | 48 ++++++++++++++++++++++++++++++++++++++++ |
| 14 | ports/linux/portdefs.h | 1 + |
| 15 | ports/linux/wrapfuncs.in | 1 + |
| 16 | 3 files changed, 50 insertions(+) |
| 17 | create mode 100644 ports/linux/guts/statx.c |
| 18 | |
| 19 | diff --git a/ports/linux/statx/guts/statx.c b/ports/linux/statx/guts/statx.c |
| 20 | new file mode 100644 |
| 21 | index 0000000..a3259c4 |
| 22 | --- /dev/null |
| 23 | +++ b/ports/linux/statx/guts/statx.c |
| 24 | @@ -0,0 +1,42 @@ |
| 25 | +/* |
| 26 | + * Copyright (c) 2019 Linux Foundation |
| 27 | + * Author: Richard Purdie |
| 28 | + * |
| 29 | + * SPDX-License-Identifier: LGPL-2.1-only |
| 30 | + * |
| 31 | + * int |
| 32 | + * statx(int dirfd, const char *pathname, int flags, unsigned int mask, struct statx *statxbuf) { |
| 33 | + * int rc = -1; |
| 34 | + */ |
| 35 | + pseudo_msg_t *msg; |
| 36 | + PSEUDO_STATBUF buf; |
| 37 | + int save_errno; |
| 38 | + |
| 39 | + rc = real_statx(dirfd, pathname, flags, mask, statxbuf); |
| 40 | + save_errno = errno; |
| 41 | + if (rc == -1) { |
| 42 | + return rc; |
| 43 | + } |
| 44 | + |
| 45 | + buf.st_uid = statxbuf->stx_uid; |
| 46 | + buf.st_gid = statxbuf->stx_gid; |
| 47 | + buf.st_dev = makedev(statxbuf->stx_dev_major, statxbuf->stx_dev_minor); |
| 48 | + buf.st_ino = statxbuf->stx_ino; |
| 49 | + buf.st_mode = statxbuf->stx_mode; |
| 50 | + buf.st_rdev = makedev(statxbuf->stx_rdev_major, statxbuf->stx_rdev_minor); |
| 51 | + buf.st_nlink = statxbuf->stx_nlink; |
| 52 | + msg = pseudo_client_op(OP_STAT, 0, -1, dirfd, pathname, &buf); |
| 53 | + if (msg && msg->result == RESULT_SUCCEED) { |
| 54 | + pseudo_debug(PDBGF_FILE, "statx(path %s), flags %o, stat rc %d, stat uid %o\n", pathname, flags, rc, statxbuf->stx_uid); |
| 55 | + statxbuf->stx_uid = msg->uid; |
| 56 | + statxbuf->stx_gid = msg->gid; |
| 57 | + statxbuf->stx_mode = msg->mode; |
| 58 | + statxbuf->stx_rdev_major = major(msg->rdev); |
| 59 | + statxbuf->stx_rdev_minor = minor(msg->rdev); |
| 60 | + } else { |
| 61 | + pseudo_debug(PDBGF_FILE, "statx(path %s) failed, flags %o, stat rc %d, stat uid %o\n", pathname, flags, rc, statxbuf->stx_uid); |
| 62 | + } |
| 63 | + errno = save_errno; |
| 64 | +/* return rc; |
| 65 | + * } |
| 66 | + */ |
| 67 | diff --git a/ports/linux/statx/portdefs.h b/ports/linux/statx/portdefs.h |
| 68 | new file mode 100644 |
| 69 | index 0000000..bf934dc |
| 70 | --- /dev/null |
| 71 | +++ b/ports/linux/statx/portdefs.h |
| 72 | @@ -0,0 +1,6 @@ |
| 73 | +/* |
| 74 | + * SPDX-License-Identifier: LGPL-2.1-only |
| 75 | + * |
| 76 | + */ |
| 77 | +#include <sys/stat.h> |
| 78 | +#include <sys/sysmacros.h> |
| 79 | diff --git a/ports/linux/statx/wrapfuncs.in b/ports/linux/statx/wrapfuncs.in |
| 80 | new file mode 100644 |
| 81 | index 0000000..c9cd4c3 |
| 82 | --- /dev/null |
| 83 | +++ b/ports/linux/statx/wrapfuncs.in |
| 84 | @@ -0,0 +1 @@ |
| 85 | +int statx(int dirfd, const char *pathname, int flags, unsigned int mask, struct statx *statxbuf); |
| 86 | diff --git a/ports/linux/subports b/ports/linux/subports |
| 87 | index a29044a..49081bf 100755 |
| 88 | --- a/ports/linux/subports |
| 89 | +++ b/ports/linux/subports |
| 90 | @@ -54,3 +54,13 @@ else |
| 91 | fi |
| 92 | rm -f dummy.c dummy.o |
| 93 | |
| 94 | +cat > dummy.c <<EOF |
| 95 | +#define _GNU_SOURCE |
| 96 | +#include <sys/stat.h> |
| 97 | +struct statx x; |
| 98 | +EOF |
| 99 | +if ${CC} -c -o dummy.o dummy.c >/dev/null 2>&1; then |
| 100 | + echo "linux/statx" |
| 101 | +fi |
| 102 | +rm -f dummy.c dummy.o |
| 103 | + |
| 104 | -- |
| 105 | 2.17.1 |
| 106 | |