11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/fs/stat.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds 7630d9c47SPaul Gortmaker #include <linux/export.h> 81da177e4SLinus Torvalds #include <linux/mm.h> 91da177e4SLinus Torvalds #include <linux/errno.h> 101da177e4SLinus Torvalds #include <linux/file.h> 111da177e4SLinus Torvalds #include <linux/highuid.h> 121da177e4SLinus Torvalds #include <linux/fs.h> 131da177e4SLinus Torvalds #include <linux/namei.h> 141da177e4SLinus Torvalds #include <linux/security.h> 155b825c3aSIngo Molnar #include <linux/cred.h> 161da177e4SLinus Torvalds #include <linux/syscalls.h> 17ba52de12STheodore Ts'o #include <linux/pagemap.h> 18*ac565de3SAl Viro #include <linux/compat.h> 191da177e4SLinus Torvalds 207c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 211da177e4SLinus Torvalds #include <asm/unistd.h> 221da177e4SLinus Torvalds 23a528d35eSDavid Howells /** 24a528d35eSDavid Howells * generic_fillattr - Fill in the basic attributes from the inode struct 25a528d35eSDavid Howells * @inode: Inode to use as the source 26a528d35eSDavid Howells * @stat: Where to fill in the attributes 27a528d35eSDavid Howells * 28a528d35eSDavid Howells * Fill in the basic attributes in the kstat structure from data that's to be 29a528d35eSDavid Howells * found on the VFS inode structure. This is the default if no getattr inode 30a528d35eSDavid Howells * operation is supplied. 31a528d35eSDavid Howells */ 321da177e4SLinus Torvalds void generic_fillattr(struct inode *inode, struct kstat *stat) 331da177e4SLinus Torvalds { 341da177e4SLinus Torvalds stat->dev = inode->i_sb->s_dev; 351da177e4SLinus Torvalds stat->ino = inode->i_ino; 361da177e4SLinus Torvalds stat->mode = inode->i_mode; 371da177e4SLinus Torvalds stat->nlink = inode->i_nlink; 381da177e4SLinus Torvalds stat->uid = inode->i_uid; 391da177e4SLinus Torvalds stat->gid = inode->i_gid; 401da177e4SLinus Torvalds stat->rdev = inode->i_rdev; 413ddcd056SLinus Torvalds stat->size = i_size_read(inode); 421da177e4SLinus Torvalds stat->atime = inode->i_atime; 431da177e4SLinus Torvalds stat->mtime = inode->i_mtime; 441da177e4SLinus Torvalds stat->ctime = inode->i_ctime; 4593407472SFabian Frederick stat->blksize = i_blocksize(inode); 463ddcd056SLinus Torvalds stat->blocks = inode->i_blocks; 471da177e4SLinus Torvalds 48a528d35eSDavid Howells if (IS_NOATIME(inode)) 49a528d35eSDavid Howells stat->result_mask &= ~STATX_ATIME; 50a528d35eSDavid Howells if (IS_AUTOMOUNT(inode)) 51a528d35eSDavid Howells stat->attributes |= STATX_ATTR_AUTOMOUNT; 52a528d35eSDavid Howells } 531da177e4SLinus Torvalds EXPORT_SYMBOL(generic_fillattr); 541da177e4SLinus Torvalds 55b7a6ec52SJ. Bruce Fields /** 56b7a6ec52SJ. Bruce Fields * vfs_getattr_nosec - getattr without security checks 57b7a6ec52SJ. Bruce Fields * @path: file to get attributes from 58b7a6ec52SJ. Bruce Fields * @stat: structure to return attributes in 59a528d35eSDavid Howells * @request_mask: STATX_xxx flags indicating what the caller wants 60a528d35eSDavid Howells * @query_flags: Query mode (KSTAT_QUERY_FLAGS) 61b7a6ec52SJ. Bruce Fields * 62b7a6ec52SJ. Bruce Fields * Get attributes without calling security_inode_getattr. 63b7a6ec52SJ. Bruce Fields * 64b7a6ec52SJ. Bruce Fields * Currently the only caller other than vfs_getattr is internal to the 65a528d35eSDavid Howells * filehandle lookup code, which uses only the inode number and returns no 66a528d35eSDavid Howells * attributes to any user. Any other code probably wants vfs_getattr. 67b7a6ec52SJ. Bruce Fields */ 68a528d35eSDavid Howells int vfs_getattr_nosec(const struct path *path, struct kstat *stat, 69a528d35eSDavid Howells u32 request_mask, unsigned int query_flags) 701da177e4SLinus Torvalds { 71bb668734SDavid Howells struct inode *inode = d_backing_inode(path->dentry); 721da177e4SLinus Torvalds 73a528d35eSDavid Howells memset(stat, 0, sizeof(*stat)); 74a528d35eSDavid Howells stat->result_mask |= STATX_BASIC_STATS; 75a528d35eSDavid Howells request_mask &= STATX_ALL; 76a528d35eSDavid Howells query_flags &= KSTAT_QUERY_FLAGS; 771da177e4SLinus Torvalds if (inode->i_op->getattr) 78a528d35eSDavid Howells return inode->i_op->getattr(path, stat, request_mask, 79a528d35eSDavid Howells query_flags); 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds generic_fillattr(inode, stat); 821da177e4SLinus Torvalds return 0; 831da177e4SLinus Torvalds } 84b7a6ec52SJ. Bruce Fields EXPORT_SYMBOL(vfs_getattr_nosec); 85b7a6ec52SJ. Bruce Fields 86a528d35eSDavid Howells /* 87a528d35eSDavid Howells * vfs_getattr - Get the enhanced basic attributes of a file 88a528d35eSDavid Howells * @path: The file of interest 89a528d35eSDavid Howells * @stat: Where to return the statistics 90a528d35eSDavid Howells * @request_mask: STATX_xxx flags indicating what the caller wants 91a528d35eSDavid Howells * @query_flags: Query mode (KSTAT_QUERY_FLAGS) 92a528d35eSDavid Howells * 93a528d35eSDavid Howells * Ask the filesystem for a file's attributes. The caller must indicate in 94a528d35eSDavid Howells * request_mask and query_flags to indicate what they want. 95a528d35eSDavid Howells * 96a528d35eSDavid Howells * If the file is remote, the filesystem can be forced to update the attributes 97a528d35eSDavid Howells * from the backing store by passing AT_STATX_FORCE_SYNC in query_flags or can 98a528d35eSDavid Howells * suppress the update by passing AT_STATX_DONT_SYNC. 99a528d35eSDavid Howells * 100a528d35eSDavid Howells * Bits must have been set in request_mask to indicate which attributes the 101a528d35eSDavid Howells * caller wants retrieving. Any such attribute not requested may be returned 102a528d35eSDavid Howells * anyway, but the value may be approximate, and, if remote, may not have been 103a528d35eSDavid Howells * synchronised with the server. 104a528d35eSDavid Howells * 105a528d35eSDavid Howells * 0 will be returned on success, and a -ve error code if unsuccessful. 106a528d35eSDavid Howells */ 107a528d35eSDavid Howells int vfs_getattr(const struct path *path, struct kstat *stat, 108a528d35eSDavid Howells u32 request_mask, unsigned int query_flags) 109b7a6ec52SJ. Bruce Fields { 110b7a6ec52SJ. Bruce Fields int retval; 111b7a6ec52SJ. Bruce Fields 1123f7036a0SAl Viro retval = security_inode_getattr(path); 113b7a6ec52SJ. Bruce Fields if (retval) 114b7a6ec52SJ. Bruce Fields return retval; 115a528d35eSDavid Howells return vfs_getattr_nosec(path, stat, request_mask, query_flags); 116b7a6ec52SJ. Bruce Fields } 1171da177e4SLinus Torvalds EXPORT_SYMBOL(vfs_getattr); 1181da177e4SLinus Torvalds 119a528d35eSDavid Howells /** 120a528d35eSDavid Howells * vfs_statx_fd - Get the enhanced basic attributes by file descriptor 121a528d35eSDavid Howells * @fd: The file descriptor referring to the file of interest 122a528d35eSDavid Howells * @stat: The result structure to fill in. 123a528d35eSDavid Howells * @request_mask: STATX_xxx flags indicating what the caller wants 124a528d35eSDavid Howells * @query_flags: Query mode (KSTAT_QUERY_FLAGS) 125a528d35eSDavid Howells * 126a528d35eSDavid Howells * This function is a wrapper around vfs_getattr(). The main difference is 127a528d35eSDavid Howells * that it uses a file descriptor to determine the file location. 128a528d35eSDavid Howells * 129a528d35eSDavid Howells * 0 will be returned on success, and a -ve error code if unsuccessful. 130a528d35eSDavid Howells */ 131a528d35eSDavid Howells int vfs_statx_fd(unsigned int fd, struct kstat *stat, 132a528d35eSDavid Howells u32 request_mask, unsigned int query_flags) 1331da177e4SLinus Torvalds { 1342903ff01SAl Viro struct fd f = fdget_raw(fd); 1351da177e4SLinus Torvalds int error = -EBADF; 1361da177e4SLinus Torvalds 1372903ff01SAl Viro if (f.file) { 138a528d35eSDavid Howells error = vfs_getattr(&f.file->f_path, stat, 139a528d35eSDavid Howells request_mask, query_flags); 1402903ff01SAl Viro fdput(f); 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds return error; 1431da177e4SLinus Torvalds } 144a528d35eSDavid Howells EXPORT_SYMBOL(vfs_statx_fd); 1451da177e4SLinus Torvalds 146a528d35eSDavid Howells /** 147a528d35eSDavid Howells * vfs_statx - Get basic and extra attributes by filename 148a528d35eSDavid Howells * @dfd: A file descriptor representing the base dir for a relative filename 149a528d35eSDavid Howells * @filename: The name of the file of interest 150a528d35eSDavid Howells * @flags: Flags to control the query 151a528d35eSDavid Howells * @stat: The result structure to fill in. 152a528d35eSDavid Howells * @request_mask: STATX_xxx flags indicating what the caller wants 153a528d35eSDavid Howells * 154a528d35eSDavid Howells * This function is a wrapper around vfs_getattr(). The main difference is 155a528d35eSDavid Howells * that it uses a filename and base directory to determine the file location. 156a528d35eSDavid Howells * Additionally, the use of AT_SYMLINK_NOFOLLOW in flags will prevent a symlink 157a528d35eSDavid Howells * at the given name from being referenced. 158a528d35eSDavid Howells * 159a528d35eSDavid Howells * The caller must have preset stat->request_mask as for vfs_getattr(). The 160a528d35eSDavid Howells * flags are also used to load up stat->query_flags. 161a528d35eSDavid Howells * 162a528d35eSDavid Howells * 0 will be returned on success, and a -ve error code if unsuccessful. 163a528d35eSDavid Howells */ 164a528d35eSDavid Howells int vfs_statx(int dfd, const char __user *filename, int flags, 165a528d35eSDavid Howells struct kstat *stat, u32 request_mask) 1660112fc22SOleg Drokin { 1672eae7a18SChristoph Hellwig struct path path; 1680112fc22SOleg Drokin int error = -EINVAL; 169a528d35eSDavid Howells unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT; 1700112fc22SOleg Drokin 171a528d35eSDavid Howells if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | 172a528d35eSDavid Howells AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0) 173a528d35eSDavid Howells return -EINVAL; 1740112fc22SOleg Drokin 175a528d35eSDavid Howells if (flags & AT_SYMLINK_NOFOLLOW) 176a528d35eSDavid Howells lookup_flags &= ~LOOKUP_FOLLOW; 177a528d35eSDavid Howells if (flags & AT_NO_AUTOMOUNT) 178a528d35eSDavid Howells lookup_flags &= ~LOOKUP_AUTOMOUNT; 179a528d35eSDavid Howells if (flags & AT_EMPTY_PATH) 18065cfc672SAl Viro lookup_flags |= LOOKUP_EMPTY; 181a528d35eSDavid Howells 182836fb7e7SJeff Layton retry: 1832eae7a18SChristoph Hellwig error = user_path_at(dfd, filename, lookup_flags, &path); 1842eae7a18SChristoph Hellwig if (error) 1852eae7a18SChristoph Hellwig goto out; 1862eae7a18SChristoph Hellwig 187a528d35eSDavid Howells error = vfs_getattr(&path, stat, request_mask, flags); 1882eae7a18SChristoph Hellwig path_put(&path); 189836fb7e7SJeff Layton if (retry_estale(error, lookup_flags)) { 190836fb7e7SJeff Layton lookup_flags |= LOOKUP_REVAL; 191836fb7e7SJeff Layton goto retry; 192836fb7e7SJeff Layton } 1930112fc22SOleg Drokin out: 1940112fc22SOleg Drokin return error; 1950112fc22SOleg Drokin } 196a528d35eSDavid Howells EXPORT_SYMBOL(vfs_statx); 1972eae7a18SChristoph Hellwig 1980112fc22SOleg Drokin 1991da177e4SLinus Torvalds #ifdef __ARCH_WANT_OLD_STAT 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds /* 2021da177e4SLinus Torvalds * For backward compatibility? Maybe this should be moved 2031da177e4SLinus Torvalds * into arch/i386 instead? 2041da177e4SLinus Torvalds */ 2051da177e4SLinus Torvalds static int cp_old_stat(struct kstat *stat, struct __old_kernel_stat __user * statbuf) 2061da177e4SLinus Torvalds { 2071da177e4SLinus Torvalds static int warncount = 5; 2081da177e4SLinus Torvalds struct __old_kernel_stat tmp; 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds if (warncount > 0) { 2111da177e4SLinus Torvalds warncount--; 2121da177e4SLinus Torvalds printk(KERN_WARNING "VFS: Warning: %s using old stat() call. Recompile your binary.\n", 2131da177e4SLinus Torvalds current->comm); 2141da177e4SLinus Torvalds } else if (warncount < 0) { 2151da177e4SLinus Torvalds /* it's laughable, but... */ 2161da177e4SLinus Torvalds warncount = 0; 2171da177e4SLinus Torvalds } 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds memset(&tmp, 0, sizeof(struct __old_kernel_stat)); 2201da177e4SLinus Torvalds tmp.st_dev = old_encode_dev(stat->dev); 2211da177e4SLinus Torvalds tmp.st_ino = stat->ino; 222afefdbb2SDavid Howells if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) 223afefdbb2SDavid Howells return -EOVERFLOW; 2241da177e4SLinus Torvalds tmp.st_mode = stat->mode; 2251da177e4SLinus Torvalds tmp.st_nlink = stat->nlink; 2261da177e4SLinus Torvalds if (tmp.st_nlink != stat->nlink) 2271da177e4SLinus Torvalds return -EOVERFLOW; 228a7c1938eSEric W. Biederman SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid)); 229a7c1938eSEric W. Biederman SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid)); 2301da177e4SLinus Torvalds tmp.st_rdev = old_encode_dev(stat->rdev); 2311da177e4SLinus Torvalds #if BITS_PER_LONG == 32 2321da177e4SLinus Torvalds if (stat->size > MAX_NON_LFS) 2331da177e4SLinus Torvalds return -EOVERFLOW; 2341da177e4SLinus Torvalds #endif 2351da177e4SLinus Torvalds tmp.st_size = stat->size; 2361da177e4SLinus Torvalds tmp.st_atime = stat->atime.tv_sec; 2371da177e4SLinus Torvalds tmp.st_mtime = stat->mtime.tv_sec; 2381da177e4SLinus Torvalds tmp.st_ctime = stat->ctime.tv_sec; 2391da177e4SLinus Torvalds return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0; 2401da177e4SLinus Torvalds } 2411da177e4SLinus Torvalds 242c7887325SDavid Howells SYSCALL_DEFINE2(stat, const char __user *, filename, 243c7887325SDavid Howells struct __old_kernel_stat __user *, statbuf) 2441da177e4SLinus Torvalds { 2451da177e4SLinus Torvalds struct kstat stat; 2462eae7a18SChristoph Hellwig int error; 2471da177e4SLinus Torvalds 2482eae7a18SChristoph Hellwig error = vfs_stat(filename, &stat); 2492eae7a18SChristoph Hellwig if (error) 2501da177e4SLinus Torvalds return error; 2512eae7a18SChristoph Hellwig 2522eae7a18SChristoph Hellwig return cp_old_stat(&stat, statbuf); 2531da177e4SLinus Torvalds } 254257ac264SHeiko Carstens 255c7887325SDavid Howells SYSCALL_DEFINE2(lstat, const char __user *, filename, 256c7887325SDavid Howells struct __old_kernel_stat __user *, statbuf) 2571da177e4SLinus Torvalds { 2581da177e4SLinus Torvalds struct kstat stat; 2592eae7a18SChristoph Hellwig int error; 2601da177e4SLinus Torvalds 2612eae7a18SChristoph Hellwig error = vfs_lstat(filename, &stat); 2622eae7a18SChristoph Hellwig if (error) 2631da177e4SLinus Torvalds return error; 2642eae7a18SChristoph Hellwig 2652eae7a18SChristoph Hellwig return cp_old_stat(&stat, statbuf); 2661da177e4SLinus Torvalds } 267257ac264SHeiko Carstens 268257ac264SHeiko Carstens SYSCALL_DEFINE2(fstat, unsigned int, fd, struct __old_kernel_stat __user *, statbuf) 2691da177e4SLinus Torvalds { 2701da177e4SLinus Torvalds struct kstat stat; 2711da177e4SLinus Torvalds int error = vfs_fstat(fd, &stat); 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds if (!error) 2741da177e4SLinus Torvalds error = cp_old_stat(&stat, statbuf); 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds return error; 2771da177e4SLinus Torvalds } 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds #endif /* __ARCH_WANT_OLD_STAT */ 2801da177e4SLinus Torvalds 281a52dd971SLinus Torvalds #if BITS_PER_LONG == 32 282a52dd971SLinus Torvalds # define choose_32_64(a,b) a 283a52dd971SLinus Torvalds #else 284a52dd971SLinus Torvalds # define choose_32_64(a,b) b 285a52dd971SLinus Torvalds #endif 286a52dd971SLinus Torvalds 2874c416f42SYaowei Bai #define valid_dev(x) choose_32_64(old_valid_dev(x),true) 288a52dd971SLinus Torvalds #define encode_dev(x) choose_32_64(old_encode_dev,new_encode_dev)(x) 289a52dd971SLinus Torvalds 2908529f613SLinus Torvalds #ifndef INIT_STRUCT_STAT_PADDING 2918529f613SLinus Torvalds # define INIT_STRUCT_STAT_PADDING(st) memset(&st, 0, sizeof(st)) 2928529f613SLinus Torvalds #endif 2938529f613SLinus Torvalds 2941da177e4SLinus Torvalds static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf) 2951da177e4SLinus Torvalds { 2961da177e4SLinus Torvalds struct stat tmp; 2971da177e4SLinus Torvalds 298a52dd971SLinus Torvalds if (!valid_dev(stat->dev) || !valid_dev(stat->rdev)) 2991da177e4SLinus Torvalds return -EOVERFLOW; 300a52dd971SLinus Torvalds #if BITS_PER_LONG == 32 301a52dd971SLinus Torvalds if (stat->size > MAX_NON_LFS) 3021da177e4SLinus Torvalds return -EOVERFLOW; 3031da177e4SLinus Torvalds #endif 3041da177e4SLinus Torvalds 3058529f613SLinus Torvalds INIT_STRUCT_STAT_PADDING(tmp); 306a52dd971SLinus Torvalds tmp.st_dev = encode_dev(stat->dev); 3071da177e4SLinus Torvalds tmp.st_ino = stat->ino; 308afefdbb2SDavid Howells if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) 309afefdbb2SDavid Howells return -EOVERFLOW; 3101da177e4SLinus Torvalds tmp.st_mode = stat->mode; 3111da177e4SLinus Torvalds tmp.st_nlink = stat->nlink; 3121da177e4SLinus Torvalds if (tmp.st_nlink != stat->nlink) 3131da177e4SLinus Torvalds return -EOVERFLOW; 314a7c1938eSEric W. Biederman SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid)); 315a7c1938eSEric W. Biederman SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid)); 316a52dd971SLinus Torvalds tmp.st_rdev = encode_dev(stat->rdev); 3171da177e4SLinus Torvalds tmp.st_size = stat->size; 3181da177e4SLinus Torvalds tmp.st_atime = stat->atime.tv_sec; 3191da177e4SLinus Torvalds tmp.st_mtime = stat->mtime.tv_sec; 3201da177e4SLinus Torvalds tmp.st_ctime = stat->ctime.tv_sec; 3211da177e4SLinus Torvalds #ifdef STAT_HAVE_NSEC 3221da177e4SLinus Torvalds tmp.st_atime_nsec = stat->atime.tv_nsec; 3231da177e4SLinus Torvalds tmp.st_mtime_nsec = stat->mtime.tv_nsec; 3241da177e4SLinus Torvalds tmp.st_ctime_nsec = stat->ctime.tv_nsec; 3251da177e4SLinus Torvalds #endif 3261da177e4SLinus Torvalds tmp.st_blocks = stat->blocks; 3271da177e4SLinus Torvalds tmp.st_blksize = stat->blksize; 3281da177e4SLinus Torvalds return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0; 3291da177e4SLinus Torvalds } 3301da177e4SLinus Torvalds 331c7887325SDavid Howells SYSCALL_DEFINE2(newstat, const char __user *, filename, 332c7887325SDavid Howells struct stat __user *, statbuf) 3331da177e4SLinus Torvalds { 3341da177e4SLinus Torvalds struct kstat stat; 3352eae7a18SChristoph Hellwig int error = vfs_stat(filename, &stat); 3361da177e4SLinus Torvalds 3372eae7a18SChristoph Hellwig if (error) 3381da177e4SLinus Torvalds return error; 3392eae7a18SChristoph Hellwig return cp_new_stat(&stat, statbuf); 3401da177e4SLinus Torvalds } 3415590ff0dSUlrich Drepper 342c7887325SDavid Howells SYSCALL_DEFINE2(newlstat, const char __user *, filename, 343c7887325SDavid Howells struct stat __user *, statbuf) 3441da177e4SLinus Torvalds { 3451da177e4SLinus Torvalds struct kstat stat; 3462eae7a18SChristoph Hellwig int error; 3471da177e4SLinus Torvalds 3482eae7a18SChristoph Hellwig error = vfs_lstat(filename, &stat); 3492eae7a18SChristoph Hellwig if (error) 3501da177e4SLinus Torvalds return error; 3512eae7a18SChristoph Hellwig 3522eae7a18SChristoph Hellwig return cp_new_stat(&stat, statbuf); 3531da177e4SLinus Torvalds } 3545590ff0dSUlrich Drepper 3552833c28aSAndreas Schwab #if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT) 356c7887325SDavid Howells SYSCALL_DEFINE4(newfstatat, int, dfd, const char __user *, filename, 3576559eed8SHeiko Carstens struct stat __user *, statbuf, int, flag) 3585590ff0dSUlrich Drepper { 3595590ff0dSUlrich Drepper struct kstat stat; 3600112fc22SOleg Drokin int error; 3615590ff0dSUlrich Drepper 3620112fc22SOleg Drokin error = vfs_fstatat(dfd, filename, &stat, flag); 3630112fc22SOleg Drokin if (error) 3645590ff0dSUlrich Drepper return error; 3650112fc22SOleg Drokin return cp_new_stat(&stat, statbuf); 3665590ff0dSUlrich Drepper } 367cff2b760SUlrich Drepper #endif 3685590ff0dSUlrich Drepper 369257ac264SHeiko Carstens SYSCALL_DEFINE2(newfstat, unsigned int, fd, struct stat __user *, statbuf) 3701da177e4SLinus Torvalds { 3711da177e4SLinus Torvalds struct kstat stat; 3721da177e4SLinus Torvalds int error = vfs_fstat(fd, &stat); 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds if (!error) 3751da177e4SLinus Torvalds error = cp_new_stat(&stat, statbuf); 3761da177e4SLinus Torvalds 3771da177e4SLinus Torvalds return error; 3781da177e4SLinus Torvalds } 3791da177e4SLinus Torvalds 3806559eed8SHeiko Carstens SYSCALL_DEFINE4(readlinkat, int, dfd, const char __user *, pathname, 3816559eed8SHeiko Carstens char __user *, buf, int, bufsiz) 3821da177e4SLinus Torvalds { 3832d8f3038SAl Viro struct path path; 3841da177e4SLinus Torvalds int error; 3851fa1e7f6SAndy Whitcroft int empty = 0; 3867955119eSJeff Layton unsigned int lookup_flags = LOOKUP_EMPTY; 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds if (bufsiz <= 0) 3891da177e4SLinus Torvalds return -EINVAL; 3901da177e4SLinus Torvalds 3917955119eSJeff Layton retry: 3927955119eSJeff Layton error = user_path_at_empty(dfd, pathname, lookup_flags, &path, &empty); 3931da177e4SLinus Torvalds if (!error) { 394bb668734SDavid Howells struct inode *inode = d_backing_inode(path.dentry); 3951da177e4SLinus Torvalds 3961fa1e7f6SAndy Whitcroft error = empty ? -ENOENT : -EINVAL; 397fd4a0edfSMiklos Szeredi /* 398fd4a0edfSMiklos Szeredi * AFS mountpoints allow readlink(2) but are not symlinks 399fd4a0edfSMiklos Szeredi */ 400fd4a0edfSMiklos Szeredi if (d_is_symlink(path.dentry) || inode->i_op->readlink) { 4012d8f3038SAl Viro error = security_inode_readlink(path.dentry); 4021da177e4SLinus Torvalds if (!error) { 40368ac1234SAl Viro touch_atime(&path); 404fd4a0edfSMiklos Szeredi error = vfs_readlink(path.dentry, buf, bufsiz); 4051da177e4SLinus Torvalds } 4061da177e4SLinus Torvalds } 4072d8f3038SAl Viro path_put(&path); 4087955119eSJeff Layton if (retry_estale(error, lookup_flags)) { 4097955119eSJeff Layton lookup_flags |= LOOKUP_REVAL; 4107955119eSJeff Layton goto retry; 4117955119eSJeff Layton } 4121da177e4SLinus Torvalds } 4131da177e4SLinus Torvalds return error; 4141da177e4SLinus Torvalds } 4151da177e4SLinus Torvalds 416002c8976SHeiko Carstens SYSCALL_DEFINE3(readlink, const char __user *, path, char __user *, buf, 417002c8976SHeiko Carstens int, bufsiz) 4185590ff0dSUlrich Drepper { 4195590ff0dSUlrich Drepper return sys_readlinkat(AT_FDCWD, path, buf, bufsiz); 4205590ff0dSUlrich Drepper } 4215590ff0dSUlrich Drepper 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvalds /* ---------- LFS-64 ----------- */ 4240753f70fSCatalin Marinas #if defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_COMPAT_STAT64) 4251da177e4SLinus Torvalds 4268529f613SLinus Torvalds #ifndef INIT_STRUCT_STAT64_PADDING 4278529f613SLinus Torvalds # define INIT_STRUCT_STAT64_PADDING(st) memset(&st, 0, sizeof(st)) 4288529f613SLinus Torvalds #endif 4298529f613SLinus Torvalds 4301da177e4SLinus Torvalds static long cp_new_stat64(struct kstat *stat, struct stat64 __user *statbuf) 4311da177e4SLinus Torvalds { 4321da177e4SLinus Torvalds struct stat64 tmp; 4331da177e4SLinus Torvalds 4348529f613SLinus Torvalds INIT_STRUCT_STAT64_PADDING(tmp); 4351da177e4SLinus Torvalds #ifdef CONFIG_MIPS 4361da177e4SLinus Torvalds /* mips has weird padding, so we don't get 64 bits there */ 4371da177e4SLinus Torvalds tmp.st_dev = new_encode_dev(stat->dev); 4381da177e4SLinus Torvalds tmp.st_rdev = new_encode_dev(stat->rdev); 4391da177e4SLinus Torvalds #else 4401da177e4SLinus Torvalds tmp.st_dev = huge_encode_dev(stat->dev); 4411da177e4SLinus Torvalds tmp.st_rdev = huge_encode_dev(stat->rdev); 4421da177e4SLinus Torvalds #endif 4431da177e4SLinus Torvalds tmp.st_ino = stat->ino; 444afefdbb2SDavid Howells if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) 445afefdbb2SDavid Howells return -EOVERFLOW; 4461da177e4SLinus Torvalds #ifdef STAT64_HAS_BROKEN_ST_INO 4471da177e4SLinus Torvalds tmp.__st_ino = stat->ino; 4481da177e4SLinus Torvalds #endif 4491da177e4SLinus Torvalds tmp.st_mode = stat->mode; 4501da177e4SLinus Torvalds tmp.st_nlink = stat->nlink; 451a7c1938eSEric W. Biederman tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid); 452a7c1938eSEric W. Biederman tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid); 4531da177e4SLinus Torvalds tmp.st_atime = stat->atime.tv_sec; 4541da177e4SLinus Torvalds tmp.st_atime_nsec = stat->atime.tv_nsec; 4551da177e4SLinus Torvalds tmp.st_mtime = stat->mtime.tv_sec; 4561da177e4SLinus Torvalds tmp.st_mtime_nsec = stat->mtime.tv_nsec; 4571da177e4SLinus Torvalds tmp.st_ctime = stat->ctime.tv_sec; 4581da177e4SLinus Torvalds tmp.st_ctime_nsec = stat->ctime.tv_nsec; 4591da177e4SLinus Torvalds tmp.st_size = stat->size; 4601da177e4SLinus Torvalds tmp.st_blocks = stat->blocks; 4611da177e4SLinus Torvalds tmp.st_blksize = stat->blksize; 4621da177e4SLinus Torvalds return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0; 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds 465c7887325SDavid Howells SYSCALL_DEFINE2(stat64, const char __user *, filename, 466c7887325SDavid Howells struct stat64 __user *, statbuf) 4671da177e4SLinus Torvalds { 4681da177e4SLinus Torvalds struct kstat stat; 4691da177e4SLinus Torvalds int error = vfs_stat(filename, &stat); 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds if (!error) 4721da177e4SLinus Torvalds error = cp_new_stat64(&stat, statbuf); 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds return error; 4751da177e4SLinus Torvalds } 476257ac264SHeiko Carstens 477c7887325SDavid Howells SYSCALL_DEFINE2(lstat64, const char __user *, filename, 478c7887325SDavid Howells struct stat64 __user *, statbuf) 4791da177e4SLinus Torvalds { 4801da177e4SLinus Torvalds struct kstat stat; 4811da177e4SLinus Torvalds int error = vfs_lstat(filename, &stat); 4821da177e4SLinus Torvalds 4831da177e4SLinus Torvalds if (!error) 4841da177e4SLinus Torvalds error = cp_new_stat64(&stat, statbuf); 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds return error; 4871da177e4SLinus Torvalds } 488257ac264SHeiko Carstens 489257ac264SHeiko Carstens SYSCALL_DEFINE2(fstat64, unsigned long, fd, struct stat64 __user *, statbuf) 4901da177e4SLinus Torvalds { 4911da177e4SLinus Torvalds struct kstat stat; 4921da177e4SLinus Torvalds int error = vfs_fstat(fd, &stat); 4931da177e4SLinus Torvalds 4941da177e4SLinus Torvalds if (!error) 4951da177e4SLinus Torvalds error = cp_new_stat64(&stat, statbuf); 4961da177e4SLinus Torvalds 4971da177e4SLinus Torvalds return error; 4981da177e4SLinus Torvalds } 4991da177e4SLinus Torvalds 500c7887325SDavid Howells SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename, 5016559eed8SHeiko Carstens struct stat64 __user *, statbuf, int, flag) 502cff2b760SUlrich Drepper { 503cff2b760SUlrich Drepper struct kstat stat; 5040112fc22SOleg Drokin int error; 505cff2b760SUlrich Drepper 5060112fc22SOleg Drokin error = vfs_fstatat(dfd, filename, &stat, flag); 5070112fc22SOleg Drokin if (error) 508cff2b760SUlrich Drepper return error; 5090112fc22SOleg Drokin return cp_new_stat64(&stat, statbuf); 510cff2b760SUlrich Drepper } 5110753f70fSCatalin Marinas #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_COMPAT_STAT64 */ 5121da177e4SLinus Torvalds 513a528d35eSDavid Howells static inline int __put_timestamp(struct timespec *kts, 514a528d35eSDavid Howells struct statx_timestamp __user *uts) 515a528d35eSDavid Howells { 516a528d35eSDavid Howells return (__put_user(kts->tv_sec, &uts->tv_sec ) || 517a528d35eSDavid Howells __put_user(kts->tv_nsec, &uts->tv_nsec ) || 518a528d35eSDavid Howells __put_user(0, &uts->__reserved )); 519a528d35eSDavid Howells } 520a528d35eSDavid Howells 521a528d35eSDavid Howells /* 522a528d35eSDavid Howells * Set the statx results. 523a528d35eSDavid Howells */ 524a528d35eSDavid Howells static long statx_set_result(struct kstat *stat, struct statx __user *buffer) 525a528d35eSDavid Howells { 526a528d35eSDavid Howells uid_t uid = from_kuid_munged(current_user_ns(), stat->uid); 527a528d35eSDavid Howells gid_t gid = from_kgid_munged(current_user_ns(), stat->gid); 528a528d35eSDavid Howells 529a528d35eSDavid Howells if (__put_user(stat->result_mask, &buffer->stx_mask ) || 530a528d35eSDavid Howells __put_user(stat->mode, &buffer->stx_mode ) || 531a528d35eSDavid Howells __clear_user(&buffer->__spare0, sizeof(buffer->__spare0)) || 532a528d35eSDavid Howells __put_user(stat->nlink, &buffer->stx_nlink ) || 533a528d35eSDavid Howells __put_user(uid, &buffer->stx_uid ) || 534a528d35eSDavid Howells __put_user(gid, &buffer->stx_gid ) || 535a528d35eSDavid Howells __put_user(stat->attributes, &buffer->stx_attributes ) || 536a528d35eSDavid Howells __put_user(stat->blksize, &buffer->stx_blksize ) || 537a528d35eSDavid Howells __put_user(MAJOR(stat->rdev), &buffer->stx_rdev_major ) || 538a528d35eSDavid Howells __put_user(MINOR(stat->rdev), &buffer->stx_rdev_minor ) || 539a528d35eSDavid Howells __put_user(MAJOR(stat->dev), &buffer->stx_dev_major ) || 540a528d35eSDavid Howells __put_user(MINOR(stat->dev), &buffer->stx_dev_minor ) || 541a528d35eSDavid Howells __put_timestamp(&stat->atime, &buffer->stx_atime ) || 542a528d35eSDavid Howells __put_timestamp(&stat->btime, &buffer->stx_btime ) || 543a528d35eSDavid Howells __put_timestamp(&stat->ctime, &buffer->stx_ctime ) || 544a528d35eSDavid Howells __put_timestamp(&stat->mtime, &buffer->stx_mtime ) || 545a528d35eSDavid Howells __put_user(stat->ino, &buffer->stx_ino ) || 546a528d35eSDavid Howells __put_user(stat->size, &buffer->stx_size ) || 547a528d35eSDavid Howells __put_user(stat->blocks, &buffer->stx_blocks ) || 548a528d35eSDavid Howells __clear_user(&buffer->__spare1, sizeof(buffer->__spare1)) || 549a528d35eSDavid Howells __clear_user(&buffer->__spare2, sizeof(buffer->__spare2))) 550a528d35eSDavid Howells return -EFAULT; 551a528d35eSDavid Howells 552a528d35eSDavid Howells return 0; 553a528d35eSDavid Howells } 554a528d35eSDavid Howells 555a528d35eSDavid Howells /** 556a528d35eSDavid Howells * sys_statx - System call to get enhanced stats 557a528d35eSDavid Howells * @dfd: Base directory to pathwalk from *or* fd to stat. 558a528d35eSDavid Howells * @filename: File to stat *or* NULL. 559a528d35eSDavid Howells * @flags: AT_* flags to control pathwalk. 560a528d35eSDavid Howells * @mask: Parts of statx struct actually required. 561a528d35eSDavid Howells * @buffer: Result buffer. 562a528d35eSDavid Howells * 563a528d35eSDavid Howells * Note that if filename is NULL, then it does the equivalent of fstat() using 564a528d35eSDavid Howells * dfd to indicate the file of interest. 565a528d35eSDavid Howells */ 566a528d35eSDavid Howells SYSCALL_DEFINE5(statx, 567a528d35eSDavid Howells int, dfd, const char __user *, filename, unsigned, flags, 568a528d35eSDavid Howells unsigned int, mask, 569a528d35eSDavid Howells struct statx __user *, buffer) 570a528d35eSDavid Howells { 571a528d35eSDavid Howells struct kstat stat; 572a528d35eSDavid Howells int error; 573a528d35eSDavid Howells 574a528d35eSDavid Howells if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE) 575a528d35eSDavid Howells return -EINVAL; 576a528d35eSDavid Howells if (!access_ok(VERIFY_WRITE, buffer, sizeof(*buffer))) 577a528d35eSDavid Howells return -EFAULT; 578a528d35eSDavid Howells 579a528d35eSDavid Howells if (filename) 580a528d35eSDavid Howells error = vfs_statx(dfd, filename, flags, &stat, mask); 581a528d35eSDavid Howells else 582a528d35eSDavid Howells error = vfs_statx_fd(dfd, &stat, mask, flags); 583a528d35eSDavid Howells if (error) 584a528d35eSDavid Howells return error; 585a528d35eSDavid Howells return statx_set_result(&stat, buffer); 586a528d35eSDavid Howells } 587a528d35eSDavid Howells 588*ac565de3SAl Viro #ifdef CONFIG_COMPAT 589*ac565de3SAl Viro static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf) 590*ac565de3SAl Viro { 591*ac565de3SAl Viro struct compat_stat tmp; 592*ac565de3SAl Viro 593*ac565de3SAl Viro if (!old_valid_dev(stat->dev) || !old_valid_dev(stat->rdev)) 594*ac565de3SAl Viro return -EOVERFLOW; 595*ac565de3SAl Viro 596*ac565de3SAl Viro memset(&tmp, 0, sizeof(tmp)); 597*ac565de3SAl Viro tmp.st_dev = old_encode_dev(stat->dev); 598*ac565de3SAl Viro tmp.st_ino = stat->ino; 599*ac565de3SAl Viro if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) 600*ac565de3SAl Viro return -EOVERFLOW; 601*ac565de3SAl Viro tmp.st_mode = stat->mode; 602*ac565de3SAl Viro tmp.st_nlink = stat->nlink; 603*ac565de3SAl Viro if (tmp.st_nlink != stat->nlink) 604*ac565de3SAl Viro return -EOVERFLOW; 605*ac565de3SAl Viro SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid)); 606*ac565de3SAl Viro SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid)); 607*ac565de3SAl Viro tmp.st_rdev = old_encode_dev(stat->rdev); 608*ac565de3SAl Viro if ((u64) stat->size > MAX_NON_LFS) 609*ac565de3SAl Viro return -EOVERFLOW; 610*ac565de3SAl Viro tmp.st_size = stat->size; 611*ac565de3SAl Viro tmp.st_atime = stat->atime.tv_sec; 612*ac565de3SAl Viro tmp.st_atime_nsec = stat->atime.tv_nsec; 613*ac565de3SAl Viro tmp.st_mtime = stat->mtime.tv_sec; 614*ac565de3SAl Viro tmp.st_mtime_nsec = stat->mtime.tv_nsec; 615*ac565de3SAl Viro tmp.st_ctime = stat->ctime.tv_sec; 616*ac565de3SAl Viro tmp.st_ctime_nsec = stat->ctime.tv_nsec; 617*ac565de3SAl Viro tmp.st_blocks = stat->blocks; 618*ac565de3SAl Viro tmp.st_blksize = stat->blksize; 619*ac565de3SAl Viro return copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0; 620*ac565de3SAl Viro } 621*ac565de3SAl Viro 622*ac565de3SAl Viro COMPAT_SYSCALL_DEFINE2(newstat, const char __user *, filename, 623*ac565de3SAl Viro struct compat_stat __user *, statbuf) 624*ac565de3SAl Viro { 625*ac565de3SAl Viro struct kstat stat; 626*ac565de3SAl Viro int error; 627*ac565de3SAl Viro 628*ac565de3SAl Viro error = vfs_stat(filename, &stat); 629*ac565de3SAl Viro if (error) 630*ac565de3SAl Viro return error; 631*ac565de3SAl Viro return cp_compat_stat(&stat, statbuf); 632*ac565de3SAl Viro } 633*ac565de3SAl Viro 634*ac565de3SAl Viro COMPAT_SYSCALL_DEFINE2(newlstat, const char __user *, filename, 635*ac565de3SAl Viro struct compat_stat __user *, statbuf) 636*ac565de3SAl Viro { 637*ac565de3SAl Viro struct kstat stat; 638*ac565de3SAl Viro int error; 639*ac565de3SAl Viro 640*ac565de3SAl Viro error = vfs_lstat(filename, &stat); 641*ac565de3SAl Viro if (error) 642*ac565de3SAl Viro return error; 643*ac565de3SAl Viro return cp_compat_stat(&stat, statbuf); 644*ac565de3SAl Viro } 645*ac565de3SAl Viro 646*ac565de3SAl Viro #ifndef __ARCH_WANT_STAT64 647*ac565de3SAl Viro COMPAT_SYSCALL_DEFINE4(newfstatat, unsigned int, dfd, 648*ac565de3SAl Viro const char __user *, filename, 649*ac565de3SAl Viro struct compat_stat __user *, statbuf, int, flag) 650*ac565de3SAl Viro { 651*ac565de3SAl Viro struct kstat stat; 652*ac565de3SAl Viro int error; 653*ac565de3SAl Viro 654*ac565de3SAl Viro error = vfs_fstatat(dfd, filename, &stat, flag); 655*ac565de3SAl Viro if (error) 656*ac565de3SAl Viro return error; 657*ac565de3SAl Viro return cp_compat_stat(&stat, statbuf); 658*ac565de3SAl Viro } 659*ac565de3SAl Viro #endif 660*ac565de3SAl Viro 661*ac565de3SAl Viro COMPAT_SYSCALL_DEFINE2(newfstat, unsigned int, fd, 662*ac565de3SAl Viro struct compat_stat __user *, statbuf) 663*ac565de3SAl Viro { 664*ac565de3SAl Viro struct kstat stat; 665*ac565de3SAl Viro int error = vfs_fstat(fd, &stat); 666*ac565de3SAl Viro 667*ac565de3SAl Viro if (!error) 668*ac565de3SAl Viro error = cp_compat_stat(&stat, statbuf); 669*ac565de3SAl Viro return error; 670*ac565de3SAl Viro } 671*ac565de3SAl Viro #endif 672*ac565de3SAl Viro 673b462707eSDmitry Monakhov /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */ 674b462707eSDmitry Monakhov void __inode_add_bytes(struct inode *inode, loff_t bytes) 6751da177e4SLinus Torvalds { 6761da177e4SLinus Torvalds inode->i_blocks += bytes >> 9; 6771da177e4SLinus Torvalds bytes &= 511; 6781da177e4SLinus Torvalds inode->i_bytes += bytes; 6791da177e4SLinus Torvalds if (inode->i_bytes >= 512) { 6801da177e4SLinus Torvalds inode->i_blocks++; 6811da177e4SLinus Torvalds inode->i_bytes -= 512; 6821da177e4SLinus Torvalds } 683b462707eSDmitry Monakhov } 684b462707eSDmitry Monakhov 685b462707eSDmitry Monakhov void inode_add_bytes(struct inode *inode, loff_t bytes) 686b462707eSDmitry Monakhov { 687b462707eSDmitry Monakhov spin_lock(&inode->i_lock); 688b462707eSDmitry Monakhov __inode_add_bytes(inode, bytes); 6891da177e4SLinus Torvalds spin_unlock(&inode->i_lock); 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds EXPORT_SYMBOL(inode_add_bytes); 6931da177e4SLinus Torvalds 6941c8924ebSJan Kara void __inode_sub_bytes(struct inode *inode, loff_t bytes) 6951da177e4SLinus Torvalds { 6961da177e4SLinus Torvalds inode->i_blocks -= bytes >> 9; 6971da177e4SLinus Torvalds bytes &= 511; 6981da177e4SLinus Torvalds if (inode->i_bytes < bytes) { 6991da177e4SLinus Torvalds inode->i_blocks--; 7001da177e4SLinus Torvalds inode->i_bytes += 512; 7011da177e4SLinus Torvalds } 7021da177e4SLinus Torvalds inode->i_bytes -= bytes; 7031c8924ebSJan Kara } 7041c8924ebSJan Kara 7051c8924ebSJan Kara EXPORT_SYMBOL(__inode_sub_bytes); 7061c8924ebSJan Kara 7071c8924ebSJan Kara void inode_sub_bytes(struct inode *inode, loff_t bytes) 7081c8924ebSJan Kara { 7091c8924ebSJan Kara spin_lock(&inode->i_lock); 7101c8924ebSJan Kara __inode_sub_bytes(inode, bytes); 7111da177e4SLinus Torvalds spin_unlock(&inode->i_lock); 7121da177e4SLinus Torvalds } 7131da177e4SLinus Torvalds 7141da177e4SLinus Torvalds EXPORT_SYMBOL(inode_sub_bytes); 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds loff_t inode_get_bytes(struct inode *inode) 7171da177e4SLinus Torvalds { 7181da177e4SLinus Torvalds loff_t ret; 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds spin_lock(&inode->i_lock); 7211da177e4SLinus Torvalds ret = (((loff_t)inode->i_blocks) << 9) + inode->i_bytes; 7221da177e4SLinus Torvalds spin_unlock(&inode->i_lock); 7231da177e4SLinus Torvalds return ret; 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds 7261da177e4SLinus Torvalds EXPORT_SYMBOL(inode_get_bytes); 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds void inode_set_bytes(struct inode *inode, loff_t bytes) 7291da177e4SLinus Torvalds { 7301da177e4SLinus Torvalds /* Caller is here responsible for sufficient locking 7311da177e4SLinus Torvalds * (ie. inode->i_lock) */ 7321da177e4SLinus Torvalds inode->i_blocks = bytes >> 9; 7331da177e4SLinus Torvalds inode->i_bytes = bytes & 511; 7341da177e4SLinus Torvalds } 7351da177e4SLinus Torvalds 7361da177e4SLinus Torvalds EXPORT_SYMBOL(inode_set_bytes); 737