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

Merge branch 'rebased-statx' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull vfs 'statx()' update from Al Viro.

This adds the new extended stat() interface that internally subsumes our
previous stat interfaces, and allows user mode to specify in more detail
what kind of information it wants.

It also allows for some explicit synchronization information to be
passed to the filesystem, which can be relevant for network filesystems:
is the cached value ok, or do you need open/close consistency, or what?

From David Howells.

Andreas Dilger points out that the first version of the extended statx
interface was posted June 29, 2010:

https://www.spinics.net/lists/linux-fsdevel/msg33831.html

* 'rebased-statx' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
statx: Add a system call to make enhanced file info available

+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
··· 1176 1176 1177 1177 if (lo->lo_state != Lo_bound) 1178 1178 return -ENXIO; 1179 - error = vfs_getattr(&file->f_path, &stat); 1179 + error = vfs_getattr(&file->f_path, &stat, 1180 + STATX_INO, AT_STATX_SYNC_AS_STAT); 1180 1181 if (error) 1181 1182 return error; 1182 1183 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
··· 1992 1992 return cifs_revalidate_mapping(inode); 1993 1993 } 1994 1994 1995 - int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry, 1996 - struct kstat *stat) 1995 + int cifs_getattr(const struct path *path, struct kstat *stat, 1996 + u32 request_mask, unsigned int flags) 1997 1997 { 1998 + struct dentry *dentry = path->dentry; 1998 1999 struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb); 1999 2000 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); 2000 2001 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
··· 300 300 * filesystem supports 64-bit inode numbers. So we need to 301 301 * actually call ->getattr, not just read i_ino: 302 302 */ 303 - error = vfs_getattr_nosec(&child_path, &stat); 303 + error = vfs_getattr_nosec(&child_path, &stat, 304 + STATX_INO, AT_STATX_SYNC_AS_STAT); 304 305 if (error) 305 306 return error; 306 307 buffer.ino = stat.ino;
+1 -2
fs/ext4/ext4.h
··· 2463 2463 extern struct inode *ext4_iget_normal(struct super_block *, unsigned long); 2464 2464 extern int ext4_write_inode(struct inode *, struct writeback_control *); 2465 2465 extern int ext4_setattr(struct dentry *, struct iattr *); 2466 - extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry, 2467 - struct kstat *stat); 2466 + extern int ext4_getattr(const struct path *, struct kstat *, u32, unsigned int); 2468 2467 extern void ext4_evict_inode(struct inode *); 2469 2468 extern void ext4_clear_inode(struct inode *); 2470 2469 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
··· 1960 1960 1961 1961 /** 1962 1962 * gfs2_getattr - Read out an inode's attributes 1963 - * @mnt: The vfsmount the inode is being accessed from 1964 - * @dentry: The dentry to stat 1963 + * @path: Object to query 1965 1964 * @stat: The inode's stats 1965 + * @request_mask: Mask of STATX_xxx flags indicating the caller's interests 1966 + * @flags: AT_STATX_xxx setting 1966 1967 * 1967 1968 * This may be called from the VFS directly, or from within GFS2 with the 1968 1969 * inode locked, so we look to see if the glock is already locked and only ··· 1974 1973 * Returns: errno 1975 1974 */ 1976 1975 1977 - static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, 1978 - struct kstat *stat) 1976 + static int gfs2_getattr(const struct path *path, struct kstat *stat, 1977 + u32 request_mask, unsigned int flags) 1979 1978 { 1980 - struct inode *inode = d_inode(dentry); 1979 + struct inode *inode = d_inode(path->dentry); 1981 1980 struct gfs2_inode *ip = GFS2_I(inode); 1982 1981 struct gfs2_holder gh; 1983 1982 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
··· 21 21 22 22 #include "internal.h" 23 23 24 - int simple_getattr(struct vfsmount *mnt, struct dentry *dentry, 25 - struct kstat *stat) 24 + int simple_getattr(const struct path *path, struct kstat *stat, 25 + u32 request_mask, unsigned int query_flags) 26 26 { 27 - struct inode *inode = d_inode(dentry); 27 + struct inode *inode = d_inode(path->dentry); 28 28 generic_fillattr(inode, stat); 29 29 stat->blocks = inode->i_mapping->nrpages << (PAGE_SHIFT - 9); 30 30 return 0; ··· 1144 1144 return ERR_PTR(-ENOENT); 1145 1145 } 1146 1146 1147 - static int empty_dir_getattr(struct vfsmount *mnt, struct dentry *dentry, 1148 - struct kstat *stat) 1147 + static int empty_dir_getattr(const struct path *path, struct kstat *stat, 1148 + u32 request_mask, unsigned int query_flags) 1149 1149 { 1150 - struct inode *inode = d_inode(dentry); 1150 + struct inode *inode = d_inode(path->dentry); 1151 1151 generic_fillattr(inode, stat); 1152 1152 return 0; 1153 1153 }
+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
··· 347 347 ovl_path_upper(parent, &parentpath); 348 348 upperdir = parentpath.dentry; 349 349 350 - err = vfs_getattr(&parentpath, &pstat); 350 + err = vfs_getattr(&parentpath, &pstat, 351 + STATX_ATIME | STATX_MTIME, AT_STATX_SYNC_AS_STAT); 351 352 if (err) 352 353 return err; 353 354 ··· 411 410 } 412 411 413 412 ovl_path_lower(next, &lowerpath); 414 - err = vfs_getattr(&lowerpath, &stat); 413 + err = vfs_getattr(&lowerpath, &stat, 414 + STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); 415 415 /* maybe truncate regular file. this has no effect on dirs */ 416 416 if (flags & O_TRUNC) 417 417 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
··· 57 57 return err; 58 58 } 59 59 60 - static int ovl_getattr(struct vfsmount *mnt, struct dentry *dentry, 61 - struct kstat *stat) 60 + static int ovl_getattr(const struct path *path, struct kstat *stat, 61 + u32 request_mask, unsigned int flags) 62 62 { 63 + struct dentry *dentry = path->dentry; 63 64 struct path realpath; 64 65 const struct cred *old_cred; 65 66 int err; 66 67 67 68 ovl_path_real(dentry, &realpath); 68 69 old_cred = ovl_override_creds(dentry->d_sb); 69 - err = vfs_getattr(&realpath, stat); 70 + err = vfs_getattr(&realpath, stat, request_mask, flags); 70 71 revert_creds(old_cred); 71 72 return err; 72 73 }
+7 -5
fs/proc/base.c
··· 1729 1729 return NULL; 1730 1730 } 1731 1731 1732 - int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 1732 + int pid_getattr(const struct path *path, struct kstat *stat, 1733 + u32 request_mask, unsigned int query_flags) 1733 1734 { 1734 - struct inode *inode = d_inode(dentry); 1735 + struct inode *inode = d_inode(path->dentry); 1735 1736 struct task_struct *task; 1736 - struct pid_namespace *pid = dentry->d_sb->s_fs_info; 1737 + struct pid_namespace *pid = path->dentry->d_sb->s_fs_info; 1737 1738 1738 1739 generic_fillattr(inode, stat); 1739 1740 ··· 3517 3516 return 0; 3518 3517 } 3519 3518 3520 - static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 3519 + static int proc_task_getattr(const struct path *path, struct kstat *stat, 3520 + u32 request_mask, unsigned int query_flags) 3521 3521 { 3522 - struct inode *inode = d_inode(dentry); 3522 + struct inode *inode = d_inode(path->dentry); 3523 3523 struct task_struct *p = get_proc_task(inode); 3524 3524 generic_fillattr(inode, stat); 3525 3525
+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
··· 151 151 * base.c 152 152 */ 153 153 extern const struct dentry_operations pid_dentry_operations; 154 - extern int pid_getattr(struct vfsmount *, struct dentry *, struct kstat *); 154 + extern int pid_getattr(const struct path *, struct kstat *, u32, unsigned int); 155 155 extern int proc_setattr(struct dentry *, struct iattr *); 156 156 extern struct inode *proc_pid_make_inode(struct super_block *, struct task_struct *, umode_t); 157 157 extern int pid_revalidate(struct dentry *, unsigned int);
+3 -3
fs/proc/proc_net.c
··· 141 141 return de; 142 142 } 143 143 144 - static int proc_tgid_net_getattr(struct vfsmount *mnt, struct dentry *dentry, 145 - struct kstat *stat) 144 + static int proc_tgid_net_getattr(const struct path *path, struct kstat *stat, 145 + u32 request_mask, unsigned int query_flags) 146 146 { 147 - struct inode *inode = d_inode(dentry); 147 + struct inode *inode = d_inode(path->dentry); 148 148 struct net *net; 149 149 150 150 net = get_proc_task_net(inode);
+3 -2
fs/proc/proc_sysctl.c
··· 802 802 return 0; 803 803 } 804 804 805 - static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 805 + static int proc_sys_getattr(const struct path *path, struct kstat *stat, 806 + u32 request_mask, unsigned int query_flags) 806 807 { 807 - struct inode *inode = d_inode(dentry); 808 + struct inode *inode = d_inode(path->dentry); 808 809 struct ctl_table_header *head = grab_header(inode); 809 810 struct ctl_table *table = PROC_I(inode)->sysctl_entry; 810 811
+3 -3
fs/proc/root.c
··· 151 151 proc_sys_init(); 152 152 } 153 153 154 - static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat 155 - ) 154 + static int proc_root_getattr(const struct path *path, struct kstat *stat, 155 + u32 request_mask, unsigned int query_flags) 156 156 { 157 - generic_fillattr(d_inode(dentry), stat); 157 + generic_fillattr(d_inode(path->dentry), stat); 158 158 stat->nlink = proc_root.nlink + nr_processes(); 159 159 return 0; 160 160 }
+176 -38
fs/stat.c
··· 19 19 #include <linux/uaccess.h> 20 20 #include <asm/unistd.h> 21 21 22 + /** 23 + * generic_fillattr - Fill in the basic attributes from the inode struct 24 + * @inode: Inode to use as the source 25 + * @stat: Where to fill in the attributes 26 + * 27 + * Fill in the basic attributes in the kstat structure from data that's to be 28 + * found on the VFS inode structure. This is the default if no getattr inode 29 + * operation is supplied. 30 + */ 22 31 void generic_fillattr(struct inode *inode, struct kstat *stat) 23 32 { 24 33 stat->dev = inode->i_sb->s_dev; ··· 43 34 stat->ctime = inode->i_ctime; 44 35 stat->blksize = i_blocksize(inode); 45 36 stat->blocks = inode->i_blocks; 46 - } 47 37 38 + if (IS_NOATIME(inode)) 39 + stat->result_mask &= ~STATX_ATIME; 40 + if (IS_AUTOMOUNT(inode)) 41 + stat->attributes |= STATX_ATTR_AUTOMOUNT; 42 + } 48 43 EXPORT_SYMBOL(generic_fillattr); 49 44 50 45 /** 51 46 * vfs_getattr_nosec - getattr without security checks 52 47 * @path: file to get attributes from 53 48 * @stat: structure to return attributes in 49 + * @request_mask: STATX_xxx flags indicating what the caller wants 50 + * @query_flags: Query mode (KSTAT_QUERY_FLAGS) 54 51 * 55 52 * Get attributes without calling security_inode_getattr. 56 53 * 57 54 * Currently the only caller other than vfs_getattr is internal to the 58 - * filehandle lookup code, which uses only the inode number and returns 59 - * no attributes to any user. Any other code probably wants 60 - * vfs_getattr. 55 + * filehandle lookup code, which uses only the inode number and returns no 56 + * attributes to any user. Any other code probably wants vfs_getattr. 61 57 */ 62 - int vfs_getattr_nosec(struct path *path, struct kstat *stat) 58 + int vfs_getattr_nosec(const struct path *path, struct kstat *stat, 59 + u32 request_mask, unsigned int query_flags) 63 60 { 64 61 struct inode *inode = d_backing_inode(path->dentry); 65 62 63 + memset(stat, 0, sizeof(*stat)); 64 + stat->result_mask |= STATX_BASIC_STATS; 65 + request_mask &= STATX_ALL; 66 + query_flags &= KSTAT_QUERY_FLAGS; 66 67 if (inode->i_op->getattr) 67 - return inode->i_op->getattr(path->mnt, path->dentry, stat); 68 + return inode->i_op->getattr(path, stat, request_mask, 69 + query_flags); 68 70 69 71 generic_fillattr(inode, stat); 70 72 return 0; 71 73 } 72 - 73 74 EXPORT_SYMBOL(vfs_getattr_nosec); 74 75 75 - int vfs_getattr(struct path *path, struct kstat *stat) 76 + /* 77 + * vfs_getattr - Get the enhanced basic attributes of a file 78 + * @path: The file of interest 79 + * @stat: Where to return the statistics 80 + * @request_mask: STATX_xxx flags indicating what the caller wants 81 + * @query_flags: Query mode (KSTAT_QUERY_FLAGS) 82 + * 83 + * Ask the filesystem for a file's attributes. The caller must indicate in 84 + * request_mask and query_flags to indicate what they want. 85 + * 86 + * If the file is remote, the filesystem can be forced to update the attributes 87 + * from the backing store by passing AT_STATX_FORCE_SYNC in query_flags or can 88 + * suppress the update by passing AT_STATX_DONT_SYNC. 89 + * 90 + * Bits must have been set in request_mask to indicate which attributes the 91 + * caller wants retrieving. Any such attribute not requested may be returned 92 + * anyway, but the value may be approximate, and, if remote, may not have been 93 + * synchronised with the server. 94 + * 95 + * 0 will be returned on success, and a -ve error code if unsuccessful. 96 + */ 97 + int vfs_getattr(const struct path *path, struct kstat *stat, 98 + u32 request_mask, unsigned int query_flags) 76 99 { 77 100 int retval; 78 101 79 102 retval = security_inode_getattr(path); 80 103 if (retval) 81 104 return retval; 82 - return vfs_getattr_nosec(path, stat); 105 + return vfs_getattr_nosec(path, stat, request_mask, query_flags); 83 106 } 84 - 85 107 EXPORT_SYMBOL(vfs_getattr); 86 108 87 - int vfs_fstat(unsigned int fd, struct kstat *stat) 109 + /** 110 + * vfs_statx_fd - Get the enhanced basic attributes by file descriptor 111 + * @fd: The file descriptor referring to the file of interest 112 + * @stat: The result structure to fill in. 113 + * @request_mask: STATX_xxx flags indicating what the caller wants 114 + * @query_flags: Query mode (KSTAT_QUERY_FLAGS) 115 + * 116 + * This function is a wrapper around vfs_getattr(). The main difference is 117 + * that it uses a file descriptor to determine the file location. 118 + * 119 + * 0 will be returned on success, and a -ve error code if unsuccessful. 120 + */ 121 + int vfs_statx_fd(unsigned int fd, struct kstat *stat, 122 + u32 request_mask, unsigned int query_flags) 88 123 { 89 124 struct fd f = fdget_raw(fd); 90 125 int error = -EBADF; 91 126 92 127 if (f.file) { 93 - error = vfs_getattr(&f.file->f_path, stat); 128 + error = vfs_getattr(&f.file->f_path, stat, 129 + request_mask, query_flags); 94 130 fdput(f); 95 131 } 96 132 return error; 97 133 } 98 - EXPORT_SYMBOL(vfs_fstat); 134 + EXPORT_SYMBOL(vfs_statx_fd); 99 135 100 - int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, 101 - int flag) 136 + /** 137 + * vfs_statx - Get basic and extra attributes by filename 138 + * @dfd: A file descriptor representing the base dir for a relative filename 139 + * @filename: The name of the file of interest 140 + * @flags: Flags to control the query 141 + * @stat: The result structure to fill in. 142 + * @request_mask: STATX_xxx flags indicating what the caller wants 143 + * 144 + * This function is a wrapper around vfs_getattr(). The main difference is 145 + * that it uses a filename and base directory to determine the file location. 146 + * Additionally, the use of AT_SYMLINK_NOFOLLOW in flags will prevent a symlink 147 + * at the given name from being referenced. 148 + * 149 + * The caller must have preset stat->request_mask as for vfs_getattr(). The 150 + * flags are also used to load up stat->query_flags. 151 + * 152 + * 0 will be returned on success, and a -ve error code if unsuccessful. 153 + */ 154 + int vfs_statx(int dfd, const char __user *filename, int flags, 155 + struct kstat *stat, u32 request_mask) 102 156 { 103 157 struct path path; 104 158 int error = -EINVAL; 105 - unsigned int lookup_flags = 0; 159 + unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT; 106 160 107 - if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | 108 - AT_EMPTY_PATH)) != 0) 109 - goto out; 161 + if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | 162 + AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0) 163 + return -EINVAL; 110 164 111 - if (!(flag & AT_SYMLINK_NOFOLLOW)) 112 - lookup_flags |= LOOKUP_FOLLOW; 113 - if (flag & AT_EMPTY_PATH) 165 + if (flags & AT_SYMLINK_NOFOLLOW) 166 + lookup_flags &= ~LOOKUP_FOLLOW; 167 + if (flags & AT_NO_AUTOMOUNT) 168 + lookup_flags &= ~LOOKUP_AUTOMOUNT; 169 + if (flags & AT_EMPTY_PATH) 114 170 lookup_flags |= LOOKUP_EMPTY; 171 + 115 172 retry: 116 173 error = user_path_at(dfd, filename, lookup_flags, &path); 117 174 if (error) 118 175 goto out; 119 176 120 - error = vfs_getattr(&path, stat); 177 + error = vfs_getattr(&path, stat, request_mask, flags); 121 178 path_put(&path); 122 179 if (retry_estale(error, lookup_flags)) { 123 180 lookup_flags |= LOOKUP_REVAL; ··· 192 117 out: 193 118 return error; 194 119 } 195 - EXPORT_SYMBOL(vfs_fstatat); 196 - 197 - int vfs_stat(const char __user *name, struct kstat *stat) 198 - { 199 - return vfs_fstatat(AT_FDCWD, name, stat, 0); 200 - } 201 - EXPORT_SYMBOL(vfs_stat); 202 - 203 - int vfs_lstat(const char __user *name, struct kstat *stat) 204 - { 205 - return vfs_fstatat(AT_FDCWD, name, stat, AT_SYMLINK_NOFOLLOW); 206 - } 207 - EXPORT_SYMBOL(vfs_lstat); 120 + EXPORT_SYMBOL(vfs_statx); 208 121 209 122 210 123 #ifdef __ARCH_WANT_OLD_STAT ··· 205 142 { 206 143 static int warncount = 5; 207 144 struct __old_kernel_stat tmp; 208 - 145 + 209 146 if (warncount > 0) { 210 147 warncount--; 211 148 printk(KERN_WARNING "VFS: Warning: %s using old stat() call. Recompile your binary.\n", ··· 230 167 #if BITS_PER_LONG == 32 231 168 if (stat->size > MAX_NON_LFS) 232 169 return -EOVERFLOW; 233 - #endif 170 + #endif 234 171 tmp.st_size = stat->size; 235 172 tmp.st_atime = stat->atime.tv_sec; 236 173 tmp.st_mtime = stat->mtime.tv_sec; ··· 508 445 return cp_new_stat64(&stat, statbuf); 509 446 } 510 447 #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_COMPAT_STAT64 */ 448 + 449 + static inline int __put_timestamp(struct timespec *kts, 450 + struct statx_timestamp __user *uts) 451 + { 452 + return (__put_user(kts->tv_sec, &uts->tv_sec ) || 453 + __put_user(kts->tv_nsec, &uts->tv_nsec ) || 454 + __put_user(0, &uts->__reserved )); 455 + } 456 + 457 + /* 458 + * Set the statx results. 459 + */ 460 + static long statx_set_result(struct kstat *stat, struct statx __user *buffer) 461 + { 462 + uid_t uid = from_kuid_munged(current_user_ns(), stat->uid); 463 + gid_t gid = from_kgid_munged(current_user_ns(), stat->gid); 464 + 465 + if (__put_user(stat->result_mask, &buffer->stx_mask ) || 466 + __put_user(stat->mode, &buffer->stx_mode ) || 467 + __clear_user(&buffer->__spare0, sizeof(buffer->__spare0)) || 468 + __put_user(stat->nlink, &buffer->stx_nlink ) || 469 + __put_user(uid, &buffer->stx_uid ) || 470 + __put_user(gid, &buffer->stx_gid ) || 471 + __put_user(stat->attributes, &buffer->stx_attributes ) || 472 + __put_user(stat->blksize, &buffer->stx_blksize ) || 473 + __put_user(MAJOR(stat->rdev), &buffer->stx_rdev_major ) || 474 + __put_user(MINOR(stat->rdev), &buffer->stx_rdev_minor ) || 475 + __put_user(MAJOR(stat->dev), &buffer->stx_dev_major ) || 476 + __put_user(MINOR(stat->dev), &buffer->stx_dev_minor ) || 477 + __put_timestamp(&stat->atime, &buffer->stx_atime ) || 478 + __put_timestamp(&stat->btime, &buffer->stx_btime ) || 479 + __put_timestamp(&stat->ctime, &buffer->stx_ctime ) || 480 + __put_timestamp(&stat->mtime, &buffer->stx_mtime ) || 481 + __put_user(stat->ino, &buffer->stx_ino ) || 482 + __put_user(stat->size, &buffer->stx_size ) || 483 + __put_user(stat->blocks, &buffer->stx_blocks ) || 484 + __clear_user(&buffer->__spare1, sizeof(buffer->__spare1)) || 485 + __clear_user(&buffer->__spare2, sizeof(buffer->__spare2))) 486 + return -EFAULT; 487 + 488 + return 0; 489 + } 490 + 491 + /** 492 + * sys_statx - System call to get enhanced stats 493 + * @dfd: Base directory to pathwalk from *or* fd to stat. 494 + * @filename: File to stat *or* NULL. 495 + * @flags: AT_* flags to control pathwalk. 496 + * @mask: Parts of statx struct actually required. 497 + * @buffer: Result buffer. 498 + * 499 + * Note that if filename is NULL, then it does the equivalent of fstat() using 500 + * dfd to indicate the file of interest. 501 + */ 502 + SYSCALL_DEFINE5(statx, 503 + int, dfd, const char __user *, filename, unsigned, flags, 504 + unsigned int, mask, 505 + struct statx __user *, buffer) 506 + { 507 + struct kstat stat; 508 + int error; 509 + 510 + if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE) 511 + return -EINVAL; 512 + if (!access_ok(VERIFY_WRITE, buffer, sizeof(*buffer))) 513 + return -EFAULT; 514 + 515 + if (filename) 516 + error = vfs_statx(dfd, filename, flags, &stat, mask); 517 + else 518 + error = vfs_statx_fd(dfd, &stat, mask, flags); 519 + if (error) 520 + return error; 521 + return statx_set_result(&stat, buffer); 522 + } 511 523 512 524 /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */ 513 525 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
··· 959 959 } 960 960 EXPORT_SYMBOL_GPL(shmem_truncate_range); 961 961 962 - static int shmem_getattr(struct vfsmount *mnt, struct dentry *dentry, 963 - struct kstat *stat) 962 + static int shmem_getattr(const struct path *path, struct kstat *stat, 963 + u32 request_mask, unsigned int query_flags) 964 964 { 965 - struct inode *inode = dentry->d_inode; 965 + struct inode *inode = path->dentry->d_inode; 966 966 struct shmem_inode_info *info = SHMEM_I(inode); 967 967 968 968 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 + }