Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

David Howells and committed by
Al Viro
a528d35e bbe08c0a

+822 -214
+2 -1
Documentation/filesystems/Locking
··· 58 58 int (*permission) (struct inode *, int, unsigned int); 59 59 int (*get_acl)(struct inode *, int); 60 60 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); 62 63 ssize_t (*listxattr) (struct dentry *, char *, size_t); 63 64 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, u64 len); 64 65 void (*update_time)(struct inode *, struct timespec *, int);
+2 -1
Documentation/filesystems/vfs.txt
··· 382 382 int (*permission) (struct inode *, int); 383 383 int (*get_acl)(struct inode *, int); 384 384 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); 386 387 ssize_t (*listxattr) (struct dentry *, char *, size_t); 387 388 void (*update_time)(struct inode *, struct timespec *, int); 388 389 int (*atomic_open)(struct inode *, struct dentry *, struct file *,
+1
arch/x86/entry/syscalls/syscall_32.tbl
··· 389 389 380 i386 pkey_mprotect sys_pkey_mprotect 390 390 381 i386 pkey_alloc sys_pkey_alloc 391 391 382 i386 pkey_free sys_pkey_free 392 + 383 i386 statx sys_statx
+1
arch/x86/entry/syscalls/syscall_64.tbl
··· 338 338 329 common pkey_mprotect sys_pkey_mprotect 339 339 330 common pkey_alloc sys_pkey_alloc 340 340 331 common pkey_free sys_pkey_free 341 + 332 common statx sys_statx 341 342 342 343 # 343 344 # x32-specific system call numbers start at 512 to avoid cache impact
+2 -1
drivers/base/devtmpfs.c
··· 309 309 if (d_really_is_positive(dentry)) { 310 310 struct kstat stat; 311 311 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); 313 314 if (!err && dev_mynode(dev, d_inode(dentry), &stat)) { 314 315 struct iattr newattrs; 315 316 /*
+2 -1
drivers/block/loop.c
··· 1175 1175 1176 1176 if (lo->lo_state != Lo_bound) 1177 1177 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); 1179 1180 if (error) 1180 1181 return error; 1181 1182 memset(info, 0, sizeof(*info));
+1 -1
drivers/mtd/ubi/build.c
··· 1159 1159 if (err) 1160 1160 return ERR_PTR(err); 1161 1161 1162 - err = vfs_getattr(&path, &stat); 1162 + err = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT); 1163 1163 path_put(&path); 1164 1164 if (err) 1165 1165 return ERR_PTR(err);
+1 -1
drivers/mtd/ubi/kapi.c
··· 314 314 if (error) 315 315 return ERR_PTR(error); 316 316 317 - error = vfs_getattr(&path, &stat); 317 + error = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT); 318 318 path_put(&path); 319 319 if (error) 320 320 return ERR_PTR(error);
+5 -4
drivers/staging/lustre/lustre/llite/file.c
··· 2952 2952 return rc; 2953 2953 } 2954 2954 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) 2956 2957 { 2957 - struct inode *inode = d_inode(de); 2958 + struct inode *inode = d_inode(path->dentry); 2958 2959 struct ll_sb_info *sbi = ll_i2sbi(inode); 2959 2960 struct ll_inode_info *lli = ll_i2info(inode); 2960 2961 int res; 2961 2962 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); 2964 2965 ll_stats_ops_tally(sbi, LPROC_LL_GETATTR, 1); 2965 2966 2966 2967 if (res)
+2 -1
drivers/staging/lustre/lustre/llite/llite_internal.h
··· 750 750 int ll_file_release(struct inode *inode, struct file *file); 751 751 int ll_release_openhandle(struct inode *, struct lookup_intent *); 752 752 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); 754 755 struct posix_acl *ll_get_acl(struct inode *inode, int type); 755 756 int ll_migrate(struct inode *parent, struct file *file, int mdtidx, 756 757 const char *name, int namelen);
+6 -4
fs/9p/vfs_inode.c
··· 1047 1047 1048 1048 /** 1049 1049 * v9fs_vfs_getattr - retrieve file metadata 1050 - * @mnt: mount information 1051 - * @dentry: file to get attributes on 1050 + * @path: Object to query 1052 1051 * @stat: metadata structure to populate 1052 + * @request_mask: Mask of STATX_xxx flags indicating the caller's interests 1053 + * @flags: AT_STATX_xxx setting 1053 1054 * 1054 1055 */ 1055 1056 1056 1057 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) 1059 1060 { 1061 + struct dentry *dentry = path->dentry; 1060 1062 struct v9fs_session_info *v9ses; 1061 1063 struct p9_fid *fid; 1062 1064 struct p9_wstat *st;
+3 -2
fs/9p/vfs_inode_dotl.c
··· 468 468 } 469 469 470 470 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) 473 473 { 474 + struct dentry *dentry = path->dentry; 474 475 struct v9fs_session_info *v9ses; 475 476 struct p9_fid *fid; 476 477 struct p9_stat_dotl *st;
+3 -5
fs/afs/inode.c
··· 375 375 /* 376 376 * read the attributes of an inode 377 377 */ 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) 380 380 { 381 - struct inode *inode; 382 - 383 - inode = d_inode(dentry); 381 + struct inode *inode = d_inode(path->dentry); 384 382 385 383 _enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation); 386 384
+1 -1
fs/afs/internal.h
··· 533 533 struct afs_callback *); 534 534 extern void afs_zap_data(struct afs_vnode *); 535 535 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); 537 537 extern int afs_setattr(struct dentry *, struct iattr *); 538 538 extern void afs_evict_inode(struct inode *); 539 539 extern int afs_drop_inode(struct inode *);
+2 -2
fs/bad_inode.c
··· 89 89 return -EIO; 90 90 } 91 91 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) 94 94 { 95 95 return -EIO; 96 96 }
+3 -3
fs/btrfs/inode.c
··· 9413 9413 return -ENOMEM; 9414 9414 } 9415 9415 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) 9418 9418 { 9419 9419 u64 delalloc_bytes; 9420 - struct inode *inode = d_inode(dentry); 9420 + struct inode *inode = d_inode(path->dentry); 9421 9421 u32 blocksize = inode->i_sb->s_blocksize; 9422 9422 9423 9423 generic_fillattr(inode, stat);
+3 -3
fs/ceph/inode.c
··· 2187 2187 * Get all attributes. Hopefully somedata we'll have a statlite() 2188 2188 * and can limit the fields we require to be accurate. 2189 2189 */ 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) 2192 2192 { 2193 - struct inode *inode = d_inode(dentry); 2193 + struct inode *inode = d_inode(path->dentry); 2194 2194 struct ceph_inode_info *ci = ceph_inode(inode); 2195 2195 int err; 2196 2196
+2 -2
fs/ceph/super.h
··· 784 784 extern int ceph_permission(struct inode *inode, int mask); 785 785 extern int __ceph_setattr(struct inode *inode, struct iattr *attr); 786 786 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); 789 789 790 790 /* xattr.c */ 791 791 int __ceph_setxattr(struct inode *, const char *, const void *, size_t, int);
+1 -1
fs/cifs/cifsfs.h
··· 83 83 extern int cifs_invalidate_mapping(struct inode *inode); 84 84 extern int cifs_revalidate_mapping(struct inode *inode); 85 85 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); 87 87 extern int cifs_setattr(struct dentry *, struct iattr *); 88 88 89 89 extern const struct inode_operations cifs_file_inode_ops;
+3 -2
fs/cifs/inode.c
··· 1990 1990 return cifs_revalidate_mapping(inode); 1991 1991 } 1992 1992 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) 1995 1995 { 1996 + struct dentry *dentry = path->dentry; 1996 1997 struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb); 1997 1998 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); 1998 1999 struct inode *inode = d_inode(dentry);
+1 -1
fs/coda/coda_linux.h
··· 47 47 int coda_release(struct inode *i, struct file *f); 48 48 int coda_permission(struct inode *inode, int mask); 49 49 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); 51 51 int coda_setattr(struct dentry *, struct iattr *); 52 52 53 53 /* this file: heloers */
+4 -3
fs/coda/inode.c
··· 255 255 coda_cache_clear_inode(inode); 256 256 } 257 257 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) 259 260 { 260 - int err = coda_revalidate_inode(d_inode(dentry)); 261 + int err = coda_revalidate_inode(d_inode(path->dentry)); 261 262 if (!err) 262 - generic_fillattr(d_inode(dentry), stat); 263 + generic_fillattr(d_inode(path->dentry), stat); 263 264 return err; 264 265 } 265 266
+8 -5
fs/ecryptfs/inode.c
··· 959 959 return rc; 960 960 } 961 961 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) 964 964 { 965 + struct dentry *dentry = path->dentry; 965 966 struct ecryptfs_mount_crypt_stat *mount_crypt_stat; 966 967 int rc = 0; 967 968 ··· 984 983 return rc; 985 984 } 986 985 987 - static int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry, 988 - struct kstat *stat) 986 + static int ecryptfs_getattr(const struct path *path, struct kstat *stat, 987 + u32 request_mask, unsigned int flags) 989 988 { 989 + struct dentry *dentry = path->dentry; 990 990 struct kstat lower_stat; 991 991 int rc; 992 992 993 - rc = vfs_getattr(ecryptfs_dentry_to_lower_path(dentry), &lower_stat); 993 + rc = vfs_getattr(ecryptfs_dentry_to_lower_path(dentry), &lower_stat, 994 + request_mask, flags); 994 995 if (!rc) { 995 996 fsstack_copy_attr_all(d_inode(dentry), 996 997 ecryptfs_inode_to_lower(d_inode(dentry)));
+2 -1
fs/exportfs/expfs.c
··· 299 299 * filesystem supports 64-bit inode numbers. So we need to 300 300 * actually call ->getattr, not just read i_ino: 301 301 */ 302 - error = vfs_getattr_nosec(&child_path, &stat); 302 + error = vfs_getattr_nosec(&child_path, &stat, 303 + STATX_INO, AT_STATX_SYNC_AS_STAT); 303 304 if (error) 304 305 return error; 305 306 buffer.ino = stat.ino;
+1 -2
fs/ext4/ext4.h
··· 2462 2462 extern struct inode *ext4_iget_normal(struct super_block *, unsigned long); 2463 2463 extern int ext4_write_inode(struct inode *, struct writeback_control *); 2464 2464 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); 2467 2466 extern void ext4_evict_inode(struct inode *); 2468 2467 extern void ext4_clear_inode(struct inode *); 2469 2468 extern int ext4_sync_inode(handle_t *, struct inode *);
+3 -3
fs/ext4/inode.c
··· 5387 5387 return error; 5388 5388 } 5389 5389 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) 5392 5392 { 5393 5393 struct inode *inode; 5394 5394 unsigned long long delalloc_blocks; 5395 5395 5396 - inode = d_inode(dentry); 5396 + inode = d_inode(path->dentry); 5397 5397 generic_fillattr(inode, stat); 5398 5398 5399 5399 /*
+2 -2
fs/f2fs/f2fs.h
··· 2040 2040 void truncate_data_blocks(struct dnode_of_data *dn); 2041 2041 int truncate_blocks(struct inode *inode, u64 from, bool lock); 2042 2042 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); 2045 2045 int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2046 2046 int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2047 2047 int truncate_data_blocks_range(struct dnode_of_data *dn, int count);
+3 -3
fs/f2fs/file.c
··· 633 633 return 0; 634 634 } 635 635 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) 638 638 { 639 - struct inode *inode = d_inode(dentry); 639 + struct inode *inode = d_inode(path->dentry); 640 640 generic_fillattr(inode, stat); 641 641 stat->blocks <<= 3; 642 642 return 0;
+2 -2
fs/fat/fat.h
··· 364 364 extern const struct inode_operations fat_file_inode_operations; 365 365 extern int fat_setattr(struct dentry *dentry, struct iattr *attr); 366 366 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); 369 369 extern int fat_file_fsync(struct file *file, loff_t start, loff_t end, 370 370 int datasync); 371 371
+3 -2
fs/fat/file.c
··· 365 365 fat_flush_inodes(inode->i_sb, inode, NULL); 366 366 } 367 367 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) 369 370 { 370 - struct inode *inode = d_inode(dentry); 371 + struct inode *inode = d_inode(path->dentry); 371 372 generic_fillattr(inode, stat); 372 373 stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size; 373 374
+3 -3
fs/fuse/dir.c
··· 1777 1777 return ret; 1778 1778 } 1779 1779 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) 1782 1782 { 1783 - struct inode *inode = d_inode(entry); 1783 + struct inode *inode = d_inode(path->dentry); 1784 1784 struct fuse_conn *fc = get_fuse_conn(inode); 1785 1785 1786 1786 if (!fuse_allow_current_process(fc))
+6 -5
fs/gfs2/inode.c
··· 1959 1959 1960 1960 /** 1961 1961 * 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 1964 1963 * @stat: The inode's stats 1964 + * @request_mask: Mask of STATX_xxx flags indicating the caller's interests 1965 + * @flags: AT_STATX_xxx setting 1965 1966 * 1966 1967 * This may be called from the VFS directly, or from within GFS2 with the 1967 1968 * inode locked, so we look to see if the glock is already locked and only ··· 1973 1972 * Returns: errno 1974 1973 */ 1975 1974 1976 - static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, 1977 - struct kstat *stat) 1975 + static int gfs2_getattr(const struct path *path, struct kstat *stat, 1976 + u32 request_mask, unsigned int flags) 1978 1977 { 1979 - struct inode *inode = d_inode(dentry); 1978 + struct inode *inode = d_inode(path->dentry); 1980 1979 struct gfs2_inode *ip = GFS2_I(inode); 1981 1980 struct gfs2_holder gh; 1982 1981 int error;
+4 -4
fs/kernfs/inode.c
··· 200 200 set_nlink(inode, kn->dir.subdirs + 2); 201 201 } 202 202 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) 205 205 { 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); 208 208 209 209 mutex_lock(&kernfs_mutex); 210 210 kernfs_refresh_inode(kn, inode);
+2 -2
fs/kernfs/kernfs-internal.h
··· 80 80 void kernfs_evict_inode(struct inode *inode); 81 81 int kernfs_iop_permission(struct inode *inode, int mask); 82 82 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); 85 85 ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size); 86 86 87 87 /*
+6 -6
fs/libfs.c
··· 20 20 21 21 #include "internal.h" 22 22 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) 25 25 { 26 - struct inode *inode = d_inode(dentry); 26 + struct inode *inode = d_inode(path->dentry); 27 27 generic_fillattr(inode, stat); 28 28 stat->blocks = inode->i_mapping->nrpages << (PAGE_SHIFT - 9); 29 29 return 0; ··· 1143 1143 return ERR_PTR(-ENOENT); 1144 1144 } 1145 1145 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) 1148 1148 { 1149 - struct inode *inode = d_inode(dentry); 1149 + struct inode *inode = d_inode(path->dentry); 1150 1150 generic_fillattr(inode, stat); 1151 1151 return 0; 1152 1152 }
+7 -4
fs/minix/inode.c
··· 622 622 return err; 623 623 } 624 624 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) 626 627 { 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) 630 633 stat->blocks = (BLOCK_SIZE / 512) * V1_minix_blocks(stat->size, sb); 631 634 else 632 635 stat->blocks = (sb->s_blocksize / 512) * V2_minix_blocks(stat->size, sb);
+1 -1
fs/minix/minix.h
··· 51 51 extern int minix_new_block(struct inode * inode); 52 52 extern void minix_free_block(struct inode *inode, unsigned long block); 53 53 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); 55 55 extern int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len); 56 56 57 57 extern void V1_minix_truncate(struct inode *);
+7 -6
fs/nfs/inode.c
··· 703 703 return false; 704 704 } 705 705 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) 707 708 { 708 - struct inode *inode = d_inode(dentry); 709 + struct inode *inode = d_inode(path->dentry); 709 710 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME; 710 711 int err = 0; 711 712 ··· 727 726 * - NFS never sets MS_NOATIME or MS_NODIRATIME so there is 728 727 * no point in checking those. 729 728 */ 730 - if ((mnt->mnt_flags & MNT_NOATIME) || 731 - ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))) 729 + if ((path->mnt->mnt_flags & MNT_NOATIME) || 730 + ((path->mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))) 732 731 need_atime = 0; 733 732 734 733 if (need_atime || nfs_need_revalidate_inode(inode)) { 735 734 struct nfs_server *server = NFS_SERVER(inode); 736 735 737 - nfs_readdirplus_parent_cache_miss(dentry); 736 + nfs_readdirplus_parent_cache_miss(path->dentry); 738 737 err = __nfs_revalidate_inode(server, inode); 739 738 } else 740 - nfs_readdirplus_parent_cache_hit(dentry); 739 + nfs_readdirplus_parent_cache_hit(path->dentry); 741 740 if (!err) { 742 741 generic_fillattr(inode, stat); 743 742 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
+5 -4
fs/nfs/namespace.c
··· 178 178 } 179 179 180 180 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) 182 183 { 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); 186 187 return 0; 187 188 } 188 189
+2 -2
fs/nfsd/nfs4xdr.c
··· 2301 2301 if (path.dentry != path.mnt->mnt_root) 2302 2302 break; 2303 2303 } 2304 - err = vfs_getattr(&path, stat); 2304 + err = vfs_getattr(&path, stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); 2305 2305 path_put(&path); 2306 2306 return err; 2307 2307 } ··· 2385 2385 goto out; 2386 2386 } 2387 2387 2388 - err = vfs_getattr(&path, &stat); 2388 + err = vfs_getattr(&path, &stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); 2389 2389 if (err) 2390 2390 goto out_nfserr; 2391 2391 if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE |
+2 -1
fs/nfsd/vfs.h
··· 135 135 { 136 136 struct path p = {.mnt = fh->fh_export->ex_path.mnt, 137 137 .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)); 139 140 } 140 141 141 142 static inline int nfsd_create_is_exclusive(int createmode)
+5 -6
fs/ocfs2/file.c
··· 1306 1306 return status; 1307 1307 } 1308 1308 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) 1312 1311 { 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; 1315 1314 struct ocfs2_super *osb = sb->s_fs_info; 1316 1315 int err; 1317 1316 1318 - err = ocfs2_inode_revalidate(dentry); 1317 + err = ocfs2_inode_revalidate(path->dentry); 1319 1318 if (err) { 1320 1319 if (err != -ENOENT) 1321 1320 mlog_errno(err);
+2 -2
fs/ocfs2/file.h
··· 68 68 int ocfs2_extend_allocation(struct inode *inode, u32 logical_start, 69 69 u32 clusters_to_add, int mark_unwritten); 70 70 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); 73 73 int ocfs2_permission(struct inode *inode, int mask); 74 74 75 75 int ocfs2_should_update_atime(struct inode *inode,
+6 -7
fs/orangefs/inode.c
··· 245 245 /* 246 246 * Obtain attributes of an object given a dentry 247 247 */ 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) 251 250 { 252 251 int ret = -ENOENT; 253 - struct inode *inode = dentry->d_inode; 252 + struct inode *inode = path->dentry->d_inode; 254 253 struct orangefs_inode_s *orangefs_inode = NULL; 255 254 256 255 gossip_debug(GOSSIP_INODE_DEBUG, 257 256 "orangefs_getattr: called on %pd\n", 258 - dentry); 257 + path->dentry); 259 258 260 259 ret = orangefs_inode_getattr(inode, 0, 0); 261 260 if (ret == 0) { 262 - generic_fillattr(inode, kstat); 261 + generic_fillattr(inode, stat); 263 262 264 263 /* override block size reported to stat */ 265 264 orangefs_inode = ORANGEFS_I(inode); 266 - kstat->blksize = orangefs_inode->blksize; 265 + stat->blksize = orangefs_inode->blksize; 267 266 } 268 267 return ret; 269 268 }
+2 -3
fs/orangefs/orangefs-kernel.h
··· 439 439 440 440 int orangefs_setattr(struct dentry *dentry, struct iattr *iattr); 441 441 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); 445 444 446 445 int orangefs_permission(struct inode *inode, int mask); 447 446
+4 -2
fs/overlayfs/copy_up.c
··· 346 346 ovl_path_upper(parent, &parentpath); 347 347 upperdir = parentpath.dentry; 348 348 349 - err = vfs_getattr(&parentpath, &pstat); 349 + err = vfs_getattr(&parentpath, &pstat, 350 + STATX_ATIME | STATX_MTIME, AT_STATX_SYNC_AS_STAT); 350 351 if (err) 351 352 return err; 352 353 ··· 410 409 } 411 410 412 411 ovl_path_lower(next, &lowerpath); 413 - err = vfs_getattr(&lowerpath, &stat); 412 + err = vfs_getattr(&lowerpath, &stat, 413 + STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); 414 414 /* maybe truncate regular file. this has no effect on dirs */ 415 415 if (flags & O_TRUNC) 416 416 stat.size = 0;
+6 -4
fs/overlayfs/dir.c
··· 138 138 return err; 139 139 } 140 140 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) 143 143 { 144 + struct dentry *dentry = path->dentry; 144 145 int err; 145 146 enum ovl_path_type type; 146 147 struct path realpath; ··· 149 148 150 149 type = ovl_path_real(dentry, &realpath); 151 150 old_cred = ovl_override_creds(dentry->d_sb); 152 - err = vfs_getattr(&realpath, stat); 151 + err = vfs_getattr(&realpath, stat, request_mask, flags); 153 152 revert_creds(old_cred); 154 153 if (err) 155 154 return err; ··· 265 264 goto out; 266 265 267 266 ovl_path_upper(dentry, &upperpath); 268 - err = vfs_getattr(&upperpath, &stat); 267 + err = vfs_getattr(&upperpath, &stat, 268 + STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); 269 269 if (err) 270 270 goto out_unlock; 271 271
+4 -3
fs/overlayfs/inode.c
··· 56 56 return err; 57 57 } 58 58 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) 61 61 { 62 + struct dentry *dentry = path->dentry; 62 63 struct path realpath; 63 64 const struct cred *old_cred; 64 65 int err; 65 66 66 67 ovl_path_real(dentry, &realpath); 67 68 old_cred = ovl_override_creds(dentry->d_sb); 68 - err = vfs_getattr(&realpath, stat); 69 + err = vfs_getattr(&realpath, stat, request_mask, flags); 69 70 revert_creds(old_cred); 70 71 return err; 71 72 }
+7 -5
fs/proc/base.c
··· 1724 1724 return NULL; 1725 1725 } 1726 1726 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) 1728 1729 { 1729 - struct inode *inode = d_inode(dentry); 1730 + struct inode *inode = d_inode(path->dentry); 1730 1731 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; 1732 1733 1733 1734 generic_fillattr(inode, stat); 1734 1735 ··· 3512 3511 return 0; 3513 3512 } 3514 3513 3515 - static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 3514 + static int proc_task_getattr(const struct path *path, struct kstat *stat, 3515 + u32 request_mask, unsigned int query_flags) 3516 3516 { 3517 - struct inode *inode = d_inode(dentry); 3517 + struct inode *inode = d_inode(path->dentry); 3518 3518 struct task_struct *p = get_proc_task(inode); 3519 3519 generic_fillattr(inode, stat); 3520 3520
+3 -3
fs/proc/generic.c
··· 118 118 return 0; 119 119 } 120 120 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) 123 123 { 124 - struct inode *inode = d_inode(dentry); 124 + struct inode *inode = d_inode(path->dentry); 125 125 struct proc_dir_entry *de = PDE(inode); 126 126 if (de && de->nlink) 127 127 set_nlink(inode, de->nlink);
+1 -1
fs/proc/internal.h
··· 149 149 * base.c 150 150 */ 151 151 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); 153 153 extern int proc_setattr(struct dentry *, struct iattr *); 154 154 extern struct inode *proc_pid_make_inode(struct super_block *, struct task_struct *, umode_t); 155 155 extern int pid_revalidate(struct dentry *, unsigned int);
+3 -3
fs/proc/proc_net.c
··· 140 140 return de; 141 141 } 142 142 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) 145 145 { 146 - struct inode *inode = d_inode(dentry); 146 + struct inode *inode = d_inode(path->dentry); 147 147 struct net *net; 148 148 149 149 net = get_proc_task_net(inode);
+3 -2
fs/proc/proc_sysctl.c
··· 801 801 return 0; 802 802 } 803 803 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) 805 806 { 806 - struct inode *inode = d_inode(dentry); 807 + struct inode *inode = d_inode(path->dentry); 807 808 struct ctl_table_header *head = grab_header(inode); 808 809 struct ctl_table *table = PROC_I(inode)->sysctl_entry; 809 810
+3 -3
fs/proc/root.c
··· 149 149 proc_sys_init(); 150 150 } 151 151 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) 154 154 { 155 - generic_fillattr(d_inode(dentry), stat); 155 + generic_fillattr(d_inode(path->dentry), stat); 156 156 stat->nlink = proc_root.nlink + nr_processes(); 157 157 return 0; 158 158 }
+176 -38
fs/stat.c
··· 18 18 #include <linux/uaccess.h> 19 19 #include <asm/unistd.h> 20 20 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 + */ 21 30 void generic_fillattr(struct inode *inode, struct kstat *stat) 22 31 { 23 32 stat->dev = inode->i_sb->s_dev; ··· 42 33 stat->ctime = inode->i_ctime; 43 34 stat->blksize = i_blocksize(inode); 44 35 stat->blocks = inode->i_blocks; 45 - } 46 36 37 + if (IS_NOATIME(inode)) 38 + stat->result_mask &= ~STATX_ATIME; 39 + if (IS_AUTOMOUNT(inode)) 40 + stat->attributes |= STATX_ATTR_AUTOMOUNT; 41 + } 47 42 EXPORT_SYMBOL(generic_fillattr); 48 43 49 44 /** 50 45 * vfs_getattr_nosec - getattr without security checks 51 46 * @path: file to get attributes from 52 47 * @stat: structure to return attributes in 48 + * @request_mask: STATX_xxx flags indicating what the caller wants 49 + * @query_flags: Query mode (KSTAT_QUERY_FLAGS) 53 50 * 54 51 * Get attributes without calling security_inode_getattr. 55 52 * 56 53 * Currently the only caller other than vfs_getattr is internal to the 57 - * filehandle lookup code, which uses only the inode number and returns 58 - * no attributes to any user. Any other code probably wants 59 - * vfs_getattr. 54 + * filehandle lookup code, which uses only the inode number and returns no 55 + * attributes to any user. Any other code probably wants vfs_getattr. 60 56 */ 61 - int vfs_getattr_nosec(struct path *path, struct kstat *stat) 57 + int vfs_getattr_nosec(const struct path *path, struct kstat *stat, 58 + u32 request_mask, unsigned int query_flags) 62 59 { 63 60 struct inode *inode = d_backing_inode(path->dentry); 64 61 62 + memset(stat, 0, sizeof(*stat)); 63 + stat->result_mask |= STATX_BASIC_STATS; 64 + request_mask &= STATX_ALL; 65 + query_flags &= KSTAT_QUERY_FLAGS; 65 66 if (inode->i_op->getattr) 66 - return inode->i_op->getattr(path->mnt, path->dentry, stat); 67 + return inode->i_op->getattr(path, stat, request_mask, 68 + query_flags); 67 69 68 70 generic_fillattr(inode, stat); 69 71 return 0; 70 72 } 71 - 72 73 EXPORT_SYMBOL(vfs_getattr_nosec); 73 74 74 - int vfs_getattr(struct path *path, struct kstat *stat) 75 + /* 76 + * vfs_getattr - Get the enhanced basic attributes of a file 77 + * @path: The file of interest 78 + * @stat: Where to return the statistics 79 + * @request_mask: STATX_xxx flags indicating what the caller wants 80 + * @query_flags: Query mode (KSTAT_QUERY_FLAGS) 81 + * 82 + * Ask the filesystem for a file's attributes. The caller must indicate in 83 + * request_mask and query_flags to indicate what they want. 84 + * 85 + * If the file is remote, the filesystem can be forced to update the attributes 86 + * from the backing store by passing AT_STATX_FORCE_SYNC in query_flags or can 87 + * suppress the update by passing AT_STATX_DONT_SYNC. 88 + * 89 + * Bits must have been set in request_mask to indicate which attributes the 90 + * caller wants retrieving. Any such attribute not requested may be returned 91 + * anyway, but the value may be approximate, and, if remote, may not have been 92 + * synchronised with the server. 93 + * 94 + * 0 will be returned on success, and a -ve error code if unsuccessful. 95 + */ 96 + int vfs_getattr(const struct path *path, struct kstat *stat, 97 + u32 request_mask, unsigned int query_flags) 75 98 { 76 99 int retval; 77 100 78 101 retval = security_inode_getattr(path); 79 102 if (retval) 80 103 return retval; 81 - return vfs_getattr_nosec(path, stat); 104 + return vfs_getattr_nosec(path, stat, request_mask, query_flags); 82 105 } 83 - 84 106 EXPORT_SYMBOL(vfs_getattr); 85 107 86 - int vfs_fstat(unsigned int fd, struct kstat *stat) 108 + /** 109 + * vfs_statx_fd - Get the enhanced basic attributes by file descriptor 110 + * @fd: The file descriptor referring to the file of interest 111 + * @stat: The result structure to fill in. 112 + * @request_mask: STATX_xxx flags indicating what the caller wants 113 + * @query_flags: Query mode (KSTAT_QUERY_FLAGS) 114 + * 115 + * This function is a wrapper around vfs_getattr(). The main difference is 116 + * that it uses a file descriptor to determine the file location. 117 + * 118 + * 0 will be returned on success, and a -ve error code if unsuccessful. 119 + */ 120 + int vfs_statx_fd(unsigned int fd, struct kstat *stat, 121 + u32 request_mask, unsigned int query_flags) 87 122 { 88 123 struct fd f = fdget_raw(fd); 89 124 int error = -EBADF; 90 125 91 126 if (f.file) { 92 - error = vfs_getattr(&f.file->f_path, stat); 127 + error = vfs_getattr(&f.file->f_path, stat, 128 + request_mask, query_flags); 93 129 fdput(f); 94 130 } 95 131 return error; 96 132 } 97 - EXPORT_SYMBOL(vfs_fstat); 133 + EXPORT_SYMBOL(vfs_statx_fd); 98 134 99 - int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, 100 - int flag) 135 + /** 136 + * vfs_statx - Get basic and extra attributes by filename 137 + * @dfd: A file descriptor representing the base dir for a relative filename 138 + * @filename: The name of the file of interest 139 + * @flags: Flags to control the query 140 + * @stat: The result structure to fill in. 141 + * @request_mask: STATX_xxx flags indicating what the caller wants 142 + * 143 + * This function is a wrapper around vfs_getattr(). The main difference is 144 + * that it uses a filename and base directory to determine the file location. 145 + * Additionally, the use of AT_SYMLINK_NOFOLLOW in flags will prevent a symlink 146 + * at the given name from being referenced. 147 + * 148 + * The caller must have preset stat->request_mask as for vfs_getattr(). The 149 + * flags are also used to load up stat->query_flags. 150 + * 151 + * 0 will be returned on success, and a -ve error code if unsuccessful. 152 + */ 153 + int vfs_statx(int dfd, const char __user *filename, int flags, 154 + struct kstat *stat, u32 request_mask) 101 155 { 102 156 struct path path; 103 157 int error = -EINVAL; 104 - unsigned int lookup_flags = 0; 158 + unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT; 105 159 106 - if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | 107 - AT_EMPTY_PATH)) != 0) 108 - goto out; 160 + if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | 161 + AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0) 162 + return -EINVAL; 109 163 110 - if (!(flag & AT_SYMLINK_NOFOLLOW)) 111 - lookup_flags |= LOOKUP_FOLLOW; 112 - if (flag & AT_EMPTY_PATH) 164 + if (flags & AT_SYMLINK_NOFOLLOW) 165 + lookup_flags &= ~LOOKUP_FOLLOW; 166 + if (flags & AT_NO_AUTOMOUNT) 167 + lookup_flags &= ~LOOKUP_AUTOMOUNT; 168 + if (flags & AT_EMPTY_PATH) 113 169 lookup_flags |= LOOKUP_EMPTY; 170 + 114 171 retry: 115 172 error = user_path_at(dfd, filename, lookup_flags, &path); 116 173 if (error) 117 174 goto out; 118 175 119 - error = vfs_getattr(&path, stat); 176 + error = vfs_getattr(&path, stat, request_mask, flags); 120 177 path_put(&path); 121 178 if (retry_estale(error, lookup_flags)) { 122 179 lookup_flags |= LOOKUP_REVAL; ··· 191 116 out: 192 117 return error; 193 118 } 194 - EXPORT_SYMBOL(vfs_fstatat); 195 - 196 - int vfs_stat(const char __user *name, struct kstat *stat) 197 - { 198 - return vfs_fstatat(AT_FDCWD, name, stat, 0); 199 - } 200 - EXPORT_SYMBOL(vfs_stat); 201 - 202 - int vfs_lstat(const char __user *name, struct kstat *stat) 203 - { 204 - return vfs_fstatat(AT_FDCWD, name, stat, AT_SYMLINK_NOFOLLOW); 205 - } 206 - EXPORT_SYMBOL(vfs_lstat); 119 + EXPORT_SYMBOL(vfs_statx); 207 120 208 121 209 122 #ifdef __ARCH_WANT_OLD_STAT ··· 204 141 { 205 142 static int warncount = 5; 206 143 struct __old_kernel_stat tmp; 207 - 144 + 208 145 if (warncount > 0) { 209 146 warncount--; 210 147 printk(KERN_WARNING "VFS: Warning: %s using old stat() call. Recompile your binary.\n", ··· 229 166 #if BITS_PER_LONG == 32 230 167 if (stat->size > MAX_NON_LFS) 231 168 return -EOVERFLOW; 232 - #endif 169 + #endif 233 170 tmp.st_size = stat->size; 234 171 tmp.st_atime = stat->atime.tv_sec; 235 172 tmp.st_mtime = stat->mtime.tv_sec; ··· 507 444 return cp_new_stat64(&stat, statbuf); 508 445 } 509 446 #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_COMPAT_STAT64 */ 447 + 448 + static inline int __put_timestamp(struct timespec *kts, 449 + struct statx_timestamp __user *uts) 450 + { 451 + return (__put_user(kts->tv_sec, &uts->tv_sec ) || 452 + __put_user(kts->tv_nsec, &uts->tv_nsec ) || 453 + __put_user(0, &uts->__reserved )); 454 + } 455 + 456 + /* 457 + * Set the statx results. 458 + */ 459 + static long statx_set_result(struct kstat *stat, struct statx __user *buffer) 460 + { 461 + uid_t uid = from_kuid_munged(current_user_ns(), stat->uid); 462 + gid_t gid = from_kgid_munged(current_user_ns(), stat->gid); 463 + 464 + if (__put_user(stat->result_mask, &buffer->stx_mask ) || 465 + __put_user(stat->mode, &buffer->stx_mode ) || 466 + __clear_user(&buffer->__spare0, sizeof(buffer->__spare0)) || 467 + __put_user(stat->nlink, &buffer->stx_nlink ) || 468 + __put_user(uid, &buffer->stx_uid ) || 469 + __put_user(gid, &buffer->stx_gid ) || 470 + __put_user(stat->attributes, &buffer->stx_attributes ) || 471 + __put_user(stat->blksize, &buffer->stx_blksize ) || 472 + __put_user(MAJOR(stat->rdev), &buffer->stx_rdev_major ) || 473 + __put_user(MINOR(stat->rdev), &buffer->stx_rdev_minor ) || 474 + __put_user(MAJOR(stat->dev), &buffer->stx_dev_major ) || 475 + __put_user(MINOR(stat->dev), &buffer->stx_dev_minor ) || 476 + __put_timestamp(&stat->atime, &buffer->stx_atime ) || 477 + __put_timestamp(&stat->btime, &buffer->stx_btime ) || 478 + __put_timestamp(&stat->ctime, &buffer->stx_ctime ) || 479 + __put_timestamp(&stat->mtime, &buffer->stx_mtime ) || 480 + __put_user(stat->ino, &buffer->stx_ino ) || 481 + __put_user(stat->size, &buffer->stx_size ) || 482 + __put_user(stat->blocks, &buffer->stx_blocks ) || 483 + __clear_user(&buffer->__spare1, sizeof(buffer->__spare1)) || 484 + __clear_user(&buffer->__spare2, sizeof(buffer->__spare2))) 485 + return -EFAULT; 486 + 487 + return 0; 488 + } 489 + 490 + /** 491 + * sys_statx - System call to get enhanced stats 492 + * @dfd: Base directory to pathwalk from *or* fd to stat. 493 + * @filename: File to stat *or* NULL. 494 + * @flags: AT_* flags to control pathwalk. 495 + * @mask: Parts of statx struct actually required. 496 + * @buffer: Result buffer. 497 + * 498 + * Note that if filename is NULL, then it does the equivalent of fstat() using 499 + * dfd to indicate the file of interest. 500 + */ 501 + SYSCALL_DEFINE5(statx, 502 + int, dfd, const char __user *, filename, unsigned, flags, 503 + unsigned int, mask, 504 + struct statx __user *, buffer) 505 + { 506 + struct kstat stat; 507 + int error; 508 + 509 + if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE) 510 + return -EINVAL; 511 + if (!access_ok(VERIFY_WRITE, buffer, sizeof(*buffer))) 512 + return -EFAULT; 513 + 514 + if (filename) 515 + error = vfs_statx(dfd, filename, flags, &stat, mask); 516 + else 517 + error = vfs_statx_fd(dfd, &stat, mask, flags); 518 + if (error) 519 + return error; 520 + return statx_set_result(&stat, buffer); 521 + } 510 522 511 523 /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */ 512 524 void __inode_add_bytes(struct inode *inode, loff_t bytes)
+4 -3
fs/sysv/itree.c
··· 440 440 return blocks; 441 441 } 442 442 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) 444 445 { 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); 447 448 stat->blocks = (s->s_blocksize / 512) * sysv_nblocks(s, stat->size); 448 449 stat->blksize = s->s_blocksize; 449 450 return 0;
+1 -1
fs/sysv/sysv.h
··· 142 142 extern int sysv_write_inode(struct inode *, struct writeback_control *wbc); 143 143 extern int sysv_sync_inode(struct inode *); 144 144 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); 146 146 extern int sysv_init_icache(void); 147 147 extern void sysv_destroy_icache(void); 148 148
+3 -3
fs/ubifs/dir.c
··· 1622 1622 return do_rename(old_dir, old_dentry, new_dir, new_dentry, flags); 1623 1623 } 1624 1624 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) 1627 1627 { 1628 1628 loff_t size; 1629 - struct inode *inode = d_inode(dentry); 1629 + struct inode *inode = d_inode(path->dentry); 1630 1630 struct ubifs_inode *ui = ubifs_inode(inode); 1631 1631 1632 1632 mutex_lock(&ui->ui_mutex);
+2 -2
fs/ubifs/ubifs.h
··· 1749 1749 /* dir.c */ 1750 1750 struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, 1751 1751 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); 1754 1754 int ubifs_check_dir_empty(struct inode *dir); 1755 1755 1756 1756 /* xattr.c */
+3 -2
fs/udf/symlink.c
··· 152 152 return err; 153 153 } 154 154 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) 157 157 { 158 + struct dentry *dentry = path->dentry; 158 159 struct inode *inode = d_backing_inode(dentry); 159 160 struct page *page; 160 161
+5 -4
fs/xfs/xfs_iops.c
··· 489 489 490 490 STATIC int 491 491 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) 495 496 { 496 - struct inode *inode = d_inode(dentry); 497 + struct inode *inode = d_inode(path->dentry); 497 498 struct xfs_inode *ip = XFS_I(inode); 498 499 struct xfs_mount *mp = ip->i_mount; 499 500
+27 -8
include/linux/fs.h
··· 1709 1709 int (*rename) (struct inode *, struct dentry *, 1710 1710 struct inode *, struct dentry *, unsigned int); 1711 1711 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); 1713 1713 ssize_t (*listxattr) (struct dentry *, char *, size_t); 1714 1714 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, 1715 1715 u64 len); ··· 2902 2902 extern const struct inode_operations page_symlink_inode_operations; 2903 2903 extern void kfree_link(void *); 2904 2904 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); 2907 2907 void __inode_add_bytes(struct inode *inode, loff_t bytes); 2908 2908 void inode_add_bytes(struct inode *inode, loff_t bytes); 2909 2909 void __inode_sub_bytes(struct inode *inode, loff_t bytes); ··· 2916 2916 2917 2917 extern int iterate_dir(struct file *, struct dir_context *); 2918 2918 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 + 2923 2942 extern const char *vfs_get_link(struct dentry *, struct delayed_call *); 2924 2943 extern int vfs_readlink(struct dentry *, char __user *, int); 2925 2944 ··· 2968 2949 extern loff_t dcache_dir_lseek(struct file *, loff_t, int); 2969 2950 extern int dcache_readdir(struct file *, struct dir_context *); 2970 2951 extern int simple_setattr(struct dentry *, struct iattr *); 2971 - extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); 2952 + extern int simple_getattr(const struct path *, struct kstat *, u32, unsigned int); 2972 2953 extern int simple_statfs(struct dentry *, struct kstatfs *); 2973 2954 extern int simple_open(struct inode *inode, struct file *file); 2974 2955 extern int simple_link(struct dentry *, struct inode *, struct dentry *);
+1 -1
include/linux/nfs_fs.h
··· 335 335 extern int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr); 336 336 extern int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr); 337 337 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); 339 339 extern void nfs_access_add_cache(struct inode *, struct nfs_access_entry *); 340 340 extern void nfs_access_set_mask(struct nfs_access_entry *, u32); 341 341 extern int nfs_permission(struct inode *, int);
+18 -6
include/linux/stat.h
··· 18 18 #include <linux/time.h> 19 19 #include <linux/uidgid.h> 20 20 21 + #define KSTAT_QUERY_FLAGS (AT_STATX_SYNC_TYPE) 22 + 21 23 struct kstat { 22 - u64 ino; 23 - dev_t dev; 24 + u32 result_mask; /* What fields the user got */ 24 25 umode_t mode; 25 26 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; 26 39 kuid_t uid; 27 40 kgid_t gid; 28 - dev_t rdev; 29 41 loff_t size; 30 - struct timespec atime; 42 + struct timespec atime; 31 43 struct timespec mtime; 32 44 struct timespec ctime; 33 - unsigned long blksize; 34 - unsigned long long blocks; 45 + struct timespec btime; /* File creation time */ 46 + u64 blocks; 35 47 }; 36 48 37 49 #endif
+3
include/linux/syscalls.h
··· 48 48 struct stat64; 49 49 struct statfs; 50 50 struct statfs64; 51 + struct statx; 51 52 struct __sysctl_args; 52 53 struct sysinfo; 53 54 struct timespec; ··· 903 902 unsigned long prot, int pkey); 904 903 asmlinkage long sys_pkey_alloc(unsigned long flags, unsigned long init_val); 905 904 asmlinkage long sys_pkey_free(int pkey); 905 + asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags, 906 + unsigned mask, struct statx __user *buffer); 906 907 907 908 #endif
+5
include/uapi/linux/fcntl.h
··· 63 63 #define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */ 64 64 #define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */ 65 65 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 + 66 71 67 72 #endif /* _UAPI_LINUX_FCNTL_H */
+131
include/uapi/linux/stat.h
··· 1 1 #ifndef _UAPI_LINUX_STAT_H 2 2 #define _UAPI_LINUX_STAT_H 3 3 4 + #include <linux/types.h> 4 5 5 6 #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) 6 7 ··· 41 40 #define S_IXOTH 00001 42 41 43 42 #endif 43 + 44 + /* 45 + * Timestamp structure for the timestamps in struct statx. 46 + * 47 + * tv_sec holds the number of seconds before (negative) or after (positive) 48 + * 00:00:00 1st January 1970 UTC. 49 + * 50 + * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is 51 + * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time. 52 + * 53 + * Note that if both tv_sec and tv_nsec are non-zero, then the two values must 54 + * either be both positive or both negative. 55 + * 56 + * __reserved is held in case we need a yet finer resolution. 57 + */ 58 + struct statx_timestamp { 59 + __s64 tv_sec; 60 + __s32 tv_nsec; 61 + __s32 __reserved; 62 + }; 63 + 64 + /* 65 + * Structures for the extended file attribute retrieval system call 66 + * (statx()). 67 + * 68 + * The caller passes a mask of what they're specifically interested in as a 69 + * parameter to statx(). What statx() actually got will be indicated in 70 + * st_mask upon return. 71 + * 72 + * For each bit in the mask argument: 73 + * 74 + * - if the datum is not supported: 75 + * 76 + * - the bit will be cleared, and 77 + * 78 + * - the datum will be set to an appropriate fabricated value if one is 79 + * available (eg. CIFS can take a default uid and gid), otherwise 80 + * 81 + * - the field will be cleared; 82 + * 83 + * - otherwise, if explicitly requested: 84 + * 85 + * - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is 86 + * set or if the datum is considered out of date, and 87 + * 88 + * - the field will be filled in and the bit will be set; 89 + * 90 + * - otherwise, if not requested, but available in approximate form without any 91 + * effort, it will be filled in anyway, and the bit will be set upon return 92 + * (it might not be up to date, however, and no attempt will be made to 93 + * synchronise the internal state first); 94 + * 95 + * - otherwise the field and the bit will be cleared before returning. 96 + * 97 + * Items in STATX_BASIC_STATS may be marked unavailable on return, but they 98 + * will have values installed for compatibility purposes so that stat() and 99 + * co. can be emulated in userspace. 100 + */ 101 + struct statx { 102 + /* 0x00 */ 103 + __u32 stx_mask; /* What results were written [uncond] */ 104 + __u32 stx_blksize; /* Preferred general I/O size [uncond] */ 105 + __u64 stx_attributes; /* Flags conveying information about the file [uncond] */ 106 + /* 0x10 */ 107 + __u32 stx_nlink; /* Number of hard links */ 108 + __u32 stx_uid; /* User ID of owner */ 109 + __u32 stx_gid; /* Group ID of owner */ 110 + __u16 stx_mode; /* File mode */ 111 + __u16 __spare0[1]; 112 + /* 0x20 */ 113 + __u64 stx_ino; /* Inode number */ 114 + __u64 stx_size; /* File size */ 115 + __u64 stx_blocks; /* Number of 512-byte blocks allocated */ 116 + __u64 __spare1[1]; 117 + /* 0x40 */ 118 + struct statx_timestamp stx_atime; /* Last access time */ 119 + struct statx_timestamp stx_btime; /* File creation time */ 120 + struct statx_timestamp stx_ctime; /* Last attribute change time */ 121 + struct statx_timestamp stx_mtime; /* Last data modification time */ 122 + /* 0x80 */ 123 + __u32 stx_rdev_major; /* Device ID of special file [if bdev/cdev] */ 124 + __u32 stx_rdev_minor; 125 + __u32 stx_dev_major; /* ID of device containing file [uncond] */ 126 + __u32 stx_dev_minor; 127 + /* 0x90 */ 128 + __u64 __spare2[14]; /* Spare space for future expansion */ 129 + /* 0x100 */ 130 + }; 131 + 132 + /* 133 + * Flags to be stx_mask 134 + * 135 + * Query request/result mask for statx() and struct statx::stx_mask. 136 + * 137 + * These bits should be set in the mask argument of statx() to request 138 + * particular items when calling statx(). 139 + */ 140 + #define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */ 141 + #define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */ 142 + #define STATX_NLINK 0x00000004U /* Want/got stx_nlink */ 143 + #define STATX_UID 0x00000008U /* Want/got stx_uid */ 144 + #define STATX_GID 0x00000010U /* Want/got stx_gid */ 145 + #define STATX_ATIME 0x00000020U /* Want/got stx_atime */ 146 + #define STATX_MTIME 0x00000040U /* Want/got stx_mtime */ 147 + #define STATX_CTIME 0x00000080U /* Want/got stx_ctime */ 148 + #define STATX_INO 0x00000100U /* Want/got stx_ino */ 149 + #define STATX_SIZE 0x00000200U /* Want/got stx_size */ 150 + #define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */ 151 + #define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */ 152 + #define STATX_BTIME 0x00000800U /* Want/got stx_btime */ 153 + #define STATX_ALL 0x00000fffU /* All currently supported flags */ 154 + 155 + /* 156 + * Attributes to be found in stx_attributes 157 + * 158 + * These give information about the features or the state of a file that might 159 + * be of use to ordinary userspace programs such as GUIs or ls rather than 160 + * specialised tools. 161 + * 162 + * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS 163 + * semantically. Where possible, the numerical value is picked to correspond 164 + * also. 165 + */ 166 + #define STATX_ATTR_COMPRESSED 0x00000004 /* [I] File is compressed by the fs */ 167 + #define STATX_ATTR_IMMUTABLE 0x00000010 /* [I] File is marked immutable */ 168 + #define STATX_ATTR_APPEND 0x00000020 /* [I] File is append-only */ 169 + #define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */ 170 + #define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */ 171 + 172 + #define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */ 44 173 45 174 46 175 #endif /* _UAPI_LINUX_STAT_H */
+3 -3
mm/shmem.c
··· 958 958 } 959 959 EXPORT_SYMBOL_GPL(shmem_truncate_range); 960 960 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) 963 963 { 964 - struct inode *inode = dentry->d_inode; 964 + struct inode *inode = path->dentry->d_inode; 965 965 struct shmem_inode_info *info = SHMEM_I(inode); 966 966 967 967 if (info->alloced - info->swapped != inode->i_mapping->nrpages) {
+6
samples/Kconfig
··· 112 112 Build a virtual tty sample driver for use as a VFIO 113 113 mediated device 114 114 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 + 115 121 endif # SAMPLES
+1 -1
samples/Makefile
··· 3 3 obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \ 4 4 hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \ 5 5 configfs/ connector/ v4l/ trace_printk/ blackfin/ \ 6 - vfio-mdev/ 6 + vfio-mdev/ statx/
+10
samples/statx/Makefile
··· 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
+254
samples/statx/test-statx.c
··· 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 + }