1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 1991, 1992 Linus Torvalds
8 #include <linux/blkdev.h>
9 #include <linux/export.h>
11 #include <linux/errno.h>
12 #include <linux/file.h>
13 #include <linux/highuid.h>
15 #include <linux/namei.h>
16 #include <linux/security.h>
17 #include <linux/cred.h>
18 #include <linux/syscalls.h>
19 #include <linux/pagemap.h>
20 #include <linux/compat.h>
22 #include <linux/uaccess.h>
23 #include <asm/unistd.h>
29 * generic_fillattr - Fill in the basic attributes from the inode struct
30 * @mnt_userns: user namespace of the mount the inode was found from
31 * @inode: Inode to use as the source
32 * @stat: Where to fill in the attributes
34 * Fill in the basic attributes in the kstat structure from data that's to be
35 * found on the VFS inode structure. This is the default if no getattr inode
36 * operation is supplied.
38 * If the inode has been found through an idmapped mount the user namespace of
39 * the vfsmount must be passed through @mnt_userns. This function will then
40 * take care to map the inode according to @mnt_userns before filling in the
41 * uid and gid filds. On non-idmapped mounts or if permission checking is to be
42 * performed on the raw inode simply passs init_user_ns.
44 void generic_fillattr(struct user_namespace *mnt_userns, struct inode *inode,
47 stat->dev = inode->i_sb->s_dev;
48 stat->ino = inode->i_ino;
49 stat->mode = inode->i_mode;
50 stat->nlink = inode->i_nlink;
51 stat->uid = i_uid_into_mnt(mnt_userns, inode);
52 stat->gid = i_gid_into_mnt(mnt_userns, inode);
53 stat->rdev = inode->i_rdev;
54 stat->size = i_size_read(inode);
55 stat->atime = inode->i_atime;
56 stat->mtime = inode->i_mtime;
57 stat->ctime = inode->i_ctime;
58 stat->blksize = i_blocksize(inode);
59 stat->blocks = inode->i_blocks;
61 EXPORT_SYMBOL(generic_fillattr);
64 * generic_fill_statx_attr - Fill in the statx attributes from the inode flags
65 * @inode: Inode to use as the source
66 * @stat: Where to fill in the attribute flags
68 * Fill in the STATX_ATTR_* flags in the kstat structure for properties of the
69 * inode that are published on i_flags and enforced by the VFS.
71 void generic_fill_statx_attr(struct inode *inode, struct kstat *stat)
73 if (inode->i_flags & S_IMMUTABLE)
74 stat->attributes |= STATX_ATTR_IMMUTABLE;
75 if (inode->i_flags & S_APPEND)
76 stat->attributes |= STATX_ATTR_APPEND;
77 stat->attributes_mask |= KSTAT_ATTR_VFS_FLAGS;
79 EXPORT_SYMBOL(generic_fill_statx_attr);
82 * vfs_getattr_nosec - getattr without security checks
83 * @path: file to get attributes from
84 * @stat: structure to return attributes in
85 * @request_mask: STATX_xxx flags indicating what the caller wants
86 * @query_flags: Query mode (AT_STATX_SYNC_TYPE)
88 * Get attributes without calling security_inode_getattr.
90 * Currently the only caller other than vfs_getattr is internal to the
91 * filehandle lookup code, which uses only the inode number and returns no
92 * attributes to any user. Any other code probably wants vfs_getattr.
94 int vfs_getattr_nosec(const struct path *path, struct kstat *stat,
95 u32 request_mask, unsigned int query_flags)
97 struct user_namespace *mnt_userns;
98 struct inode *inode = d_backing_inode(path->dentry);
100 memset(stat, 0, sizeof(*stat));
101 stat->result_mask |= STATX_BASIC_STATS;
102 query_flags &= AT_STATX_SYNC_TYPE;
104 /* allow the fs to override these if it really wants to */
105 /* SB_NOATIME means filesystem supplies dummy atime value */
106 if (inode->i_sb->s_flags & SB_NOATIME)
107 stat->result_mask &= ~STATX_ATIME;
110 * Note: If you add another clause to set an attribute flag, please
111 * update attributes_mask below.
113 if (IS_AUTOMOUNT(inode))
114 stat->attributes |= STATX_ATTR_AUTOMOUNT;
117 stat->attributes |= STATX_ATTR_DAX;
119 stat->attributes_mask |= (STATX_ATTR_AUTOMOUNT |
122 mnt_userns = mnt_user_ns(path->mnt);
123 if (inode->i_op->getattr)
124 return inode->i_op->getattr(mnt_userns, path, stat,
125 request_mask, query_flags);
127 generic_fillattr(mnt_userns, inode, stat);
130 EXPORT_SYMBOL(vfs_getattr_nosec);
133 * vfs_getattr - Get the enhanced basic attributes of a file
134 * @path: The file of interest
135 * @stat: Where to return the statistics
136 * @request_mask: STATX_xxx flags indicating what the caller wants
137 * @query_flags: Query mode (AT_STATX_SYNC_TYPE)
139 * Ask the filesystem for a file's attributes. The caller must indicate in
140 * request_mask and query_flags to indicate what they want.
142 * If the file is remote, the filesystem can be forced to update the attributes
143 * from the backing store by passing AT_STATX_FORCE_SYNC in query_flags or can
144 * suppress the update by passing AT_STATX_DONT_SYNC.
146 * Bits must have been set in request_mask to indicate which attributes the
147 * caller wants retrieving. Any such attribute not requested may be returned
148 * anyway, but the value may be approximate, and, if remote, may not have been
149 * synchronised with the server.
151 * 0 will be returned on success, and a -ve error code if unsuccessful.
153 int vfs_getattr(const struct path *path, struct kstat *stat,
154 u32 request_mask, unsigned int query_flags)
158 retval = security_inode_getattr(path);
161 return vfs_getattr_nosec(path, stat, request_mask, query_flags);
163 EXPORT_SYMBOL(vfs_getattr);
166 * vfs_fstat - Get the basic attributes by file descriptor
167 * @fd: The file descriptor referring to the file of interest
168 * @stat: The result structure to fill in.
170 * This function is a wrapper around vfs_getattr(). The main difference is
171 * that it uses a file descriptor to determine the file location.
173 * 0 will be returned on success, and a -ve error code if unsuccessful.
175 int vfs_fstat(int fd, struct kstat *stat)
183 error = vfs_getattr(&f.file->f_path, stat, STATX_BASIC_STATS, 0);
188 int getname_statx_lookup_flags(int flags)
190 int lookup_flags = 0;
192 if (!(flags & AT_SYMLINK_NOFOLLOW))
193 lookup_flags |= LOOKUP_FOLLOW;
194 if (!(flags & AT_NO_AUTOMOUNT))
195 lookup_flags |= LOOKUP_AUTOMOUNT;
196 if (flags & AT_EMPTY_PATH)
197 lookup_flags |= LOOKUP_EMPTY;
203 * vfs_statx - Get basic and extra attributes by filename
204 * @dfd: A file descriptor representing the base dir for a relative filename
205 * @filename: The name of the file of interest
206 * @flags: Flags to control the query
207 * @stat: The result structure to fill in.
208 * @request_mask: STATX_xxx flags indicating what the caller wants
210 * This function is a wrapper around vfs_getattr(). The main difference is
211 * that it uses a filename and base directory to determine the file location.
212 * Additionally, the use of AT_SYMLINK_NOFOLLOW in flags will prevent a symlink
213 * at the given name from being referenced.
215 * 0 will be returned on success, and a -ve error code if unsuccessful.
217 static int vfs_statx(int dfd, struct filename *filename, int flags,
218 struct kstat *stat, u32 request_mask)
221 unsigned int lookup_flags = getname_statx_lookup_flags(flags);
224 if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_EMPTY_PATH |
229 error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
233 error = vfs_getattr(&path, stat, request_mask, flags);
235 stat->mnt_id = real_mount(path.mnt)->mnt_id;
236 stat->result_mask |= STATX_MNT_ID;
238 if (path.mnt->mnt_root == path.dentry)
239 stat->attributes |= STATX_ATTR_MOUNT_ROOT;
240 stat->attributes_mask |= STATX_ATTR_MOUNT_ROOT;
242 /* Handle STATX_DIOALIGN for block devices. */
243 if (request_mask & STATX_DIOALIGN) {
244 struct inode *inode = d_backing_inode(path.dentry);
246 if (S_ISBLK(inode->i_mode))
247 bdev_statx_dioalign(inode, stat);
251 if (retry_estale(error, lookup_flags)) {
252 lookup_flags |= LOOKUP_REVAL;
259 int vfs_fstatat(int dfd, const char __user *filename,
260 struct kstat *stat, int flags)
263 int statx_flags = flags | AT_NO_AUTOMOUNT;
264 struct filename *name;
266 name = getname_flags(filename, getname_statx_lookup_flags(statx_flags), NULL);
267 ret = vfs_statx(dfd, name, statx_flags, stat, STATX_BASIC_STATS);
273 #ifdef __ARCH_WANT_OLD_STAT
276 * For backward compatibility? Maybe this should be moved
277 * into arch/i386 instead?
279 static int cp_old_stat(struct kstat *stat, struct __old_kernel_stat __user * statbuf)
281 static int warncount = 5;
282 struct __old_kernel_stat tmp;
286 printk(KERN_WARNING "VFS: Warning: %s using old stat() call. Recompile your binary.\n",
288 } else if (warncount < 0) {
289 /* it's laughable, but... */
293 memset(&tmp, 0, sizeof(struct __old_kernel_stat));
294 tmp.st_dev = old_encode_dev(stat->dev);
295 tmp.st_ino = stat->ino;
296 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
298 tmp.st_mode = stat->mode;
299 tmp.st_nlink = stat->nlink;
300 if (tmp.st_nlink != stat->nlink)
302 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
303 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
304 tmp.st_rdev = old_encode_dev(stat->rdev);
305 #if BITS_PER_LONG == 32
306 if (stat->size > MAX_NON_LFS)
309 tmp.st_size = stat->size;
310 tmp.st_atime = stat->atime.tv_sec;
311 tmp.st_mtime = stat->mtime.tv_sec;
312 tmp.st_ctime = stat->ctime.tv_sec;
313 return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
316 SYSCALL_DEFINE2(stat, const char __user *, filename,
317 struct __old_kernel_stat __user *, statbuf)
322 error = vfs_stat(filename, &stat);
326 return cp_old_stat(&stat, statbuf);
329 SYSCALL_DEFINE2(lstat, const char __user *, filename,
330 struct __old_kernel_stat __user *, statbuf)
335 error = vfs_lstat(filename, &stat);
339 return cp_old_stat(&stat, statbuf);
342 SYSCALL_DEFINE2(fstat, unsigned int, fd, struct __old_kernel_stat __user *, statbuf)
345 int error = vfs_fstat(fd, &stat);
348 error = cp_old_stat(&stat, statbuf);
353 #endif /* __ARCH_WANT_OLD_STAT */
355 #ifdef __ARCH_WANT_NEW_STAT
357 #if BITS_PER_LONG == 32
358 # define choose_32_64(a,b) a
360 # define choose_32_64(a,b) b
363 #ifndef INIT_STRUCT_STAT_PADDING
364 # define INIT_STRUCT_STAT_PADDING(st) memset(&st, 0, sizeof(st))
367 static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf)
371 if (sizeof(tmp.st_dev) < 4 && !old_valid_dev(stat->dev))
373 if (sizeof(tmp.st_rdev) < 4 && !old_valid_dev(stat->rdev))
375 #if BITS_PER_LONG == 32
376 if (stat->size > MAX_NON_LFS)
380 INIT_STRUCT_STAT_PADDING(tmp);
381 tmp.st_dev = new_encode_dev(stat->dev);
382 tmp.st_ino = stat->ino;
383 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
385 tmp.st_mode = stat->mode;
386 tmp.st_nlink = stat->nlink;
387 if (tmp.st_nlink != stat->nlink)
389 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
390 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
391 tmp.st_rdev = new_encode_dev(stat->rdev);
392 tmp.st_size = stat->size;
393 tmp.st_atime = stat->atime.tv_sec;
394 tmp.st_mtime = stat->mtime.tv_sec;
395 tmp.st_ctime = stat->ctime.tv_sec;
396 #ifdef STAT_HAVE_NSEC
397 tmp.st_atime_nsec = stat->atime.tv_nsec;
398 tmp.st_mtime_nsec = stat->mtime.tv_nsec;
399 tmp.st_ctime_nsec = stat->ctime.tv_nsec;
401 tmp.st_blocks = stat->blocks;
402 tmp.st_blksize = stat->blksize;
403 return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
406 SYSCALL_DEFINE2(newstat, const char __user *, filename,
407 struct stat __user *, statbuf)
410 int error = vfs_stat(filename, &stat);
414 return cp_new_stat(&stat, statbuf);
417 SYSCALL_DEFINE2(newlstat, const char __user *, filename,
418 struct stat __user *, statbuf)
423 error = vfs_lstat(filename, &stat);
427 return cp_new_stat(&stat, statbuf);
430 #if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT)
431 SYSCALL_DEFINE4(newfstatat, int, dfd, const char __user *, filename,
432 struct stat __user *, statbuf, int, flag)
437 error = vfs_fstatat(dfd, filename, &stat, flag);
440 return cp_new_stat(&stat, statbuf);
444 SYSCALL_DEFINE2(newfstat, unsigned int, fd, struct stat __user *, statbuf)
447 int error = vfs_fstat(fd, &stat);
450 error = cp_new_stat(&stat, statbuf);
456 static int do_readlinkat(int dfd, const char __user *pathname,
457 char __user *buf, int bufsiz)
462 unsigned int lookup_flags = LOOKUP_EMPTY;
468 error = user_path_at_empty(dfd, pathname, lookup_flags, &path, &empty);
470 struct inode *inode = d_backing_inode(path.dentry);
472 error = empty ? -ENOENT : -EINVAL;
474 * AFS mountpoints allow readlink(2) but are not symlinks
476 if (d_is_symlink(path.dentry) || inode->i_op->readlink) {
477 error = security_inode_readlink(path.dentry);
480 error = vfs_readlink(path.dentry, buf, bufsiz);
484 if (retry_estale(error, lookup_flags)) {
485 lookup_flags |= LOOKUP_REVAL;
492 SYSCALL_DEFINE4(readlinkat, int, dfd, const char __user *, pathname,
493 char __user *, buf, int, bufsiz)
495 return do_readlinkat(dfd, pathname, buf, bufsiz);
498 SYSCALL_DEFINE3(readlink, const char __user *, path, char __user *, buf,
501 return do_readlinkat(AT_FDCWD, path, buf, bufsiz);
505 /* ---------- LFS-64 ----------- */
506 #if defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_COMPAT_STAT64)
508 #ifndef INIT_STRUCT_STAT64_PADDING
509 # define INIT_STRUCT_STAT64_PADDING(st) memset(&st, 0, sizeof(st))
512 static long cp_new_stat64(struct kstat *stat, struct stat64 __user *statbuf)
516 INIT_STRUCT_STAT64_PADDING(tmp);
518 /* mips has weird padding, so we don't get 64 bits there */
519 tmp.st_dev = new_encode_dev(stat->dev);
520 tmp.st_rdev = new_encode_dev(stat->rdev);
522 tmp.st_dev = huge_encode_dev(stat->dev);
523 tmp.st_rdev = huge_encode_dev(stat->rdev);
525 tmp.st_ino = stat->ino;
526 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
528 #ifdef STAT64_HAS_BROKEN_ST_INO
529 tmp.__st_ino = stat->ino;
531 tmp.st_mode = stat->mode;
532 tmp.st_nlink = stat->nlink;
533 tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
534 tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
535 tmp.st_atime = stat->atime.tv_sec;
536 tmp.st_atime_nsec = stat->atime.tv_nsec;
537 tmp.st_mtime = stat->mtime.tv_sec;
538 tmp.st_mtime_nsec = stat->mtime.tv_nsec;
539 tmp.st_ctime = stat->ctime.tv_sec;
540 tmp.st_ctime_nsec = stat->ctime.tv_nsec;
541 tmp.st_size = stat->size;
542 tmp.st_blocks = stat->blocks;
543 tmp.st_blksize = stat->blksize;
544 return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
547 SYSCALL_DEFINE2(stat64, const char __user *, filename,
548 struct stat64 __user *, statbuf)
551 int error = vfs_stat(filename, &stat);
554 error = cp_new_stat64(&stat, statbuf);
559 SYSCALL_DEFINE2(lstat64, const char __user *, filename,
560 struct stat64 __user *, statbuf)
563 int error = vfs_lstat(filename, &stat);
566 error = cp_new_stat64(&stat, statbuf);
571 SYSCALL_DEFINE2(fstat64, unsigned long, fd, struct stat64 __user *, statbuf)
574 int error = vfs_fstat(fd, &stat);
577 error = cp_new_stat64(&stat, statbuf);
582 SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename,
583 struct stat64 __user *, statbuf, int, flag)
588 error = vfs_fstatat(dfd, filename, &stat, flag);
591 return cp_new_stat64(&stat, statbuf);
593 #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_COMPAT_STAT64 */
595 static noinline_for_stack int
596 cp_statx(const struct kstat *stat, struct statx __user *buffer)
600 memset(&tmp, 0, sizeof(tmp));
602 tmp.stx_mask = stat->result_mask;
603 tmp.stx_blksize = stat->blksize;
604 tmp.stx_attributes = stat->attributes;
605 tmp.stx_nlink = stat->nlink;
606 tmp.stx_uid = from_kuid_munged(current_user_ns(), stat->uid);
607 tmp.stx_gid = from_kgid_munged(current_user_ns(), stat->gid);
608 tmp.stx_mode = stat->mode;
609 tmp.stx_ino = stat->ino;
610 tmp.stx_size = stat->size;
611 tmp.stx_blocks = stat->blocks;
612 tmp.stx_attributes_mask = stat->attributes_mask;
613 tmp.stx_atime.tv_sec = stat->atime.tv_sec;
614 tmp.stx_atime.tv_nsec = stat->atime.tv_nsec;
615 tmp.stx_btime.tv_sec = stat->btime.tv_sec;
616 tmp.stx_btime.tv_nsec = stat->btime.tv_nsec;
617 tmp.stx_ctime.tv_sec = stat->ctime.tv_sec;
618 tmp.stx_ctime.tv_nsec = stat->ctime.tv_nsec;
619 tmp.stx_mtime.tv_sec = stat->mtime.tv_sec;
620 tmp.stx_mtime.tv_nsec = stat->mtime.tv_nsec;
621 tmp.stx_rdev_major = MAJOR(stat->rdev);
622 tmp.stx_rdev_minor = MINOR(stat->rdev);
623 tmp.stx_dev_major = MAJOR(stat->dev);
624 tmp.stx_dev_minor = MINOR(stat->dev);
625 tmp.stx_mnt_id = stat->mnt_id;
626 tmp.stx_dio_mem_align = stat->dio_mem_align;
627 tmp.stx_dio_offset_align = stat->dio_offset_align;
629 return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0;
632 int do_statx(int dfd, struct filename *filename, unsigned int flags,
633 unsigned int mask, struct statx __user *buffer)
638 if (mask & STATX__RESERVED)
640 if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE)
643 error = vfs_statx(dfd, filename, flags, &stat, mask);
647 return cp_statx(&stat, buffer);
651 * sys_statx - System call to get enhanced stats
652 * @dfd: Base directory to pathwalk from *or* fd to stat.
653 * @filename: File to stat or "" with AT_EMPTY_PATH
654 * @flags: AT_* flags to control pathwalk.
655 * @mask: Parts of statx struct actually required.
656 * @buffer: Result buffer.
658 * Note that fstat() can be emulated by setting dfd to the fd of interest,
659 * supplying "" as the filename and setting AT_EMPTY_PATH in the flags.
661 SYSCALL_DEFINE5(statx,
662 int, dfd, const char __user *, filename, unsigned, flags,
664 struct statx __user *, buffer)
667 struct filename *name;
669 name = getname_flags(filename, getname_statx_lookup_flags(flags), NULL);
670 ret = do_statx(dfd, name, flags, mask, buffer);
676 #if defined(CONFIG_COMPAT) && defined(__ARCH_WANT_COMPAT_STAT)
677 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
679 struct compat_stat tmp;
681 if (sizeof(tmp.st_dev) < 4 && !old_valid_dev(stat->dev))
683 if (sizeof(tmp.st_rdev) < 4 && !old_valid_dev(stat->rdev))
686 memset(&tmp, 0, sizeof(tmp));
687 tmp.st_dev = new_encode_dev(stat->dev);
688 tmp.st_ino = stat->ino;
689 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
691 tmp.st_mode = stat->mode;
692 tmp.st_nlink = stat->nlink;
693 if (tmp.st_nlink != stat->nlink)
695 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
696 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
697 tmp.st_rdev = new_encode_dev(stat->rdev);
698 if ((u64) stat->size > MAX_NON_LFS)
700 tmp.st_size = stat->size;
701 tmp.st_atime = stat->atime.tv_sec;
702 tmp.st_atime_nsec = stat->atime.tv_nsec;
703 tmp.st_mtime = stat->mtime.tv_sec;
704 tmp.st_mtime_nsec = stat->mtime.tv_nsec;
705 tmp.st_ctime = stat->ctime.tv_sec;
706 tmp.st_ctime_nsec = stat->ctime.tv_nsec;
707 tmp.st_blocks = stat->blocks;
708 tmp.st_blksize = stat->blksize;
709 return copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0;
712 COMPAT_SYSCALL_DEFINE2(newstat, const char __user *, filename,
713 struct compat_stat __user *, statbuf)
718 error = vfs_stat(filename, &stat);
721 return cp_compat_stat(&stat, statbuf);
724 COMPAT_SYSCALL_DEFINE2(newlstat, const char __user *, filename,
725 struct compat_stat __user *, statbuf)
730 error = vfs_lstat(filename, &stat);
733 return cp_compat_stat(&stat, statbuf);
736 #ifndef __ARCH_WANT_STAT64
737 COMPAT_SYSCALL_DEFINE4(newfstatat, unsigned int, dfd,
738 const char __user *, filename,
739 struct compat_stat __user *, statbuf, int, flag)
744 error = vfs_fstatat(dfd, filename, &stat, flag);
747 return cp_compat_stat(&stat, statbuf);
751 COMPAT_SYSCALL_DEFINE2(newfstat, unsigned int, fd,
752 struct compat_stat __user *, statbuf)
755 int error = vfs_fstat(fd, &stat);
758 error = cp_compat_stat(&stat, statbuf);
763 /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */
764 void __inode_add_bytes(struct inode *inode, loff_t bytes)
766 inode->i_blocks += bytes >> 9;
768 inode->i_bytes += bytes;
769 if (inode->i_bytes >= 512) {
771 inode->i_bytes -= 512;
774 EXPORT_SYMBOL(__inode_add_bytes);
776 void inode_add_bytes(struct inode *inode, loff_t bytes)
778 spin_lock(&inode->i_lock);
779 __inode_add_bytes(inode, bytes);
780 spin_unlock(&inode->i_lock);
783 EXPORT_SYMBOL(inode_add_bytes);
785 void __inode_sub_bytes(struct inode *inode, loff_t bytes)
787 inode->i_blocks -= bytes >> 9;
789 if (inode->i_bytes < bytes) {
791 inode->i_bytes += 512;
793 inode->i_bytes -= bytes;
796 EXPORT_SYMBOL(__inode_sub_bytes);
798 void inode_sub_bytes(struct inode *inode, loff_t bytes)
800 spin_lock(&inode->i_lock);
801 __inode_sub_bytes(inode, bytes);
802 spin_unlock(&inode->i_lock);
805 EXPORT_SYMBOL(inode_sub_bytes);
807 loff_t inode_get_bytes(struct inode *inode)
811 spin_lock(&inode->i_lock);
812 ret = __inode_get_bytes(inode);
813 spin_unlock(&inode->i_lock);
817 EXPORT_SYMBOL(inode_get_bytes);
819 void inode_set_bytes(struct inode *inode, loff_t bytes)
821 /* Caller is here responsible for sufficient locking
822 * (ie. inode->i_lock) */
823 inode->i_blocks = bytes >> 9;
824 inode->i_bytes = bytes & 511;
827 EXPORT_SYMBOL(inode_set_bytes);