diff options
Diffstat (limited to 'fs/open.c')
| -rw-r--r-- | fs/open.c | 43 |
1 files changed, 37 insertions, 6 deletions
| @@ -222,7 +222,7 @@ SYSCALL_DEFINE2(ftruncate64, unsigned int, fd, loff_t, length) | |||
| 222 | #endif /* BITS_PER_LONG == 32 */ | 222 | #endif /* BITS_PER_LONG == 32 */ |
| 223 | 223 | ||
| 224 | 224 | ||
| 225 | int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len) | 225 | int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) |
| 226 | { | 226 | { |
| 227 | struct inode *inode = file_inode(file); | 227 | struct inode *inode = file_inode(file); |
| 228 | long ret; | 228 | long ret; |
| @@ -295,9 +295,21 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len) | |||
| 295 | 295 | ||
| 296 | sb_start_write(inode->i_sb); | 296 | sb_start_write(inode->i_sb); |
| 297 | ret = file->f_op->fallocate(file, mode, offset, len); | 297 | ret = file->f_op->fallocate(file, mode, offset, len); |
| 298 | |||
| 299 | /* | ||
| 300 | * Create inotify and fanotify events. | ||
| 301 | * | ||
| 302 | * To keep the logic simple always create events if fallocate succeeds. | ||
| 303 | * This implies that events are even created if the file size remains | ||
| 304 | * unchanged, e.g. when using flag FALLOC_FL_KEEP_SIZE. | ||
| 305 | */ | ||
| 306 | if (ret == 0) | ||
| 307 | fsnotify_modify(file); | ||
| 308 | |||
| 298 | sb_end_write(inode->i_sb); | 309 | sb_end_write(inode->i_sb); |
| 299 | return ret; | 310 | return ret; |
| 300 | } | 311 | } |
| 312 | EXPORT_SYMBOL_GPL(vfs_fallocate); | ||
| 301 | 313 | ||
| 302 | SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len) | 314 | SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len) |
| 303 | { | 315 | { |
| @@ -305,7 +317,7 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len) | |||
| 305 | int error = -EBADF; | 317 | int error = -EBADF; |
| 306 | 318 | ||
| 307 | if (f.file) { | 319 | if (f.file) { |
| 308 | error = do_fallocate(f.file, mode, offset, len); | 320 | error = vfs_fallocate(f.file, mode, offset, len); |
| 309 | fdput(f); | 321 | fdput(f); |
| 310 | } | 322 | } |
| 311 | return error; | 323 | return error; |
| @@ -516,7 +528,7 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode) | |||
| 516 | int err = -EBADF; | 528 | int err = -EBADF; |
| 517 | 529 | ||
| 518 | if (f.file) { | 530 | if (f.file) { |
| 519 | audit_inode(NULL, f.file->f_path.dentry, 0); | 531 | audit_file(f.file); |
| 520 | err = chmod_common(&f.file->f_path, mode); | 532 | err = chmod_common(&f.file->f_path, mode); |
| 521 | fdput(f); | 533 | fdput(f); |
| 522 | } | 534 | } |
| @@ -642,7 +654,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group) | |||
| 642 | error = mnt_want_write_file(f.file); | 654 | error = mnt_want_write_file(f.file); |
| 643 | if (error) | 655 | if (error) |
| 644 | goto out_fput; | 656 | goto out_fput; |
| 645 | audit_inode(NULL, f.file->f_path.dentry, 0); | 657 | audit_file(f.file); |
| 646 | error = chown_common(&f.file->f_path, user, group); | 658 | error = chown_common(&f.file->f_path, user, group); |
| 647 | mnt_drop_write_file(f.file); | 659 | mnt_drop_write_file(f.file); |
| 648 | out_fput: | 660 | out_fput: |
| @@ -823,8 +835,7 @@ struct file *dentry_open(const struct path *path, int flags, | |||
| 823 | f = get_empty_filp(); | 835 | f = get_empty_filp(); |
| 824 | if (!IS_ERR(f)) { | 836 | if (!IS_ERR(f)) { |
| 825 | f->f_flags = flags; | 837 | f->f_flags = flags; |
| 826 | f->f_path = *path; | 838 | error = vfs_open(path, f, cred); |
| 827 | error = do_dentry_open(f, NULL, cred); | ||
| 828 | if (!error) { | 839 | if (!error) { |
| 829 | /* from now on we need fput() to dispose of f */ | 840 | /* from now on we need fput() to dispose of f */ |
| 830 | error = open_check_o_direct(f); | 841 | error = open_check_o_direct(f); |
| @@ -841,6 +852,26 @@ struct file *dentry_open(const struct path *path, int flags, | |||
| 841 | } | 852 | } |
| 842 | EXPORT_SYMBOL(dentry_open); | 853 | EXPORT_SYMBOL(dentry_open); |
| 843 | 854 | ||
| 855 | /** | ||
| 856 | * vfs_open - open the file at the given path | ||
| 857 | * @path: path to open | ||
| 858 | * @filp: newly allocated file with f_flag initialized | ||
| 859 | * @cred: credentials to use | ||
| 860 | */ | ||
| 861 | int vfs_open(const struct path *path, struct file *filp, | ||
| 862 | const struct cred *cred) | ||
| 863 | { | ||
| 864 | struct inode *inode = path->dentry->d_inode; | ||
| 865 | |||
| 866 | if (inode->i_op->dentry_open) | ||
| 867 | return inode->i_op->dentry_open(path->dentry, filp, cred); | ||
| 868 | else { | ||
| 869 | filp->f_path = *path; | ||
| 870 | return do_dentry_open(filp, NULL, cred); | ||
| 871 | } | ||
| 872 | } | ||
| 873 | EXPORT_SYMBOL(vfs_open); | ||
| 874 | |||
| 844 | static inline int build_open_flags(int flags, umode_t mode, struct open_flags *op) | 875 | static inline int build_open_flags(int flags, umode_t mode, struct open_flags *op) |
| 845 | { | 876 | { |
| 846 | int lookup_flags = 0; | 877 | int lookup_flags = 0; |
