diff options
Diffstat (limited to 'fs/reiserfs/ioctl.c')
| -rw-r--r-- | fs/reiserfs/ioctl.c | 129 |
1 files changed, 70 insertions, 59 deletions
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c index 830332021ed..501ed6811a2 100644 --- a/fs/reiserfs/ioctl.c +++ b/fs/reiserfs/ioctl.c @@ -5,54 +5,62 @@ #include <linux/capability.h> #include <linux/fs.h> #include <linux/mount.h> -#include <linux/reiserfs_fs.h> +#include "reiserfs.h" #include <linux/time.h> #include <asm/uaccess.h> #include <linux/pagemap.h> -#include <linux/smp_lock.h> #include <linux/compat.h> /* -** reiserfs_ioctl - handler for ioctl for inode -** supported commands: -** 1) REISERFS_IOC_UNPACK - try to unpack tail from direct item into indirect -** and prevent packing file (argument arg has to be non-zero) -** 2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION -** 3) That's all for a while ... -*/ -int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, - unsigned long arg) + * reiserfs_ioctl - handler for ioctl for inode + * supported commands: + * 1) REISERFS_IOC_UNPACK - try to unpack tail from direct item into indirect + * and prevent packing file (argument arg has t + * be non-zero) + * 2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION + * 3) That's all for a while ... + */ +long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { + struct inode *inode = file_inode(filp); unsigned int flags; int err = 0; + reiserfs_write_lock(inode->i_sb); + switch (cmd) { case REISERFS_IOC_UNPACK: if (S_ISREG(inode->i_mode)) { if (arg) - return reiserfs_unpack(inode, filp); - else - return 0; + err = reiserfs_unpack(inode, filp); } else - return -ENOTTY; - /* following two cases are taken from fs/ext2/ioctl.c by Remy - Card (card@masi.ibp.fr) */ + err = -ENOTTY; + break; + /* + * following two cases are taken from fs/ext2/ioctl.c by Remy + * Card (card@masi.ibp.fr) + */ case REISERFS_IOC_GETFLAGS: - if (!reiserfs_attrs(inode->i_sb)) - return -ENOTTY; + if (!reiserfs_attrs(inode->i_sb)) { + err = -ENOTTY; + break; + } flags = REISERFS_I(inode)->i_attrs; i_attrs_to_sd_attrs(inode, (__u16 *) & flags); - return put_user(flags, (int __user *)arg); + err = put_user(flags, (int __user *)arg); + break; case REISERFS_IOC_SETFLAGS:{ - if (!reiserfs_attrs(inode->i_sb)) - return -ENOTTY; + if (!reiserfs_attrs(inode->i_sb)) { + err = -ENOTTY; + break; + } - err = mnt_want_write(filp->f_path.mnt); + err = mnt_want_write_file(filp); if (err) - return err; + break; - if (!is_owner_or_cap(inode)) { + if (!inode_owner_or_capable(inode)) { err = -EPERM; goto setflags_out; } @@ -89,17 +97,20 @@ int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, inode->i_ctime = CURRENT_TIME_SEC; mark_inode_dirty(inode); setflags_out: - mnt_drop_write(filp->f_path.mnt); - return err; + mnt_drop_write_file(filp); + break; } case REISERFS_IOC_GETVERSION: - return put_user(inode->i_generation, (int __user *)arg); + err = put_user(inode->i_generation, (int __user *)arg); + break; case REISERFS_IOC_SETVERSION: - if (!is_owner_or_cap(inode)) - return -EPERM; - err = mnt_want_write(filp->f_path.mnt); + if (!inode_owner_or_capable(inode)) { + err = -EPERM; + break; + } + err = mnt_want_write_file(filp); if (err) - return err; + break; if (get_user(inode->i_generation, (int __user *)arg)) { err = -EFAULT; goto setversion_out; @@ -107,21 +118,25 @@ setflags_out: inode->i_ctime = CURRENT_TIME_SEC; mark_inode_dirty(inode); setversion_out: - mnt_drop_write(filp->f_path.mnt); - return err; + mnt_drop_write_file(filp); + break; default: - return -ENOTTY; + err = -ENOTTY; } + + reiserfs_write_unlock(inode->i_sb); + + return err; } #ifdef CONFIG_COMPAT long reiserfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct inode *inode = file->f_path.dentry->d_inode; - int ret; - - /* These are just misnamed, they actually get/put from/to user an int */ + /* + * These are just misnamed, they actually + * get/put from/to user an int + */ switch (cmd) { case REISERFS_IOC32_UNPACK: cmd = REISERFS_IOC_UNPACK; @@ -141,22 +156,18 @@ long reiserfs_compat_ioctl(struct file *file, unsigned int cmd, default: return -ENOIOCTLCMD; } - lock_kernel(); - ret = reiserfs_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg)); - unlock_kernel(); - return ret; + + return reiserfs_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); } #endif int reiserfs_commit_write(struct file *f, struct page *page, unsigned from, unsigned to); -int reiserfs_prepare_write(struct file *f, struct page *page, - unsigned from, unsigned to); /* -** reiserfs_unpack -** Function try to convert tail from direct item into indirect. -** It set up nopack attribute in the REISERFS_I(inode)->nopack -*/ + * reiserfs_unpack + * Function try to convert tail from direct item into indirect. + * It set up nopack attribute in the REISERFS_I(inode)->nopack + */ int reiserfs_unpack(struct inode *inode, struct file *filp) { int retval = 0; @@ -175,10 +186,9 @@ int reiserfs_unpack(struct inode *inode, struct file *filp) return 0; } - /* we need to make sure nobody is changing the file size beneath - ** us - */ - mutex_lock(&inode->i_mutex); + /* we need to make sure nobody is changing the file size beneath us */ + reiserfs_mutex_lock_safe(&inode->i_mutex, inode->i_sb); + reiserfs_write_lock(inode->i_sb); write_from = inode->i_size & (blocksize - 1); @@ -188,9 +198,10 @@ int reiserfs_unpack(struct inode *inode, struct file *filp) goto out; } - /* we unpack by finding the page with the tail, and calling - ** reiserfs_prepare_write on that page. This will force a - ** reiserfs_get_block to unpack the tail for us. + /* + * we unpack by finding the page with the tail, and calling + * __reiserfs_write_begin on that page. This will force a + * reiserfs_get_block to unpack the tail for us. */ index = inode->i_size >> PAGE_CACHE_SHIFT; mapping = inode->i_mapping; @@ -199,7 +210,7 @@ int reiserfs_unpack(struct inode *inode, struct file *filp) if (!page) { goto out; } - retval = reiserfs_prepare_write(NULL, page, write_from, write_from); + retval = __reiserfs_write_begin(page, write_from, 0); if (retval) goto out_unlock; @@ -208,11 +219,11 @@ int reiserfs_unpack(struct inode *inode, struct file *filp) retval = reiserfs_commit_write(NULL, page, write_from, write_from); REISERFS_I(inode)->i_flags |= i_nopack_mask; - out_unlock: +out_unlock: unlock_page(page); page_cache_release(page); - out: +out: mutex_unlock(&inode->i_mutex); reiserfs_write_unlock(inode->i_sb); return retval; |
