From: "Paul E. McKenney" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected],
Feiyang Chen <[email protected]>,
Huacai Chen <[email protected]>, Willy Tarreau <[email protected]>,
"Paul E . McKenney" <[email protected]>
Subject: [PATCH nolibc 11/14] tools/nolibc: Add statx() and make stat() rely on statx() if necessary
Date: Mon, 20 Mar 2023 18:11:34 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <6a3206d0-e5cd-4990-9604-444a24a8207c@paulmck-laptop>
From: Feiyang Chen <[email protected]>
LoongArch and RISC-V 32-bit only have statx(). ARC, Hexagon, Nios2 and
OpenRISC have statx() and stat64() but not stat() or newstat(). Add
statx() and make stat() rely on statx() if necessary to make them happy.
We may just use statx() for all architectures in the future.
Signed-off-by: Feiyang Chen <[email protected]>
Acked-by: Huacai Chen <[email protected]>
Signed-off-by: Willy Tarreau <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
tools/include/nolibc/sys.h | 56 ++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 41cad6d6137e..5d624dc63a42 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -20,6 +20,7 @@
#include <linux/time.h>
#include <linux/auxvec.h>
#include <linux/fcntl.h> // for O_* and AT_*
+#include <linux/stat.h> // for statx()
#include "arch.h"
#include "errno.h"
@@ -1090,12 +1091,66 @@ pid_t setsid(void)
return ret;
}
+#if defined(__NR_statx)
+/*
+ * int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf);
+ */
+
+static __attribute__((unused))
+int sys_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf)
+{
+ return my_syscall5(__NR_statx, fd, path, flags, mask, buf);
+}
+
+static __attribute__((unused))
+int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf)
+{
+ int ret = sys_statx(fd, path, flags, mask, buf);
+
+ if (ret < 0) {
+ SET_ERRNO(-ret);
+ ret = -1;
+ }
+ return ret;
+}
+#endif
/*
* int stat(const char *path, struct stat *buf);
* Warning: the struct stat's layout is arch-dependent.
*/
+#if defined(__NR_statx) && !defined(__NR_newfstatat) && !defined(__NR_stat)
+/*
+ * Maybe we can just use statx() when available for all architectures?
+ */
+static __attribute__((unused))
+int sys_stat(const char *path, struct stat *buf)
+{
+ struct statx statx;
+ long ret;
+
+ ret = sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx);
+ buf->st_dev = ((statx.stx_dev_minor & 0xff)
+ | (statx.stx_dev_major << 8)
+ | ((statx.stx_dev_minor & ~0xff) << 12));
+ buf->st_ino = statx.stx_ino;
+ buf->st_mode = statx.stx_mode;
+ buf->st_nlink = statx.stx_nlink;
+ buf->st_uid = statx.stx_uid;
+ buf->st_gid = statx.stx_gid;
+ buf->st_rdev = ((statx.stx_rdev_minor & 0xff)
+ | (statx.stx_rdev_major << 8)
+ | ((statx.stx_rdev_minor & ~0xff) << 12));
+ buf->st_size = statx.stx_size;
+ buf->st_blksize = statx.stx_blksize;
+ buf->st_blocks = statx.stx_blocks;
+ buf->st_atime = statx.stx_atime.tv_sec;
+ buf->st_mtime = statx.stx_mtime.tv_sec;
+ buf->st_ctime = statx.stx_ctime.tv_sec;
+ return ret;
+}
+#else
static __attribute__((unused))
int sys_stat(const char *path, struct stat *buf)
{
@@ -1125,6 +1180,7 @@ int sys_stat(const char *path, struct stat *buf)
buf->st_ctime = stat.st_ctime;
return ret;
}
+#endif
static __attribute__((unused))
int stat(const char *path, struct stat *buf)
--
2.40.0.rc2
next prev parent reply other threads:[~2023-03-21 1:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 1:11 [PATCH nolibc 0/14] nolibc updates for v6.4 Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 01/14] tools/nolibc: always disable stack protector for tests Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 02/14] tools/nolibc: Add gitignore to avoid git complaints about sysroot Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 03/14] tools/nolibc: add stdint.h Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 04/14] tools/nolibc: add integer types and integer limit macros Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 05/14] tools/nolibc: enlarge column width of tests Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 06/14] tools/nolibc: add tests for the integer limits in stdint.h Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 07/14] tools/nolibc: add getuid() and geteuid() Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 08/14] selftests/nolibc: skip the chroot_root and link_dir tests when not privileged Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 09/14] tools/nolibc: check for S_I* macros before defining them Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 10/14] tools/nolibc: Include linux/fcntl.h and remove duplicate code Paul E. McKenney
2023-03-21 1:11 ` Paul E. McKenney [this message]
2023-03-21 1:11 ` [PATCH nolibc 12/14] tools/nolibc: Add support for LoongArch Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 13/14] selftests/nolibc: " Paul E. McKenney
2023-03-21 1:11 ` [PATCH nolibc 14/14] selftests/nolibc: Adjust indentation for Makefile Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox