7 #include <linux/string.h>
12 #include <linux/module.h>
13 #include <linux/tty.h>
16 #include <linux/capability.h>
17 #include <linux/securebits.h>
20 #include <linux/fcntl.h>
21 #include <linux/slab.h>
22 #include <asm/uaccess.h>
24 #include <linux/personality.h>
28 #include <linux/audit.h>
29 #include <linux/falloc.h>
40 struct iattr newattrs;
64 static long do_sys_truncate(
const char __user *
pathname, loff_t
length)
94 goto mnt_drop_write_and_out;
98 goto mnt_drop_write_and_out;
100 error = get_write_access(inode);
102 goto mnt_drop_write_and_out;
108 error = break_lease(inode,
O_WRONLY);
110 goto put_write_and_out;
112 error = locks_verify_truncate(inode,
NULL, length);
114 error = security_path_truncate(&
path);
119 put_write_access(inode);
120 mnt_drop_write_and_out:
130 return do_sys_truncate(
path, length);
133 static long do_sys_ftruncate(
unsigned int fd, loff_t length,
int small)
152 dentry =
f.file->f_path.dentry;
167 sb_start_write(inode->
i_sb);
168 error = locks_verify_truncate(inode,
f.file, length);
170 error = security_path_truncate(&
f.file->f_path);
173 sb_end_write(inode->
i_sb);
182 long ret = do_sys_ftruncate(fd, length, 1);
189 #if BITS_PER_LONG == 32
192 return do_sys_truncate(path, length);
194 #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
195 asmlinkage long SyS_truncate64(
long path, loff_t length)
197 return SYSC_truncate64((
const char __user *) path, length);
204 long ret = do_sys_ftruncate(fd, length, 0);
209 #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
210 asmlinkage long SyS_ftruncate64(
long fd, loff_t length)
212 return SYSC_ftruncate64((
unsigned int) fd, length);
221 struct inode *inode = file->
f_path.dentry->d_inode;
224 if (offset < 0 || len <= 0)
240 if (mode & FALLOC_FL_PUNCH_HOLE &&
IS_APPEND(inode))
265 if (((offset + len) > inode->
i_sb->s_maxbytes) || ((offset + len) < 0))
268 if (!file->
f_op->fallocate)
271 sb_start_write(inode->
i_sb);
272 ret = file->
f_op->fallocate(file, mode, offset, len);
273 sb_end_write(inode->
i_sb);
279 struct fd f = fdget(fd);
289 #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
290 asmlinkage long SyS_fallocate(
long fd,
long mode, loff_t offset, loff_t len)
292 return SYSC_fallocate((
int)fd, (
int)mode, offset, len);
304 const struct cred *old_cred;
305 struct cred *override_cred;
317 override_cred->
fsuid = override_cred->
uid;
318 override_cred->
fsgid = override_cred->
gid;
323 if (!uid_eq(override_cred->
uid, root_uid))
336 inode = path.
dentry->d_inode;
345 goto out_path_release;
351 goto out_path_release;
369 put_cred(override_cred);
401 struct fd f = fdget_raw(fd);
409 inode = f.
file->f_path.dentry->d_inode;
440 error = security_path_chroot(&path);
452 static int chmod_common(
struct path *path,
umode_t mode)
454 struct inode *inode = path->
dentry->d_inode;
455 struct iattr newattrs;
462 error = security_path_chmod(path, mode);
482 err = chmod_common(&file->
f_path, mode);
495 error = chmod_common(&path, mode);
508 struct inode *inode = path->
dentry->d_inode;
510 struct iattr newattrs;
518 if (user != (
uid_t) -1) {
522 newattrs.ia_uid =
uid;
524 if (group != (
gid_t) -1) {
528 newattrs.ia_gid =
gid;
534 error = security_path_chown(path, uid, gid);
561 error = chown_common(&path, user, group);
582 struct fd f = fdget(fd);
591 audit_inode(
NULL, f.
file->f_path.dentry, 0);
592 error = chown_common(&f.
file->f_path, user, group);
606 static inline int __get_file_write_access(
struct inode *inode,
610 error = get_write_access(inode);
624 put_write_access(inode);
642 static int do_dentry_open(
struct file *
f,
643 int (*
open)(
struct inode *,
struct file *),
657 inode = f->
f_path.dentry->d_inode;
659 error = __get_file_write_access(inode, f->
f_path.mnt);
671 f->
f_op = &empty_fops;
681 error = break_lease(inode, f->
f_flags);
688 error =
open(inode, f);
693 i_readcount_inc(inode);
705 put_write_access(inode);
736 int (*
open)(
struct inode *,
struct file *),
742 file->
f_path.dentry = dentry;
762 file->
f_path.dentry = dentry;
768 const struct cred *cred)
773 validate_creds(cred);
781 return ERR_PTR(error);
785 error = do_dentry_open(f,
NULL, cred);
802 int lookup_flags = 0;
848 if (flags & O_CREAT) {
875 int lookup = build_open_flags(flags, mode, &op);
892 struct filename name = {.
name = filename};
901 int lookup = build_open_flags(flags, 0, &op);
904 if (!filename && (flags & O_DIRECTORY))
905 if (!dentry->
d_inode->i_op->lookup)
914 int lookup = build_open_flags(flags, mode, &op);
916 int fd = PTR_ERR(tmp);
988 if (filp->
f_op && filp->
f_op->flush)
989 retval = filp->
f_op->flush(filp,
id);