nfsd: remove pointless paths in file headers
[safe/jmp/linux-2.6] / fs / ext3 / ioctl.c
index 4a2a02c..8897481 100644 (file)
 #include <linux/capability.h>
 #include <linux/ext3_fs.h>
 #include <linux/ext3_jbd.h>
+#include <linux/mount.h>
 #include <linux/time.h>
 #include <linux/compat.h>
-#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 
-int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
-               unsigned long arg)
+long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
+       struct inode *inode = filp->f_dentry->d_inode;
        struct ext3_inode_info *ei = EXT3_I(inode);
        unsigned int flags;
        unsigned short rsv_window_size;
@@ -38,19 +38,25 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
                unsigned int oldflags;
                unsigned int jflag;
 
-               if (IS_RDONLY(inode))
-                       return -EROFS;
-
                if (!is_owner_or_cap(inode))
                        return -EACCES;
 
                if (get_user(flags, (int __user *) arg))
                        return -EFAULT;
 
-               if (!S_ISDIR(inode->i_mode))
-                       flags &= ~EXT3_DIRSYNC_FL;
+               err = mnt_want_write(filp->f_path.mnt);
+               if (err)
+                       return err;
+
+               flags = ext3_mask_flags(inode->i_mode, flags);
 
                mutex_lock(&inode->i_mutex);
+
+               /* Is it quota file? Do not allow user to mess with it */
+               err = -EPERM;
+               if (IS_NOQUOTA(inode))
+                       goto flags_out;
+
                oldflags = ei->i_flags;
 
                /* The JOURNAL_DATA flag is modifiable only by root */
@@ -63,10 +69,8 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
                 * This test looks nicer. Thanks to Pauline Middelink
                 */
                if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
-                       if (!capable(CAP_LINUX_IMMUTABLE)) {
-                               mutex_unlock(&inode->i_mutex);
-                               return -EPERM;
-                       }
+                       if (!capable(CAP_LINUX_IMMUTABLE))
+                               goto flags_out;
                }
 
                /*
@@ -74,17 +78,14 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
                 * the relevant capability.
                 */
                if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) {
-                       if (!capable(CAP_SYS_RESOURCE)) {
-                               mutex_unlock(&inode->i_mutex);
-                               return -EPERM;
-                       }
+                       if (!capable(CAP_SYS_RESOURCE))
+                               goto flags_out;
                }
 
-
                handle = ext3_journal_start(inode, 1);
                if (IS_ERR(handle)) {
-                       mutex_unlock(&inode->i_mutex);
-                       return PTR_ERR(handle);
+                       err = PTR_ERR(handle);
+                       goto flags_out;
                }
                if (IS_SYNC(inode))
                        handle->h_sync = 1;
@@ -102,14 +103,14 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
                err = ext3_mark_iloc_dirty(handle, inode, &iloc);
 flags_err:
                ext3_journal_stop(handle);
-               if (err) {
-                       mutex_unlock(&inode->i_mutex);
-                       return err;
-               }
+               if (err)
+                       goto flags_out;
 
                if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL))
                        err = ext3_change_inode_journal_flag(inode, jflag);
+flags_out:
                mutex_unlock(&inode->i_mutex);
+               mnt_drop_write(filp->f_path.mnt);
                return err;
        }
        case EXT3_IOC_GETVERSION:
@@ -124,14 +125,20 @@ flags_err:
 
                if (!is_owner_or_cap(inode))
                        return -EPERM;
-               if (IS_RDONLY(inode))
-                       return -EROFS;
-               if (get_user(generation, (int __user *) arg))
-                       return -EFAULT;
+
+               err = mnt_want_write(filp->f_path.mnt);
+               if (err)
+                       return err;
+               if (get_user(generation, (int __user *) arg)) {
+                       err = -EFAULT;
+                       goto setversion_out;
+               }
 
                handle = ext3_journal_start(inode, 1);
-               if (IS_ERR(handle))
-                       return PTR_ERR(handle);
+               if (IS_ERR(handle)) {
+                       err = PTR_ERR(handle);
+                       goto setversion_out;
+               }
                err = ext3_reserve_inode_write(handle, inode, &iloc);
                if (err == 0) {
                        inode->i_ctime = CURRENT_TIME_SEC;
@@ -139,6 +146,8 @@ flags_err:
                        err = ext3_mark_iloc_dirty(handle, inode, &iloc);
                }
                ext3_journal_stop(handle);
+setversion_out:
+               mnt_drop_write(filp->f_path.mnt);
                return err;
        }
 #ifdef CONFIG_JBD_DEBUG
@@ -174,18 +183,24 @@ flags_err:
                }
                return -ENOTTY;
        case EXT3_IOC_SETRSVSZ: {
+               int err;
 
                if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
                        return -ENOTTY;
 
-               if (IS_RDONLY(inode))
-                       return -EROFS;
+               err = mnt_want_write(filp->f_path.mnt);
+               if (err)
+                       return err;
 
-               if (!is_owner_or_cap(inode))
-                       return -EACCES;
+               if (!is_owner_or_cap(inode)) {
+                       err = -EACCES;
+                       goto setrsvsz_out;
+               }
 
-               if (get_user(rsv_window_size, (int __user *)arg))
-                       return -EFAULT;
+               if (get_user(rsv_window_size, (int __user *)arg)) {
+                       err = -EFAULT;
+                       goto setrsvsz_out;
+               }
 
                if (rsv_window_size > EXT3_MAX_RESERVE_BLOCKS)
                        rsv_window_size = EXT3_MAX_RESERVE_BLOCKS;
@@ -203,49 +218,62 @@ flags_err:
                        rsv->rsv_goal_size = rsv_window_size;
                }
                mutex_unlock(&ei->truncate_mutex);
-               return 0;
+setrsvsz_out:
+               mnt_drop_write(filp->f_path.mnt);
+               return err;
        }
        case EXT3_IOC_GROUP_EXTEND: {
                ext3_fsblk_t n_blocks_count;
                struct super_block *sb = inode->i_sb;
-               int err;
+               int err, err2;
 
                if (!capable(CAP_SYS_RESOURCE))
                        return -EPERM;
 
-               if (IS_RDONLY(inode))
-                       return -EROFS;
-
-               if (get_user(n_blocks_count, (__u32 __user *)arg))
-                       return -EFAULT;
+               err = mnt_want_write(filp->f_path.mnt);
+               if (err)
+                       return err;
 
+               if (get_user(n_blocks_count, (__u32 __user *)arg)) {
+                       err = -EFAULT;
+                       goto group_extend_out;
+               }
                err = ext3_group_extend(sb, EXT3_SB(sb)->s_es, n_blocks_count);
                journal_lock_updates(EXT3_SB(sb)->s_journal);
-               journal_flush(EXT3_SB(sb)->s_journal);
+               err2 = journal_flush(EXT3_SB(sb)->s_journal);
                journal_unlock_updates(EXT3_SB(sb)->s_journal);
-
+               if (err == 0)
+                       err = err2;
+group_extend_out:
+               mnt_drop_write(filp->f_path.mnt);
                return err;
        }
        case EXT3_IOC_GROUP_ADD: {
                struct ext3_new_group_data input;
                struct super_block *sb = inode->i_sb;
-               int err;
+               int err, err2;
 
                if (!capable(CAP_SYS_RESOURCE))
                        return -EPERM;
 
-               if (IS_RDONLY(inode))
-                       return -EROFS;
+               err = mnt_want_write(filp->f_path.mnt);
+               if (err)
+                       return err;
 
                if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
-                               sizeof(input)))
-                       return -EFAULT;
+                               sizeof(input))) {
+                       err = -EFAULT;
+                       goto group_add_out;
+               }
 
                err = ext3_group_add(sb, &input);
                journal_lock_updates(EXT3_SB(sb)->s_journal);
-               journal_flush(EXT3_SB(sb)->s_journal);
+               err2 = journal_flush(EXT3_SB(sb)->s_journal);
                journal_unlock_updates(EXT3_SB(sb)->s_journal);
-
+               if (err == 0)
+                       err = err2;
+group_add_out:
+               mnt_drop_write(filp->f_path.mnt);
                return err;
        }
 
@@ -258,9 +286,6 @@ flags_err:
 #ifdef CONFIG_COMPAT
 long ext3_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 */
        switch (cmd) {
        case EXT3_IOC32_GETFLAGS:
@@ -300,9 +325,6 @@ long ext3_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        default:
                return -ENOIOCTLCMD;
        }
-       lock_kernel();
-       ret = ext3_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
-       unlock_kernel();
-       return ret;
+       return ext3_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
 }
 #endif