Lines Matching full:stat

3  *  linux/fs/stat.c
33 * @stat: where to store the resulting values
38 * in @stat. When fetching the value, flag it as QUERIED (if not already)
45 void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode) in fill_mg_cmtime() argument
51 stat->result_mask &= ~(STATX_CTIME|STATX_MTIME); in fill_mg_cmtime()
55 stat->mtime = inode_get_mtime(inode); in fill_mg_cmtime()
56 stat->ctime.tv_sec = inode->i_ctime_sec; in fill_mg_cmtime()
57 stat->ctime.tv_nsec = (u32)atomic_read(pcn); in fill_mg_cmtime()
58 if (!(stat->ctime.tv_nsec & I_CTIME_QUERIED)) in fill_mg_cmtime()
59 stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn)); in fill_mg_cmtime()
60 stat->ctime.tv_nsec &= ~I_CTIME_QUERIED; in fill_mg_cmtime()
61 trace_fill_mg_cmtime(inode, &stat->ctime, &stat->mtime); in fill_mg_cmtime()
70 * @stat: Where to fill in the attributes
83 struct inode *inode, struct kstat *stat) in generic_fillattr() argument
88 stat->dev = inode->i_sb->s_dev; in generic_fillattr()
89 stat->ino = inode->i_ino; in generic_fillattr()
90 stat->mode = inode->i_mode; in generic_fillattr()
91 stat->nlink = inode->i_nlink; in generic_fillattr()
92 stat->uid = vfsuid_into_kuid(vfsuid); in generic_fillattr()
93 stat->gid = vfsgid_into_kgid(vfsgid); in generic_fillattr()
94 stat->rdev = inode->i_rdev; in generic_fillattr()
95 stat->size = i_size_read(inode); in generic_fillattr()
96 stat->atime = inode_get_atime(inode); in generic_fillattr()
99 fill_mg_cmtime(stat, request_mask, inode); in generic_fillattr()
101 stat->ctime = inode_get_ctime(inode); in generic_fillattr()
102 stat->mtime = inode_get_mtime(inode); in generic_fillattr()
105 stat->blksize = i_blocksize(inode); in generic_fillattr()
106 stat->blocks = inode->i_blocks; in generic_fillattr()
109 stat->result_mask |= STATX_CHANGE_COOKIE; in generic_fillattr()
110 stat->change_cookie = inode_query_iversion(inode); in generic_fillattr()
119 * @stat: Where to fill in the attribute flags
124 void generic_fill_statx_attr(struct inode *inode, struct kstat *stat) in generic_fill_statx_attr() argument
127 stat->attributes |= STATX_ATTR_IMMUTABLE; in generic_fill_statx_attr()
129 stat->attributes |= STATX_ATTR_APPEND; in generic_fill_statx_attr()
130 stat->attributes_mask |= KSTAT_ATTR_VFS_FLAGS; in generic_fill_statx_attr()
136 * @stat: Where to fill in the attribute flags
143 void generic_fill_statx_atomic_writes(struct kstat *stat, in generic_fill_statx_atomic_writes() argument
148 stat->result_mask |= STATX_WRITE_ATOMIC; in generic_fill_statx_atomic_writes()
151 stat->attributes_mask |= STATX_ATTR_WRITE_ATOMIC; in generic_fill_statx_atomic_writes()
154 stat->atomic_write_unit_min = unit_min; in generic_fill_statx_atomic_writes()
155 stat->atomic_write_unit_max = unit_max; in generic_fill_statx_atomic_writes()
157 stat->atomic_write_segments_max = 1; in generic_fill_statx_atomic_writes()
160 stat->attributes |= STATX_ATTR_WRITE_ATOMIC; in generic_fill_statx_atomic_writes()
168 * @stat: structure to return attributes in
178 int vfs_getattr_nosec(const struct path *path, struct kstat *stat, in vfs_getattr_nosec() argument
184 memset(stat, 0, sizeof(*stat)); in vfs_getattr_nosec()
185 stat->result_mask |= STATX_BASIC_STATS; in vfs_getattr_nosec()
191 stat->result_mask &= ~STATX_ATIME; in vfs_getattr_nosec()
198 stat->attributes |= STATX_ATTR_AUTOMOUNT; in vfs_getattr_nosec()
201 stat->attributes |= STATX_ATTR_DAX; in vfs_getattr_nosec()
203 stat->attributes_mask |= (STATX_ATTR_AUTOMOUNT | in vfs_getattr_nosec()
208 return inode->i_op->getattr(idmap, path, stat, in vfs_getattr_nosec()
212 generic_fillattr(idmap, request_mask, inode, stat); in vfs_getattr_nosec()
220 * @stat: Where to return the statistics
238 int vfs_getattr(const struct path *path, struct kstat *stat, in vfs_getattr() argument
246 return vfs_getattr_nosec(path, stat, request_mask, query_flags); in vfs_getattr()
253 * @stat: The result structure to fill in.
260 int vfs_fstat(int fd, struct kstat *stat) in vfs_fstat() argument
265 return vfs_getattr(&fd_file(f)->f_path, stat, STATX_BASIC_STATS, 0); in vfs_fstat()
280 static int vfs_statx_path(struct path *path, int flags, struct kstat *stat, in vfs_statx_path() argument
283 int error = vfs_getattr(path, stat, request_mask, flags); in vfs_statx_path()
288 stat->mnt_id = real_mount(path->mnt)->mnt_id_unique; in vfs_statx_path()
289 stat->result_mask |= STATX_MNT_ID_UNIQUE; in vfs_statx_path()
291 stat->mnt_id = real_mount(path->mnt)->mnt_id; in vfs_statx_path()
292 stat->result_mask |= STATX_MNT_ID; in vfs_statx_path()
296 stat->attributes |= STATX_ATTR_MOUNT_ROOT; in vfs_statx_path()
297 stat->attributes_mask |= STATX_ATTR_MOUNT_ROOT; in vfs_statx_path()
304 if (S_ISBLK(stat->mode)) in vfs_statx_path()
305 bdev_statx(path, stat, request_mask); in vfs_statx_path()
310 static int vfs_statx_fd(int fd, int flags, struct kstat *stat, in vfs_statx_fd() argument
316 return vfs_statx_path(&fd_file(f)->f_path, flags, stat, request_mask); in vfs_statx_fd()
324 * @stat: The result structure to fill in.
335 struct kstat *stat, u32 request_mask) in vfs_statx() argument
349 error = vfs_statx_path(&path, flags, stat, request_mask); in vfs_statx()
359 struct kstat *stat, int flags) in vfs_fstatat() argument
366 return vfs_fstat(dfd, stat); in vfs_fstatat()
368 ret = vfs_statx(dfd, name, statx_flags, stat, STATX_BASIC_STATS); in vfs_fstatat()
380 static int cp_old_stat(struct kstat *stat, struct __old_kernel_stat __user * statbuf) in cp_old_stat() argument
387 printk(KERN_WARNING "VFS: Warning: %s using old stat() call. Recompile your binary.\n", in cp_old_stat()
395 tmp.st_dev = old_encode_dev(stat->dev); in cp_old_stat()
396 tmp.st_ino = stat->ino; in cp_old_stat()
397 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) in cp_old_stat()
399 tmp.st_mode = stat->mode; in cp_old_stat()
400 tmp.st_nlink = stat->nlink; in cp_old_stat()
401 if (tmp.st_nlink != stat->nlink) in cp_old_stat()
403 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid)); in cp_old_stat()
404 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid)); in cp_old_stat()
405 tmp.st_rdev = old_encode_dev(stat->rdev); in cp_old_stat()
407 if (stat->size > MAX_NON_LFS) in cp_old_stat()
410 tmp.st_size = stat->size; in cp_old_stat()
411 tmp.st_atime = stat->atime.tv_sec; in cp_old_stat()
412 tmp.st_mtime = stat->mtime.tv_sec; in cp_old_stat()
413 tmp.st_ctime = stat->ctime.tv_sec; in cp_old_stat()
417 SYSCALL_DEFINE2(stat, const char __user *, filename, in SYSCALL_DEFINE2() argument
420 struct kstat stat; in SYSCALL_DEFINE2() local
423 error = vfs_stat(filename, &stat); in SYSCALL_DEFINE2()
427 return cp_old_stat(&stat, statbuf); in SYSCALL_DEFINE2()
433 struct kstat stat; in SYSCALL_DEFINE2() local
436 error = vfs_lstat(filename, &stat); in SYSCALL_DEFINE2()
440 return cp_old_stat(&stat, statbuf); in SYSCALL_DEFINE2()
445 struct kstat stat; in SYSCALL_DEFINE2() local
446 int error = vfs_fstat(fd, &stat); in SYSCALL_DEFINE2()
449 error = cp_old_stat(&stat, statbuf); in SYSCALL_DEFINE2()
462 static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf) in cp_new_stat() argument
464 struct stat tmp; in cp_new_stat()
466 if (sizeof(tmp.st_dev) < 4 && !old_valid_dev(stat->dev)) in cp_new_stat()
468 if (sizeof(tmp.st_rdev) < 4 && !old_valid_dev(stat->rdev)) in cp_new_stat()
471 if (stat->size > MAX_NON_LFS) in cp_new_stat()
476 tmp.st_dev = new_encode_dev(stat->dev); in cp_new_stat()
477 tmp.st_ino = stat->ino; in cp_new_stat()
478 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) in cp_new_stat()
480 tmp.st_mode = stat->mode; in cp_new_stat()
481 tmp.st_nlink = stat->nlink; in cp_new_stat()
482 if (tmp.st_nlink != stat->nlink) in cp_new_stat()
484 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid)); in cp_new_stat()
485 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid)); in cp_new_stat()
486 tmp.st_rdev = new_encode_dev(stat->rdev); in cp_new_stat()
487 tmp.st_size = stat->size; in cp_new_stat()
488 tmp.st_atime = stat->atime.tv_sec; in cp_new_stat()
489 tmp.st_mtime = stat->mtime.tv_sec; in cp_new_stat()
490 tmp.st_ctime = stat->ctime.tv_sec; in cp_new_stat()
492 tmp.st_atime_nsec = stat->atime.tv_nsec; in cp_new_stat()
493 tmp.st_mtime_nsec = stat->mtime.tv_nsec; in cp_new_stat()
494 tmp.st_ctime_nsec = stat->ctime.tv_nsec; in cp_new_stat()
496 tmp.st_blocks = stat->blocks; in cp_new_stat()
497 tmp.st_blksize = stat->blksize; in cp_new_stat()
502 struct stat __user *, statbuf) in SYSCALL_DEFINE2()
504 struct kstat stat; in SYSCALL_DEFINE2() local
505 int error = vfs_stat(filename, &stat); in SYSCALL_DEFINE2()
509 return cp_new_stat(&stat, statbuf); in SYSCALL_DEFINE2()
513 struct stat __user *, statbuf) in SYSCALL_DEFINE2()
515 struct kstat stat; in SYSCALL_DEFINE2() local
518 error = vfs_lstat(filename, &stat); in SYSCALL_DEFINE2()
522 return cp_new_stat(&stat, statbuf); in SYSCALL_DEFINE2()
527 struct stat __user *, statbuf, int, flag) in SYSCALL_DEFINE4()
529 struct kstat stat; in SYSCALL_DEFINE4() local
532 error = vfs_fstatat(dfd, filename, &stat, flag); in SYSCALL_DEFINE4()
535 return cp_new_stat(&stat, statbuf); in SYSCALL_DEFINE4()
539 SYSCALL_DEFINE2(newfstat, unsigned int, fd, struct stat __user *, statbuf) in SYSCALL_DEFINE2()
541 struct kstat stat; in SYSCALL_DEFINE2() local
542 int error = vfs_fstat(fd, &stat); in SYSCALL_DEFINE2()
545 error = cp_new_stat(&stat, statbuf); in SYSCALL_DEFINE2()
612 static long cp_new_stat64(struct kstat *stat, struct stat64 __user *statbuf) in cp_new_stat64() argument
619 tmp.st_dev = new_encode_dev(stat->dev); in cp_new_stat64()
620 tmp.st_rdev = new_encode_dev(stat->rdev); in cp_new_stat64()
622 tmp.st_dev = huge_encode_dev(stat->dev); in cp_new_stat64()
623 tmp.st_rdev = huge_encode_dev(stat->rdev); in cp_new_stat64()
625 tmp.st_ino = stat->ino; in cp_new_stat64()
626 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) in cp_new_stat64()
629 tmp.__st_ino = stat->ino; in cp_new_stat64()
631 tmp.st_mode = stat->mode; in cp_new_stat64()
632 tmp.st_nlink = stat->nlink; in cp_new_stat64()
633 tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid); in cp_new_stat64()
634 tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid); in cp_new_stat64()
635 tmp.st_atime = stat->atime.tv_sec; in cp_new_stat64()
636 tmp.st_atime_nsec = stat->atime.tv_nsec; in cp_new_stat64()
637 tmp.st_mtime = stat->mtime.tv_sec; in cp_new_stat64()
638 tmp.st_mtime_nsec = stat->mtime.tv_nsec; in cp_new_stat64()
639 tmp.st_ctime = stat->ctime.tv_sec; in cp_new_stat64()
640 tmp.st_ctime_nsec = stat->ctime.tv_nsec; in cp_new_stat64()
641 tmp.st_size = stat->size; in cp_new_stat64()
642 tmp.st_blocks = stat->blocks; in cp_new_stat64()
643 tmp.st_blksize = stat->blksize; in cp_new_stat64()
650 struct kstat stat; in SYSCALL_DEFINE2() local
651 int error = vfs_stat(filename, &stat); in SYSCALL_DEFINE2()
654 error = cp_new_stat64(&stat, statbuf); in SYSCALL_DEFINE2()
662 struct kstat stat; in SYSCALL_DEFINE2() local
663 int error = vfs_lstat(filename, &stat); in SYSCALL_DEFINE2()
666 error = cp_new_stat64(&stat, statbuf); in SYSCALL_DEFINE2()
673 struct kstat stat; in SYSCALL_DEFINE2() local
674 int error = vfs_fstat(fd, &stat); in SYSCALL_DEFINE2()
677 error = cp_new_stat64(&stat, statbuf); in SYSCALL_DEFINE2()
685 struct kstat stat; in SYSCALL_DEFINE4() local
688 error = vfs_fstatat(dfd, filename, &stat, flag); in SYSCALL_DEFINE4()
691 return cp_new_stat64(&stat, statbuf); in SYSCALL_DEFINE4()
696 cp_statx(const struct kstat *stat, struct statx __user *buffer) in cp_statx() argument
703 tmp.stx_mask = stat->result_mask & ~STATX_CHANGE_COOKIE; in cp_statx()
704 tmp.stx_blksize = stat->blksize; in cp_statx()
706 tmp.stx_attributes = stat->attributes & ~STATX_ATTR_CHANGE_MONOTONIC; in cp_statx()
707 tmp.stx_nlink = stat->nlink; in cp_statx()
708 tmp.stx_uid = from_kuid_munged(current_user_ns(), stat->uid); in cp_statx()
709 tmp.stx_gid = from_kgid_munged(current_user_ns(), stat->gid); in cp_statx()
710 tmp.stx_mode = stat->mode; in cp_statx()
711 tmp.stx_ino = stat->ino; in cp_statx()
712 tmp.stx_size = stat->size; in cp_statx()
713 tmp.stx_blocks = stat->blocks; in cp_statx()
714 tmp.stx_attributes_mask = stat->attributes_mask; in cp_statx()
715 tmp.stx_atime.tv_sec = stat->atime.tv_sec; in cp_statx()
716 tmp.stx_atime.tv_nsec = stat->atime.tv_nsec; in cp_statx()
717 tmp.stx_btime.tv_sec = stat->btime.tv_sec; in cp_statx()
718 tmp.stx_btime.tv_nsec = stat->btime.tv_nsec; in cp_statx()
719 tmp.stx_ctime.tv_sec = stat->ctime.tv_sec; in cp_statx()
720 tmp.stx_ctime.tv_nsec = stat->ctime.tv_nsec; in cp_statx()
721 tmp.stx_mtime.tv_sec = stat->mtime.tv_sec; in cp_statx()
722 tmp.stx_mtime.tv_nsec = stat->mtime.tv_nsec; in cp_statx()
723 tmp.stx_rdev_major = MAJOR(stat->rdev); in cp_statx()
724 tmp.stx_rdev_minor = MINOR(stat->rdev); in cp_statx()
725 tmp.stx_dev_major = MAJOR(stat->dev); in cp_statx()
726 tmp.stx_dev_minor = MINOR(stat->dev); in cp_statx()
727 tmp.stx_mnt_id = stat->mnt_id; in cp_statx()
728 tmp.stx_dio_mem_align = stat->dio_mem_align; in cp_statx()
729 tmp.stx_dio_offset_align = stat->dio_offset_align; in cp_statx()
730 tmp.stx_dio_read_offset_align = stat->dio_read_offset_align; in cp_statx()
731 tmp.stx_subvol = stat->subvol; in cp_statx()
732 tmp.stx_atomic_write_unit_min = stat->atomic_write_unit_min; in cp_statx()
733 tmp.stx_atomic_write_unit_max = stat->atomic_write_unit_max; in cp_statx()
734 tmp.stx_atomic_write_segments_max = stat->atomic_write_segments_max; in cp_statx()
742 struct kstat stat; in do_statx() local
756 error = vfs_statx(dfd, filename, flags, &stat, mask); in do_statx()
760 return cp_statx(&stat, buffer); in do_statx()
766 struct kstat stat; in do_statx_fd() local
780 error = vfs_statx_fd(fd, flags, &stat, mask); in do_statx_fd()
784 return cp_statx(&stat, buffer); in do_statx_fd()
789 * @dfd: Base directory to pathwalk from *or* fd to stat.
790 * @filename: File to stat or either NULL or "" with AT_EMPTY_PATH
817 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf) in cp_compat_stat() argument
821 if (sizeof(tmp.st_dev) < 4 && !old_valid_dev(stat->dev)) in cp_compat_stat()
823 if (sizeof(tmp.st_rdev) < 4 && !old_valid_dev(stat->rdev)) in cp_compat_stat()
827 tmp.st_dev = new_encode_dev(stat->dev); in cp_compat_stat()
828 tmp.st_ino = stat->ino; in cp_compat_stat()
829 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) in cp_compat_stat()
831 tmp.st_mode = stat->mode; in cp_compat_stat()
832 tmp.st_nlink = stat->nlink; in cp_compat_stat()
833 if (tmp.st_nlink != stat->nlink) in cp_compat_stat()
835 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid)); in cp_compat_stat()
836 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid)); in cp_compat_stat()
837 tmp.st_rdev = new_encode_dev(stat->rdev); in cp_compat_stat()
838 if ((u64) stat->size > MAX_NON_LFS) in cp_compat_stat()
840 tmp.st_size = stat->size; in cp_compat_stat()
841 tmp.st_atime = stat->atime.tv_sec; in cp_compat_stat()
842 tmp.st_atime_nsec = stat->atime.tv_nsec; in cp_compat_stat()
843 tmp.st_mtime = stat->mtime.tv_sec; in cp_compat_stat()
844 tmp.st_mtime_nsec = stat->mtime.tv_nsec; in cp_compat_stat()
845 tmp.st_ctime = stat->ctime.tv_sec; in cp_compat_stat()
846 tmp.st_ctime_nsec = stat->ctime.tv_nsec; in cp_compat_stat()
847 tmp.st_blocks = stat->blocks; in cp_compat_stat()
848 tmp.st_blksize = stat->blksize; in cp_compat_stat()
855 struct kstat stat; in COMPAT_SYSCALL_DEFINE2() local
858 error = vfs_stat(filename, &stat); in COMPAT_SYSCALL_DEFINE2()
861 return cp_compat_stat(&stat, statbuf); in COMPAT_SYSCALL_DEFINE2()
867 struct kstat stat; in COMPAT_SYSCALL_DEFINE2() local
870 error = vfs_lstat(filename, &stat); in COMPAT_SYSCALL_DEFINE2()
873 return cp_compat_stat(&stat, statbuf); in COMPAT_SYSCALL_DEFINE2()
881 struct kstat stat; in COMPAT_SYSCALL_DEFINE4() local
884 error = vfs_fstatat(dfd, filename, &stat, flag); in COMPAT_SYSCALL_DEFINE4()
887 return cp_compat_stat(&stat, statbuf); in COMPAT_SYSCALL_DEFINE4()
894 struct kstat stat; in COMPAT_SYSCALL_DEFINE2() local
895 int error = vfs_fstat(fd, &stat); in COMPAT_SYSCALL_DEFINE2()
898 error = cp_compat_stat(&stat, statbuf); in COMPAT_SYSCALL_DEFINE2()