[05/14] Add src/internal/statx.h

Submitted by Stefan O'Rear on Sept. 3, 2020, 11:23 a.m.

Details

Message ID 20200903112309.102601-6-sorear@fastmail.com
State New
Series "riscv32 support"
Headers show

Commit Message

Stefan O'Rear Sept. 3, 2020, 11:23 a.m.
We need to make internal syscalls to SYS_statx when SYS_fstatat is not
available without changing the musl API.
---
 src/internal/statx.h | 28 ++++++++++++++++++++++++++++
 src/stat/fstatat.c   | 28 ++--------------------------
 2 files changed, 30 insertions(+), 26 deletions(-)
 create mode 100644 src/internal/statx.h

Patch hide | download patch | download mbox

diff --git a/src/internal/statx.h b/src/internal/statx.h
new file mode 100644
index 00000000..46b16f62
--- /dev/null
+++ b/src/internal/statx.h
@@ -0,0 +1,28 @@ 
+struct statx {
+	uint32_t stx_mask;
+	uint32_t stx_blksize;
+	uint64_t stx_attributes;
+	uint32_t stx_nlink;
+	uint32_t stx_uid;
+	uint32_t stx_gid;
+	uint16_t stx_mode;
+	uint16_t pad1;
+	uint64_t stx_ino;
+	uint64_t stx_size;
+	uint64_t stx_blocks;
+	uint64_t stx_attributes_mask;
+	struct {
+		int64_t tv_sec;
+		uint32_t tv_nsec;
+		int32_t pad;
+	} stx_atime, stx_btime, stx_ctime, stx_mtime;
+	uint32_t stx_rdev_major;
+	uint32_t stx_rdev_minor;
+	uint32_t stx_dev_major;
+	uint32_t stx_dev_minor;
+	uint64_t spare[14];
+};
+
+#define STATX_TYPE         0x001U
+#define STATX_SIZE         0x200U
+#define STATX_BASIC_STATS  0x7ffU
diff --git a/src/stat/fstatat.c b/src/stat/fstatat.c
index de165b5c..230a83fc 100644
--- a/src/stat/fstatat.c
+++ b/src/stat/fstatat.c
@@ -7,37 +7,13 @@ 
 #include <sys/sysmacros.h>
 #include "syscall.h"
 #include "kstat.h"
-
-struct statx {
-	uint32_t stx_mask;
-	uint32_t stx_blksize;
-	uint64_t stx_attributes;
-	uint32_t stx_nlink;
-	uint32_t stx_uid;
-	uint32_t stx_gid;
-	uint16_t stx_mode;
-	uint16_t pad1;
-	uint64_t stx_ino;
-	uint64_t stx_size;
-	uint64_t stx_blocks;
-	uint64_t stx_attributes_mask;
-	struct {
-		int64_t tv_sec;
-		uint32_t tv_nsec;
-		int32_t pad;
-	} stx_atime, stx_btime, stx_ctime, stx_mtime;
-	uint32_t stx_rdev_major;
-	uint32_t stx_rdev_minor;
-	uint32_t stx_dev_major;
-	uint32_t stx_dev_minor;
-	uint64_t spare[14];
-};
+#include "statx.h"
 
 static int fstatat_statx(int fd, const char *restrict path, struct stat *restrict st, int flag)
 {
 	struct statx stx;
 
-	int ret = __syscall(SYS_statx, fd, path, flag, 0x7ff, &stx);
+	int ret = __syscall(SYS_statx, fd, path, flag, STATX_BASIC_STATS, &stx);
 	if (ret) return ret;
 
 	*st = (struct stat){

Comments

Arnd Bergmann Sept. 3, 2020, 3:39 p.m.
On Thu, Sep 3, 2020 at 1:24 PM Stefan O'Rear <sorear@fastmail.com> wrote:
>
> We need to make internal syscalls to SYS_statx when SYS_fstatat is not
> available without changing the musl API.
> ---
>  src/internal/statx.h | 28 ++++++++++++++++++++++++++++
>  src/stat/fstatat.c   | 28 ++--------------------------
>  2 files changed, 30 insertions(+), 26 deletions(-)
>  create mode 100644 src/internal/statx.h
>
> diff --git a/src/internal/statx.h b/src/internal/statx.h
> new file mode 100644
> index 00000000..46b16f62
> --- /dev/null
> +++ b/src/internal/statx.h
> @@ -0,0 +1,28 @@
> +struct statx {
> +       uint32_t stx_mask;
> +       uint32_t stx_blksize;
> +       uint64_t stx_attributes;
> +       uint32_t stx_nlink;
> +       uint32_t stx_uid;
> +       uint32_t stx_gid;
> +       uint16_t stx_mode;
> +       uint16_t pad1;
> +       uint64_t stx_ino;
> +       uint64_t stx_size;
> +       uint64_t stx_blocks;
> +       uint64_t stx_attributes_mask;
> +       struct {
> +               int64_t tv_sec;
> +               uint32_t tv_nsec;
> +               int32_t pad;
> +       } stx_atime, stx_btime, stx_ctime, stx_mtime;
> +       uint32_t stx_rdev_major;
> +       uint32_t stx_rdev_minor;
> +       uint32_t stx_dev_major;
> +       uint32_t stx_dev_minor;
> +       uint64_t spare[14];
> +};

Unrelated to your patch that just moves this, I notice that
the kernel version has gained an stx_mnt_id field.

     Arnd
Rich Felker Sept. 3, 2020, 3:51 p.m.
On Thu, Sep 03, 2020 at 05:39:51PM +0200, Arnd Bergmann wrote:
> On Thu, Sep 3, 2020 at 1:24 PM Stefan O'Rear <sorear@fastmail.com> wrote:
> >
> > We need to make internal syscalls to SYS_statx when SYS_fstatat is not
> > available without changing the musl API.
> > ---
> >  src/internal/statx.h | 28 ++++++++++++++++++++++++++++
> >  src/stat/fstatat.c   | 28 ++--------------------------
> >  2 files changed, 30 insertions(+), 26 deletions(-)
> >  create mode 100644 src/internal/statx.h
> >
> > diff --git a/src/internal/statx.h b/src/internal/statx.h
> > new file mode 100644
> > index 00000000..46b16f62
> > --- /dev/null
> > +++ b/src/internal/statx.h
> > @@ -0,0 +1,28 @@
> > +struct statx {
> > +       uint32_t stx_mask;
> > +       uint32_t stx_blksize;
> > +       uint64_t stx_attributes;
> > +       uint32_t stx_nlink;
> > +       uint32_t stx_uid;
> > +       uint32_t stx_gid;
> > +       uint16_t stx_mode;
> > +       uint16_t pad1;
> > +       uint64_t stx_ino;
> > +       uint64_t stx_size;
> > +       uint64_t stx_blocks;
> > +       uint64_t stx_attributes_mask;
> > +       struct {
> > +               int64_t tv_sec;
> > +               uint32_t tv_nsec;
> > +               int32_t pad;
> > +       } stx_atime, stx_btime, stx_ctime, stx_mtime;
> > +       uint32_t stx_rdev_major;
> > +       uint32_t stx_rdev_minor;
> > +       uint32_t stx_dev_major;
> > +       uint32_t stx_dev_minor;
> > +       uint64_t spare[14];
> > +};
> 
> Unrelated to your patch that just moves this, I notice that
> the kernel version has gained an stx_mnt_id field.

This could potentially be added, but should be a separate change, and
really only makes sense if/when we put this in a public header since
nothing internal is using it.

Rich
Arnd Bergmann Sept. 3, 2020, 6:08 p.m.
On Thu, Sep 3, 2020 at 5:51 PM Rich Felker <dalias@libc.org> wrote:
> On Thu, Sep 03, 2020 at 05:39:51PM +0200, Arnd Bergmann wrote:
> > On Thu, Sep 3, 2020 at 1:24 PM Stefan O'Rear <sorear@fastmail.com> wrote:
> >
> > Unrelated to your patch that just moves this, I notice that
> > the kernel version has gained an stx_mnt_id field.
>
> This could potentially be added, but should be a separate change, and
> really only makes sense if/when we put this in a public header since
> nothing internal is using it.

Agreed to all of those, I just mentioned it when I noticed the difference.

     Arnd