[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <b9bbf73286238bb4657d855c9d50983aa17953e2.1675851111.git.chenfeiyang@loongson.cn>
Date: Wed, 8 Feb 2023 18:17:51 +0800
From: chris.chenfeiyang@...il.com
To: w@....eu, paulmck@...nel.org
Cc: Feiyang Chen <chenfeiyang@...ngson.cn>, arnd@...db.de,
chenhuacai@...nel.org, jiaxun.yang@...goat.com,
chris.chenfeiyang@...il.com, loongarch@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 2/5] tools/nolibc: Add statx() and make stat() rely on statx() when available
From: Feiyang Chen <chenfeiyang@...ngson.cn>
loongarch and riscv32 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() to make them happy.
Signed-off-by: Feiyang Chen <chenfeiyang@...ngson.cn>
---
tools/include/nolibc/sys.h | 51 ++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index c4818a9c8823..46b6b3bb3b4e 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"
@@ -1048,12 +1049,61 @@ pid_t setsid(void)
return ret;
}
+/*
+ * 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;
+}
/*
* int stat(const char *path, struct stat *buf);
* Warning: the struct stat's layout is arch-dependent.
*/
+#ifdef __NR_statx
+static __attribute__((unused))
+int sys_stat(const char *path, struct stat *buf)
+{
+ struct statx stat;
+ long ret;
+
+ ret = sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &stat);
+ buf->st_dev = ((stat.stx_dev_minor & 0xff)
+ | (stat.stx_dev_major << 8)
+ | ((stat.stx_dev_minor & ~0xff) << 12));
+ buf->st_ino = stat.stx_ino;
+ buf->st_mode = stat.stx_mode;
+ buf->st_nlink = stat.stx_nlink;
+ buf->st_uid = stat.stx_uid;
+ buf->st_gid = stat.stx_gid;
+ buf->st_rdev = ((stat.stx_rdev_minor & 0xff)
+ | (stat.stx_rdev_major << 8)
+ | ((stat.stx_rdev_minor & ~0xff) << 12));
+ buf->st_size = stat.stx_size;
+ buf->st_blksize = stat.stx_blksize;
+ buf->st_blocks = stat.stx_blocks;
+ buf->st_atime = stat.stx_atime.tv_sec;
+ buf->st_mtime = stat.stx_mtime.tv_sec;
+ buf->st_ctime = stat.stx_ctime.tv_sec;
+ return ret;
+}
+#else
static __attribute__((unused))
int sys_stat(const char *path, struct stat *buf)
{
@@ -1083,6 +1133,7 @@ int sys_stat(const char *path, struct stat *buf)
buf->st_ctime = stat.st_ctime;
return ret;
}
+#endif /* __NR_statx */
static __attribute__((unused))
int stat(const char *path, struct stat *buf)
--
2.39.0
Powered by blists - more mailing lists