History

statx: Add a system call to make enhanced file info available

Add a system call to make extended file information available, including file creation and some attribute flags where available through the underlying filesystem. The getattr inode operation is altered to take two additional arguments: a u32 request_mask and an unsigned int flags that indicate the synchronisation mode. This change is propagated to the vfs_getattr*() function. Functions like vfs_stat() are now inline wrappers around new functions vfs_statx() and vfs_statx_fd() to reduce stack usage. ======== OVERVIEW ======== The idea was initially proposed as a set of xattrs that could be retrieved with getxattr(), but the general preference proved to be for a new syscall with an extended stat structure. A number of requests were gathered for features to be included. The following have been included: (1) Make the fields a consistent size on all arches and make them large. (2) Spare space, request flags and information flags are provided for future expansion. (3) Better support for the y2038 problem [Arnd Bergmann] (tv_sec is an __s64). (4) Creation time: The SMB protocol carries the creation time, which could be exported by Samba, which will in turn help CIFS make use of FS-Cache as that can be used for coherency data (stx_btime). This is also specified in NFSv4 as a recommended attribute and could be exported by NFSD [Steve French]. (5) Lightweight stat: Ask for just those details of interest, and allow a netfs (such as NFS) to approximate anything not of interest, possibly without going to the server [Trond Myklebust, Ulrich Drepper, Andreas Dilger] (AT_STATX_DONT_SYNC). (6) Heavyweight stat: Force a netfs to go to the server, even if it thinks its cached attributes are up to date [Trond Myklebust] (AT_STATX_FORCE_SYNC). And the following have been left out for future extension: (7) Data version number: Could be used by userspace NFS servers [Aneesh Kumar]. Can also be used to modify fill_post_wcc() in NFSD which retrieves i_version directly, but has just called vfs_getattr(). It could get it from the kstat struct if it used vfs_xgetattr() instead. (There's disagreement on the exact semantics of a single field, since not all filesystems do this the same way). (8) BSD stat compatibility: Including more fields from the BSD stat such as creation time (st_btime) and inode generation number (st_gen) [Jeremy Allison, Bernd Schubert]. (9) Inode generation number: Useful for FUSE and userspace NFS servers [Bernd Schubert]. (This was asked for but later deemed unnecessary with the open-by-handle capability available and caused disagreement as to whether it's a security hole or not). (10) Extra coherency data may be useful in making backups [Andreas Dilger]. (No particular data were offered, but things like last backup timestamp, the data version number and the DOS archive bit would come into this category). (11) Allow the filesystem to indicate what it can/cannot provide: A filesystem can now say it doesn't support a standard stat feature if that isn't available, so if, for instance, inode numbers or UIDs don't exist or are fabricated locally... (This requires a separate system call - I have an fsinfo() call idea for this). (12) Store a 16-byte volume ID in the superblock that can be returned in struct xstat [Steve French]. (Deferred to fsinfo). (13) Include granularity fields in the time data to indicate the granularity of each of the times (NFSv4 time_delta) [Steve French]. (Deferred to fsinfo). (14) FS_IOC_GETFLAGS value. These could be translated to BSD's st_flags. Note that the Linux IOC flags are a mess and filesystems such as Ext4 define flags that aren't in linux/fs.h, so translation in the kernel may be a necessity (or, possibly, we provide the filesystem type too). (Some attributes are made available in stx_attributes, but the general feeling was that the IOC flags were to ext[234]-specific and shouldn't be exposed through statx this way). (15) Mask of features available on file (eg: ACLs, seclabel) [Brad Boyer, Michael Kerrisk]. (Deferred, probably to fsinfo. Finding out if there's an ACL or seclabal might require extra filesystem operations). (16) Femtosecond-resolution timestamps [Dave Chinner]. (A __reserved field has been left in the statx_timestamp struct for this - if there proves to be a need). (17) A set multiple attributes syscall to go with this. =============== NEW SYSTEM CALL =============== The new system call is: int ret = statx(int dfd, const char *filename, unsigned int flags, unsigned int mask, struct statx *buffer); The dfd, filename and flags parameters indicate the file to query, in a similar way to fstatat(). There is no equivalent of lstat() as that can be emulated with statx() by passing AT_SYMLINK_NOFOLLOW in flags. There is also no equivalent of fstat() as that can be emulated by passing a NULL filename to statx() with the fd of interest in dfd. Whether or not statx() synchronises the attributes with the backing store can be controlled by OR'ing a value into the flags argument (this typically only affects network filesystems): (1) AT_STATX_SYNC_AS_STAT tells statx() to behave as stat() does in this respect. (2) AT_STATX_FORCE_SYNC will require a network filesystem to synchronise its attributes with the server - which might require data writeback to occur to get the timestamps correct. (3) AT_STATX_DONT_SYNC will suppress synchronisation with the server in a network filesystem. The resulting values should be considered approximate. mask is a bitmask indicating the fields in struct statx that are of interest to the caller. The user should set this to STATX_BASIC_STATS to get the basic set returned by stat(). It should be noted that asking for more information may entail extra I/O operations. buffer points to the destination for the data. This must be 256 bytes in size. ====================== MAIN ATTRIBUTES RECORD ====================== The following structures are defined in which to return the main attribute set: struct statx_timestamp { __s64 tv_sec; __s32 tv_nsec; __s32 __reserved; }; struct statx { __u32 stx_mask; __u32 stx_blksize; __u64 stx_attributes; __u32 stx_nlink; __u32 stx_uid; __u32 stx_gid; __u16 stx_mode; __u16 __spare0[1]; __u64 stx_ino; __u64 stx_size; __u64 stx_blocks; __u64 __spare1[1]; struct statx_timestamp stx_atime; struct statx_timestamp stx_btime; struct statx_timestamp stx_ctime; struct statx_timestamp stx_mtime; __u32 stx_rdev_major; __u32 stx_rdev_minor; __u32 stx_dev_major; __u32 stx_dev_minor; __u64 __spare2[14]; }; The defined bits in request_mask and stx_mask are: STATX_TYPE Want/got stx_mode & S_IFMT STATX_MODE Want/got stx_mode & ~S_IFMT STATX_NLINK Want/got stx_nlink STATX_UID Want/got stx_uid STATX_GID Want/got stx_gid STATX_ATIME Want/got stx_atime{,_ns} STATX_MTIME Want/got stx_mtime{,_ns} STATX_CTIME Want/got stx_ctime{,_ns} STATX_INO Want/got stx_ino STATX_SIZE Want/got stx_size STATX_BLOCKS Want/got stx_blocks STATX_BASIC_STATS [The stuff in the normal stat struct] STATX_BTIME Want/got stx_btime{,_ns} STATX_ALL [All currently available stuff] stx_btime is the file creation time, stx_mask is a bitmask indicating the data provided and __spares*[] are where as-yet undefined fields can be placed. Time fields are structures with separate seconds and nanoseconds fields plus a reserved field in case we want to add even finer resolution. Note that times will be negative if before 1970; in such a case, the nanosecond fields will also be negative if not zero. The bits defined in the stx_attributes field convey information about a file, how it is accessed, where it is and what it does. The following attributes map to FS_*_FL flags and are the same numerical value: STATX_ATTR_COMPRESSED File is compressed by the fs STATX_ATTR_IMMUTABLE File is marked immutable STATX_ATTR_APPEND File is append-only STATX_ATTR_NODUMP File is not to be dumped STATX_ATTR_ENCRYPTED File requires key to decrypt in fs Within the kernel, the supported flags are listed by: KSTAT_ATTR_FS_IOC_FLAGS [Are any other IOC flags of sufficient general interest to be exposed through this interface?] New flags include: STATX_ATTR_AUTOMOUNT Object is an automount trigger These are for the use of GUI tools that might want to mark files specially, depending on what they are. Fields in struct statx come in a number of classes: (0) stx_dev_*, stx_blksize. These are local system information and are always available. (1) stx_mode, stx_nlinks, stx_uid, stx_gid, stx_[amc]time, stx_ino, stx_size, stx_blocks. These will be returned whether the caller asks for them or not. The corresponding bits in stx_mask will be set to indicate whether they actually have valid values. If the caller didn't ask for them, then they may be approximated. For example, NFS won't waste any time updating them from the server, unless as a byproduct of updating something requested. If the values don't actually exist for the underlying object (such as UID or GID on a DOS file), then the bit won't be set in the stx_mask, even if the caller asked for the value. In such a case, the returned value will be a fabrication. Note that there are instances where the type might not be valid, for instance Windows reparse points. (2) stx_rdev_*. This will be set only if stx_mode indicates we're looking at a blockdev or a chardev, otherwise will be 0. (3) stx_btime. Similar to (1), except this will be set to 0 if it doesn't exist. ======= TESTING ======= The following test program can be used to test the statx system call: samples/statx/test-statx.c Just compile and run, passing it paths to the files you want to examine. The file is built automatically if CONFIG_SAMPLES is enabled. Here's some example output. Firstly, an NFS directory that crosses to another FSID. Note that the AUTOMOUNT attribute is set because transiting this directory will cause d_automount to be invoked by the VFS. [root@andromeda ~]# /tmp/test-statx -A /warthog/data statx(/warthog/data) = 0 results=7ff Size: 4096 Blocks: 8 IO Block: 1048576 directory Device: 00:26 Inode: 1703937 Links: 125 Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041 Access: 2016-11-24 09:02:12.219699527+0000 Modify: 2016-11-17 10:44:36.225653653+0000 Change: 2016-11-17 10:44:36.225653653+0000 Attributes: 0000000000001000 (-------- -------- -------- -------- -------- -------- ---m---- --------) Secondly, the result of automounting on that directory. [root@andromeda ~]# /tmp/test-statx /warthog/data statx(/warthog/data) = 0 results=7ff Size: 4096 Blocks: 8 IO Block: 1048576 directory Device: 00:27 Inode: 2 Links: 125 Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041 Access: 2016-11-24 09:02:12.219699527+0000 Modify: 2016-11-17 10:44:36.225653653+0000 Change: 2016-11-17 10:44:36.225653653+0000

David Howells committed 9 years ago

Commit a528d351 parent bbe08c072 files · +822 −214Browse files

Unified · Split

72 files
  1. Documentation/filesystems/Locking +2 −1
  2. Documentation/filesystems/vfs.txt +2 −1
  3. arch/x86/entry/syscalls/syscall_32.tbl +1 −0
  4. arch/x86/entry/syscalls/syscall_64.tbl +1 −0
  5. drivers/base/devtmpfs.c +2 −1
  6. drivers/block/loop.c +2 −1
  7. drivers/mtd/ubi/build.c +1 −1
  8. drivers/mtd/ubi/kapi.c +1 −1
  9. drivers/staging/lustre/lustre/llite/file.c +5 −4
  10. drivers/staging/lustre/lustre/llite/llite_internal.h +2 −1
  11. fs/9p/vfs_inode.c +6 −4
  12. fs/9p/vfs_inode_dotl.c +3 −2
  13. fs/afs/inode.c +3 −5
  14. fs/afs/internal.h +1 −1
  15. fs/bad_inode.c +2 −2
  16. fs/btrfs/inode.c +3 −3
  17. fs/ceph/inode.c +3 −3
  18. fs/ceph/super.h +2 −2
  19. fs/cifs/cifsfs.h +1 −1
  20. fs/cifs/inode.c +3 −2
  21. fs/coda/coda_linux.h +1 −1
  22. fs/coda/inode.c +4 −3
  23. fs/ecryptfs/inode.c +8 −5
  24. fs/exportfs/expfs.c +2 −1
  25. fs/ext4/ext4.h +1 −2
  26. fs/ext4/inode.c +3 −3
  27. fs/f2fs/f2fs.h +2 −2
  28. fs/f2fs/file.c +3 −3
  29. fs/fat/fat.h +2 −2
  30. fs/fat/file.c +3 −2
  31. fs/fuse/dir.c +3 −3
  32. fs/gfs2/inode.c +6 −5
  33. fs/kernfs/inode.c +4 −4
  34. fs/kernfs/kernfs-internal.h +2 −2
  35. fs/libfs.c +6 −6
  36. fs/minix/inode.c +7 −4
  37. fs/minix/minix.h +1 −1
  38. fs/nfs/inode.c +7 −6
  39. fs/nfs/namespace.c +5 −4
  40. fs/nfsd/nfs4xdr.c +2 −2
  41. fs/nfsd/vfs.h +2 −1
  42. fs/ocfs2/file.c +5 −6
  43. fs/ocfs2/file.h +2 −2
  44. fs/orangefs/inode.c +6 −7
  45. fs/orangefs/orangefs-kernel.h +2 −3
  46. fs/overlayfs/copy_up.c +4 −2
  47. fs/overlayfs/dir.c +6 −4
  48. fs/overlayfs/inode.c +4 −3
  49. fs/proc/base.c +7 −5
  50. fs/proc/generic.c +3 −3
  51. fs/proc/internal.h +1 −1
  52. fs/proc/proc_net.c +3 −3
  53. fs/proc/proc_sysctl.c +3 −2
  54. fs/proc/root.c +3 −3
  55. fs/stat.c +176 −38
  56. fs/sysv/itree.c +4 −3
  57. fs/sysv/sysv.h +1 −1
  58. fs/ubifs/dir.c +3 −3
  59. fs/ubifs/ubifs.h +2 −2
  60. fs/udf/symlink.c +3 −2
  61. fs/xfs/xfs_iops.c +5 −4
  62. include/linux/fs.h +27 −8
  63. include/linux/nfs_fs.h +1 −1
  64. include/linux/stat.h +18 −6
  65. include/linux/syscalls.h +3 −0
  66. include/uapi/linux/fcntl.h +5 −0
  67. include/uapi/linux/stat.h +131 −0
  68. mm/shmem.c +3 −3
  69. samples/Kconfig +6 −0
  70. samples/Makefile +1 −1
  71. samples/statx/Makefile +10 −0
  72. samples/statx/test-statx.c +254 −0
Documentation/filesystems/Locking+2−1
@@ -58,7 +58,8 @@ prototypes: · 57 unmodified lines
5858 int (*permission) (struct inode *, int, unsigned int);
5959 int (*get_acl)(struct inode *, int);
6060 int (*setattr) (struct dentry *, struct iattr *);
61− int (*getattr) (struct vfsmount *, struct dentry *, struct kstat *);
61+ int (*getattr) (const struct path *, struct dentry *, struct kstat *,
62+ u32, unsigned int);
6263 ssize_t (*listxattr) (struct dentry *, char *, size_t);
6364 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, u64 len);
6465 void (*update_time)(struct inode *, struct timespec *, int);
Documentation/filesystems/vfs.txt+2−1
@@ -382,7 +382,8 @@ struct inode_operations { · 381 unmodified lines
382382 int (*permission) (struct inode *, int);
383383 int (*get_acl)(struct inode *, int);
384384 int (*setattr) (struct dentry *, struct iattr *);
385− int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
385+ int (*getattr) (const struct path *, struct dentry *, struct kstat *,
386+ u32, unsigned int);
386387 ssize_t (*listxattr) (struct dentry *, char *, size_t);
387388 void (*update_time)(struct inode *, struct timespec *, int);
388389 int (*atomic_open)(struct inode *, struct dentry *, struct file *,
arch/x86/entry/syscalls/syscall_32.tbl+1−0
@@ -389,3 +389,4 @@ · 388 unmodified lines
389389 380 i386 pkey_mprotect sys_pkey_mprotect
390390 381 i386 pkey_alloc sys_pkey_alloc
391391 382 i386 pkey_free sys_pkey_free
392+383 i386 statx sys_statx
arch/x86/entry/syscalls/syscall_64.tbl+1−0
@@ -338,6 +338,7 @@ · 337 unmodified lines
338338 329 common pkey_mprotect sys_pkey_mprotect
339339 330 common pkey_alloc sys_pkey_alloc
340340 331 common pkey_free sys_pkey_free
341+332 common statx sys_statx
341342
342343 #
343344 # x32-specific system call numbers start at 512 to avoid cache impact
drivers/base/devtmpfs.c+2−1
@@ -309,7 +309,8 @@ static int handle_remove(const char *nodename, struct device *dev) · 308 unmodified lines
309309 if (d_really_is_positive(dentry)) {
310310 struct kstat stat;
311311 struct path p = {.mnt = parent.mnt, .dentry = dentry};
312− err = vfs_getattr(&p, &stat);
312+ err = vfs_getattr(&p, &stat, STATX_TYPE | STATX_MODE,
313+ AT_STATX_SYNC_AS_STAT);
313314 if (!err && dev_mynode(dev, d_inode(dentry), &stat)) {
314315 struct iattr newattrs;
315316 /*
drivers/block/loop.c+2−1
@@ -1175,7 +1175,8 @@ loop_get_status(struct loop_device *lo, struct loop_info64 *info) · 1174 unmodified lines
11751175
11761176 if (lo->lo_state != Lo_bound)
11771177 return -ENXIO;
1178− error = vfs_getattr(&file->f_path, &stat);
1178+ error = vfs_getattr(&file->f_path, &stat,
1179+ STATX_INO, AT_STATX_SYNC_AS_STAT);
11791180 if (error)
11801181 return error;
11811182 memset(info, 0, sizeof(*info));
drivers/mtd/ubi/build.c+1−1
@@ -1159,7 +1159,7 @@ static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev) · 1158 unmodified lines
11591159 if (err)
11601160 return ERR_PTR(err);
11611161
1162− err = vfs_getattr(&path, &stat);
1162+ err = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT);
11631163 path_put(&path);
11641164 if (err)
11651165 return ERR_PTR(err);
drivers/mtd/ubi/kapi.c+1−1
@@ -314,7 +314,7 @@ struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) · 313 unmodified lines
314314 if (error)
315315 return ERR_PTR(error);
316316
317− error = vfs_getattr(&path, &stat);
317+ error = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT);
318318 path_put(&path);
319319 if (error)
320320 return ERR_PTR(error);
drivers/staging/lustre/lustre/llite/file.c+5−4
@@ -2952,15 +2952,16 @@ static int ll_inode_revalidate(struct dentry *dentry, __u64 ibits) · 2951 unmodified lines
29522952 return rc;
29532953 }
29542954
2955−int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat)
2955+int ll_getattr(const struct path *path, struct kstat *stat,
2956+ u32 request_mask, unsigned int flags)
29562957 {
2957− struct inode *inode = d_inode(de);
2958+ struct inode *inode = d_inode(path->dentry);
29582959 struct ll_sb_info *sbi = ll_i2sbi(inode);
29592960 struct ll_inode_info *lli = ll_i2info(inode);
29602961 int res;
29612962
2962− res = ll_inode_revalidate(de, MDS_INODELOCK_UPDATE |
2963− MDS_INODELOCK_LOOKUP);
2963+ res = ll_inode_revalidate(path->dentry,
2964+ MDS_INODELOCK_UPDATE | MDS_INODELOCK_LOOKUP);
29642965 ll_stats_ops_tally(sbi, LPROC_LL_GETATTR, 1);
29652966
29662967 if (res)
drivers/staging/lustre/lustre/llite/llite_internal.h+2−1
@@ -750,7 +750,8 @@ int ll_file_open(struct inode *inode, struct file *file); · 749 unmodified lines
750750 int ll_file_release(struct inode *inode, struct file *file);
751751 int ll_release_openhandle(struct inode *, struct lookup_intent *);
752752 int ll_md_real_close(struct inode *inode, fmode_t fmode);
753−int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
753+int ll_getattr(const struct path *path, struct kstat *stat,
754+ u32 request_mask, unsigned int flags);
754755 struct posix_acl *ll_get_acl(struct inode *inode, int type);
755756 int ll_migrate(struct inode *parent, struct file *file, int mdtidx,
756757 const char *name, int namelen);
fs/9p/vfs_inode.c+6−4
@@ -1047,16 +1047,18 @@ done: · 1046 unmodified lines
10471047
10481048 /**
10491049 * v9fs_vfs_getattr - retrieve file metadata
1050− * @mnt: mount information
1051− * @dentry: file to get attributes on
1050+ * @path: Object to query
10521051 * @stat: metadata structure to populate
1052+ * @request_mask: Mask of STATX_xxx flags indicating the caller's interests
1053+ * @flags: AT_STATX_xxx setting
10531054 *
10541055 */
10551056
10561057 static int
1057−v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1058− struct kstat *stat)
1058+v9fs_vfs_getattr(const struct path *path, struct kstat *stat,
1059+ u32 request_mask, unsigned int flags)
10591060 {
1061+ struct dentry *dentry = path->dentry;
10601062 struct v9fs_session_info *v9ses;
10611063 struct p9_fid *fid;
10621064 struct p9_wstat *st;
fs/9p/vfs_inode_dotl.c+3−2
@@ -468,9 +468,10 @@ error: · 467 unmodified lines
468468 }
469469
470470 static int
471−v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
472− struct kstat *stat)
471+v9fs_vfs_getattr_dotl(const struct path *path, struct kstat *stat,
472+ u32 request_mask, unsigned int flags)
473473 {
474+ struct dentry *dentry = path->dentry;
474475 struct v9fs_session_info *v9ses;
475476 struct p9_fid *fid;
476477 struct p9_stat_dotl *st;
fs/afs/inode.c+3−5
@@ -375,12 +375,10 @@ error_unlock: · 374 unmodified lines
375375 /*
376376 * read the attributes of an inode
377377 */
378−int afs_getattr(struct vfsmount *mnt, struct dentry *dentry,
379− struct kstat *stat)
378+int afs_getattr(const struct path *path, struct kstat *stat,
379+ u32 request_mask, unsigned int query_flags)
380380 {
381− struct inode *inode;
382−
383− inode = d_inode(dentry);
381+ struct inode *inode = d_inode(path->dentry);
384382
385383 _enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation);
386384
fs/afs/internal.h+1−1
@@ -533,7 +533,7 @@ extern struct inode *afs_iget(struct super_block *, struct key *, · 532 unmodified lines
533533 struct afs_callback *);
534534 extern void afs_zap_data(struct afs_vnode *);
535535 extern int afs_validate(struct afs_vnode *, struct key *);
536−extern int afs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
536+extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
537537 extern int afs_setattr(struct dentry *, struct iattr *);
538538 extern void afs_evict_inode(struct inode *);
539539 extern int afs_drop_inode(struct inode *);
fs/bad_inode.c+2−2
@@ -89,8 +89,8 @@ static int bad_inode_permission(struct inode *inode, int mask) · 88 unmodified lines
8989 return -EIO;
9090 }
9191
92−static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
93− struct kstat *stat)
92+static int bad_inode_getattr(const struct path *path, struct kstat *stat,
93+ u32 request_mask, unsigned int query_flags)
9494 {
9595 return -EIO;
9696 }
fs/btrfs/inode.c+3−3
@@ -9413,11 +9413,11 @@ fail: · 9412 unmodified lines
94139413 return -ENOMEM;
94149414 }
94159415
9416−static int btrfs_getattr(struct vfsmount *mnt,
9417− struct dentry *dentry, struct kstat *stat)
9416+static int btrfs_getattr(const struct path *path, struct kstat *stat,
9417+ u32 request_mask, unsigned int flags)
94189418 {
94199419 u64 delalloc_bytes;
9420− struct inode *inode = d_inode(dentry);
9420+ struct inode *inode = d_inode(path->dentry);
94219421 u32 blocksize = inode->i_sb->s_blocksize;
94229422
94239423 generic_fillattr(inode, stat);
fs/ceph/inode.c+3−3
@@ -2187,10 +2187,10 @@ int ceph_permission(struct inode *inode, int mask) · 2186 unmodified lines
21872187 * Get all attributes. Hopefully somedata we'll have a statlite()
21882188 * and can limit the fields we require to be accurate.
21892189 */
2190−int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry,
2191− struct kstat *stat)
2190+int ceph_getattr(const struct path *path, struct kstat *stat,
2191+ u32 request_mask, unsigned int flags)
21922192 {
2193− struct inode *inode = d_inode(dentry);
2193+ struct inode *inode = d_inode(path->dentry);
21942194 struct ceph_inode_info *ci = ceph_inode(inode);
21952195 int err;
21962196
fs/ceph/super.h+2−2
@@ -784,8 +784,8 @@ static inline int ceph_do_getattr(struct inode *inode, int mask, bool force) · 783 unmodified lines
784784 extern int ceph_permission(struct inode *inode, int mask);
785785 extern int __ceph_setattr(struct inode *inode, struct iattr *attr);
786786 extern int ceph_setattr(struct dentry *dentry, struct iattr *attr);
787−extern int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry,
788− struct kstat *stat);
787+extern int ceph_getattr(const struct path *path, struct kstat *stat,
788+ u32 request_mask, unsigned int flags);
789789
790790 /* xattr.c */
791791 int __ceph_setxattr(struct inode *, const char *, const void *, size_t, int);
fs/cifs/cifsfs.h+1−1
@@ -83,7 +83,7 @@ extern int cifs_revalidate_dentry(struct dentry *); · 82 unmodified lines
8383 extern int cifs_invalidate_mapping(struct inode *inode);
8484 extern int cifs_revalidate_mapping(struct inode *inode);
8585 extern int cifs_zap_mapping(struct inode *inode);
86−extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
86+extern int cifs_getattr(const struct path *, struct kstat *, u32, unsigned int);
8787 extern int cifs_setattr(struct dentry *, struct iattr *);
8888
8989 extern const struct inode_operations cifs_file_inode_ops;
fs/cifs/inode.c+3−2
@@ -1990,9 +1990,10 @@ int cifs_revalidate_dentry(struct dentry *dentry) · 1989 unmodified lines
19901990 return cifs_revalidate_mapping(inode);
19911991 }
19921992
1993−int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1994− struct kstat *stat)
1993+int cifs_getattr(const struct path *path, struct kstat *stat,
1994+ u32 request_mask, unsigned int flags)
19951995 {
1996+ struct dentry *dentry = path->dentry;
19961997 struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
19971998 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
19981999 struct inode *inode = d_inode(dentry);
fs/coda/coda_linux.h+1−1
@@ -47,7 +47,7 @@ int coda_open(struct inode *i, struct file *f); · 46 unmodified lines
4747 int coda_release(struct inode *i, struct file *f);
4848 int coda_permission(struct inode *inode, int mask);
4949 int coda_revalidate_inode(struct inode *);
50−int coda_getattr(struct vfsmount *, struct dentry *, struct kstat *);
50+int coda_getattr(const struct path *, struct kstat *, u32, unsigned int);
5151 int coda_setattr(struct dentry *, struct iattr *);
5252
5353 /* this file: heloers */
fs/coda/inode.c+4−3
@@ -255,11 +255,12 @@ static void coda_evict_inode(struct inode *inode) · 254 unmodified lines
255255 coda_cache_clear_inode(inode);
256256 }
257257
258−int coda_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
258+int coda_getattr(const struct path *path, struct kstat *stat,
259+ u32 request_mask, unsigned int flags)
259260 {
260− int err = coda_revalidate_inode(d_inode(dentry));
261+ int err = coda_revalidate_inode(d_inode(path->dentry));
261262 if (!err)
262− generic_fillattr(d_inode(dentry), stat);
263+ generic_fillattr(d_inode(path->dentry), stat);
263264 return err;
264265 }
265266
fs/ecryptfs/inode.c+8−5
@@ -959,9 +959,10 @@ out: · 958 unmodified lines
959959 return rc;
960960 }
961961
962−static int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
963− struct kstat *stat)
962+static int ecryptfs_getattr_link(const struct path *path, struct kstat *stat,
963+ u32 request_mask, unsigned int flags)
964964 {
965+ struct dentry *dentry = path->dentry;
965966 struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
966967 int rc = 0;
967968
@@ -983,13 +984,15 @@ static int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry, · 15 unmodified lines
983984 return rc;
984985 }
985986
986−static int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
987− struct kstat *stat)
987+static int ecryptfs_getattr(const struct path *path, struct kstat *stat,
988+ u32 request_mask, unsigned int flags)
988989 {
990+ struct dentry *dentry = path->dentry;
989991 struct kstat lower_stat;
990992 int rc;
991993
992− rc = vfs_getattr(ecryptfs_dentry_to_lower_path(dentry), &lower_stat);
994+ rc = vfs_getattr(ecryptfs_dentry_to_lower_path(dentry), &lower_stat,
995+ request_mask, flags);
993996 if (!rc) {
994997 fsstack_copy_attr_all(d_inode(dentry),
995998 ecryptfs_inode_to_lower(d_inode(dentry)));
fs/exportfs/expfs.c+2−1
@@ -299,7 +299,8 @@ static int get_name(const struct path *path, char *name, struct dentry *child) · 298 unmodified lines
299299 * filesystem supports 64-bit inode numbers. So we need to
300300 * actually call ->getattr, not just read i_ino:
301301 */
302− error = vfs_getattr_nosec(&child_path, &stat);
302+ error = vfs_getattr_nosec(&child_path, &stat,
303+ STATX_INO, AT_STATX_SYNC_AS_STAT);
303304 if (error)
304305 return error;
305306 buffer.ino = stat.ino;
fs/ext4/ext4.h+1−2
@@ -2462,8 +2462,7 @@ extern struct inode *ext4_iget(struct super_block *, unsigned long); · 2461 unmodified lines
24622462 extern struct inode *ext4_iget_normal(struct super_block *, unsigned long);
24632463 extern int ext4_write_inode(struct inode *, struct writeback_control *);
24642464 extern int ext4_setattr(struct dentry *, struct iattr *);
2465−extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
2466− struct kstat *stat);
2465+extern int ext4_getattr(const struct path *, struct kstat *, u32, unsigned int);
24672466 extern void ext4_evict_inode(struct inode *);
24682467 extern void ext4_clear_inode(struct inode *);
24692468 extern int ext4_sync_inode(handle_t *, struct inode *);
fs/ext4/inode.c+3−3
@@ -5387,13 +5387,13 @@ err_out: · 5386 unmodified lines
53875387 return error;
53885388 }
53895389
5390−int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
5391− struct kstat *stat)
5390+int ext4_getattr(const struct path *path, struct kstat *stat,
5391+ u32 request_mask, unsigned int query_flags)
53925392 {
53935393 struct inode *inode;
53945394 unsigned long long delalloc_blocks;
53955395
5396− inode = d_inode(dentry);
5396+ inode = d_inode(path->dentry);
53975397 generic_fillattr(inode, stat);
53985398
53995399 /*
fs/f2fs/f2fs.h+2−2
@@ -2040,8 +2040,8 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); · 2039 unmodified lines
20402040 void truncate_data_blocks(struct dnode_of_data *dn);
20412041 int truncate_blocks(struct inode *inode, u64 from, bool lock);
20422042 int f2fs_truncate(struct inode *inode);
2043−int f2fs_getattr(struct vfsmount *mnt, struct dentry *dentry,
2044− struct kstat *stat);
2043+int f2fs_getattr(const struct path *path, struct kstat *stat,
2044+ u32 request_mask, unsigned int flags);
20452045 int f2fs_setattr(struct dentry *dentry, struct iattr *attr);
20462046 int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end);
20472047 int truncate_data_blocks_range(struct dnode_of_data *dn, int count);
fs/f2fs/file.c+3−3
@@ -633,10 +633,10 @@ int f2fs_truncate(struct inode *inode) · 632 unmodified lines
633633 return 0;
634634 }
635635
636−int f2fs_getattr(struct vfsmount *mnt,
637− struct dentry *dentry, struct kstat *stat)
636+int f2fs_getattr(const struct path *path, struct kstat *stat,
637+ u32 request_mask, unsigned int flags)
638638 {
639− struct inode *inode = d_inode(dentry);
639+ struct inode *inode = d_inode(path->dentry);
640640 generic_fillattr(inode, stat);
641641 stat->blocks <<= 3;
642642 return 0;
fs/fat/fat.h+2−2
@@ -364,8 +364,8 @@ extern const struct file_operations fat_file_operations; · 363 unmodified lines
364364 extern const struct inode_operations fat_file_inode_operations;
365365 extern int fat_setattr(struct dentry *dentry, struct iattr *attr);
366366 extern void fat_truncate_blocks(struct inode *inode, loff_t offset);
367−extern int fat_getattr(struct vfsmount *mnt, struct dentry *dentry,
368− struct kstat *stat);
367+extern int fat_getattr(const struct path *path, struct kstat *stat,
368+ u32 request_mask, unsigned int flags);
369369 extern int fat_file_fsync(struct file *file, loff_t start, loff_t end,
370370 int datasync);
371371
fs/fat/file.c+3−2
@@ -365,9 +365,10 @@ void fat_truncate_blocks(struct inode *inode, loff_t offset) · 364 unmodified lines
365365 fat_flush_inodes(inode->i_sb, inode, NULL);
366366 }
367367
368−int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
368+int fat_getattr(const struct path *path, struct kstat *stat,
369+ u32 request_mask, unsigned int flags)
369370 {
370− struct inode *inode = d_inode(dentry);
371+ struct inode *inode = d_inode(path->dentry);
371372 generic_fillattr(inode, stat);
372373 stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size;
373374
fs/fuse/dir.c+3−3
@@ -1777,10 +1777,10 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr) · 1776 unmodified lines
17771777 return ret;
17781778 }
17791779
1780−static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
1781− struct kstat *stat)
1780+static int fuse_getattr(const struct path *path, struct kstat *stat,
1781+ u32 request_mask, unsigned int flags)
17821782 {
1783− struct inode *inode = d_inode(entry);
1783+ struct inode *inode = d_inode(path->dentry);
17841784 struct fuse_conn *fc = get_fuse_conn(inode);
17851785
17861786 if (!fuse_allow_current_process(fc))
fs/gfs2/inode.c+6−5
@@ -1959,9 +1959,10 @@ out: · 1958 unmodified lines
19591959
19601960 /**
19611961 * gfs2_getattr - Read out an inode's attributes
1962− * @mnt: The vfsmount the inode is being accessed from
1963− * @dentry: The dentry to stat
1962+ * @path: Object to query
19641963 * @stat: The inode's stats
1964+ * @request_mask: Mask of STATX_xxx flags indicating the caller's interests
1965+ * @flags: AT_STATX_xxx setting
19651966 *
19661967 * This may be called from the VFS directly, or from within GFS2 with the
19671968 * inode locked, so we look to see if the glock is already locked and only
@@ -1972,10 +1973,10 @@ out: · 4 unmodified lines
19721973 * Returns: errno
19731974 */
19741975
1975−static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1976− struct kstat *stat)
1976+static int gfs2_getattr(const struct path *path, struct kstat *stat,
1977+ u32 request_mask, unsigned int flags)
19771978 {
1978− struct inode *inode = d_inode(dentry);
1979+ struct inode *inode = d_inode(path->dentry);
19791980 struct gfs2_inode *ip = GFS2_I(inode);
19801981 struct gfs2_holder gh;
19811982 int error;
fs/kernfs/inode.c+4−4
@@ -200,11 +200,11 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) · 199 unmodified lines
200200 set_nlink(inode, kn->dir.subdirs + 2);
201201 }
202202
203−int kernfs_iop_getattr(struct vfsmount *mnt, struct dentry *dentry,
204− struct kstat *stat)
203+int kernfs_iop_getattr(const struct path *path, struct kstat *stat,
204+ u32 request_mask, unsigned int query_flags)
205205 {
206− struct kernfs_node *kn = dentry->d_fsdata;
207− struct inode *inode = d_inode(dentry);
206+ struct kernfs_node *kn = path->dentry->d_fsdata;
207+ struct inode *inode = d_inode(path->dentry);
208208
209209 mutex_lock(&kernfs_mutex);
210210 kernfs_refresh_inode(kn, inode);
fs/kernfs/kernfs-internal.h+2−2
@@ -80,8 +80,8 @@ extern const struct xattr_handler *kernfs_xattr_handlers[]; · 79 unmodified lines
8080 void kernfs_evict_inode(struct inode *inode);
8181 int kernfs_iop_permission(struct inode *inode, int mask);
8282 int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr);
83−int kernfs_iop_getattr(struct vfsmount *mnt, struct dentry *dentry,
84− struct kstat *stat);
83+int kernfs_iop_getattr(const struct path *path, struct kstat *stat,
84+ u32 request_mask, unsigned int query_flags);
8585 ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size);
8686
8787 /*
fs/libfs.c+6−6
@@ -20,10 +20,10 @@ · 19 unmodified lines
2020
2121 #include "internal.h"
2222
23−int simple_getattr(struct vfsmount *mnt, struct dentry *dentry,
24− struct kstat *stat)
23+int simple_getattr(const struct path *path, struct kstat *stat,
24+ u32 request_mask, unsigned int query_flags)
2525 {
26− struct inode *inode = d_inode(dentry);
26+ struct inode *inode = d_inode(path->dentry);
2727 generic_fillattr(inode, stat);
2828 stat->blocks = inode->i_mapping->nrpages << (PAGE_SHIFT - 9);
2929 return 0;
@@ -1143,10 +1143,10 @@ static struct dentry *empty_dir_lookup(struct inode *dir, struct dentry *dentry, · 1113 unmodified lines
11431143 return ERR_PTR(-ENOENT);
11441144 }
11451145
1146−static int empty_dir_getattr(struct vfsmount *mnt, struct dentry *dentry,
1147− struct kstat *stat)
1146+static int empty_dir_getattr(const struct path *path, struct kstat *stat,
1147+ u32 request_mask, unsigned int query_flags)
11481148 {
1149− struct inode *inode = d_inode(dentry);
1149+ struct inode *inode = d_inode(path->dentry);
11501150 generic_fillattr(inode, stat);
11511151 return 0;
11521152 }
fs/minix/inode.c+7−4
@@ -622,11 +622,14 @@ static int minix_write_inode(struct inode *inode, struct writeback_control *wbc) · 621 unmodified lines
622622 return err;
623623 }
624624
625−int minix_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
625+int minix_getattr(const struct path *path, struct kstat *stat,
626+ u32 request_mask, unsigned int flags)
626627 {
627− struct super_block *sb = dentry->d_sb;
628− generic_fillattr(d_inode(dentry), stat);
629− if (INODE_VERSION(d_inode(dentry)) == MINIX_V1)
628+ struct super_block *sb = path->dentry->d_sb;
629+ struct inode *inode = d_inode(path->dentry);
630+
631+ generic_fillattr(inode, stat);
632+ if (INODE_VERSION(inode) == MINIX_V1)
630633 stat->blocks = (BLOCK_SIZE / 512) * V1_minix_blocks(stat->size, sb);
631634 else
632635 stat->blocks = (sb->s_blocksize / 512) * V2_minix_blocks(stat->size, sb);
fs/minix/minix.h+1−1
@@ -51,7 +51,7 @@ extern unsigned long minix_count_free_inodes(struct super_block *sb); · 50 unmodified lines
5151 extern int minix_new_block(struct inode * inode);
5252 extern void minix_free_block(struct inode *inode, unsigned long block);
5353 extern unsigned long minix_count_free_blocks(struct super_block *sb);
54−extern int minix_getattr(struct vfsmount *, struct dentry *, struct kstat *);
54+extern int minix_getattr(const struct path *, struct kstat *, u32, unsigned int);
5555 extern int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len);
5656
5757 extern void V1_minix_truncate(struct inode *);
fs/nfs/inode.c+7−6
@@ -703,9 +703,10 @@ static bool nfs_need_revalidate_inode(struct inode *inode) · 702 unmodified lines
703703 return false;
704704 }
705705
706−int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
706+int nfs_getattr(const struct path *path, struct kstat *stat,
707+ u32 request_mask, unsigned int query_flags)
707708 {
708− struct inode *inode = d_inode(dentry);
709+ struct inode *inode = d_inode(path->dentry);
709710 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
710711 int err = 0;
711712
@@ -726,17 +727,17 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) · 14 unmodified lines
726727 * - NFS never sets MS_NOATIME or MS_NODIRATIME so there is
727728 * no point in checking those.
728729 */
729− if ((mnt->mnt_flags & MNT_NOATIME) ||
730− ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
730+ if ((path->mnt->mnt_flags & MNT_NOATIME) ||
731+ ((path->mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
731732 need_atime = 0;
732733
733734 if (need_atime || nfs_need_revalidate_inode(inode)) {
734735 struct nfs_server *server = NFS_SERVER(inode);
735736
736− nfs_readdirplus_parent_cache_miss(dentry);
737+ nfs_readdirplus_parent_cache_miss(path->dentry);
737738 err = __nfs_revalidate_inode(server, inode);
738739 } else
739− nfs_readdirplus_parent_cache_hit(dentry);
740+ nfs_readdirplus_parent_cache_hit(path->dentry);
740741 if (!err) {
741742 generic_fillattr(inode, stat);
742743 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
fs/nfs/namespace.c+5−4
@@ -178,11 +178,12 @@ out_nofree: · 177 unmodified lines
178178 }
179179
180180 static int
181−nfs_namespace_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
181+nfs_namespace_getattr(const struct path *path, struct kstat *stat,
182+ u32 request_mask, unsigned int query_flags)
182183 {
183− if (NFS_FH(d_inode(dentry))->size != 0)
184− return nfs_getattr(mnt, dentry, stat);
185− generic_fillattr(d_inode(dentry), stat);
184+ if (NFS_FH(d_inode(path->dentry))->size != 0)
185+ return nfs_getattr(path, stat, request_mask, query_flags);
186+ generic_fillattr(d_inode(path->dentry), stat);
186187 return 0;
187188 }
188189
fs/nfsd/nfs4xdr.c+2−2
@@ -2301,7 +2301,7 @@ static int get_parent_attributes(struct svc_export *exp, struct kstat *stat) · 2300 unmodified lines
23012301 if (path.dentry != path.mnt->mnt_root)
23022302 break;
23032303 }
2304− err = vfs_getattr(&path, stat);
2304+ err = vfs_getattr(&path, stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
23052305 path_put(&path);
23062306 return err;
23072307 }
@@ -2385,7 +2385,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, · 77 unmodified lines
23852385 goto out;
23862386 }
23872387
2388− err = vfs_getattr(&path, &stat);
2388+ err = vfs_getattr(&path, &stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
23892389 if (err)
23902390 goto out_nfserr;
23912391 if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE |
fs/nfsd/vfs.h+2−1
@@ -135,7 +135,8 @@ static inline __be32 fh_getattr(struct svc_fh *fh, struct kstat *stat) · 134 unmodified lines
135135 {
136136 struct path p = {.mnt = fh->fh_export->ex_path.mnt,
137137 .dentry = fh->fh_dentry};
138− return nfserrno(vfs_getattr(&p, stat));
138+ return nfserrno(vfs_getattr(&p, stat, STATX_BASIC_STATS,
139+ AT_STATX_SYNC_AS_STAT));
139140 }
140141
141142 static inline int nfsd_create_is_exclusive(int createmode)
fs/ocfs2/file.c+5−6
@@ -1306,16 +1306,15 @@ bail: · 1305 unmodified lines
13061306 return status;
13071307 }
13081308
1309−int ocfs2_getattr(struct vfsmount *mnt,
1310− struct dentry *dentry,
1311− struct kstat *stat)
1309+int ocfs2_getattr(const struct path *path, struct kstat *stat,
1310+ u32 request_mask, unsigned int flags)
13121311 {
1313− struct inode *inode = d_inode(dentry);
1314− struct super_block *sb = dentry->d_sb;
1312+ struct inode *inode = d_inode(path->dentry);
1313+ struct super_block *sb = path->dentry->d_sb;
13151314 struct ocfs2_super *osb = sb->s_fs_info;
13161315 int err;
13171316
1318− err = ocfs2_inode_revalidate(dentry);
1317+ err = ocfs2_inode_revalidate(path->dentry);
13191318 if (err) {
13201319 if (err != -ENOENT)
13211320 mlog_errno(err);
fs/ocfs2/file.h+2−2
@@ -68,8 +68,8 @@ int ocfs2_zero_extend(struct inode *inode, struct buffer_head *di_bh, · 67 unmodified lines
6868 int ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
6969 u32 clusters_to_add, int mark_unwritten);
7070 int ocfs2_setattr(struct dentry *dentry, struct iattr *attr);
71−int ocfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
72− struct kstat *stat);
71+int ocfs2_getattr(const struct path *path, struct kstat *stat,
72+ u32 request_mask, unsigned int flags);
7373 int ocfs2_permission(struct inode *inode, int mask);
7474
7575 int ocfs2_should_update_atime(struct inode *inode,
fs/orangefs/inode.c+6−7
@@ -245,25 +245,24 @@ out: · 244 unmodified lines
245245 /*
246246 * Obtain attributes of an object given a dentry
247247 */
248−int orangefs_getattr(struct vfsmount *mnt,
249− struct dentry *dentry,
250− struct kstat *kstat)
248+int orangefs_getattr(const struct path *path, struct kstat *stat,
249+ u32 request_mask, unsigned int flags)
251250 {
252251 int ret = -ENOENT;
253− struct inode *inode = dentry->d_inode;
252+ struct inode *inode = path->dentry->d_inode;
254253 struct orangefs_inode_s *orangefs_inode = NULL;
255254
256255 gossip_debug(GOSSIP_INODE_DEBUG,
257256 "orangefs_getattr: called on %pd\n",
258− dentry);
257+ path->dentry);
259258
260259 ret = orangefs_inode_getattr(inode, 0, 0);
261260 if (ret == 0) {
262− generic_fillattr(inode, kstat);
261+ generic_fillattr(inode, stat);
263262
264263 /* override block size reported to stat */
265264 orangefs_inode = ORANGEFS_I(inode);
266− kstat->blksize = orangefs_inode->blksize;
265+ stat->blksize = orangefs_inode->blksize;
267266 }
268267 return ret;
269268 }
fs/orangefs/orangefs-kernel.h+2−3
@@ -439,9 +439,8 @@ struct inode *orangefs_new_inode(struct super_block *sb, · 438 unmodified lines
439439
440440 int orangefs_setattr(struct dentry *dentry, struct iattr *iattr);
441441
442−int orangefs_getattr(struct vfsmount *mnt,
443− struct dentry *dentry,
444− struct kstat *kstat);
442+int orangefs_getattr(const struct path *path, struct kstat *stat,
443+ u32 request_mask, unsigned int flags);
445444
446445 int orangefs_permission(struct inode *inode, int mask);
447446
fs/overlayfs/copy_up.c+4−2
@@ -346,7 +346,8 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry, · 345 unmodified lines
346346 ovl_path_upper(parent, &parentpath);
347347 upperdir = parentpath.dentry;
348348
349− err = vfs_getattr(&parentpath, &pstat);
349+ err = vfs_getattr(&parentpath, &pstat,
350+ STATX_ATIME | STATX_MTIME, AT_STATX_SYNC_AS_STAT);
350351 if (err)
351352 return err;
352353
@@ -409,7 +410,8 @@ int ovl_copy_up_flags(struct dentry *dentry, int flags) · 56 unmodified lines
409410 }
410411
411412 ovl_path_lower(next, &lowerpath);
412− err = vfs_getattr(&lowerpath, &stat);
413+ err = vfs_getattr(&lowerpath, &stat,
414+ STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
413415 /* maybe truncate regular file. this has no effect on dirs */
414416 if (flags & O_TRUNC)
415417 stat.size = 0;
fs/overlayfs/dir.c+6−4
@@ -138,9 +138,10 @@ static int ovl_set_opaque(struct dentry *dentry, struct dentry *upperdentry) · 137 unmodified lines
138138 return err;
139139 }
140140
141−static int ovl_dir_getattr(struct vfsmount *mnt, struct dentry *dentry,
142− struct kstat *stat)
141+static int ovl_dir_getattr(const struct path *path, struct kstat *stat,
142+ u32 request_mask, unsigned int flags)
143143 {
144+ struct dentry *dentry = path->dentry;
144145 int err;
145146 enum ovl_path_type type;
146147 struct path realpath;
@@ -148,7 +149,7 @@ static int ovl_dir_getattr(struct vfsmount *mnt, struct dentry *dentry, · 1 unmodified line
148149
149150 type = ovl_path_real(dentry, &realpath);
150151 old_cred = ovl_override_creds(dentry->d_sb);
151− err = vfs_getattr(&realpath, stat);
152+ err = vfs_getattr(&realpath, stat, request_mask, flags);
152153 revert_creds(old_cred);
153154 if (err)
154155 return err;
@@ -264,7 +265,8 @@ static struct dentry *ovl_clear_empty(struct dentry *dentry, · 109 unmodified lines
264265 goto out;
265266
266267 ovl_path_upper(dentry, &upperpath);
267− err = vfs_getattr(&upperpath, &stat);
268+ err = vfs_getattr(&upperpath, &stat,
269+ STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
268270 if (err)
269271 goto out_unlock;
270272
fs/overlayfs/inode.c+4−3
@@ -56,16 +56,17 @@ out: · 55 unmodified lines
5656 return err;
5757 }
5858
59−static int ovl_getattr(struct vfsmount *mnt, struct dentry *dentry,
60− struct kstat *stat)
59+static int ovl_getattr(const struct path *path, struct kstat *stat,
60+ u32 request_mask, unsigned int flags)
6161 {
62+ struct dentry *dentry = path->dentry;
6263 struct path realpath;
6364 const struct cred *old_cred;
6465 int err;
6566
6667 ovl_path_real(dentry, &realpath);
6768 old_cred = ovl_override_creds(dentry->d_sb);
68− err = vfs_getattr(&realpath, stat);
69+ err = vfs_getattr(&realpath, stat, request_mask, flags);
6970 revert_creds(old_cred);
7071 return err;
7172 }
fs/proc/base.c+7−5
@@ -1724,11 +1724,12 @@ out_unlock: · 1723 unmodified lines
17241724 return NULL;
17251725 }
17261726
1727−int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1727+int pid_getattr(const struct path *path, struct kstat *stat,
1728+ u32 request_mask, unsigned int query_flags)
17281729 {
1729− struct inode *inode = d_inode(dentry);
1730+ struct inode *inode = d_inode(path->dentry);
17301731 struct task_struct *task;
1731− struct pid_namespace *pid = dentry->d_sb->s_fs_info;
1732+ struct pid_namespace *pid = path->dentry->d_sb->s_fs_info;
17321733
17331734 generic_fillattr(inode, stat);
17341735
@@ -3511,9 +3512,10 @@ static int proc_task_readdir(struct file *file, struct dir_context *ctx) · 1776 unmodified lines
35113512 return 0;
35123513 }
35133514
3514−static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3515+static int proc_task_getattr(const struct path *path, struct kstat *stat,
3516+ u32 request_mask, unsigned int query_flags)
35153517 {
3516− struct inode *inode = d_inode(dentry);
3518+ struct inode *inode = d_inode(path->dentry);
35173519 struct task_struct *p = get_proc_task(inode);
35183520 generic_fillattr(inode, stat);
35193521
fs/proc/generic.c+3−3
@@ -118,10 +118,10 @@ static int proc_notify_change(struct dentry *dentry, struct iattr *iattr) · 117 unmodified lines
118118 return 0;
119119 }
120120
121−static int proc_getattr(struct vfsmount *mnt, struct dentry *dentry,
122− struct kstat *stat)
121+static int proc_getattr(const struct path *path, struct kstat *stat,
122+ u32 request_mask, unsigned int query_flags)
123123 {
124− struct inode *inode = d_inode(dentry);
124+ struct inode *inode = d_inode(path->dentry);
125125 struct proc_dir_entry *de = PDE(inode);
126126 if (de && de->nlink)
127127 set_nlink(inode, de->nlink);
fs/proc/internal.h+1−1
@@ -149,7 +149,7 @@ extern int proc_pid_statm(struct seq_file *, struct pid_namespace *, · 148 unmodified lines
149149 * base.c
150150 */
151151 extern const struct dentry_operations pid_dentry_operations;
152−extern int pid_getattr(struct vfsmount *, struct dentry *, struct kstat *);
152+extern int pid_getattr(const struct path *, struct kstat *, u32, unsigned int);
153153 extern int proc_setattr(struct dentry *, struct iattr *);
154154 extern struct inode *proc_pid_make_inode(struct super_block *, struct task_struct *, umode_t);
155155 extern int pid_revalidate(struct dentry *, unsigned int);
fs/proc/proc_net.c+3−3
@@ -140,10 +140,10 @@ static struct dentry *proc_tgid_net_lookup(struct inode *dir, · 139 unmodified lines
140140 return de;
141141 }
142142
143−static int proc_tgid_net_getattr(struct vfsmount *mnt, struct dentry *dentry,
144− struct kstat *stat)
143+static int proc_tgid_net_getattr(const struct path *path, struct kstat *stat,
144+ u32 request_mask, unsigned int query_flags)
145145 {
146− struct inode *inode = d_inode(dentry);
146+ struct inode *inode = d_inode(path->dentry);
147147 struct net *net;
148148
149149 net = get_proc_task_net(inode);
fs/proc/proc_sysctl.c+3−2
@@ -801,9 +801,10 @@ static int proc_sys_setattr(struct dentry *dentry, struct iattr *attr) · 800 unmodified lines
801801 return 0;
802802 }
803803
804−static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
804+static int proc_sys_getattr(const struct path *path, struct kstat *stat,
805+ u32 request_mask, unsigned int query_flags)
805806 {
806− struct inode *inode = d_inode(dentry);
807+ struct inode *inode = d_inode(path->dentry);
807808 struct ctl_table_header *head = grab_header(inode);
808809 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
809810
fs/proc/root.c+3−3
@@ -149,10 +149,10 @@ void __init proc_root_init(void) · 148 unmodified lines
149149 proc_sys_init();
150150 }
151151
152−static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
153−)
152+static int proc_root_getattr(const struct path *path, struct kstat *stat,
153+ u32 request_mask, unsigned int query_flags)
154154 {
155− generic_fillattr(d_inode(dentry), stat);
155+ generic_fillattr(d_inode(path->dentry), stat);
156156 stat->nlink = proc_root.nlink + nr_processes();
157157 return 0;
158158 }
fs/stat.c+176−38
@@ -18,6 +18,15 @@ · 17 unmodified lines
1818 #include <linux/uaccess.h>
1919 #include <asm/unistd.h>
2020
21+/**
22+ * generic_fillattr - Fill in the basic attributes from the inode struct
23+ * @inode: Inode to use as the source
24+ * @stat: Where to fill in the attributes
25+ *
26+ * Fill in the basic attributes in the kstat structure from data that's to be
27+ * found on the VFS inode structure. This is the default if no getattr inode
28+ * operation is supplied.
29+ */
2130 void generic_fillattr(struct inode *inode, struct kstat *stat)
2231 {
2332 stat->dev = inode->i_sb->s_dev;
@@ -33,81 +42,147 @@ void generic_fillattr(struct inode *inode, struct kstat *stat) · 9 unmodified lines
3342 stat->ctime = inode->i_ctime;
3443 stat->blksize = i_blocksize(inode);
3544 stat->blocks = inode->i_blocks;
36−}
3745
46+ if (IS_NOATIME(inode))
47+ stat->result_mask &= ~STATX_ATIME;
48+ if (IS_AUTOMOUNT(inode))
49+ stat->attributes |= STATX_ATTR_AUTOMOUNT;
50+}
3851 EXPORT_SYMBOL(generic_fillattr);
3952
4053 /**
4154 * vfs_getattr_nosec - getattr without security checks
4255 * @path: file to get attributes from
4356 * @stat: structure to return attributes in
57+ * @request_mask: STATX_xxx flags indicating what the caller wants
58+ * @query_flags: Query mode (KSTAT_QUERY_FLAGS)
4459 *
4560 * Get attributes without calling security_inode_getattr.
4661 *
4762 * Currently the only caller other than vfs_getattr is internal to the
48− * filehandle lookup code, which uses only the inode number and returns
49− * no attributes to any user. Any other code probably wants
50− * vfs_getattr.
63+ * filehandle lookup code, which uses only the inode number and returns no
64+ * attributes to any user. Any other code probably wants vfs_getattr.
5165 */
52−int vfs_getattr_nosec(struct path *path, struct kstat *stat)
66+int vfs_getattr_nosec(const struct path *path, struct kstat *stat,
67+ u32 request_mask, unsigned int query_flags)
5368 {
5469 struct inode *inode = d_backing_inode(path->dentry);
5570
71+ memset(stat, 0, sizeof(*stat));
72+ stat->result_mask |= STATX_BASIC_STATS;
73+ request_mask &= STATX_ALL;
74+ query_flags &= KSTAT_QUERY_FLAGS;
5675 if (inode->i_op->getattr)
57− return inode->i_op->getattr(path->mnt, path->dentry, stat);
76+ return inode->i_op->getattr(path, stat, request_mask,
77+ query_flags);
5878
5979 generic_fillattr(inode, stat);
6080 return 0;
6181 }
62−
6382 EXPORT_SYMBOL(vfs_getattr_nosec);
6483
65−int vfs_getattr(struct path *path, struct kstat *stat)
84+/*
85+ * vfs_getattr - Get the enhanced basic attributes of a file
86+ * @path: The file of interest
87+ * @stat: Where to return the statistics
88+ * @request_mask: STATX_xxx flags indicating what the caller wants
89+ * @query_flags: Query mode (KSTAT_QUERY_FLAGS)
90+ *
91+ * Ask the filesystem for a file's attributes. The caller must indicate in
92+ * request_mask and query_flags to indicate what they want.
93+ *
94+ * If the file is remote, the filesystem can be forced to update the attributes
95+ * from the backing store by passing AT_STATX_FORCE_SYNC in query_flags or can
96+ * suppress the update by passing AT_STATX_DONT_SYNC.
97+ *
98+ * Bits must have been set in request_mask to indicate which attributes the
99+ * caller wants retrieving. Any such attribute not requested may be returned
100+ * anyway, but the value may be approximate, and, if remote, may not have been
101+ * synchronised with the server.
102+ *
103+ * 0 will be returned on success, and a -ve error code if unsuccessful.
104+ */
105+int vfs_getattr(const struct path *path, struct kstat *stat,
106+ u32 request_mask, unsigned int query_flags)
66107 {
67108 int retval;
68109
69110 retval = security_inode_getattr(path);
70111 if (retval)
71112 return retval;
72− return vfs_getattr_nosec(path, stat);
113+ return vfs_getattr_nosec(path, stat, request_mask, query_flags);
73114 }
74−
75115 EXPORT_SYMBOL(vfs_getattr);
76116
77−int vfs_fstat(unsigned int fd, struct kstat *stat)
117+/**
118+ * vfs_statx_fd - Get the enhanced basic attributes by file descriptor
119+ * @fd: The file descriptor referring to the file of interest
120+ * @stat: The result structure to fill in.
121+ * @request_mask: STATX_xxx flags indicating what the caller wants
122+ * @query_flags: Query mode (KSTAT_QUERY_FLAGS)
123+ *
124+ * This function is a wrapper around vfs_getattr(). The main difference is
125+ * that it uses a file descriptor to determine the file location.
126+ *
127+ * 0 will be returned on success, and a -ve error code if unsuccessful.
128+ */
129+int vfs_statx_fd(unsigned int fd, struct kstat *stat,
130+ u32 request_mask, unsigned int query_flags)
78131 {
79132 struct fd f = fdget_raw(fd);
80133 int error = -EBADF;
81134
82135 if (f.file) {
83− error = vfs_getattr(&f.file->f_path, stat);
136+ error = vfs_getattr(&f.file->f_path, stat,
137+ request_mask, query_flags);
84138 fdput(f);
85139 }
86140 return error;
87141 }
88−EXPORT_SYMBOL(vfs_fstat);
142+EXPORT_SYMBOL(vfs_statx_fd);
89143
90−int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat,
91− int flag)
144+/**
145+ * vfs_statx - Get basic and extra attributes by filename
146+ * @dfd: A file descriptor representing the base dir for a relative filename
147+ * @filename: The name of the file of interest
148+ * @flags: Flags to control the query
149+ * @stat: The result structure to fill in.
150+ * @request_mask: STATX_xxx flags indicating what the caller wants
151+ *
152+ * This function is a wrapper around vfs_getattr(). The main difference is
153+ * that it uses a filename and base directory to determine the file location.
154+ * Additionally, the use of AT_SYMLINK_NOFOLLOW in flags will prevent a symlink
155+ * at the given name from being referenced.
156+ *
157+ * The caller must have preset stat->request_mask as for vfs_getattr(). The
158+ * flags are also used to load up stat->query_flags.
159+ *
160+ * 0 will be returned on success, and a -ve error code if unsuccessful.
161+ */
162+int vfs_statx(int dfd, const char __user *filename, int flags,
163+ struct kstat *stat, u32 request_mask)
92164 {
93165 struct path path;
94166 int error = -EINVAL;
95− unsigned int lookup_flags = 0;
167+ unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT;
96168
97− if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
98− AT_EMPTY_PATH)) != 0)
99− goto out;
169+ if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
170+ AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0)
171+ return -EINVAL;
100172
101− if (!(flag & AT_SYMLINK_NOFOLLOW))
102− lookup_flags |= LOOKUP_FOLLOW;
103− if (flag & AT_EMPTY_PATH)
173+ if (flags & AT_SYMLINK_NOFOLLOW)
174+ lookup_flags &= ~LOOKUP_FOLLOW;
175+ if (flags & AT_NO_AUTOMOUNT)
176+ lookup_flags &= ~LOOKUP_AUTOMOUNT;
177+ if (flags & AT_EMPTY_PATH)
104178 lookup_flags |= LOOKUP_EMPTY;
179+
105180 retry:
106181 error = user_path_at(dfd, filename, lookup_flags, &path);
107182 if (error)
108183 goto out;
109184
110− error = vfs_getattr(&path, stat);
185+ error = vfs_getattr(&path, stat, request_mask, flags);
111186 path_put(&path);
112187 if (retry_estale(error, lookup_flags)) {
113188 lookup_flags |= LOOKUP_REVAL;
@@ -116,19 +191,7 @@ retry: · 2 unmodified lines
116191 out:
117192 return error;
118193 }
119−EXPORT_SYMBOL(vfs_fstatat);
120−
121−int vfs_stat(const char __user *name, struct kstat *stat)
122−{
123− return vfs_fstatat(AT_FDCWD, name, stat, 0);
124−}
125−EXPORT_SYMBOL(vfs_stat);
126−
127−int vfs_lstat(const char __user *name, struct kstat *stat)
128−{
129− return vfs_fstatat(AT_FDCWD, name, stat, AT_SYMLINK_NOFOLLOW);
130−}
131−EXPORT_SYMBOL(vfs_lstat);
194+EXPORT_SYMBOL(vfs_statx);
132195
133196
134197 #ifdef __ARCH_WANT_OLD_STAT
@@ -141,7 +204,7 @@ static int cp_old_stat(struct kstat *stat, struct __old_kernel_stat __user * sta · 6 unmodified lines
141204 {
142205 static int warncount = 5;
143206 struct __old_kernel_stat tmp;
144−
207+
145208 if (warncount > 0) {
146209 warncount--;
147210 printk(KERN_WARNING "VFS: Warning: %s using old stat() call. Recompile your binary.\n",
@@ -166,7 +229,7 @@ static int cp_old_stat(struct kstat *stat, struct __old_kernel_stat __user * sta · 18 unmodified lines
166229 #if BITS_PER_LONG == 32
167230 if (stat->size > MAX_NON_LFS)
168231 return -EOVERFLOW;
169−#endif
232+#endif
170233 tmp.st_size = stat->size;
171234 tmp.st_atime = stat->atime.tv_sec;
172235 tmp.st_mtime = stat->mtime.tv_sec;
@@ -445,6 +508,81 @@ SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename, · 272 unmodified lines
445508 }
446509 #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_COMPAT_STAT64 */
447510
511+static inline int __put_timestamp(struct timespec *kts,
512+ struct statx_timestamp __user *uts)
513+{
514+ return (__put_user(kts->tv_sec, &uts->tv_sec ) ||
515+ __put_user(kts->tv_nsec, &uts->tv_nsec ) ||
516+ __put_user(0, &uts->__reserved ));
517+}
518+
519+/*
520+ * Set the statx results.
521+ */
522+static long statx_set_result(struct kstat *stat, struct statx __user *buffer)
523+{
524+ uid_t uid = from_kuid_munged(current_user_ns(), stat->uid);
525+ gid_t gid = from_kgid_munged(current_user_ns(), stat->gid);
526+
527+ if (__put_user(stat->result_mask, &buffer->stx_mask ) ||
528+ __put_user(stat->mode, &buffer->stx_mode ) ||
529+ __clear_user(&buffer->__spare0, sizeof(buffer->__spare0)) ||
530+ __put_user(stat->nlink, &buffer->stx_nlink ) ||
531+ __put_user(uid, &buffer->stx_uid ) ||
532+ __put_user(gid, &buffer->stx_gid ) ||
533+ __put_user(stat->attributes, &buffer->stx_attributes ) ||
534+ __put_user(stat->blksize, &buffer->stx_blksize ) ||
535+ __put_user(MAJOR(stat->rdev), &buffer->stx_rdev_major ) ||
536+ __put_user(MINOR(stat->rdev), &buffer->stx_rdev_minor ) ||
537+ __put_user(MAJOR(stat->dev), &buffer->stx_dev_major ) ||
538+ __put_user(MINOR(stat->dev), &buffer->stx_dev_minor ) ||
539+ __put_timestamp(&stat->atime, &buffer->stx_atime ) ||
540+ __put_timestamp(&stat->btime, &buffer->stx_btime ) ||
541+ __put_timestamp(&stat->ctime, &buffer->stx_ctime ) ||
542+ __put_timestamp(&stat->mtime, &buffer->stx_mtime ) ||
543+ __put_user(stat->ino, &buffer->stx_ino ) ||
544+ __put_user(stat->size, &buffer->stx_size ) ||
545+ __put_user(stat->blocks, &buffer->stx_blocks ) ||
546+ __clear_user(&buffer->__spare1, sizeof(buffer->__spare1)) ||
547+ __clear_user(&buffer->__spare2, sizeof(buffer->__spare2)))
548+ return -EFAULT;
549+
550+ return 0;
551+}
552+
553+/**
554+ * sys_statx - System call to get enhanced stats
555+ * @dfd: Base directory to pathwalk from *or* fd to stat.
556+ * @filename: File to stat *or* NULL.
557+ * @flags: AT_* flags to control pathwalk.
558+ * @mask: Parts of statx struct actually required.
559+ * @buffer: Result buffer.
560+ *
561+ * Note that if filename is NULL, then it does the equivalent of fstat() using
562+ * dfd to indicate the file of interest.
563+ */
564+SYSCALL_DEFINE5(statx,
565+ int, dfd, const char __user *, filename, unsigned, flags,
566+ unsigned int, mask,
567+ struct statx __user *, buffer)
568+{
569+ struct kstat stat;
570+ int error;
571+
572+ if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE)
573+ return -EINVAL;
574+ if (!access_ok(VERIFY_WRITE, buffer, sizeof(*buffer)))
575+ return -EFAULT;
576+
577+ if (filename)
578+ error = vfs_statx(dfd, filename, flags, &stat, mask);
579+ else
580+ error = vfs_statx_fd(dfd, &stat, mask, flags);
581+ if (error)
582+ return error;
583+ return statx_set_result(&stat, buffer);
584+}
585+
448586 /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */
449587 void __inode_add_bytes(struct inode *inode, loff_t bytes)
450588 {
fs/sysv/itree.c+4−3
@@ -440,10 +440,11 @@ static unsigned sysv_nblocks(struct super_block *s, loff_t size) · 439 unmodified lines
440440 return blocks;
441441 }
442442
443−int sysv_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
443+int sysv_getattr(const struct path *path, struct kstat *stat,
444+ u32 request_mask, unsigned int flags)
444445 {
445− struct super_block *s = dentry->d_sb;
446− generic_fillattr(d_inode(dentry), stat);
446+ struct super_block *s = path->dentry->d_sb;
447+ generic_fillattr(d_inode(path->dentry), stat);
447448 stat->blocks = (s->s_blocksize / 512) * sysv_nblocks(s, stat->size);
448449 stat->blksize = s->s_blocksize;
449450 return 0;
fs/sysv/sysv.h+1−1
@@ -142,7 +142,7 @@ extern struct inode *sysv_iget(struct super_block *, unsigned int); · 141 unmodified lines
142142 extern int sysv_write_inode(struct inode *, struct writeback_control *wbc);
143143 extern int sysv_sync_inode(struct inode *);
144144 extern void sysv_set_inode(struct inode *, dev_t);
145−extern int sysv_getattr(struct vfsmount *, struct dentry *, struct kstat *);
145+extern int sysv_getattr(const struct path *, struct kstat *, u32, unsigned int);
146146 extern int sysv_init_icache(void);
147147 extern void sysv_destroy_icache(void);
148148
fs/ubifs/dir.c+3−3
@@ -1622,11 +1622,11 @@ static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry, · 1621 unmodified lines
16221622 return do_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
16231623 }
16241624
1625−int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1626− struct kstat *stat)
1625+int ubifs_getattr(const struct path *path, struct kstat *stat,
1626+ u32 request_mask, unsigned int flags)
16271627 {
16281628 loff_t size;
1629− struct inode *inode = d_inode(dentry);
1629+ struct inode *inode = d_inode(path->dentry);
16301630 struct ubifs_inode *ui = ubifs_inode(inode);
16311631
16321632 mutex_lock(&ui->ui_mutex);
fs/ubifs/ubifs.h+2−2
@@ -1749,8 +1749,8 @@ int ubifs_update_time(struct inode *inode, struct timespec *time, int flags); · 1748 unmodified lines
17491749 /* dir.c */
17501750 struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,
17511751 umode_t mode);
1752−int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1753− struct kstat *stat);
1752+int ubifs_getattr(const struct path *path, struct kstat *stat,
1753+ u32 request_mask, unsigned int flags);
17541754 int ubifs_check_dir_empty(struct inode *dir);
17551755
17561756 /* xattr.c */
fs/udf/symlink.c+3−2
@@ -152,9 +152,10 @@ out_unmap: · 151 unmodified lines
152152 return err;
153153 }
154154
155−static int udf_symlink_getattr(struct vfsmount *mnt, struct dentry *dentry,
156− struct kstat *stat)
155+static int udf_symlink_getattr(const struct path *path, struct kstat *stat,
156+ u32 request_mask, unsigned int flags)
157157 {
158+ struct dentry *dentry = path->dentry;
158159 struct inode *inode = d_backing_inode(dentry);
159160 struct page *page;
160161
fs/xfs/xfs_iops.c+5−4
@@ -489,11 +489,12 @@ xfs_vn_get_link_inline( · 488 unmodified lines
489489
490490 STATIC int
491491 xfs_vn_getattr(
492− struct vfsmount *mnt,
493− struct dentry *dentry,
494− struct kstat *stat)
492+ const struct path *path,
493+ struct kstat *stat,
494+ u32 request_mask,
495+ unsigned int query_flags)
495496 {
496− struct inode *inode = d_inode(dentry);
497+ struct inode *inode = d_inode(path->dentry);
497498 struct xfs_inode *ip = XFS_I(inode);
498499 struct xfs_mount *mp = ip->i_mount;
499500
include/linux/fs.h+27−8
@@ -1709,7 +1709,7 @@ struct inode_operations { · 1708 unmodified lines
17091709 int (*rename) (struct inode *, struct dentry *,
17101710 struct inode *, struct dentry *, unsigned int);
17111711 int (*setattr) (struct dentry *, struct iattr *);
1712− int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
1712+ int (*getattr) (const struct path *, struct kstat *, u32, unsigned int);
17131713 ssize_t (*listxattr) (struct dentry *, char *, size_t);
17141714 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
17151715 u64 len);
@@ -2902,8 +2902,8 @@ extern int page_symlink(struct inode *inode, const char *symname, int len); · 1186 unmodified lines
29022902 extern const struct inode_operations page_symlink_inode_operations;
29032903 extern void kfree_link(void *);
29042904 extern void generic_fillattr(struct inode *, struct kstat *);
2905−int vfs_getattr_nosec(struct path *path, struct kstat *stat);
2906−extern int vfs_getattr(struct path *, struct kstat *);
2905+extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int);
2906+extern int vfs_getattr(const struct path *, struct kstat *, u32, unsigned int);
29072907 void __inode_add_bytes(struct inode *inode, loff_t bytes);
29082908 void inode_add_bytes(struct inode *inode, loff_t bytes);
29092909 void __inode_sub_bytes(struct inode *inode, loff_t bytes);
@@ -2916,10 +2916,29 @@ extern const struct inode_operations simple_symlink_inode_operations; · 6 unmodified lines
29162916
29172917 extern int iterate_dir(struct file *, struct dir_context *);
29182918
2919−extern int vfs_stat(const char __user *, struct kstat *);
2920−extern int vfs_lstat(const char __user *, struct kstat *);
2921−extern int vfs_fstat(unsigned int, struct kstat *);
2922−extern int vfs_fstatat(int , const char __user *, struct kstat *, int);
2919+extern int vfs_statx(int, const char __user *, int, struct kstat *, u32);
2920+extern int vfs_statx_fd(unsigned int, struct kstat *, u32, unsigned int);
2921+
2922+static inline int vfs_stat(const char __user *filename, struct kstat *stat)
2923+{
2924+ return vfs_statx(AT_FDCWD, filename, 0, stat, STATX_BASIC_STATS);
2925+}
2926+static inline int vfs_lstat(const char __user *name, struct kstat *stat)
2927+{
2928+ return vfs_statx(AT_FDCWD, name, AT_SYMLINK_NOFOLLOW,
2929+ stat, STATX_BASIC_STATS);
2930+}
2931+static inline int vfs_fstatat(int dfd, const char __user *filename,
2932+ struct kstat *stat, int flags)
2933+{
2934+ return vfs_statx(dfd, filename, flags, stat, STATX_BASIC_STATS);
2935+}
2936+static inline int vfs_fstat(int fd, struct kstat *stat)
2937+{
2938+ return vfs_statx_fd(fd, stat, STATX_BASIC_STATS, 0);
2939+}
2940+
2941+
29232942 extern const char *vfs_get_link(struct dentry *, struct delayed_call *);
29242943 extern int vfs_readlink(struct dentry *, char __user *, int);
29252944
@@ -2949,7 +2968,7 @@ extern int dcache_dir_close(struct inode *, struct file *); · 23 unmodified lines
29492968 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
29502969 extern int dcache_readdir(struct file *, struct dir_context *);
29512970 extern int simple_setattr(struct dentry *, struct iattr *);
2952−extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
2971+extern int simple_getattr(const struct path *, struct kstat *, u32, unsigned int);
29532972 extern int simple_statfs(struct dentry *, struct kstatfs *);
29542973 extern int simple_open(struct inode *inode, struct file *file);
29552974 extern int simple_link(struct dentry *, struct inode *, struct dentry *);
include/linux/nfs_fs.h+1−1
@@ -335,7 +335,7 @@ extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *); · 334 unmodified lines
335335 extern int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr);
336336 extern int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr);
337337 extern int nfs_post_op_update_inode_force_wcc_locked(struct inode *inode, struct nfs_fattr *fattr);
338−extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
338+extern int nfs_getattr(const struct path *, struct kstat *, u32, unsigned int);
339339 extern void nfs_access_add_cache(struct inode *, struct nfs_access_entry *);
340340 extern void nfs_access_set_mask(struct nfs_access_entry *, u32);
341341 extern int nfs_permission(struct inode *, int);
include/linux/stat.h+18−6
@@ -18,20 +18,32 @@ · 17 unmodified lines
1818 #include <linux/time.h>
1919 #include <linux/uidgid.h>
2020
21+#define KSTAT_QUERY_FLAGS (AT_STATX_SYNC_TYPE)
22+
2123 struct kstat {
22− u64 ino;
23− dev_t dev;
24+ u32 result_mask; /* What fields the user got */
2425 umode_t mode;
2526 unsigned int nlink;
27+ uint32_t blksize; /* Preferred I/O size */
28+ u64 attributes;
29+#define KSTAT_ATTR_FS_IOC_FLAGS \
30+ (STATX_ATTR_COMPRESSED | \
31+ STATX_ATTR_IMMUTABLE | \
32+ STATX_ATTR_APPEND | \
33+ STATX_ATTR_NODUMP | \
34+ STATX_ATTR_ENCRYPTED \
35+ )/* Attrs corresponding to FS_*_FL flags */
36+ u64 ino;
37+ dev_t dev;
38+ dev_t rdev;
2639 kuid_t uid;
2740 kgid_t gid;
28− dev_t rdev;
2941 loff_t size;
30− struct timespec atime;
42+ struct timespec atime;
3143 struct timespec mtime;
3244 struct timespec ctime;
33− unsigned long blksize;
34− unsigned long long blocks;
45+ struct timespec btime; /* File creation time */
46+ u64 blocks;
3547 };
3648
3749 #endif
include/linux/syscalls.h+3−0
@@ -48,6 +48,7 @@ struct stat; · 47 unmodified lines
4848 struct stat64;
4949 struct statfs;
5050 struct statfs64;
51+struct statx;
5152 struct __sysctl_args;
5253 struct sysinfo;
5354 struct timespec;
@@ -902,5 +903,7 @@ asmlinkage long sys_pkey_mprotect(unsigned long start, size_t len, · 848 unmodified lines
902903 unsigned long prot, int pkey);
903904 asmlinkage long sys_pkey_alloc(unsigned long flags, unsigned long init_val);
904905 asmlinkage long sys_pkey_free(int pkey);
906+asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags,
907+ unsigned mask, struct statx __user *buffer);
905908
906909 #endif
include/uapi/linux/fcntl.h+5−0
@@ -63,5 +63,10 @@ · 62 unmodified lines
6363 #define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
6464 #define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */
6565
66+#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
67+#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
68+#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
69+#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
70+
6671
6772 #endif /* _UAPI_LINUX_FCNTL_H */
include/uapi/linux/stat.h+131−0
@@ -1,6 +1,7 @@
11 #ifndef _UAPI_LINUX_STAT_H
22 #define _UAPI_LINUX_STAT_H
33
4+#include <linux/types.h>
45
56 #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
67
@@ -41,5 +42,135 @@ · 34 unmodified lines
4142
4243 #endif
4344
45+/*
46+ * Timestamp structure for the timestamps in struct statx.
47+ *
48+ * tv_sec holds the number of seconds before (negative) or after (positive)
49+ * 00:00:00 1st January 1970 UTC.
50+ *
51+ * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
52+ * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
53+ *
54+ * Note that if both tv_sec and tv_nsec are non-zero, then the two values must
55+ * either be both positive or both negative.
56+ *
57+ * __reserved is held in case we need a yet finer resolution.
58+ */
59+struct statx_timestamp {
60+ __s64 tv_sec;
61+ __s32 tv_nsec;
62+ __s32 __reserved;
63+};
64+
65+/*
66+ * Structures for the extended file attribute retrieval system call
67+ * (statx()).
68+ *
69+ * The caller passes a mask of what they're specifically interested in as a
70+ * parameter to statx(). What statx() actually got will be indicated in
71+ * st_mask upon return.
72+ *
73+ * For each bit in the mask argument:
74+ *
75+ * - if the datum is not supported:
76+ *
77+ * - the bit will be cleared, and
78+ *
79+ * - the datum will be set to an appropriate fabricated value if one is
80+ * available (eg. CIFS can take a default uid and gid), otherwise
81+ *
82+ * - the field will be cleared;
83+ *
84+ * - otherwise, if explicitly requested:
85+ *
86+ * - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
87+ * set or if the datum is considered out of date, and
88+ *
89+ * - the field will be filled in and the bit will be set;
90+ *
91+ * - otherwise, if not requested, but available in approximate form without any
92+ * effort, it will be filled in anyway, and the bit will be set upon return
93+ * (it might not be up to date, however, and no attempt will be made to
94+ * synchronise the internal state first);
95+ *
96+ * - otherwise the field and the bit will be cleared before returning.
97+ *
98+ * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
99+ * will have values installed for compatibility purposes so that stat() and
100+ * co. can be emulated in userspace.
101+ */
102+struct statx {
103+ /* 0x00 */
104+ __u32 stx_mask; /* What results were written [uncond] */
105+ __u32 stx_blksize; /* Preferred general I/O size [uncond] */
106+ __u64 stx_attributes; /* Flags conveying information about the file [uncond] */
107+ /* 0x10 */
108+ __u32 stx_nlink; /* Number of hard links */
109+ __u32 stx_uid; /* User ID of owner */
110+ __u32 stx_gid; /* Group ID of owner */
111+ __u16 stx_mode; /* File mode */
112+ __u16 __spare0[1];
113+ /* 0x20 */
114+ __u64 stx_ino; /* Inode number */
115+ __u64 stx_size; /* File size */
116+ __u64 stx_blocks; /* Number of 512-byte blocks allocated */
117+ __u64 __spare1[1];
118+ /* 0x40 */
119+ struct statx_timestamp stx_atime; /* Last access time */
120+ struct statx_timestamp stx_btime; /* File creation time */
121+ struct statx_timestamp stx_ctime; /* Last attribute change time */
122+ struct statx_timestamp stx_mtime; /* Last data modification time */
123+ /* 0x80 */
124+ __u32 stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
125+ __u32 stx_rdev_minor;
126+ __u32 stx_dev_major; /* ID of device containing file [uncond] */
127+ __u32 stx_dev_minor;
128+ /* 0x90 */
129+ __u64 __spare2[14]; /* Spare space for future expansion */
130+ /* 0x100 */
131+};
132+
133+/*
134+ * Flags to be stx_mask
135+ *
136+ * Query request/result mask for statx() and struct statx::stx_mask.
137+ *
138+ * These bits should be set in the mask argument of statx() to request
139+ * particular items when calling statx().
140+ */
141+#define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
142+#define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
143+#define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
144+#define STATX_UID 0x00000008U /* Want/got stx_uid */
145+#define STATX_GID 0x00000010U /* Want/got stx_gid */
146+#define STATX_ATIME 0x00000020U /* Want/got stx_atime */
147+#define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
148+#define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
149+#define STATX_INO 0x00000100U /* Want/got stx_ino */
150+#define STATX_SIZE 0x00000200U /* Want/got stx_size */
151+#define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
152+#define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
153+#define STATX_BTIME 0x00000800U /* Want/got stx_btime */
154+#define STATX_ALL 0x00000fffU /* All currently supported flags */
155+
156+/*
157+ * Attributes to be found in stx_attributes
158+ *
159+ * These give information about the features or the state of a file that might
160+ * be of use to ordinary userspace programs such as GUIs or ls rather than
161+ * specialised tools.
162+ *
163+ * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
164+ * semantically. Where possible, the numerical value is picked to correspond
165+ * also.
166+ */
167+#define STATX_ATTR_COMPRESSED 0x00000004 /* [I] File is compressed by the fs */
168+#define STATX_ATTR_IMMUTABLE 0x00000010 /* [I] File is marked immutable */
169+#define STATX_ATTR_APPEND 0x00000020 /* [I] File is append-only */
170+#define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */
171+#define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */
172+
173+#define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */
174+
44175
45176 #endif /* _UAPI_LINUX_STAT_H */
mm/shmem.c+3−3
@@ -958,10 +958,10 @@ void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend) · 957 unmodified lines
958958 }
959959 EXPORT_SYMBOL_GPL(shmem_truncate_range);
960960
961−static int shmem_getattr(struct vfsmount *mnt, struct dentry *dentry,
962− struct kstat *stat)
961+static int shmem_getattr(const struct path *path, struct kstat *stat,
962+ u32 request_mask, unsigned int query_flags)
963963 {
964− struct inode *inode = dentry->d_inode;
964+ struct inode *inode = path->dentry->d_inode;
965965 struct shmem_inode_info *info = SHMEM_I(inode);
966966
967967 if (info->alloced - info->swapped != inode->i_mapping->nrpages) {
samples/Kconfig+6−0
@@ -112,4 +112,10 @@ config SAMPLE_VFIO_MDEV_MTTY · 111 unmodified lines
112112 Build a virtual tty sample driver for use as a VFIO
113113 mediated device
114114
115+config SAMPLE_STATX
116+ bool "Build example extended-stat using code"
117+ depends on BROKEN
118+ help
119+ Build example userspace program to use the new extended-stat syscall.
120+
115121 endif # SAMPLES
samples/Makefile+1−1
@@ -3,4 +3,4 @@ · 2 unmodified lines
33 obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \
44 hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \
55 configfs/ connector/ v4l/ trace_printk/ blackfin/ \
6− vfio-mdev/
6+ vfio-mdev/ statx/
samples/statx/Makefile+10−0
@@ -0,0 +1,10 @@
1+# kbuild trick to avoid linker error. Can be omitted if a module is built.
2+obj- := dummy.o
3+
4+# List of programs to build
5+hostprogs-$(CONFIG_SAMPLE_STATX) := test-statx
6+
7+# Tell kbuild to always build the programs
8+always := $(hostprogs-y)
9+
10+HOSTCFLAGS_test-statx.o += -I$(objtree)/usr/include
samples/statx/test-statx.c+254−0
@@ -0,0 +1,254 @@
1+/* Test the statx() system call.
2+ *
3+ * Note that the output of this program is intended to look like the output of
4+ * /bin/stat where possible.
5+ *
6+ * Copyright (C) 2015 Red Hat, Inc. All Rights Reserved.
7+ * Written by David Howells (dhowells@redhat.com)
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public Licence
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the Licence, or (at your option) any later version.
13+ */
14+
15+#define _GNU_SOURCE
16+#define _ATFILE_SOURCE
17+#include <stdio.h>
18+#include <stdlib.h>
19+#include <string.h>
20+#include <unistd.h>
21+#include <ctype.h>
22+#include <errno.h>
23+#include <time.h>
24+#include <sys/syscall.h>
25+#include <sys/types.h>
26+#include <linux/stat.h>
27+#include <linux/fcntl.h>
28+#include <sys/stat.h>
29+
30+#define AT_STATX_SYNC_TYPE 0x6000
31+#define AT_STATX_SYNC_AS_STAT 0x0000
32+#define AT_STATX_FORCE_SYNC 0x2000
33+#define AT_STATX_DONT_SYNC 0x4000
34+
35+static __attribute__((unused))
36+ssize_t statx(int dfd, const char *filename, unsigned flags,
37+ unsigned int mask, struct statx *buffer)
38+{
39+ return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
40+}
41+
42+static void print_time(const char *field, struct statx_timestamp *ts)
43+{
44+ struct tm tm;
45+ time_t tim;
46+ char buffer[100];
47+ int len;
48+
49+ tim = ts->tv_sec;
50+ if (!localtime_r(&tim, &tm)) {
51+ perror("localtime_r");
52+ exit(1);
53+ }
54+ len = strftime(buffer, 100, "%F %T", &tm);
55+ if (len == 0) {
56+ perror("strftime");
57+ exit(1);
58+ }
59+ printf("%s", field);
60+ fwrite(buffer, 1, len, stdout);
61+ printf(".%09u", ts->tv_nsec);
62+ len = strftime(buffer, 100, "%z", &tm);
63+ if (len == 0) {
64+ perror("strftime2");
65+ exit(1);
66+ }
67+ fwrite(buffer, 1, len, stdout);
68+ printf("\n");
69+}
70+
71+static void dump_statx(struct statx *stx)
72+{
73+ char buffer[256], ft = '?';
74+
75+ printf("results=%x\n", stx->stx_mask);
76+
77+ printf(" ");
78+ if (stx->stx_mask & STATX_SIZE)
79+ printf(" Size: %-15llu", (unsigned long long)stx->stx_size);
80+ if (stx->stx_mask & STATX_BLOCKS)
81+ printf(" Blocks: %-10llu", (unsigned long long)stx->stx_blocks);
82+ printf(" IO Block: %-6llu", (unsigned long long)stx->stx_blksize);
83+ if (stx->stx_mask & STATX_TYPE) {
84+ switch (stx->stx_mode & S_IFMT) {
85+ case S_IFIFO: printf(" FIFO\n"); ft = 'p'; break;
86+ case S_IFCHR: printf(" character special file\n"); ft = 'c'; break;
87+ case S_IFDIR: printf(" directory\n"); ft = 'd'; break;
88+ case S_IFBLK: printf(" block special file\n"); ft = 'b'; break;
89+ case S_IFREG: printf(" regular file\n"); ft = '-'; break;
90+ case S_IFLNK: printf(" symbolic link\n"); ft = 'l'; break;
91+ case S_IFSOCK: printf(" socket\n"); ft = 's'; break;
92+ default:
93+ printf(" unknown type (%o)\n", stx->stx_mode & S_IFMT);
94+ break;
95+ }
96+ } else {
97+ printf(" no type\n");
98+ }
99+
100+ sprintf(buffer, "%02x:%02x", stx->stx_dev_major, stx->stx_dev_minor);
101+ printf("Device: %-15s", buffer);
102+ if (stx->stx_mask & STATX_INO)
103+ printf(" Inode: %-11llu", (unsigned long long) stx->stx_ino);
104+ if (stx->stx_mask & STATX_NLINK)
105+ printf(" Links: %-5u", stx->stx_nlink);
106+ if (stx->stx_mask & STATX_TYPE) {
107+ switch (stx->stx_mode & S_IFMT) {
108+ case S_IFBLK:
109+ case S_IFCHR:
110+ printf(" Device type: %u,%u",
111+ stx->stx_rdev_major, stx->stx_rdev_minor);
112+ break;
113+ }
114+ }
115+ printf("\n");
116+
117+ if (stx->stx_mask & STATX_MODE)
118+ printf("Access: (%04o/%c%c%c%c%c%c%c%c%c%c) ",
119+ stx->stx_mode & 07777,
120+ ft,
121+ stx->stx_mode & S_IRUSR ? 'r' : '-',
122+ stx->stx_mode & S_IWUSR ? 'w' : '-',
123+ stx->stx_mode & S_IXUSR ? 'x' : '-',
124+ stx->stx_mode & S_IRGRP ? 'r' : '-',
125+ stx->stx_mode & S_IWGRP ? 'w' : '-',
126+ stx->stx_mode & S_IXGRP ? 'x' : '-',
127+ stx->stx_mode & S_IROTH ? 'r' : '-',
128+ stx->stx_mode & S_IWOTH ? 'w' : '-',
129+ stx->stx_mode & S_IXOTH ? 'x' : '-');
130+ if (stx->stx_mask & STATX_UID)
131+ printf("Uid: %5d ", stx->stx_uid);
132+ if (stx->stx_mask & STATX_GID)
133+ printf("Gid: %5d\n", stx->stx_gid);
134+
135+ if (stx->stx_mask & STATX_ATIME)
136+ print_time("Access: ", &stx->stx_atime);
137+ if (stx->stx_mask & STATX_MTIME)
138+ print_time("Modify: ", &stx->stx_mtime);
139+ if (stx->stx_mask & STATX_CTIME)
140+ print_time("Change: ", &stx->stx_ctime);
141+ if (stx->stx_mask & STATX_BTIME)
142+ print_time(" Birth: ", &stx->stx_btime);
143+
144+ if (stx->stx_attributes) {
145+ unsigned char bits;
146+ int loop, byte;
147+
148+ static char attr_representation[64 + 1] =
149+ /* STATX_ATTR_ flags: */
150+ "????????" /* 63-56 */
151+ "????????" /* 55-48 */
152+ "????????" /* 47-40 */
153+ "????????" /* 39-32 */
154+ "????????" /* 31-24 0x00000000-ff000000 */
155+ "????????" /* 23-16 0x00000000-00ff0000 */
156+ "???me???" /* 15- 8 0x00000000-0000ff00 */
157+ "?dai?c??" /* 7- 0 0x00000000-000000ff */
158+ ;
159+
160+ printf("Attributes: %016llx (", stx->stx_attributes);
161+ for (byte = 64 - 8; byte >= 0; byte -= 8) {
162+ bits = stx->stx_attributes >> byte;
163+ for (loop = 7; loop >= 0; loop--) {
164+ int bit = byte + loop;
165+
166+ if (bits & 0x80)
167+ putchar(attr_representation[63 - bit]);
168+ else
169+ putchar('-');
170+ bits <<= 1;
171+ }
172+ if (byte)
173+ putchar(' ');
174+ }
175+ printf(")\n");
176+ }
177+}
178+
179+static void dump_hex(unsigned long long *data, int from, int to)
180+{
181+ unsigned offset, print_offset = 1, col = 0;
182+
183+ from /= 8;
184+ to = (to + 7) / 8;
185+
186+ for (offset = from; offset < to; offset++) {
187+ if (print_offset) {
188+ printf("%04x: ", offset * 8);
189+ print_offset = 0;
190+ }
191+ printf("%016llx", data[offset]);
192+ col++;
193+ if ((col & 3) == 0) {
194+ printf("\n");
195+ print_offset = 1;
196+ } else {
197+ printf(" ");
198+ }
199+ }
200+
201+ if (!print_offset)
202+ printf("\n");
203+}
204+
205+int main(int argc, char **argv)
206+{
207+ struct statx stx;
208+ int ret, raw = 0, atflag = AT_SYMLINK_NOFOLLOW;
209+
210+ unsigned int mask = STATX_ALL;
211+
212+ for (argv++; *argv; argv++) {
213+ if (strcmp(*argv, "-F") == 0) {
214+ atflag &= ~AT_STATX_SYNC_TYPE;
215+ atflag |= AT_STATX_FORCE_SYNC;
216+ continue;
217+ }
218+ if (strcmp(*argv, "-D") == 0) {
219+ atflag &= ~AT_STATX_SYNC_TYPE;
220+ atflag |= AT_STATX_DONT_SYNC;
221+ continue;
222+ }
223+ if (strcmp(*argv, "-L") == 0) {
224+ atflag &= ~AT_SYMLINK_NOFOLLOW;
225+ continue;
226+ }
227+ if (strcmp(*argv, "-O") == 0) {
228+ mask &= ~STATX_BASIC_STATS;
229+ continue;
230+ }
231+ if (strcmp(*argv, "-A") == 0) {
232+ atflag |= AT_NO_AUTOMOUNT;
233+ continue;
234+ }
235+ if (strcmp(*argv, "-R") == 0) {
236+ raw = 1;
237+ continue;
238+ }
239+
240+ memset(&stx, 0xbf, sizeof(stx));
241+ ret = statx(AT_FDCWD, *argv, atflag, mask, &stx);
242+ printf("statx(%s) = %d\n", *argv, ret);
243+ if (ret < 0) {
244+ perror(*argv);
245+ exit(1);
246+ }
247+
248+ if (raw)
249+ dump_hex((unsigned long long *)&stx, 0, sizeof(stx));
250+
251+ dump_statx(&stx);
252+ }
253+ return 0;
254+}