xfs: report crtime and attribute flags to statx
Subsystems (4)
PATCH 1/1 xfs: report crtime and attribute flags to statx
statx has the ability to report inode creation times and inode flags, so hook up di_crtime and di_flags to that functionality.
--- fs/xfs/xfs_iops.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/xfs/xfs_iops.c +14 -0
@@ -516,6 +516,20 @@ xfs_vn_getattr( stat->blocks =XFS_FSB_TO_BB (mp, ip->i_d.di_nblocks + ip->i_delayed_blks); +if (ip->i_d.di_version ==3 ) { +if (request_mask &STATX_BTIME ) { + stat->result_mask |=STATX_BTIME ; + stat->btime.tv_sec = ip->i_d.di_crtime.t_sec; + stat->btime.tv_nsec = ip->i_d.di_crtime.t_nsec; + } + } + +if (ip->i_d.di_flags &XFS_DIFLAG_IMMUTABLE ) + stat->attributes |=STATX_ATTR_IMMUTABLE ; +if (ip->i_d.di_flags &XFS_DIFLAG_APPEND ) + stat->attributes |=STATX_ATTR_APPEND ; +if (ip->i_d.di_flags &XFS_DIFLAG_NODUMP ) + stat->attributes |=STATX_ATTR_NODUMP ;switch (inode->i_mode &S_IFMT ) {case S_IFBLK :
Quoted 2 lines · Darrick J. Wong
statx has the ability to report inode creation times and inode flags, so hook up
di_crtimeanddi_flagsto that functionality.
This would be great to have in 4.11 together with the initial statx implementation. But until I see documentation and testcases for statx I don't really feel comfortable reviewing anything related to it.
statx manpage
Quoted 3 lines · Christoph Hellwig
This would be great to have in 4.11 together with the initial statx implementation. But until I see documentation and testcases for statx I don't really feel comfortable reviewing anything related to it.
Well, since you asked for documentation, here's a manual page for you to review:-)
Note that as it isn't in glibc yet, I've left out all the set-this-and-that-#define-to-make-it-appear stuff except where it is pertinent to particular constants.
I don't suppose you know where the documentation on writing xfstests tests is? xfstests-dev/doc/ only contains an old and out of date changelog.
David
---
'\" t
.\" Copyright (c) 1992 Drew Eckhardt ([email protected]), March 28, 1992 .\" Parts Copyright (c) 1995 Nicolai Langfeldt ([email protected]), 1/1/95 .\" and Copyright (c) 2006, 2007, 2014 Michael Kerrisk <[email protected]> .\" and Copyright (c) 2017 David Howells <[email protected]>
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END
.\"
.TH STATX 2 2017-03-07 "Linux" "Linux Programmer's Manual"
.SH NAME
statx \- Get file status (extended)
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.br
.B #include <sys/stat.h>
.br
.B #include <unistd.h>
.br
.BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
.sp
.BI "int statx(int " dirfd ", const char *" pathname ", int " flags ","
.BI " unsigned int " mask ", struct statx *" buf );
.fi
.sp
.in -4n
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.in
.ad l
.PD 0
.sp
.RS 4
<unknown as yet>
.RE
.PD
.ad
.SH DESCRIPTION
.PP
This function returns information about a file, storing it in the buffer pointed to by
.IR buf .
The buffer is filled in according to the following type:
.PP
.in +4n
.nf
struct statx {
__u32 stx_mask; -- Mask of bits indicating filled fields
__u32 stx_blksize; -- Block size for filesystem I/O
__u64 stx_attributes; -- Extra file attribute indicators
__u32 stx_nlink; -- Number of hard links
__u32 stx_uid; -- User ID of owner
__u32 stx_gid; -- Group ID of owner
__u16 stx_mode; -- File type and mode
__u64 stx_ino; -- Inode number
__u64 stx_size; -- Total size in bytes
__u64 stx_blocks; -- Number of 512B blocks allocated
struct statx_timestamp stx_atime; -- Time of last access
struct statx_timestamp stx_btime; -- Time of creation
struct statx_timestamp stx_ctime; -- Time of last status change
struct statx_timestamp stx_mtime; -- Time of last modification __u32 stx_rdev_major; } Device number if device file
__u32 stx_rdev_minor; }
__u32 stx_dev_major; } Device number of containing file
__u32 stx_dev_minor; }
};
.fi
.in
.PP
Where the timestamps are defined as:
.PP
.in +4n
.nf
struct statx_timestamp {
__s64 tv_sec; -- Number of seconds before or since 1970
__s32 tv_nsec; -- Number of nanoseconds before or since tv_sec
};
.fi
.in
.PP
(Note that reserved space and padding is ommitted)
.SS
Invoking \fBstatx\fR():
.PP
To access a file's status, no permissions are required on the file itself, but in the case of
.BR statx ()
with a path, execute (search) permission is required on all of the directories in
.I pathname
that lead to the file.
.PP
.BR statx ()
uses
.IR pathname ", " dirfd " and " flags
to locate the target file in one of a variety of ways:
.TP
[*] By absolute path.
.I pathname
points to an absolute path and
.I dirfd
is ignored. The file is looked up by name, starting from the root of the filesystem as seen by the calling process.
.TP
[*] By cwd-relative path.
.I pathname
points to a relative path and
.IR dirfd " is " AT_FDCWD .
The file is looked up by name, starting from the current working directory. .TP
[*] By dir-relative path.
.I pathname
points to relative path and
.I dirfd
indicates a file descriptor pointing to a directory. The file is looked up by name, starting from the directory specified by
.IR dirfd .
.TP
[*] By file descriptor.
.IR pathname " is " NULL " and " dirfd
indicates a file descriptor. The file attached to the file descriptor is queried directly. The file descriptor may point to any type of file, not just a directory.
.PP
.I flags
can be used to influence a path-based lookup. A value for
.I flags
is constructed by OR'ing together zero or more of the following constants:
.TP
.BR AT_EMPTY_PATH " (since Linux 2.6.39)"
.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
If
.I pathname
is an empty string, operate on the file referred to by
.IR dirfd
(which may have been obtained using the
.BR open (2)
.B O_PATH
flag).
If
.I dirfd
is
.BR AT_FDCWD ,
the call operates on the current working directory.
In this case,
.I dirfd
can refer to any type of file, not just a directory.
This flag is Linux-specific; define
.B _GNU_SOURCE
.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
to obtain its definition.
.TP
.BR AT_NO_AUTOMOUNT " (since Linux 2.6.38)"
Don't automount the terminal ("basename") component of
.I pathname
if it is a directory that is an automount point.
This allows the caller to gather attributes of an automount point (rather than the location it would mount).
This flag can be used in tools that scan directories
to prevent mass-automounting of a directory of automount points. The
.B AT_NO_AUTOMOUNT
flag has no effect if the mount point has already been mounted over. This flag is Linux-specific; define
.B _GNU_SOURCE
.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
to obtain its definition.
.TP
.B AT_SYMLINK_NOFOLLOW
If
.I pathname
is a symbolic link, do not dereference it:
instead return information about the link itself, like
.BR lstat ().
.PP
.I flags
can also be used to control what sort of synchronisation the kernel will do when querying a file on a remote filesystem. This is done by OR'ing in one of the following values:
.TPAT_STATX_SYNC_AS_STAT
Do whatever
.BR stat ()
does. This is the default and is very much filesystem specific. .TPAT_STATX_FORCE_SYNC
Force the attributes to be synchronised with the server. This may require that a network filesystem perform a data writeback to get the timestamps correct. .TPAT_STATX_DONT_SYNC
Don't synchronise anything, but rather just take whatever the system has cached if possible. This may mean that the information returned is approximate, but, on a network filesystem, it may not involve a round trip to the server - even if no lease is held.
.PP
The
.I mask
argument to
.BR statx ()
is used to tell the kernel which fields the caller is interested in .I mask
is an OR'ed combination of the following constants:
.PP
.in +4n
.TS
lB l.STATX_TYPE Want stx_mode & S_IFMTSTATX_MODE Want stx_mode & ~S_IFMTSTATX_NLINK Want stx_nlinkSTATX_UID Want stx_uidSTATX_GID Want stx_gidSTATX_ATIME Want stx_atime{,_ns}STATX_MTIME Want stx_mtime{,_ns}STATX_CTIME Want stx_ctime{,_ns}STATX_INO Want stx_inoSTATX_SIZE Want stx_sizeSTATX_BLOCKS Want stx_blocksSTATX_BASIC_STATS [The stuff in the normal stat struct]STATX_BTIME Want stx_btime{,_ns}STATX_ALL [All currently available stuff]
.TE
.in
.PP
.B "Do not"
simply set
.I mask
to UINT_MAX as one or more bits may, in future, be used to specify an extension to the buffer.
.SS
The returned information
.PP
The status information for the target file is returned in the
.I statx
structure pointed to by
.IR buf .
Included in this is
.I stx_mask
which indicates what other information has been returned.
.I stx_mask
has the same format as the mask argument and bits are set in it to indicate which fields have been filled in.
.PP
It should be noted that the kernel may return fields that weren't requested and may fail to return fields that were requested, depending on what the backing filesystem supports. In either case,
.I stx_mask
will not be equal
.IR mask .
.PP
If a filesystem does not support a field or if it has an unrepresentable value (for instance, a file with an exotic type), then the mask bit corresponding to that field will be cleared in
.I stx_mask
even if the user asked for it and a dummy value will be filled in for compatibility purposes if one is available (e.g. a dummy uid and gid may be specified to mount under some circumstances).
.PP
A filesystem may also fill in fields that the caller didn't ask for if it has values for them available at no extra cost. If this happens, the corresponding bits will be set in
.IR stx_mask .
.PP
.\" Background: inode attributes are modified with i_mutex held, but .\" read by stat() without taking the mutex.
.I Note:
For performance and simplicity reasons, different fields in the
.I statx
structure may contain state information from different moments during the execution of the system call.
For example, if
.IR stx_mode
or
.IR stx_uid
is changed by another process by calling
.BR chmod (2)
or
.BR chown (2),
.BR stat ()
might return the old
.I stx_mode
together with the new
.IR stx_uid ,
or the old
.I stx_uid
together with the new
.IR stx_mode .
.PP
Apart from stx_mask (which is described above), the fields in the .I statx
structure are:
.TP
.I stx_mode
The file type and mode. This is described in more detail below. .TP
.I stx_size
The size of the file (if it is a regular file or a symbolic link) in bytes. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte.
.TP
.I stx_blocks
The number of blocks allocated to the file on the medium, in 512-byte units. (This may be smaller than
.IR stx_size /512
when the file has holes.)
.TP
.I stx_blksize
The "preferred" blocksize for efficient filesystem I/O. (Writing to a file in smaller chunks may cause an inefficient read-modify-rewrite.)
.TP
.I stx_nlink
The number of hard links on a file.
.TP
.I stx_uid
The user ID of the file's owner.
.TP
.I stx_gid
The ID of the group that may access the file.
.TP
.IR stx_dev_major " and " stx_dev_minor
The device on which this file (inode) resides.
.TP
.IR stx_rdev_major " and " stx_rdev_minor
The device that this file (inode) represents if the file is of block or character device type.
.TP
.I stx_attributes
Further status information about the file. This consists of zero or more of the following constants OR'ed together:
.in +4n
.TS
lB l.STATX_ATTR_COMPRESSED File is compressed by the fsSTATX_ATTR_IMMUTABLE File is marked immutableSTATX_ATTR_APPEND File is append-onlySTATX_ATTR_NODUMP File is not to be dumpedSTATX_ATTR_ENCRYPTED File requires key to decrypt in fs
.TE
.in
.TP
.I stx_atime
The file's last access timestamp.
This field is changed by file accesses, for example, by
.BR execve (2),
.BR mknod (2),
.BR pipe (2),
.BR utime (2),
and
.BR read (2)
(of more than zero bytes).
Other routines, such as
.BR mmap (2),
may or may not update it.
.TP
.I stx_btime
The file's creation timestamp. This is set on file creation and not changed subsequently.
.TP
.I stx_ctime
The file's last status change timestamp. This field is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.). .TP
.I stx_mtime
The file's last modification timestamp. This is changed by file modifications, for example, by
.BR mknod (2),
.BR truncate (2),
.BR utime (2),
and
.BR write (2)
(of more than zero bytes). Moreover, the modification time of a directory is changed by the creation or deletion of files in that directory. This field is .I not
changed for changes in owner, group, hard link count, or mode.
.PP
Not all of the Linux filesystems implement all of the timestamp fields. Some filesystems allow mounting in such a way that file and/or directory accesses do not cause an update of the
.I stx_atime
field.
(See
.IR noatime ,
.IR nodiratime ,
and
.I relatime
in
.BR mount (8),
and related information in
.BR mount (2).)
In addition,
.I stx_atime
is not updated if a file is opened with the
.BR O_NOATIME ;
see
.BR open (2).
.SS File type and mode
.PP
The
.I stx_mode
field contains the combined file type and mode. POSIX refers to the bits in this field corresponding to the mask
.B S_IFMT
(see below) as the
.IR "file type" ,
the 12 bits corresponding to the mask 07777 as the
.IR "file mode bits"
and the least significant 9 bits (0777) as the
.IR "file permission bits" .
.IP
The following mask values are defined for the file type of the .I stx_mode
field:
.in +4n
.TS
lB l l.S_IFMT 0170000 bit mask for the file type bit field
S_IFSOCK 0140000 socketS_IFLNK 0120000 symbolic linkS_IFREG 0100000 regular fileS_IFBLK 0060000 block deviceS_IFDIR 0040000 directoryS_IFCHR 0020000 character deviceS_IFIFO 0010000 FIFO
.TE
.in
.IP
Note that
.I stx_mode
has two mask flags covering it: one for the type and one for the mode bits. .PP
To test for a regular file (for example), one could write:
.nf
.in +4nstatx(AT_FDCWD, pathname, 0, STATX_BASIC_STATS, &sb);
if ((sb.stx_mode & S_IFMT) == S_IFREG) {
/* Handle regular file */
}.in
.fi
.PP
Because tests of the above form are common, additional macros are defined by POSIX to allow the test of the file type in
.I stx_mode
to be written more concisely:
.RS 4
.TS
lB l.
\fBS_ISREG\fR(m) Is it a regular file?
\fBS_ISDIR\fR(m) Is it a directory?
\fBS_ISCHR\fR(m) Is it a character device?
\fBS_ISBLK\fR(m) Is it a block device?
\fBS_ISFIFO\fR(m) Is it a FIFO (named pipe)?
\fBS_ISLNK\fR(m) Is it a symbolic link? (Not in POSIX.1-1996.)
\fBS_ISSOCK\fR(m) Is it a socket? (Not in POSIX.1-1996.)
.TE
.RE
.PP
The preceding code snippet could thus be rewritten as:
.nf
.in +4nstatx(AT_FDCWD, pathname, 0, STATX_BASIC_STATS, &sb);
if (S_ISREG(sb.stx_mode)) {
/* Handle regular file */
}.in
.fi
.PP
The definitions of most of the above file type test macros are provided if any of the following feature test macros is defined:
.BR _BSD_SOURCE
(in glibc 2.19 and earlier),
.BR _SVID_SOURCE
(in glibc 2.19 and earlier),
or
.BR _DEFAULT_SOURCE
(in glibc 2.20 and later).
In addition, definitions of all of the above macros except .BR S_IFSOCK
and
.BR S_ISSOCK ()
are provided if
.BR _XOPEN_SOURCE
is defined.
The definition of
.BR S_IFSOCK
can also be exposed by defining
.BR _XOPEN_SOURCE
with a value of 500 or greater.
The definition of
.BR S_ISSOCK ()
is exposed if any of the following feature test macros is defined:
.BR _BSD_SOURCE
(in glibc 2.19 and earlier),
.BR _DEFAULT_SOURCE
(in glibc 2.20 and later),
.BR _XOPEN_SOURCE
with a value of 500 or greater, or
.BR _POSIX_C_SOURCE
with a value of 200112L or greater.
.PP
The following mask values are defined for
the file mode component of the
.I stx_mode
field:
.in +4n
.TS
lB l l.
S_ISUID 04000 set-user-ID bit S_ISGID 02000 set-group-ID bit (see below) S_ISVTX 01000 sticky bit (see below)
S_IRWXU 00700 owner has read, write, and execute permission S_IRUSR 00400 owner has read permission S_IWUSR 00200 owner has write permission S_IXUSR 00100 owner has execute permission
S_IRWXG 00070 group has read, write, and execute permission S_IRGRP 00040 group has read permission S_IWGRP 00020 group has write permission S_IXGRP 00010 group has execute permission
S_IRWXO 00007 T{
others (not in group) have read, write, and execute permission T}
S_IROTH 00004 others have read permission S_IWOTH 00002 others have write permission S_IXOTH 00001 others have execute permission
.TE
.in
.P
The set-group-ID bit
.RB ( S_ISGID )
has several special uses.
For a directory, it indicates that BSD semantics is to be used for that directory: files created there inherit their group ID from the directory, not from the effective group ID of the creating process, and directories created there will also get the
.B S_ISGID
bit set.
For a file that does not have the group execution bit
.RB ( S_IXGRP )
set,
the set-group-ID bit indicates mandatory file/record locking. .P
The sticky bit
.RB ( S_ISVTX )
on a directory means that a file
in that directory can be renamed or deleted only by the owner of the file, by the owner of the directory, and by a privileged process.
.SH RETURN VALUE
On success, zero is returned.
On error, \-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EINVAL
Invalid flag specified in
.IR flags .
.TP
.B EACCES
Search permission is denied for one of the directories in the path prefix of
.IR pathname .
(See also
.BR path_resolution (7).)
.TP
.B EBADF
.I dirfd
is not a valid open file descriptor.
.TP
.B EFAULT
Bad address.
.TP
.B ELOOP
Too many symbolic links encountered while traversing the path. .TP
.B ENAMETOOLONG
.I pathname
is too long.
.TP
.B ENOENT
A component of
.I pathname
does not exist, or
.I pathname
is an empty string.
.TP
.B ENOMEM
Out of memory (i.e., kernel memory).
.TP
.B ENOTDIR
A component of the path prefix of
.I pathname
is not a directory or
.I pathname
is relative and
.I dirfd
is a file descriptor referring to a file other than a directory. .SH VERSIONS
.BR statx ()
was added to Linux in kernel 4.11;
library support is not yet added to glibc.
.SH SEE ALSO
.BR ls (1),
.BR stat (1),
.BR access (2),
.BR chmod (2),
.BR chown (2),
.BR readlink (2),
.BR utime (2),
.BR capabilities (7),
.BR symlink (7)
Re: statx manpage
Quoted 8 lines · David Howells
Quoted 3 lines · Christoph Hellwig
This would be great to have in 4.11 together with the initial statx implementation. But until I see documentation and testcases for statx I don't really feel comfortable reviewing anything related to it.
Well, since you asked for documentation, here's a manual page for you to review:-)
HA, ok. This came in while I was scribbling a reply to Christoph's email. I'll have a look.
Quoted 6 lines
Note that as it isn't in glibc yet, I've left out all the set-this-and-that-#define-to-make-it-appear stuff except where it is pertinent to particular constants.
I don't suppose you know where the documentation on writing xfstests tests is? xfstests-dev/doc/ only contains an old and out of date changelog.
/me usually just copies one of the newer tests and changes it. <cough>
Quoted 83 lines
David
---
'\" t
.\" Copyright (c) 1992 Drew Eckhardt ([email protected]), March 28, 1992 .\" Parts Copyright (c) 1995 Nicolai Langfeldt ([email protected]), 1/1/95 .\" and Copyright (c) 2006, 2007, 2014 Michael Kerrisk <[email protected]> .\" and Copyright (c) 2017 David Howells <[email protected]>
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END
.\"
.TH STATX 2 2017-03-07 "Linux" "Linux Programmer's Manual"
.SH NAME
statx \- Get file status (extended)
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.br
.B #include <sys/stat.h>
.br
.B #include <unistd.h>
.br
.BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
.sp
.BI "int statx(int " dirfd ", const char *" pathname ", int " flags ","
.BI " unsigned int " mask ", struct statx *" buf );
.fi
.sp
.in -4n
Feature Test Macro Requirements for glibc (see
.BRfeature_test_macros(7)):
.in
.ad l
.PD 0
.sp
.RS 4
<unknown as yet>
.RE
.PD
.ad
.SH DESCRIPTION
.PP
This function returns information about a file, storing it in the buffer pointed to by
.IR buf .
The buffer is filled in according to the following type:
.PP
.in +4n
.nf
struct statx {__u32 stx_mask; -- Mask of bits indicating filled fields __u32 stx_blksize; -- Block size for filesystem I/O __u64 stx_attributes; -- Extra file attribute indicators __u32 stx_nlink; -- Number of hard links __u32 stx_uid; -- User ID of owner __u32 stx_gid; -- Group ID of owner __u16 stx_mode; -- File type and mode __u64 stx_ino; -- Inode number __u64 stx_size; -- Total size in bytes __u64 stx_blocks; -- Number of 512B blocks allocated struct statx_timestamp stx_atime; -- Time of last access struct statx_timestamp stx_btime; -- Time of creation struct statx_timestamp stx_ctime; -- Time of last status change struct statx_timestamp stx_mtime; -- Time of last modification
Quoted 1 line
__u32stx_rdev_major; } Device number if device file
"of device file" ?
Quoted 3 lines
__u32 stx_rdev_minor; }
__u32 stx_dev_major; } Device number of containing file
__u32 stx_dev_minor; }"Device number of device containing file"?
Or perhaps just "ID of device containing file" from the stat(2) manpage?
Quoted 74 lines
};
.fi
.in
.PP
Where the timestamps are defined as:
.PP
.in +4n
.nf
structstatx_timestamp{
__s64tv_sec; -- Number of seconds before or since 1970
__s32tv_nsec; -- Number of nanoseconds before or sincetv_sec
};
.fi
.in
.PP
(Note that reserved space and padding is ommitted)
.SS
Invoking \fBstatx\fR():
.PP
To access a file's status, no permissions are required on the file itself, but in the case of
.BR statx ()
with a path, execute (search) permission is required on all of the directories in
.I pathname
that lead to the file.
.PP
.BR statx ()
uses
.IR pathname ", " dirfd " and " flags
to locate the target file in one of a variety of ways:
.TP
[*] By absolute path.
.I pathname
points to an absolute path and
.I dirfd
is ignored. The file is looked up by name, starting from the root of the filesystem as seen by the calling process.
.TP
[*] By cwd-relative path.
.I pathname
points to a relative path and
.IR dirfd " is "AT_FDCWD.
The file is looked up by name, starting from the current working directory. .TP
[*] By dir-relative path.
.I pathname
points to relative path and
.I dirfd
indicates a file descriptor pointing to a directory. The file is looked up by name, starting from the directory specified by
.IR dirfd .
.TP
[*] By file descriptor.
.IR pathname " is " NULL " and " dirfd
indicates a file descriptor. The file attached to the file descriptor is queried directly. The file descriptor may point to any type of file, not just a directory.
.PP
.I flags
can be used to influence a path-based lookup. A value for
.I flags
is constructed by OR'ing together zero or more of the following constants:
.TP
.BRAT_EMPTY_PATH" (since Linux 2.6.39)"
.\" commit65cfc6722361570bfe255698d9cd4dccaf47570d
If
.I pathname
is an empty string, operate on the file referred to by
.IR dirfd
(which may have been obtained using the
.BR open (2)
.BO_PATH
flag).
Quoted 8 lines
If
.I dirfd
is
.BRAT_FDCWD,
the call operates on the current working directory. In this case,
.I dirfd
can refer to any type of file, not just a directory.
Is (flags & AT_EMPTY_PATH) is the same as (pathname == NULL)?
Quoted 116 lines
This flag is Linux-specific; define
.B_GNU_SOURCE
.\" Before glibc 2.16, defining_ATFILE_SOURCEsufficed
to obtain its definition.
.TP
.BRAT_NO_AUTOMOUNT" (since Linux 2.6.38)"
Don't automount the terminal ("basename") component of
.I pathname
if it is a directory that is an automount point.
This allows the caller to gather attributes of an automount point (rather than the location it would mount).
This flag can be used in tools that scan directories
to prevent mass-automounting of a directory of automount points. The
.BAT_NO_AUTOMOUNT
flag has no effect if the mount point has already been mounted over. This flag is Linux-specific; define
.B_GNU_SOURCE
.\" Before glibc 2.16, defining_ATFILE_SOURCEsufficed
to obtain its definition.
.TP
.BAT_SYMLINK_NOFOLLOW
If
.I pathname
is a symbolic link, do not dereference it:
instead return information about the link itself, like
.BR lstat ().
.PP
.I flags
can also be used to control what sort of synchronisation the kernel will do when querying a file on a remote filesystem. This is done by OR'ing in one of the following values:
.TPAT_STATX_SYNC_AS_STAT
Do whatever
.BR stat ()
does. This is the default and is very much filesystem specific. .TPAT_STATX_FORCE_SYNC
Force the attributes to be synchronised with the server. This may require that a network filesystem perform a data writeback to get the timestamps correct. .TPAT_STATX_DONT_SYNC
Don't synchronise anything, but rather just take whatever the system has cached if possible. This may mean that the information returned is approximate, but, on a network filesystem, it may not involve a round trip to the server - even if no lease is held.
.PP
The
.I mask
argument to
.BR statx ()
is used to tell the kernel which fields the caller is interested in .I mask
is an OR'ed combination of the following constants:
.PP
.in +4n
.TS
lB l.STATX_TYPEWantstx_mode&S_IFMTSTATX_MODEWantstx_mode& ~S_IFMTSTATX_NLINKWantstx_nlinkSTATX_UIDWantstx_uidSTATX_GIDWantstx_gidSTATX_ATIMEWant stx_atime{,_ns}STATX_MTIMEWant stx_mtime{,_ns}STATX_CTIMEWant stx_ctime{,_ns}STATX_INOWantstx_inoSTATX_SIZEWantstx_sizeSTATX_BLOCKSWantstx_blocksSTATX_BASIC_STATS[The stuff in the normal stat struct]STATX_BTIMEWant stx_btime{,_ns}STATX_ALL[All currently available stuff]
.TE
.in
.PP
.B "Do not"
simply set
.I mask
toUINT_MAXas one or more bits may, in future, be used to specify an extension to the buffer.
.SS
The returned information
.PP
The status information for the target file is returned in the
.I statx
structure pointed to by
.IR buf .
Included in this is
.Istx_mask
which indicates what other information has been returned.
.Istx_mask
has the same format as the mask argument and bits are set in it to indicate which fields have been filled in.
.PP
It should be noted that the kernel may return fields that weren't requested and may fail to return fields that were requested, depending on what the backing filesystem supports. In either case,
.Istx_mask
will not be equal
.IR mask .
.PP
If a filesystem does not support a field or if it has an unrepresentable value (for instance, a file with an exotic type), then the mask bit corresponding to that field will be cleared in
.Istx_mask
even if the user asked for it and a dummy value will be filled in for compatibility purposes if one is available (e.g. a dummy uid and gid may be specified to mount under some circumstances).
.PP
A filesystem may also fill in fields that the caller didn't ask for if it has values for them available at no extra cost. If this happens, the corresponding bits will be set in
.IRstx_mask.
.PP
Quoted 7 lines
.\" Background: inode attributes are modified with
i_mutexheld, but .\" read bystat()without taking the mutex.
.I Note:
For performance and simplicity reasons, different fields in the .I statx
structure may contain state information from different moments during the execution of the system call.
Hm. Judging from the ext4 patch you proposed, I gather this is expected, at least in the btime case.
--D
Quoted 353 lines
For example, if
.IRstx_mode
or
.IRstx_uid
is changed by another process by calling
.BR chmod (2)
or
.BR chown (2),
.BR stat ()
might return the old
.Istx_mode
together with the new
.IRstx_uid,
or the old
.Istx_uid
together with the new
.IRstx_mode.
.PP
Apart fromstx_mask(which is described above), the fields in the .I statx
structure are:
.TP
.Istx_mode
The file type and mode. This is described in more detail below. .TP
.Istx_size
The size of the file (if it is a regular file or a symbolic link) in bytes. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte.
.TP
.Istx_blocks
The number of blocks allocated to the file on the medium, in 512-byte units. (This may be smaller than
.IRstx_size/512
when the file has holes.)
.TP
.Istx_blksize
The "preferred" blocksize for efficient filesystem I/O. (Writing to a file in smaller chunks may cause an inefficient read-modify-rewrite.)
.TP
.Istx_nlink
The number of hard links on a file.
.TP
.Istx_uid
The user ID of the file's owner.
.TP
.Istx_gid
The ID of the group that may access the file.
.TP
.IRstx_dev_major" and "stx_dev_minor
The device on which this file (inode) resides.
.TP
.IRstx_rdev_major" and "stx_rdev_minor
The device that this file (inode) represents if the file is of block or character device type.
.TP
.Istx_attributes
Further status information about the file. This consists of zero or more of the following constants OR'ed together:
.in +4n
.TS
lB l.STATX_ATTR_COMPRESSEDFile is compressed by the fsSTATX_ATTR_IMMUTABLEFile is marked immutableSTATX_ATTR_APPENDFile is append-onlySTATX_ATTR_NODUMPFile is not to be dumpedSTATX_ATTR_ENCRYPTEDFile requires key to decrypt in fs
.TE
.in
.TP
.Istx_atime
The file's last access timestamp.
This field is changed by file accesses, for example, by
.BR execve (2),
.BR mknod (2),
.BR pipe (2),
.BR utime (2),
and
.BR read (2)
(of more than zero bytes).
Other routines, such as
.BR mmap (2),
may or may not update it.
.TP
.Istx_btime
The file's creation timestamp. This is set on file creation and not changed subsequently.
.TP
.Istx_ctime
The file's last status change timestamp. This field is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.). .TP
.Istx_mtime
The file's last modification timestamp. This is changed by file modifications, for example, by
.BR mknod (2),
.BR truncate (2),
.BR utime (2),
and
.BR write (2)
(of more than zero bytes). Moreover, the modification time of a directory is changed by the creation or deletion of files in that directory. This field is .I not
changed for changes in owner, group, hard link count, or mode..PP
Not all of the Linux filesystems implement all of the timestamp fields. Some filesystems allow mounting in such a way that file and/or directory accesses do not cause an update of the
.Istx_atime
field.
(See
.IR noatime ,
.IR nodiratime ,
and
.I relatime
in
.BR mount (8),
and related information in
.BR mount (2).)
In addition,
.Istx_atime
is not updated if a file is opened with the
.BRO_NOATIME;
see
.BR open (2)..SS File type and mode
.PP
The
.Istx_mode
field contains the combined file type and mode. POSIX refers to the bits in this field corresponding to the mask
.BS_IFMT
(see below) as the
.IR "file type" ,
the 12 bits corresponding to the mask 07777 as the
.IR "file mode bits"
and the least significant 9 bits (0777) as the
.IR "file permission bits" .
.IP
The following mask values are defined for the file type of the .Istx_mode
field:
.in +4n
.TS
lB l l.S_IFMT0170000 bit mask for the file type bit field
S_IFSOCK0140000 socketS_IFLNK0120000 symbolic linkS_IFREG0100000 regular fileS_IFBLK0060000 block deviceS_IFDIR0040000 directoryS_IFCHR0020000 character deviceS_IFIFO0010000 FIFO
.TE
.in
.IP
Note that
.Istx_mode
has two mask flags covering it: one for the type and one for the mode bits. .PP
To test for a regular file (for example), one could write:
.nf
.in +4nstatx(AT_FDCWD, pathname, 0, STATX_BASIC_STATS, &sb);if ((sb.stx_mode & S_IFMT) == S_IFREG) { /* Handle regular file */ }.in
.fi
.PP
Because tests of the above form are common, additional macros are defined by POSIX to allow the test of the file type in
.Istx_mode
to be written more concisely:
.RS 4
.TS
lB l.
\fBS_ISREG\fR(m) Is it a regular file?
\fBS_ISDIR\fR(m) Is it a directory?
\fBS_ISCHR\fR(m) Is it a character device?
\fBS_ISBLK\fR(m) Is it a block device?
\fBS_ISFIFO\fR(m) Is it a FIFO (named pipe)?
\fBS_ISLNK\fR(m) Is it a symbolic link? (Not in POSIX.1-1996.)
\fBS_ISSOCK\fR(m) Is it a socket? (Not in POSIX.1-1996.)
.TE
.RE
.PP
The preceding code snippet could thus be rewritten as:.nf
.in +4nstatx(AT_FDCWD, pathname, 0, STATX_BASIC_STATS, &sb);if (S_ISREG(sb.stx_mode)) { /* Handle regular file */ }.in
.fi
.PP
The definitions of most of the above file type test macros are provided if any of the following feature test macros is defined:
.BR_BSD_SOURCE
(in glibc 2.19 and earlier),
.BR_SVID_SOURCE
(in glibc 2.19 and earlier),
or
.BR_DEFAULT_SOURCE
(in glibc 2.20 and later).
In addition, definitions of all of the above macros except .BRS_IFSOCK
and
.BRS_ISSOCK()
are provided if
.BR_XOPEN_SOURCE
is defined.
The definition of
.BRS_IFSOCK
can also be exposed by defining
.BR_XOPEN_SOURCE
with a value of 500 or greater.The definition of
.BRS_ISSOCK()
is exposed if any of the following feature test macros is defined:
.BR_BSD_SOURCE
(in glibc 2.19 and earlier),
.BR_DEFAULT_SOURCE
(in glibc 2.20 and later),
.BR_XOPEN_SOURCE
with a value of 500 or greater, or
.BR_POSIX_C_SOURCE
with a value of 200112L or greater.
.PP
The following mask values are defined for
the file mode component of the
.Istx_mode
field:
.in +4n
.TS
lB l l.S_ISUID 04000 set-user-ID bit S_ISGID 02000 set-group-ID bit (see below) S_ISVTX 01000 sticky bit (see below)S_IRWXU 00700 owner has read, write, and execute permission S_IRUSR 00400 owner has read permission S_IWUSR 00200 owner has write permission S_IXUSR 00100 owner has execute permissionS_IRWXG 00070 group has read, write, and execute permission S_IRGRP 00040 group has read permission S_IWGRP 00020 group has write permission S_IXGRP 00010 group has execute permission
S_IRWXO00007 T{
others (not in group) have read, write, and execute permission T}S_IROTH 00004 others have read permission S_IWOTH 00002 others have write permission S_IXOTH 00001 others have execute permission.TE
.in
.P
The set-group-ID bit
.RB (S_ISGID)
has several special uses.
For a directory, it indicates that BSD semantics is to be used for that directory: files created there inherit their group ID from the directory, not from the effective group ID of the creating process, and directories created there will also get the
.BS_ISGID
bit set.
For a file that does not have the group execution bit
.RB (S_IXGRP)
set,
the set-group-ID bit indicates mandatory file/record locking. .P
The sticky bit
.RB (S_ISVTX)
on a directory means that a file
in that directory can be renamed or deleted only by the owner of the file, by the owner of the directory, and by a privileged process..SH RETURN VALUE
On success, zero is returned.
On error, \-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EINVAL
Invalid flag specified in
.IR flags .
.TP
.B EACCES
Search permission is denied for one of the directories in the path prefix of
.IR pathname .
(See also
.BRpath_resolution(7).)
.TP
.B EBADF
.I dirfd
is not a valid open file descriptor.
.TP
.B EFAULT
Bad address.
.TP
.B ELOOP
Too many symbolic links encountered while traversing the path. .TP
.B ENAMETOOLONG
.I pathname
is too long.
.TP
.B ENOENT
A component of
.I pathname
does not exist, or
.I pathname
is an empty string.
.TP
.B ENOMEM
Out of memory (i.e., kernel memory).
.TP
.B ENOTDIR
A component of the path prefix of
.I pathname
is not a directory or
.I pathname
is relative and
.I dirfd
is a file descriptor referring to a file other than a directory. .SH VERSIONS
.BR statx ()
was added to Linux in kernel 4.11;
library support is not yet added to glibc.
.SH SEE ALSO
.BR ls (1),
.BR stat (1),
.BR access (2),
.BR chmod (2),
.BR chown (2),
.BR readlink (2),
.BR utime (2),
.BR capabilities (7),
.BR symlink (7)
Re: statx manpage
Quoted 8 lines · David Howells
Quoted 1 line · Darrick J. Wong
Is (flags &
AT_EMPTY_PATH) is the same as (pathname == NULL)?I'm not sure. I was wondering about that whilst writing this. The text describing the option is copied from the stat(2) manpage. It specified an empty path (presumably "") rather than NULL. I'm also not sure whether it has other ramifications.
<nod>
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
.I Note:
For performance and simplicity reasons, different fields in the .I statx
structure may contain state information from different moments during the execution of the system call.Hm. Judging from the ext4 patch you proposed, I gather this is expected, at least in the btime case.
Ugh, I put that in the wrong part -- this was supposed to be a comment about the part where the manpage states that filesystems can return more than userspace asked for. My eyes are bad at reading manpage source. :/
(Sorry for the noise.)
--D
Quoted 4 lines
This is copied from the stat(2) manpage. The comment in the source there says it's because there's no locking in the getattr path against the setattr path.
David
Re: statx manpage
In reply to Darrick J. WongQuoted 1 line · Darrick J. Wong
Is (flags &
AT_EMPTY_PATH) is the same as (pathname == NULL)?
I'm not sure. I was wondering about that whilst writing this. The text describing the option is copied from the stat(2) manpage. It specified an empty path (presumably "") rather than NULL. I'm also not sure whether it has other ramifications.
Quoted 8 lines
Quoted 5 lines
.I Note:
For performance and simplicity reasons, different fields in the .I statx
structure may contain state information from different moments during the execution of the system call.Hm. Judging from the ext4 patch you proposed, I gather this is expected, at least in the btime case.
This is copied from the stat(2) manpage. The comment in the source there says it's because there's no locking in the getattr path against the setattr path.
David
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Darrick J. Wong
statx has the ability to report inode creation times and inode flags, so hook up
di_crtimeanddi_flagsto that functionality.This would be great to have in 4.11 together with the initial statx implementation. But until I see documentation and testcases for statx I don't really feel comfortable reviewing anything related to it.
Same feeling here -- aside from cargo-culting from the proposed ext4 patch I don't have much to go on other than floating a test balloon to see if Mr. Howells responds.
(FWIW the samples/test-statx.c program reported the flags & btime.)
--D
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: statx manpage
In reply to David HowellsQuoted 114 lines · David Howells
Quoted 3 lines · Christoph Hellwig
This would be great to have in 4.11 together with the initial statx implementation. But until I see documentation and testcases for statx I don't really feel comfortable reviewing anything related to it.
Well, since you asked for documentation, here's a manual page for you to review:-)
Note that as it isn't in glibc yet, I've left out all the set-this-and-that-#define-to-make-it-appear stuff except where it is pertinent to particular constants.
I don't suppose you know where the documentation on writing xfstests tests is? xfstests-dev/doc/ only contains an old and out of date changelog.
David
---
'\" t
.\" Copyright (c) 1992 Drew Eckhardt ([email protected]), March 28, 1992 .\" Parts Copyright (c) 1995 Nicolai Langfeldt ([email protected]), 1/1/95 .\" and Copyright (c) 2006, 2007, 2014 Michael Kerrisk <[email protected]> .\" and Copyright (c) 2017 David Howells <[email protected]>
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END
.\"
.TH STATX 2 2017-03-07 "Linux" "Linux Programmer's Manual"
.SH NAME
statx \- Get file status (extended)
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.br
.B #include <sys/stat.h>
.br
.B #include <unistd.h>
.br
.BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
.sp
.BI "int statx(int " dirfd ", const char *" pathname ", int " flags ","
.BI " unsigned int " mask ", struct statx *" buf );
.fi
.sp
.in -4n
Feature Test Macro Requirements for glibc (see
.BRfeature_test_macros(7)):
.in
.ad l
.PD 0
.sp
.RS 4
<unknown as yet>
.RE
.PD
.ad
.SH DESCRIPTION
.PP
This function returns information about a file, storing it in the buffer pointed to by
.IR buf .
The buffer is filled in according to the following type:
.PP
.in +4n
.nf
struct statx {__u32 stx_mask; -- Mask of bits indicating filled fields __u32 stx_blksize; -- Block size for filesystem I/O __u64 stx_attributes; -- Extra file attribute indicators __u32 stx_nlink; -- Number of hard links __u32 stx_uid; -- User ID of owner __u32 stx_gid; -- Group ID of owner __u16 stx_mode; -- File type and mode __u64 stx_ino; -- Inode number __u64 stx_size; -- Total size in bytes __u64 stx_blocks; -- Number of 512B blocks allocated struct statx_timestamp stx_atime; -- Time of last access struct statx_timestamp stx_btime; -- Time of creation struct statx_timestamp stx_ctime; -- Time of last status change struct statx_timestamp stx_mtime; -- Time of last modification
__u32stx_rdev_major; } Device number if device file
__u32stx_rdev_minor; }
__u32stx_dev_major; } Device number of containing file
__u32stx_dev_minor; }
};
.fi
.in
.PP
Where the timestamps are defined as:
.PP
.in +4n
.nf
Quoted 8 lines
struct
statx_timestamp{
__s64tv_sec; -- Number of seconds before or since 1970
__s32tv_nsec; -- Number of nanoseconds before or sincetv_sec
};
.fi
.in
.PP
(Note that reserved space and padding is ommitted)
Do you think that not including the padding could be problematic for users?
Quoted 245 lines
.SS
Invoking \fBstatx\fR():
.PP
To access a file's status, no permissions are required on the file itself, but in the case of
.BR statx ()
with a path, execute (search) permission is required on all of the directories in
.I pathname
that lead to the file.
.PP
.BR statx ()
uses
.IR pathname ", " dirfd " and " flags
to locate the target file in one of a variety of ways:
.TP
[*] By absolute path.
.I pathname
points to an absolute path and
.I dirfd
is ignored. The file is looked up by name, starting from the root of the filesystem as seen by the calling process.
.TP
[*] By cwd-relative path.
.I pathname
points to a relative path and
.IR dirfd " is "AT_FDCWD.
The file is looked up by name, starting from the current working directory. .TP
[*] By dir-relative path.
.I pathname
points to relative path and
.I dirfd
indicates a file descriptor pointing to a directory. The file is looked up by name, starting from the directory specified by
.IR dirfd .
.TP
[*] By file descriptor.
.IR pathname " is " NULL " and " dirfd
indicates a file descriptor. The file attached to the file descriptor is queried directly. The file descriptor may point to any type of file, not just a directory.
.PP
.I flags
can be used to influence a path-based lookup. A value for
.I flags
is constructed by OR'ing together zero or more of the following constants:
.TP
.BRAT_EMPTY_PATH" (since Linux 2.6.39)"
.\" commit65cfc6722361570bfe255698d9cd4dccaf47570d
If
.I pathname
is an empty string, operate on the file referred to by
.IR dirfd
(which may have been obtained using the
.BR open (2)
.BO_PATH
flag).
If
.I dirfd
is
.BRAT_FDCWD,
the call operates on the current working directory.
In this case,
.I dirfd
can refer to any type of file, not just a directory.
This flag is Linux-specific; define
.B_GNU_SOURCE
.\" Before glibc 2.16, defining_ATFILE_SOURCEsufficed
to obtain its definition.
.TP
.BRAT_NO_AUTOMOUNT" (since Linux 2.6.38)"
Don't automount the terminal ("basename") component of
.I pathname
if it is a directory that is an automount point.
This allows the caller to gather attributes of an automount point (rather than the location it would mount).
This flag can be used in tools that scan directories
to prevent mass-automounting of a directory of automount points. The
.BAT_NO_AUTOMOUNT
flag has no effect if the mount point has already been mounted over. This flag is Linux-specific; define
.B_GNU_SOURCE
.\" Before glibc 2.16, defining_ATFILE_SOURCEsufficed
to obtain its definition.
.TP
.BAT_SYMLINK_NOFOLLOW
If
.I pathname
is a symbolic link, do not dereference it:
instead return information about the link itself, like
.BR lstat ().
.PP
.I flags
can also be used to control what sort of synchronisation the kernel will do when querying a file on a remote filesystem. This is done by OR'ing in one of the following values:
.TPAT_STATX_SYNC_AS_STAT
Do whatever
.BR stat ()
does. This is the default and is very much filesystem specific. .TPAT_STATX_FORCE_SYNC
Force the attributes to be synchronised with the server. This may require that a network filesystem perform a data writeback to get the timestamps correct. .TPAT_STATX_DONT_SYNC
Don't synchronise anything, but rather just take whatever the system has cached if possible. This may mean that the information returned is approximate, but, on a network filesystem, it may not involve a round trip to the server - even if no lease is held.
.PP
The
.I mask
argument to
.BR statx ()
is used to tell the kernel which fields the caller is interested in .I mask
is an OR'ed combination of the following constants:
.PP
.in +4n
.TS
lB l.STATX_TYPEWantstx_mode&S_IFMTSTATX_MODEWantstx_mode& ~S_IFMTSTATX_NLINKWantstx_nlinkSTATX_UIDWantstx_uidSTATX_GIDWantstx_gidSTATX_ATIMEWant stx_atime{,_ns}STATX_MTIMEWant stx_mtime{,_ns}STATX_CTIMEWant stx_ctime{,_ns}STATX_INOWantstx_inoSTATX_SIZEWantstx_sizeSTATX_BLOCKSWantstx_blocksSTATX_BASIC_STATS[The stuff in the normal stat struct]STATX_BTIMEWant stx_btime{,_ns}STATX_ALL[All currently available stuff]
.TE
.in
.PP
.B "Do not"
simply set
.I mask
toUINT_MAXas one or more bits may, in future, be used to specify an extension to the buffer.
.SS
The returned information
.PP
The status information for the target file is returned in the
.I statx
structure pointed to by
.IR buf .
Included in this is
.Istx_mask
which indicates what other information has been returned.
.Istx_mask
has the same format as the mask argument and bits are set in it to indicate which fields have been filled in.
.PP
It should be noted that the kernel may return fields that weren't requested and may fail to return fields that were requested, depending on what the backing filesystem supports. In either case,
.Istx_mask
will not be equal
.IR mask .
.PP
If a filesystem does not support a field or if it has an unrepresentable value (for instance, a file with an exotic type), then the mask bit corresponding to that field will be cleared in
.Istx_mask
even if the user asked for it and a dummy value will be filled in for compatibility purposes if one is available (e.g. a dummy uid and gid may be specified to mount under some circumstances).
.PP
A filesystem may also fill in fields that the caller didn't ask for if it has values for them available at no extra cost. If this happens, the corresponding bits will be set in
.IRstx_mask.
.PP.\" Background: inode attributes are modified with
i_mutexheld, but .\" read bystat()without taking the mutex.
.I Note:
For performance and simplicity reasons, different fields in the .I statx
structure may contain state information from different moments during the execution of the system call.
For example, if
.IRstx_mode
or
.IRstx_uid
is changed by another process by calling
.BR chmod (2)
or
.BR chown (2),
.BR stat ()
might return the old
.Istx_mode
together with the new
.IRstx_uid,
or the old
.Istx_uid
together with the new
.IRstx_mode.
.PP
Apart fromstx_mask(which is described above), the fields in the .I statx
structure are:
.TP
.Istx_mode
The file type and mode. This is described in more detail below. .TP
.Istx_size
The size of the file (if it is a regular file or a symbolic link) in bytes. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte.
.TP
.Istx_blocks
The number of blocks allocated to the file on the medium, in 512-byte units. (This may be smaller than
.IRstx_size/512
when the file has holes.)
.TP
.Istx_blksize
The "preferred" blocksize for efficient filesystem I/O. (Writing to a file in smaller chunks may cause an inefficient read-modify-rewrite.)
.TP
.Istx_nlink
The number of hard links on a file.
.TP
.Istx_uid
The user ID of the file's owner.
.TP
.Istx_gid
The ID of the group that may access the file.
.TP
.IRstx_dev_major" and "stx_dev_minor
The device on which this file (inode) resides.
.TP
.IRstx_rdev_major" and "stx_rdev_minor
The device that this file (inode) represents if the file is of block or character device type.
.TP
Quoted 8 lines
.I
stx_attributes
Further status information about the file. This consists of zero or more of the following constants OR'ed together:
.in +4n
.TS
lB l.STATX_ATTR_COMPRESSEDFile is compressed by the fsSTATX_ATTR_IMMUTABLEFile is marked immutable
This definition is circular... Maybe "File cannot be changed once closed"?
Quoted 1 line
STATX_ATTR_APPENDFile is append-only
This is also circular. Maybe "file can only be written after .B stx_size"?
Quoted 1 line
STATX_ATTR_NODUMPFile is not to be dumped
This one is also circular. Maybe "not to be included in backups"?
Quoted 103 lines
STATX_ATTR_ENCRYPTEDFile requires key to decrypt in fs
.TE
.in
.TP
.Istx_atime
The file's last access timestamp.
This field is changed by file accesses, for example, by
.BR execve (2),
.BR mknod (2),
.BR pipe (2),
.BR utime (2),
and
.BR read (2)
(of more than zero bytes).
Other routines, such as
.BR mmap (2),
may or may not update it.
.TP
.Istx_btime
The file's creation timestamp. This is set on file creation and not changed subsequently.
.TP
.Istx_ctime
The file's last status change timestamp. This field is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.). .TP
.Istx_mtime
The file's last modification timestamp. This is changed by file modifications, for example, by
.BR mknod (2),
.BR truncate (2),
.BR utime (2),
and
.BR write (2)
(of more than zero bytes). Moreover, the modification time of a directory is changed by the creation or deletion of files in that directory. This field is .I not
changed for changes in owner, group, hard link count, or mode..PP
Not all of the Linux filesystems implement all of the timestamp fields. Some filesystems allow mounting in such a way that file and/or directory accesses do not cause an update of the
.Istx_atime
field.
(See
.IR noatime ,
.IR nodiratime ,
and
.I relatime
in
.BR mount (8),
and related information in
.BR mount (2).)
In addition,
.Istx_atime
is not updated if a file is opened with the
.BRO_NOATIME;
see
.BR open (2)..SS File type and mode
.PP
The
.Istx_mode
field contains the combined file type and mode. POSIX refers to the bits in this field corresponding to the mask
.BS_IFMT
(see below) as the
.IR "file type" ,
the 12 bits corresponding to the mask 07777 as the
.IR "file mode bits"
and the least significant 9 bits (0777) as the
.IR "file permission bits" .
.IP
The following mask values are defined for the file type of the .Istx_mode
field:
.in +4n
.TS
lB l l.S_IFMT0170000 bit mask for the file type bit field
S_IFSOCK0140000 socketS_IFLNK0120000 symbolic linkS_IFREG0100000 regular fileS_IFBLK0060000 block deviceS_IFDIR0040000 directoryS_IFCHR0020000 character deviceS_IFIFO0010000 FIFO
.TE
.in
.IP
Note that
.Istx_mode
has two mask flags covering it: one for the type and one for the mode bits. .PP
To test for a regular file (for example), one could write:
.nf
.in +4nstatx(AT_FDCWD, pathname, 0, STATX_BASIC_STATS, &sb);
Quoted 3 lines
if ((sb.stx_mode & S_IFMT) == S_IFREG) {
/* Handle regular file */
}Two notes on these two examples:
- users unfamiliar with statx() may benefit from seeing STATX_TYPE used here instead of STATX_BASIC_STATS
- the check should also look for the presence of STATX_TYPE in the returned stx_mask to ensure it is valid before use?
To test whether a path is a regular file (for example), one could write:
.nf
.in +4n
rc = statx(AT_FDCWD, pathname, 0, STATX_TYPE, &stx);
if (stx.stx_mask & STATX_TYPE && S_ISREG(sb.stx_mode)) {
/* Handle regular file */
}Quoted 4 lines
Because tests of the above form are common, additional macros are defined by POSIX to allow the test of the file type in
.Istx_mode
to be written more concisely:
Should this all just reference the existing stat(2) man page instead of duplicating the whole contents here? This is spending a lot of space discussing the stx_mode field which could be avoided.
Quoted 159 lines
.RS 4
.TS
lB l.
\fBS_ISREG\fR(m) Is it a regular file?
\fBS_ISDIR\fR(m) Is it a directory?
\fBS_ISCHR\fR(m) Is it a character device?
\fBS_ISBLK\fR(m) Is it a block device?
\fBS_ISFIFO\fR(m) Is it a FIFO (named pipe)?
\fBS_ISLNK\fR(m) Is it a symbolic link? (Not in POSIX.1-1996.)
\fBS_ISSOCK\fR(m) Is it a socket? (Not in POSIX.1-1996.)
.TE
.RE
.PP
The preceding code snippet could thus be rewritten as:.nf
.in +4nstatx(AT_FDCWD, pathname, 0, STATX_BASIC_STATS, &sb);if (S_ISREG(sb.stx_mode)) { /* Handle regular file */ }.in
.fi
.PP
The definitions of most of the above file type test macros are provided if any of the following feature test macros is defined:
.BR_BSD_SOURCE
(in glibc 2.19 and earlier),
.BR_SVID_SOURCE
(in glibc 2.19 and earlier),
or
.BR_DEFAULT_SOURCE
(in glibc 2.20 and later).
In addition, definitions of all of the above macros except .BRS_IFSOCK
and
.BRS_ISSOCK()
are provided if
.BR_XOPEN_SOURCE
is defined.
The definition of
.BRS_IFSOCK
can also be exposed by defining
.BR_XOPEN_SOURCE
with a value of 500 or greater.The definition of
.BRS_ISSOCK()
is exposed if any of the following feature test macros is defined:
.BR_BSD_SOURCE
(in glibc 2.19 and earlier),
.BR_DEFAULT_SOURCE
(in glibc 2.20 and later),
.BR_XOPEN_SOURCE
with a value of 500 or greater, or
.BR_POSIX_C_SOURCE
with a value of 200112L or greater.
.PP
The following mask values are defined for
the file mode component of the
.Istx_mode
field:
.in +4n
.TS
lB l l.S_ISUID 04000 set-user-ID bit S_ISGID 02000 set-group-ID bit (see below) S_ISVTX 01000 sticky bit (see below)S_IRWXU 00700 owner has read, write, and execute permission S_IRUSR 00400 owner has read permission S_IWUSR 00200 owner has write permission S_IXUSR 00100 owner has execute permissionS_IRWXG 00070 group has read, write, and execute permission S_IRGRP 00040 group has read permission S_IWGRP 00020 group has write permission S_IXGRP 00010 group has execute permission
S_IRWXO00007 T{
others (not in group) have read, write, and execute permission T}S_IROTH 00004 others have read permission S_IWOTH 00002 others have write permission S_IXOTH 00001 others have execute permission.TE
.in
.P
The set-group-ID bit
.RB (S_ISGID)
has several special uses.
For a directory, it indicates that BSD semantics is to be used for that directory: files created there inherit their group ID from the directory, not from the effective group ID of the creating process, and directories created there will also get the
.BS_ISGID
bit set.
For a file that does not have the group execution bit
.RB (S_IXGRP)
set,
the set-group-ID bit indicates mandatory file/record locking. .P
The sticky bit
.RB (S_ISVTX)
on a directory means that a file
in that directory can be renamed or deleted only by the owner of the file, by the owner of the directory, and by a privileged process..SH RETURN VALUE
On success, zero is returned.
On error, \-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EINVAL
Invalid flag specified in
.IR flags .
.TP
.B EACCES
Search permission is denied for one of the directories in the path prefix of
.IR pathname .
(See also
.BRpath_resolution(7).)
.TP
.B EBADF
.I dirfd
is not a valid open file descriptor.
.TP
.B EFAULT
Bad address.
.TP
.B ELOOP
Too many symbolic links encountered while traversing the path. .TP
.B ENAMETOOLONG
.I pathname
is too long.
.TP
.B ENOENT
A component of
.I pathname
does not exist, or
.I pathname
is an empty string.
.TP
.B ENOMEM
Out of memory (i.e., kernel memory).
.TP
.B ENOTDIR
A component of the path prefix of
.I pathname
is not a directory or
.I pathname
is relative and
.I dirfd
Quoted 8 lines
is a file descriptor referring to a file other than a directory. .SH VERSIONS
.BR statx ()
was added to Linux in kernel 4.11;
library support is not yet added to glibc.
.SH SEE ALSO
.BR ls (1),
.BR stat (1),
Maybe stat(2) ? :-)
Quoted 7 lines
.BR access (2),
.BR chmod (2),
.BR chown (2),
.BR readlink (2),
.BR utime (2),
.BR capabilities (7),
.BR symlink (7)
Cheers, Andreas
Re: statx manpage
In reply to Darrick J. WongQuoted 6 lines · Darrick J. Wong
Quoted 2 lines
Quoted 2 lines
Hm. Judging from the ext4 patch you proposed, I gather this is expected, at least in the btime case.
Ugh, I put that in the wrong part -- this was supposed to be a comment about the part where the manpage states that filesystems can return more than userspace asked for.
In that case, sort of. You could just ask for STATX_TYPE | STATX_MODE, for example, but the kernel is perfectly at liberty to add STATX_MTIME, STATX_SIZE, STATX_INO, etc. even if it doesn't add STATX_BTIME as well.
Quoted 1 line
My eyes are bad at reading manpage source. :/
I know what you mean.
David
Re: statx manpage
In reply to David HowellsQuoted 4 lines · David Howells
.fi
.in
.PP
(Note that reserved space and padding is ommitted)
ommitted => omitted
Quoted 2 lines
.TP
.BRAT_EMPTY_PATH" (since Linux 2.6.39)"
...
Quoted 2 lines
.TP
.BRAT_NO_AUTOMOUNT" (since Linux 2.6.38)"
Given that statx is just being added now in 4.11, saying "since Linux 2.6.39" and "since Linux 2.6.38" for these flags seems unneeded.
Quoted 7 lines
The
.I mask
argument to
.BR statx ()
is used to tell the kernel which fields the caller is interested in .I mask
is an OR'ed combination of the following constants:
Missing a period between "interested in" and "mask".
Quoted 5 lines
.B "Do not"
simply set
.I mask
toUINT_MAXas one or more bits may, in future, be used to specify an extension to the buffer.
"in future" => "in the future".
Quoted 14 lines
.I Note:
For performance and simplicity reasons, different fields in the .I statx
structure may contain state information from different moments during the execution of the system call.
For example, if
.IRstx_mode
or
.IRstx_uid
is changed by another process by calling
.BR chmod (2)
or
.BR chown (2),
.BR stat ()
Quoted 8 lines
might return the old
.Istx_mode
together with the new
.IRstx_uid,
or the old
.Istx_uid
together with the new
.IRstx_mode.
This example is confusing because chmod() doesn't change st_uid, and chown() doesn't ordinarily change st_mode. A better example would be that if chown() is used to change both the owner and group, it's possible that statx() would return the new owner paired with the old group, or the new group paired with the old owner. Or, the new owner and group could be observed before the new ctime. Also, it seems this note belongs in a BUGS section of the man page, since it is a bug.
Quoted 5 lines
.SH ERRORS
.TP
.B EINVAL
Invalid flag specified in
.IR flags .
Actually, the behavior when specifying invalid flags differs depending on whether a path is specified.
If a path is specified, then statx() fails with EINVAL if unrecognized flags are specified.
However, the behavior differs when no path is specified. For example, the the following call with invalid flags succeeds:
statx(fd, NULL, 0xFFFF0000, 0, &stbuf);
I think this is a bug, and it should be fixed by applying the same 'flags' validation regardless of whether a path is specified.
Quoted 6 lines
.B ENOENT
A component of
.I pathname
does not exist, or
.I pathname
is an empty string.
is an empty string and AT_EMPTY_PATH was not specified in flags.
Quoted 3 lines
.SH SEE ALSO
.BR ls (1),
.BR stat (1),
Shouldn't this link to stat (2), not stat (1)?
- Eric
Re: statx manpage
In reply to David HowellsQuoted 9 lines · David Howells
Quoted 3 lines · Christoph Hellwig
This would be great to have in 4.11 together with the initial statx implementation. But until I see documentation and testcases for statx I don't really feel comfortable reviewing anything related to it.
Well, since you asked for documentation, here's a manual page for you to review:-)
Quoted 6 lines
Note that as it isn't in glibc yet, I've left out all the set-this-and-that-#define-to-make-it-appear stuff except where it is pertinent to particular constants.
I don't suppose you know where the documentation on writing xfstests tests is? xfstests-dev/doc/ only contains an old and out of date changelog.
There's a "ADDING TO THE FSQA SUITE" section in README file, basically it's telling you to use './new' script to generate new test template. So based on what type of new test you're going to create, you could run:
./new generic # new generic test
./new xfs # new xfs test
./new ext4 # new ext4 test
./new shared # new shared test
...
It finds the first free seq number and creates test template and a default .out file in tests/<type> dir and add a new entry in tests/<type>/group file. You could just edit the template and update the .out file with expected output from the test run.
E.g. currently 416 is the first free seq number in generic tests, ./new generic will create
./tests/generic/416
./tests/generic/416.out
I think statx test should be a new generic test.
Thanks,
Eryu
Re: statx manpage
In reply to Andreas DilgerQuoted 3 lines · Andreas Dilger
Quoted 1 line
(Note that reserved space and padding is ommitted)
Do you think that not including the padding could be problematic for users?
Interesting question. Do you think it would be? I don't see why it should be a problem, since they shouldn't be touching it anyway. Also, the stat(2) manpage also gives the same warning and omits padding and doesn't seem to have been amended.
But if you would prefer, I can put it back.
The only reason I can really see for explicitly including it is to say that this is where future extensions will go.
Quoted 3 lines
Quoted 1 line
STATX_ATTR_IMMUTABLEFile is marked immutable...
Quoted 1 line
STATX_ATTR_APPENDFile is append-only
I should copy the definitions in chattr(1).
Quoted 7 lines
To test whether a path is a regular file (for example), one could write:
.nf
.in +4n
rc = statx(AT_FDCWD, pathname, 0, STATX_TYPE, &stx);
if (stx.stx_mask & STATX_TYPE && S_ISREG(sb.stx_mode)) {
/* Handle regular file */
}Good idea.
Quoted 8 lines
Quoted 4 lines
Because tests of the above form are common, additional macros are defined by POSIX to allow the test of the file type in
.Istx_mode
to be written more concisely:Should this all just reference the existing stat(2) man page instead of duplicating the whole contents here? This is spending a lot of space discussing the
stx_modefield which could be avoided.
Possibly. On the other hand, it means that everything you need to refer to is in one page from the user's PoV. I'm not sure what the best policy on this is.
If I do defer to stat(2), I do need to make some sort of note that the examples are different and the field name is stx_mask, not st_mask.
David
Re: statx manpage
In reply to Eric BiggersQuoted 23 lines · Eric Biggers
Quoted 14 lines
.I Note:
For performance and simplicity reasons, different fields in the .I statx
structure may contain state information from different moments during the execution of the system call.
For example, if
.IRstx_mode
or
.IRstx_uid
is changed by another process by calling
.BR chmod (2)
or
.BR chown (2),
.BR stat ()Quoted 8 lines
might return the old
.Istx_mode
together with the new
.IRstx_uid,
or the old
.Istx_uid
together with the new
.IRstx_mode.
Quoted 2 lines
This example is confusing because
chmod()doesn't changest_uid, andchown()doesn't ordinarily changest_mode.
Doesn't chown() clear the S_ISUID and S_ISGID flags?
Quoted 4 lines
A better example would be that if
chown()is used to change both the owner and group, it's possible thatstatx()would return the new owner paired with the old group, or the new group paired with the old owner. Or, the new owner and group could be observed before the new ctime.
This is copied more or less verbatim from stat(2), so what you said applies there too.
Quoted 2 lines
Also, it seems this note belongs in a BUGS section of the man page, since it is a bug.
No, it's not a bug, exactly. It's a design decision. It might be worth adding an AT_STAT_LOCK flag to synchronise against attribute setting, but it will cost you something in terms of performance - and even then, over a network filesystem it might not achieve anything.
Quoted 8 lines
Quoted 5 lines
.SH ERRORS
.TP
.B EINVAL
Invalid flag specified in
.IR flags .Actually, the behavior when specifying invalid flags differs depending on whether a path is specified.
Good point. Should I reject AT_EMPTY_PATH, AT_NO_AUTOMOUNT and AT_SYMLINK_NOFOLLOW if pathname is NULL, I wonder?
Quoted 8 lines
Quoted 6 lines
.B ENOENT
A component of
.I pathname
does not exist, or
.I pathname
is an empty string.is an empty string and
AT_EMPTY_PATHwas not specified in flags.
That needs fixing in stat(2) also.
Quoted 5 lines
Quoted 3 lines
.SH SEE ALSO
.BR ls (1),
.BR stat (1),Shouldn't this link to stat (2), not stat (1)?
Depends whether stat(1) ends up using statx() or not. I can take it out for now.
David
Re: statx manpage
In reply to David HowellsQuoted 11 lines · David Howells
Quoted 3 lines · Andreas Dilger
Quoted 1 line
(Note that reserved space and padding is ommitted)
Do you think that not including the padding could be problematic for users?
Interesting question. Do you think it would be? I don't see why it should be a problem, since they shouldn't be touching it anyway. Also, the stat(2) manpage also gives the same warning and omits padding and doesn't seem to have been amended.
Quoted 5 lines
But if you would prefer, I can put it back.
The only reason I can really see for explicitly including it is to say that this is where future extensions will go.
It seems like we really ought to have 2 statx manpages:
A small statx(2) manpage that describes the kernel<->userland interface (showing structs with padding), and then the "real" statx(3) manpage that shows the glibc userland API.
The kernel<->userland one could be very small, and just say "This is not the function you're interested in. Look at statx(3) for the C library interface.", similar to what readdir(2) does.
Quoted 15 lines
Quoted 4 lines
Quoted 1 line
STATX_ATTR_IMMUTABLEFile is marked immutable...
Quoted 1 line
STATX_ATTR_APPENDFile is append-onlyI should copy the definitions in chattr(1).
Quoted 7 lines
To test whether a path is a regular file (for example), one could write: .nf .in +4n rc = statx(AT_FDCWD, pathname, 0, STATX_TYPE, &stx); if (stx.stx_mask & STATX_TYPE && S_ISREG(sb.stx_mode)) { /* Handle regular file */ }
Quoted 1 line
Good idea.
Note that & and && have similar precedence, IIRC, so you probably want to wrap that flag check in parenthesis.
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Because tests of the above form are common, additional macros are defined by POSIX to allow the test of the file type in
.Istx_mode
to be written more concisely:Should this all just reference the existing stat(2) man page instead of duplicating the whole contents here? This is spending a lot of space discussing the
stx_modefield which could be avoided.
Quoted 7 lines
Possibly. On the other hand, it means that everything you need to refer to is in one page from the user's PoV. I'm not sure what the best policy on this is.
If I do defer to stat(2), I do need to make some sort of note that the examples are different and the field name is
stx_mask, notst_mask.
If the plan is to eventually (in some far away future) to deprecate stat(), then we probably don't want this manpage to refer to it as a canonical source of information. I say duplicate it here.
It might also not hurt to consider updating the stat(2) manpage with a NOTE that points to the statx manpage as well.
Signature · 1 line
Jeff Layton <[email protected]>
Re: statx manpage
Quoted 10 lines · Eryu Guan
There's a "ADDING TO THE FSQA SUITE" section in README file, basically it's telling you to use './new' script to generate new test template. So based on what type of new test you're going to create, you could run:
./new generic # new generic test
./new xfs # new xfs test
./new ext4 # new ext4 test
./new shared # new shared test
...
Quoted 4 lines
It finds the first free seq number and creates test template and a default .out file in tests/<type> dir and add a new entry in tests/<type>/group file. You could just edit the template and update the .out file with expected output from the test run.
Yes, I'd spotted the ./new script, but it's not as simple as that since shell scripts can't call system calls directly.
David
Re: statx manpage
Quoted 12 lines · David Howells
Quoted 10 lines · Eryu Guan
There's a "ADDING TO THE FSQA SUITE" section in README file, basically it's telling you to use './new' script to generate new test template. So based on what type of new test you're going to create, you could run:
./new generic # new generic test
./new xfs # new xfs test
./new ext4 # new ext4 test
./new shared # new shared test
...
Quoted 7 lines
Quoted 4 lines
It finds the first free seq number and creates test template and a default .out file in tests/<type> dir and add a new entry in tests/<type>/group file. You could just edit the template and update the .out file with expected output from the test run.
Yes, I'd spotted the ./new script, but it's not as simple as that since shell scripts can't call system calls directly.
A normal way we take for fstests is adding new syscall support to xfs_io first, then writing new tests based on it, as some other new syscalls/utilities do, e.g. set|get_encpolicy were added to xfs_io in January to set|get encryption policy for ext4 encryption testing.
Thanks,
Eryu
Re: statx manpage
In reply to David HowellsQuoted 12 lines · David Howells
Quoted 10 lines · Eryu Guan
There's a "ADDING TO THE FSQA SUITE" section in README file, basically it's telling you to use './new' script to generate new test template. So based on what type of new test you're going to create, you could run:
./new generic # new generic test
./new xfs # new xfs test
./new ext4 # new ext4 test
./new shared # new shared test
...
Quoted 7 lines
Quoted 4 lines
It finds the first free seq number and creates test template and a default .out file in tests/<type> dir and add a new entry in tests/<type>/group file. You could just edit the template and update the .out file with expected output from the test run.
Yes, I'd spotted the ./new script, but it's not as simple as that since shell scripts can't call system calls directly.
Probably best to place a program in src/ so that xfstests can make the raw syscalls early while we wait for glibc to invent a wrapper.
--D
Quoted 2 lines
David
Re: statx manpage
In reply to Eryu GuanQuoted 4 lines · Eryu Guan
A normal way we take for fstests is adding new syscall support to
xfs_iofirst, then writing new tests based on it, as some other new syscalls/utilities do, e.g. set|get_encpolicy were added toxfs_ioin January to set|get encryption policy for ext4 encryption testing.
Please add this to the docs.
Thanks,
David
Re: statx manpage
In reply to Darrick J. WongQuoted 2 lines · Darrick J. Wong
Probably best to place a program in src/ so that xfstests can make the raw syscalls early while we wait for glibc to invent a wrapper.
Іn general don't invent new programs if we can avoid it and add a statx command to xfs_io, that all the tests can be built around.
Re: statx manpage
In reply to David HowellsQuoted 6 lines · David Howells
Quoted 3 lines
This example is confusing because
chmod()doesn't changest_uid, andchown()doesn't ordinarily changest_mode.Doesn't
chown()clear theS_ISUIDandS_ISGIDflags?
It can, but it's not a straightforward example.
Quoted 6 lines
No, it's not a bug, exactly. It's a design decision. It might be worth adding an
AT_STAT_LOCKflag to synchronise against attribute setting, but it will cost you something in terms of performance - and even then, over a network filesystem it might not achieve anything.
Well, regardless of whether people want to fix it or not, I do think it's a bug. Currently even the update of a timestamp is non-atomic, since that involves updating both tv_sec and tv_nsec. Therefore, stat() might return the new tv_sec along with the old tv_nsec, or vice versa. This can cause some very strange behavior, such as two successively observed timestamps going backwards in time.
I expect that historically people haven't complained enough for this to be worthwhile to fix. But in theory I think it could be fixed with little performance loss by protecting all the stat data with a sequence count, similar to how reads of i_size are made atomic on 32-bit platforms by using i_size_seqcount.
Quoted 4 lines
Good point. Should I reject
AT_EMPTY_PATH,AT_NO_AUTOMOUNTandAT_SYMLINK_NOFOLLOWif pathname is NULL, I wonder?
It could be argued either way, but I was thinking those particular flags should just be ignored, as they have known meanings but simply aren't relevant. It could also cause confusion for
statx(dfd, "", AT_EMPTY_PATH, 0, buffer)
to succeed but for
statx(dfd, NULL, AT_EMPTY_PATH, 0, buffer)
to fail (for example).
- Eric
Re: statx manpage
In reply to Jeff LaytonQuoted 10 lines · Jeff Layton
Quoted 9 lines · David Howells
Quoted 7 lines · Andreas Dilger
To test whether a path is a regular file (for example), one could write: .nf .in +4n rc = statx(AT_FDCWD, pathname, 0, STATX_TYPE, &stx); if (stx.stx_mask & STATX_TYPE && S_ISREG(sb.stx_mode)) { /* Handle regular file */ }
Quoted 4 lines
Quoted 1 line
Good idea.
Note that & and && have similar precedence, IIRC, so you probably want to wrap that flag check in parenthesis.
They're actually pretty far apart. & is priority 8 and && is priority 11. But the fact that you thought they were similar shows that most of us don't really know what C's operator precedence is (beyond + and *) and we should err on the side of clarity by using the unnecessary parens.
Quoted 3 lines
If the plan is to eventually (in some far away future) to deprecate
stat(), then we probably don't want this manpage to refer to it as a canonical source of information. I say duplicate it here.
We haven't even deprecated select() in favour of poll() ... indeed, pselect() was added. I can't imagine stat() ever being deprecated.
Re: statx manpage
Quoted 13 lines · Matthew Wilcox
Quoted 12 lines · Jeff Layton
Quoted 10 lines · David Howells
Quoted 7 lines · Andreas Dilger
To test whether a path is a regular file (for example), one could write: .nf .in +4n rc = statx(AT_FDCWD, pathname, 0, STATX_TYPE, &stx); if (stx.stx_mask & STATX_TYPE && S_ISREG(sb.stx_mode)) { /* Handle regular file */ }Good idea.
Quoted 8 lines
Quoted 2 lines
Note that & and && have similar precedence, IIRC, so you probably want to wrap that flag check in parenthesis.
They're actually pretty far apart. & is priority 8 and && is priority 11. But the fact that you thought they were similar shows that most of us don't really know what C's operator precedence is (beyond + and *) and we should err on the side of clarity by using the unnecessary parens.
Ahh, good to know. My rules are generally: multiplication and division come before addition and subtraction, and put parenthesis around everything else. :)
Quoted 6 lines
Quoted 3 lines
If the plan is to eventually (in some far away future) to deprecate
stat(), then we probably don't want this manpage to refer to it as a canonical source of information. I say duplicate it here.We haven't even deprecated
select()in favour ofpoll()... indeed,pselect()was added. I can't imaginestat()ever being deprecated.
Ok, deprecated is probably the wrong choice of words. You're correct that we'll never be able to fully rip it out just due to the volume of old programs that use it.
My thinking is that statx will come to supplant stat in newer code, and stat will eventually become a "legacy" syscall. Typically we don't want to have to refer to "legacy" manpages for canonical info in new interfaces. If anything we may want to remove that info from stat(2) manpage and have it refer to statx(2) for it.
Signature · 1 line
Jeff Layton <[email protected]>
Re: statx manpage
In reply to David HowellsQuoted 9 lines · David Howells
STATX_ALL[All currently available stuff]
.TE
.in
.PP
.B "Do not"
simply set
.I mask
toUINT_MAXas one or more bits may, in future, be used to specify an extension to the buffer.
To clarify, will an "extension to the buffer" be an increase in the size of struct statx? I think it would have to be, otherwise programs filling a struct statx with STATX_ALL would start breaking as soon as they're rebuilt with the new value of STATX_ALL, no? Or would these "extension to the buffer" bits not be added to STATX_ALL ...?
And I don't suppose there's anything we can do to stop programs from asking for mask bits that haven't been defined yet, then breaking later if they happen to be defined as "extensions"? Maybe adding an extra "buffer size" argument to the syscall?
I'm concerned that the idea of "extensions" isn't well thought out, and in practice we'll just be stuck with the current struct size (256 bytes) forever.
- Eric
Re: statx manpage
Quoted 14 lines · Eric Biggers
Quoted 9 lines · David Howells
STATX_ALL[All currently available stuff]
.TE
.in
.PP
.B "Do not"
simply set
.I mask
toUINT_MAXas one or more bits may, in future, be used to specify an extension to the buffer.
Quoted 5 lines
To clarify, will an "extension to the buffer" be an increase in the size of struct statx? I think it would have to be, otherwise programs filling a struct statx with
STATX_ALLwould start breaking as soon as they're rebuilt with the new value ofSTATX_ALL, no? Or would these "extension to the buffer" bits not be added toSTATX_ALL...?
The value of STATX_ALL would match the size of struct statx in the header at compilation time, so this would always be consistent.
Quoted 5 lines
And I don't suppose there's anything we can do to stop programs from asking for mask bits that haven't been defined yet, then breaking later if they happen to be defined as "extensions"? Maybe adding an extra "buffer size" argument to the syscall?
You can't stop applications from doing dumb things, like asking to read 1MB of data into a buffer that is only 512KB in size. That will also work fine as long as the application only reads a files smaller than 512KB.
Similarly, if the statx() API says that the STATX_ALL mask is the list of currently-supported bits, but the app asks for more bits than it allocates a buffer for, there isn't much that the kernel can do.
Quoted 2 lines
I'm concerned that the idea of "extensions" isn't well thought out, and in practice we'll just be stuck with the current struct size (256 bytes) forever.
The extensions work exactly as they should - the client sets bits for fields that it needs (and by definition it shouldn't ask for anything that it doesn't understand), and the kernel masks this down to the bits that it understands.
If the client asks for more bits than the kernel understands, it is likely a
newer application on an older kernel, and it will only get back the fields
that the kernel understands. The reverse (client asking for fewer bits than
the kernel understands) is normal behaviour for this interface. The kernel should only fill in fields that the client requested and for which there is space in the struct.
Cheers, Andreas
Re: statx manpage
In reply to Eric BiggersQuoted 11 lines · Eric Biggers
Quoted 9 lines · David Howells
STATX_ALL[All currently available stuff]
.TE
.in
.PP
.B "Do not"
simply set
.I mask
toUINT_MAXas one or more bits may, in future, be used to specify an extension to the buffer.
Quoted 2 lines
To clarify, will an "extension to the buffer" be an increase in the size of struct statx?
Yes. I can make that more explicit, say perhaps "... specify an extension to the size of the buffer".
Quoted 4 lines
I think it would have to be, otherwise programs filling a struct statx with
STATX_ALLwould start breaking as soon as they're rebuilt with the new value ofSTATX_ALL, no? Or would these "extension to the buffer" bits not be added toSTATX_ALL...?
It would have to work that way. I can put this in a comment for future guidance in the kernel header file if you'd prefer.
Quoted 3 lines
And I don't suppose there's anything we can do to stop programs from asking for mask bits that haven't been defined yet, then breaking later if they happen to be defined as "extensions"?
If someone decides not to read the documentation, one could argue they get what they deserve.
Quoted 1 line
Maybe adding an extra "buffer size" argument to the syscall?
This idea has already been rejected.
Quoted 2 lines
I'm concerned that the idea of "extensions" isn't well thought out, and in practice we'll just be stuck with the current struct size (256 bytes) forever.
One or more bits (probably just one) are tentatively reserved to indicate that the buffer is now bigger. How much bigger I cannot say at this point, not knowing the circumstances yet that will require the extension.
David
Re: statx manpage
Quoted 43 lines · Andreas Dilger
Quoted 14 lines · Eric Biggers
Quoted 9 lines · David Howells
STATX_ALL[All currently available stuff]
.TE
.in
.PP
.B "Do not"
simply set
.I mask
toUINT_MAXas one or more bits may, in future, be used to specify an extension to the buffer.Quoted 5 lines
To clarify, will an "extension to the buffer" be an increase in the size of struct statx? I think it would have to be, otherwise programs filling a struct statx with
STATX_ALLwould start breaking as soon as they're rebuilt with the new value ofSTATX_ALL, no? Or would these "extension to the buffer" bits not be added toSTATX_ALL...?The value of
STATX_ALLwould match the size of struct statx in the header at compilation time, so this would always be consistent.Quoted 5 lines
And I don't suppose there's anything we can do to stop programs from asking for mask bits that haven't been defined yet, then breaking later if they happen to be defined as "extensions"? Maybe adding an extra "buffer size" argument to the syscall?
You can't stop applications from doing dumb things, like asking to read 1MB of data into a buffer that is only 512KB in size. That will also work fine as long as the application only reads a files smaller than 512KB.
Similarly, if the
statx()API says that theSTATX_ALLmask is the list of currently-supported bits, but the app asks for more bits than it allocates a buffer for, there isn't much that the kernel can do.Quoted 2 lines
I'm concerned that the idea of "extensions" isn't well thought out, and in practice we'll just be stuck with the current struct size (256 bytes) forever.
The extensions work exactly as they should - the client sets bits for fields that it needs (and by definition it shouldn't ask for anything that it doesn't understand), and the kernel masks this down to the bits that it understands.
Quoted 6 lines
If the client asks for more bits than the kernel understands, it is likely a newer application on an older kernel, and it will only get back the fields that the kernel understands. The reverse (client asking for fewer bits than the kernel understands) is normal behaviour for this interface. The kernel should only fill in fields that the client requested and for which there is space in the struct.
During the statx session at LSF last week I asked if filesystems ought to fill in fields that weren't asked for (btime, specifically) and the impression I got was that it's ok to go ahead and fill out fields that weren't asked for if we already have the data.
Since statx backends can do that, they'll have to check the structure size, and not rely on "you asked for this field so we assume that you allocated enough memory in userspace to hold it".
Or we could just shift the precedent now -- programs only get the information they ask for, and in asking for it we assume that we can write to that part of the buffer. Frankly I'd prefer that behavior (see the XFS statx patch), but I don't own the interface. :)
--D
Quoted 7 lines
Cheers, Andreas
Re: statx manpage
Quoted 4 lines · Darrick J. Wong
During the statx session at LSF last week I asked if filesystems ought to fill in fields that weren't asked for (btime, specifically) and the impression I got was that it's ok to go ahead and fill out fields that weren't asked for if we already have the data.
Yes. The filesystem may return data that it wasn't asked for.
Quoted 3 lines
Since statx backends can do that, they'll have to check the structure size, and not rely on "you asked for this field so we assume that you allocated enough memory in userspace to hold it".
Kind of. I'm assuming that the extension fields will be in struct kstat and can be set directly by the filesystem unconditionally, and the core can choose whether to copy them or not. However, assuming that one of the mask bits is reserved to indicate a buffer extension, this will be made available to the fs to let the fs know whether it's pointless to return it.
However, at the moment I have no extensions to play with.
Would it help you if I marked one of the mask bits reserved for this purpose?
Quoted 4 lines
Or we could just shift the precedent now -- programs only get the information they ask for, and in asking for it we assume that we can write to that part of the buffer. Frankly I'd prefer that behavior (see the XFS statx patch), but I don't own the interface. :)
That means a filesystem can't simply return non-basic data unconditionally if possible. I prefer letting it do so if it doesn't incur any extra I/O overheads.
David
Re: statx manpage
Quoted 3 lines · David Howells
That means a filesystem can't simply return non-basic data unconditionally if possible. I prefer letting it do so if it doesn't incur any extra I/O overheads.
This seems like it will lead to userspace expecting certain fields to just be there, and a lot harder to properly verify for tests. Which btw we all need for these odd behaviors. If we can't get them any time soon (e.g. before -rc6) I think we'll simply have to revert statx instead of leaving this untested mess in the tree.
Re: statx manpage
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · David Howells
That means a filesystem can't simply return non-basic data unconditionally if possible. I prefer letting it do so if it doesn't incur any extra I/O overheads.
This seems like it will lead to userspace expecting certain fields to just be there, and a lot harder to properly verify for tests. Which btw we all need for these odd behaviors. If we can't get them any time soon (e.g. before -rc6) I think we'll simply have to revert statx instead of leaving this untested mess in the tree.
Have you reviewed the manpage yet?
David
Re: statx manpage
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
Quoted 3 lines · David Howells
That means a filesystem can't simply return non-basic data unconditionally if possible. I prefer letting it do so if it doesn't incur any extra I/O overheads.
This seems like it will lead to userspace expecting certain fields to just be there, and a lot harder to properly verify for tests. Which btw we all need for these odd behaviors. If we can't get them any time soon (e.g. before -rc6) I think we'll simply have to revert statx instead of leaving this untested mess in the tree.
I don't think so.
I think we just have to clearly document that that will not be the case. If they really expect the field to be there, then they need to set the bit in the "want" mask -- it's really as simple as that.
Signature · 1 line
Jeff Layton <[email protected]>
PATCH 1/1 Add initial batch of statx() LTP tests
In reply to Christoph HellwigQuoted 9 lines · Christoph Hellwig
Quoted 3 lines
That means a filesystem can't simply return non-basic data unconditionally if possible. I prefer letting it do so if it doesn't incur any extra I/O overheads.
This seems like it will lead to userspace expecting certain fields to just be there, and a lot harder to properly verify for tests. Which btw we all need for these odd behaviors. If we can't get them any time soon (e.g. before -rc6) I think we'll simply have to revert statx instead of leaving this untested mess in the tree.
Here you go. First batch of tests. Please review - and test:-)
David
---
commit fff886ec7ee53aa266a12d9dbb2825952fa1adb9
Author: David Howells <[email protected]> Date: Mon Mar 27 21:42:32 2017 +0100
Add initial batch of statx() LTP tests
Add an initial batch of statx() tests for LTP, deriving them from all of the stat(), fstat() and lstat() tests.
Note that since statx() is not yet implemented in glibc, a header file is added to provide the missing system call bits.
include/linux-statx.h new file +158 -0
@@ -0,0 +1,158 @@ +#ifndef _EXTENDED_LINUX_STAT_H +#define _EXTENDED_LINUX_STAT_H + +#include <sys/stat.h> +#include <linux/types.h> +#include <linux/stat.h> + +#ifndef STATX_TYPE + +#ifndef __NR_statx +#if defined(__x86_64__) +#define __NR_statx 332 +#elif defined(__i386__) +#define __NR_statx 383 +#endif +#endif /* !__NR_statx */ + +/* +* Timestamp structure for the timestamps in struct statx. +* +* tv_sec holds the number of seconds before (negative) or after (positive) +* 00:00:00 1st January 1970 UTC. +* +* tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is +* negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time. +* +* Note that if both tv_sec and tv_nsec are non-zero, then the two values must +* either be both positive or both negative. +* +* __reserved is held in case we need a yet finer resolution. +*/ +struct statx_timestamp { +__s64 tv_sec; +__s32 tv_nsec; +__s32 __reserved; +}; + +/* +* Structures for the extended file attribute retrieval system call +* (statx()). +* +* The caller passes a mask of what they're specifically interested in as a +* parameter to statx(). What statx() actually got will be indicated in +* st_mask upon return. +* +* For each bit in the mask argument: +* +* - if the datum is not supported: +* +* - the bit will be cleared, and +* +* - the datum will be set to an appropriate fabricated value if one is +* available (eg. CIFS can take a default uid and gid), otherwise +* +* - the field will be cleared; +* +* - otherwise, if explicitly requested: +* +* - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is +* set or if the datum is considered out of date, and +* +* - the field will be filled in and the bit will be set; +* +* - otherwise, if not requested, but available in approximate form without any +* effort, it will be filled in anyway, and the bit will be set upon return +* (it might not be up to date, however, and no attempt will be made to +* synchronise the internal state first); +* +* - otherwise the field and the bit will be cleared before returning. +* +* Items in STATX_BASIC_STATS may be marked unavailable on return, but they +* will have values installed for compatibility purposes so that stat() and +* co. can be emulated in userspace. +*/ +struct statx { +/* 0x00 */ +__u32 stx_mask;/* What results were written [uncond] */ +__u32 stx_blksize;/* Preferred general I/O size [uncond] */ +__u64 stx_attributes;/* Flags conveying information about the file [uncond] */ +/* 0x10 */ +__u32 stx_nlink;/* Number of hard links */ +__u32 stx_uid;/* User ID of owner */ +__u32 stx_gid;/* Group ID of owner */ +__u16 stx_mode;/* File mode */ +__u16 __spare0[1 ]; +/* 0x20 */ +__u64 stx_ino;/* Inode number */ +__u64 stx_size;/* File size */ +__u64 stx_blocks;/* Number of 512-byte blocks allocated */ +__u64 __spare1[1 ]; +/* 0x40 */ +struct statx_timestamp stx_atime;/* Last access time */ +struct statx_timestamp stx_btime;/* File creation time */ +struct statx_timestamp stx_ctime;/* Last attribute change time */ +struct statx_timestamp stx_mtime;/* Last data modification time */ +/* 0x80 */ +__u32 stx_rdev_major;/* Device ID of special file [if bdev/cdev] */ +__u32 stx_rdev_minor; +__u32 stx_dev_major;/* ID of device containing file [uncond] */ +__u32 stx_dev_minor; +/* 0x90 */ +__u64 __spare2[14 ];/* Spare space for future expansion */ +/* 0x100 */ +}; + +/* +* Flags to be stx_mask +* +* Query request/result mask for statx() and struct statx::stx_mask. +* +* These bits should be set in the mask argument of statx() to request +* particular items when calling statx(). +*/ +#define STATX_TYPE 0x00000001U/* Want/got stx_mode & S_IFMT */ +#define STATX_MODE 0x00000002U/* Want/got stx_mode & ~S_IFMT */ +#define STATX_NLINK 0x00000004U/* Want/got stx_nlink */ +#define STATX_UID 0x00000008U/* Want/got stx_uid */ +#define STATX_GID 0x00000010U/* Want/got stx_gid */ +#define STATX_ATIME 0x00000020U/* Want/got stx_atime */ +#define STATX_MTIME 0x00000040U/* Want/got stx_mtime */ +#define STATX_CTIME 0x00000080U/* Want/got stx_ctime */ +#define STATX_INO 0x00000100U/* Want/got stx_ino */ +#define STATX_SIZE 0x00000200U/* Want/got stx_size */ +#define STATX_BLOCKS 0x00000400U/* Want/got stx_blocks */ +#define STATX_BASIC_STATS 0x000007ffU/* The stuff in the normal stat struct */ +#define STATX_BTIME 0x00000800U/* Want/got stx_btime */ +#define STATX_ALL 0x00000fffU/* All currently supported flags */ + +/* +* Attributes to be found in stx_attributes +* +* These give information about the features or the state of a file that might +* be of use to ordinary userspace programs such as GUIs or ls rather than +* specialised tools. +* +* Note that the flags marked [I] correspond to generic FS_IOC_FLAGS +* semantically. Where possible, the numerical value is picked to correspond +* also. +*/ +#define STATX_ATTR_COMPRESSED 0x00000004/* [I] File is compressed by the fs */ +#define STATX_ATTR_IMMUTABLE 0x00000010/* [I] File is marked immutable */ +#define STATX_ATTR_APPEND 0x00000020/* [I] File is append-only */ +#define STATX_ATTR_NODUMP 0x00000040/* [I] File is not to be dumped */ +#define STATX_ATTR_ENCRYPTED 0x00000800/* [I] File requires key to decrypt in fs */ + +#define STATX_ATTR_AUTOMOUNT 0x00001000/* Dir: Automount trigger */ + + +static inline +ssize_t statx (int dfd,const char *filename,unsigned flags, +unsigned int mask,struct statx *buffer) +{ +return syscall (__NR_statx, dfd, filename, flags, mask, buffer); +} + +#endif /* STATX_TYPE */ + +#endif /* _EXTENDED_LINUX_STAT_H */
include/tst_fs.h +7 -0
@@ -201,4 +201,11 @@ static inline int tst_dir_is_empty(void (*cleanup)(void), const char *name, int }#endif +/* +* Compare the contents of a statx struct with that of a stat struct and check +* that they're the same. +*/ +struct statx ; +int tst_cmp_statx (const struct statx *stx,const struct stat *st); +#endif /* TST_FS_H__ */
lib/tst_cmp_stat.c new file +73 -0
73 lines not on this page · raw message
testcases/kernel/syscalls/statx/Makefile new file +26 -0
@@ -0,0 +1,26 @@ +# +# Copyright (c) International Business Machines Corp., 2001 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(abs_srcdir)/../utils/newer_64.mk + +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/statx/statx01.c new file +166 -0
166 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx02.c new file +243 -0
243 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx03.c new file +388 -0
388 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx05.c new file +206 -0
206 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx06.c new file +355 -0
355 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx11.c new file +179 -0
179 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx12.c new file +164 -0
164 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx13.c new file +163 -0
163 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx15.c new file +248 -0
248 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx21.c new file +215 -0
215 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx22.c new file +192 -0
192 lines not on this page · raw message
testcases/kernel/syscalls/statx/statx23.c new file +136 -0
136 lines not on this page · raw message
Re: [PATCH] Add initial batch of statx() LTP tests
Quoted 6 lines · David Howells
Quoted 4 lines · Christoph Hellwig
Quoted 3 lines
That means a filesystem can't simply return non-basic data unconditionally if possible. I prefer letting it do so if it doesn't incur any extra I/O overheads.
Quoted 7 lines
Quoted 5 lines
This seems like it will lead to userspace expecting certain fields to just be there, and a lot harder to properly verify for tests. Which btw we all need for these odd behaviors. If we can't get them any time soon (e.g. before -rc6) I think we'll simply have to revert statx instead of leaving this untested mess in the tree.
Here you go. First batch of tests. Please review - and test:-)
ltp is a trainwreck. Please send xfstests test like for all other file system functionality. You're really trying to make it as hard as possible for fs developers, don't you?
Re: [PATCH] Add initial batch of statx() LTP tests
Quoted 3 lines · Christoph Hellwig
ltp is a trainwreck. Please send xfstests test like for all other file system functionality. You're really trying to make it as hard as possible for fs developers, don't you?
Sorry, Christoph, but, in my opinion, xfstests is in worse shape than LTP. It's not self-contained (the code to make statx available seems to have to be added to xfsprogs) and it's practically undocumented. LTP, on the other hand, is pretty easy to modify.
David
Re: statx manpage
In reply to Jeff LaytonQuoted 13 lines · Jeff Layton
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · David Howells
That means a filesystem can't simply return non-basic data unconditionally if possible. I prefer letting it do so if it doesn't incur any extra I/O overheads.
This seems like it will lead to userspace expecting certain fields to just be there, and a lot harder to properly verify for tests. Which btw we all need for these odd behaviors. If we can't get them any time soon (e.g. before -rc6) I think we'll simply have to revert statx instead of leaving this untested mess in the tree.
Quoted 5 lines
I don't think so.
I think we just have to clearly document that that will not be the case. If they really expect the field to be there, then they need to set the bit in the "want" mask -- it's really as simple as that.
It would be my preference to only return attributes which are explicitly requested (Lustre won't return fields for which the bit is not set), but there was a request for this behaviour in NFS I recall.
That said, there are also flags for "lazy" attributes for NFS. I wonder if it is enough to pass AT_STATX_DONT_SYNC and request STATX_SIZE | STATX_CTIME, or whatever NFS is worried about, and return the client-local version of the attributes?
I guess the real question is what an application is going to do with fields that it didn't actually request, and has no way to know if they are valid or contain garbage?
Cheers, Andreas
Re: statx manpage
Quoted 24 lines · Andreas Dilger
Quoted 13 lines · Jeff Layton
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · David Howells
That means a filesystem can't simply return non-basic data unconditionally if possible. I prefer letting it do so if it doesn't incur any extra I/O overheads.
This seems like it will lead to userspace expecting certain fields to just be there, and a lot harder to properly verify for tests. Which btw we all need for these odd behaviors. If we can't get them any time soon (e.g. before -rc6) I think we'll simply have to revert statx instead of leaving this untested mess in the tree.
Quoted 5 lines
I don't think so.
I think we just have to clearly document that that will not be the case. If they really expect the field to be there, then they need to set the bit in the "want" mask -- it's really as simple as that.
It would be my preference to only return attributes which are explicitly requested (Lustre won't return fields for which the bit is not set), but there was a request for this behaviour in NFS I recall.
Quoted 9 lines
That said, there are also flags for "lazy" attributes for NFS. I wonder if it is enough to pass
AT_STATX_DONT_SYNCand requestSTATX_SIZE|STATX_CTIME, or whatever NFS is worried about, and return the client-local version of the attributes?I guess the real question is what an application is going to do with fields that it didn't actually request, and has no way to know if they are valid or contain garbage?
You certainly do have a way to know if they're valid. You can check the stx_mask.
Basically, if you request something, you're guaranteed to get it, or an error. If you don't request it, you might get it but you had better check the stx_mask before assuming that you did.
TBQH though, I don't _really_ expect userland to use this that often.
The main reason I'm arguing for this is for simplicity of the in-kernel implementations. Having to check each bit in the mask before filling out its field is cumbersome. It's much simpler to fill out the kstat struct with what you have and set the stx_mask unconditionally.
It's also not 100% clear to me how the unrequested fields would be set if we don't allow this. zeroing them out seems like the obvious thing to do, but that doesn't really provide any guarantee that someone won't try to interpret it as valid.
Signature · 1 line
Jeff Layton <[email protected]>
Re: statx manpage
In reply to Jeff LaytonQuoted 3 lines · Jeff Layton
I think we just have to clearly document that that will not be the case. If they really expect the field to be there, then they need to set the bit in the "want" mask -- it's really as simple as that.
If the usual local file systems set it but say NFS doesn't I will very much expect that people don't set the flag and create buggy programs a lot. An API that doesn't give you more than you ask for is a lot more obvious.
Re: statx manpage
In reply to David HowellsQuoted 6 lines · David Howells
Quoted 3 lines · Christoph Hellwig
This would be great to have in 4.11 together with the initial statx implementation. But until I see documentation and testcases for statx I don't really feel comfortable reviewing anything related to it.
Quoted 6 lines
Well, since you asked for documentation, here's a manual page for you to review:-)
Note that as it isn't in glibc yet, I've left out all the set-this-and-that-#define-to-make-it-appear stuff except where it is pertinent to particular constants.
I think we'll initially need to make this a section 2 page as libcs will take a while to pick things up. But in the end Michael will have to decide. Adding linux-man to the Cc list so that the right people are involved.
Quoting the rendered page below:
Quoted 1 line
Invoking
statx():
This is an odd header for a man page. Usually this would start as
DESCRIPTION
(in bold).
Quoted 1 line
[*] By absolute path.
Odd way to enumerate in a man page - I'll leave it to the linux-man regulars to point out the right way, because I don't know it off-hand.
Quoted 1 line
AT_EMPTY_PATH (since Linux 2.6.39)
All these have been there since statx was added, so we can remove the annotation.
Quoted 1 line
STATX_BASIC_STATS[The stuff in the normal stat struct]
Please enumerate the actual fields.
Quoted 1 line
STATX_ALL[All currently available stuff]
How about "All currently available fields"
Re: statx manpage
Quoted 9 lines · Christoph Hellwig
Quoting the rendered page below:
Quoted 1 line
Invoking
statx():This is an odd header for a man page. Usually this would start as
DESCRIPTION
(in bold).
Yes, I know. But it seems to make more sense this way round. Putting the struct definition before the description of how to access it means that I can refer to it in the definitions of the flags that you OR into the mask and means you get to the struct much faster. Maybe I should put it under the SYNOPSIS section?
Quoted 4 lines
Quoted 1 line
[*] By absolute path.
Odd way to enumerate in a man page - I'll leave it to the linux-man regulars to point out the right way, because I don't know it off-hand.
Me neither.
Quoted 4 lines
Quoted 1 line
AT_EMPTY_PATH (since Linux 2.6.39)All these have been there since statx was added, so we can remove the annotation.
You're not the first to note this. I've already taken that out.
Quoted 3 lines
Quoted 1 line
STATX_BASIC_STATS[The stuff in the normal stat struct]Please enumerate the actual fields.
They're enumerated immediately prior. I've changed it to:
STATX_BASIC_STATS [All of the above]
Quoted 3 lines
Quoted 1 line
STATX_ALL[All currently available stuff]How about "All currently available fields"
Sure.
David
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html