Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1 | /* |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2 | * linux/fs/ext4/ioctl.c |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1993, 1994, 1995 |
| 5 | * Remy Card (card@masi.ibp.fr) |
| 6 | * Laboratoire MASI - Institut Blaise Pascal |
| 7 | * Universite Pierre et Marie Curie (Paris VI) |
| 8 | */ |
| 9 | |
| 10 | #include <linux/fs.h> |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 11 | #include <linux/jbd2.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 12 | #include <linux/capability.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 13 | #include <linux/time.h> |
| 14 | #include <linux/compat.h> |
| 15 | #include <linux/smp_lock.h> |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 16 | #include <linux/mount.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 17 | #include <asm/uaccess.h> |
Christoph Hellwig | 3dcf545 | 2008-04-29 18:13:32 -0400 | [diff] [blame] | 18 | #include "ext4_jbd2.h" |
| 19 | #include "ext4.h" |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 20 | |
Andi Kleen | 5cdd7b2 | 2008-04-29 22:03:54 -0400 | [diff] [blame] | 21 | long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 22 | { |
Andi Kleen | 5cdd7b2 | 2008-04-29 22:03:54 -0400 | [diff] [blame] | 23 | struct inode *inode = filp->f_dentry->d_inode; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 24 | struct ext4_inode_info *ei = EXT4_I(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 25 | unsigned int flags; |
| 26 | unsigned short rsv_window_size; |
| 27 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 28 | ext4_debug ("cmd = %u, arg = %lu\n", cmd, arg); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 29 | |
| 30 | switch (cmd) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 31 | case EXT4_IOC_GETFLAGS: |
Jan Kara | ff9ddf7 | 2007-07-18 09:24:20 -0400 | [diff] [blame] | 32 | ext4_get_inode_flags(ei); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 33 | flags = ei->i_flags & EXT4_FL_USER_VISIBLE; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 34 | return put_user(flags, (int __user *) arg); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 35 | case EXT4_IOC_SETFLAGS: { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 36 | handle_t *handle = NULL; |
| 37 | int err; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 38 | struct ext4_iloc iloc; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 39 | unsigned int oldflags; |
| 40 | unsigned int jflag; |
| 41 | |
Satyam Sharma | 3bd858a | 2007-07-17 15:00:08 +0530 | [diff] [blame] | 42 | if (!is_owner_or_cap(inode)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 43 | return -EACCES; |
| 44 | |
| 45 | if (get_user(flags, (int __user *) arg)) |
| 46 | return -EFAULT; |
| 47 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 48 | err = mnt_want_write(filp->f_path.mnt); |
| 49 | if (err) |
| 50 | return err; |
| 51 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 52 | if (!S_ISDIR(inode->i_mode)) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 53 | flags &= ~EXT4_DIRSYNC_FL; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 54 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 55 | err = -EPERM; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 56 | mutex_lock(&inode->i_mutex); |
Jan Kara | e47776a | 2007-11-14 16:58:56 -0800 | [diff] [blame] | 57 | /* Is it quota file? Do not allow user to mess with it */ |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 58 | if (IS_NOQUOTA(inode)) |
| 59 | goto flags_out; |
| 60 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 61 | oldflags = ei->i_flags; |
| 62 | |
| 63 | /* The JOURNAL_DATA flag is modifiable only by root */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 64 | jflag = flags & EXT4_JOURNAL_DATA_FL; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 65 | |
| 66 | /* |
| 67 | * The IMMUTABLE and APPEND_ONLY flags can only be changed by |
| 68 | * the relevant capability. |
| 69 | * |
| 70 | * This test looks nicer. Thanks to Pauline Middelink |
| 71 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 72 | if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) { |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 73 | if (!capable(CAP_LINUX_IMMUTABLE)) |
| 74 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
| 78 | * The JOURNAL_DATA flag can only be changed by |
| 79 | * the relevant capability. |
| 80 | */ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 81 | if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) { |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 82 | if (!capable(CAP_SYS_RESOURCE)) |
| 83 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 86 | handle = ext4_journal_start(inode, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 87 | if (IS_ERR(handle)) { |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 88 | err = PTR_ERR(handle); |
| 89 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 90 | } |
| 91 | if (IS_SYNC(inode)) |
| 92 | handle->h_sync = 1; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 93 | err = ext4_reserve_inode_write(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 94 | if (err) |
| 95 | goto flags_err; |
| 96 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 97 | flags = flags & EXT4_FL_USER_MODIFIABLE; |
| 98 | flags |= oldflags & ~EXT4_FL_USER_MODIFIABLE; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 99 | ei->i_flags = flags; |
| 100 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 101 | ext4_set_inode_flags(inode); |
Kalpak Shah | ef7f383 | 2007-07-18 09:15:20 -0400 | [diff] [blame] | 102 | inode->i_ctime = ext4_current_time(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 103 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 104 | err = ext4_mark_iloc_dirty(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 105 | flags_err: |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 106 | ext4_journal_stop(handle); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 107 | if (err) |
| 108 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 109 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 110 | if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) |
| 111 | err = ext4_change_inode_journal_flag(inode, jflag); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 112 | flags_out: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 113 | mutex_unlock(&inode->i_mutex); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 114 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 115 | return err; |
| 116 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 117 | case EXT4_IOC_GETVERSION: |
| 118 | case EXT4_IOC_GETVERSION_OLD: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 119 | return put_user(inode->i_generation, (int __user *) arg); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 120 | case EXT4_IOC_SETVERSION: |
| 121 | case EXT4_IOC_SETVERSION_OLD: { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 122 | handle_t *handle; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 123 | struct ext4_iloc iloc; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 124 | __u32 generation; |
| 125 | int err; |
| 126 | |
Satyam Sharma | 3bd858a | 2007-07-17 15:00:08 +0530 | [diff] [blame] | 127 | if (!is_owner_or_cap(inode)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 128 | return -EPERM; |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 129 | |
| 130 | err = mnt_want_write(filp->f_path.mnt); |
| 131 | if (err) |
| 132 | return err; |
| 133 | if (get_user(generation, (int __user *) arg)) { |
| 134 | err = -EFAULT; |
| 135 | goto setversion_out; |
| 136 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 137 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 138 | handle = ext4_journal_start(inode, 1); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 139 | if (IS_ERR(handle)) { |
| 140 | err = PTR_ERR(handle); |
| 141 | goto setversion_out; |
| 142 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 143 | err = ext4_reserve_inode_write(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 144 | if (err == 0) { |
Kalpak Shah | ef7f383 | 2007-07-18 09:15:20 -0400 | [diff] [blame] | 145 | inode->i_ctime = ext4_current_time(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 146 | inode->i_generation = generation; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 147 | err = ext4_mark_iloc_dirty(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 148 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 149 | ext4_journal_stop(handle); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 150 | setversion_out: |
| 151 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 152 | return err; |
| 153 | } |
Jose R. Santos | e23291b | 2007-07-18 08:57:06 -0400 | [diff] [blame] | 154 | #ifdef CONFIG_JBD2_DEBUG |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 155 | case EXT4_IOC_WAIT_FOR_READONLY: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 156 | /* |
| 157 | * This is racy - by the time we're woken up and running, |
| 158 | * the superblock could be released. And the module could |
| 159 | * have been unloaded. So sue me. |
| 160 | * |
| 161 | * Returns 1 if it slept, else zero. |
| 162 | */ |
| 163 | { |
| 164 | struct super_block *sb = inode->i_sb; |
| 165 | DECLARE_WAITQUEUE(wait, current); |
| 166 | int ret = 0; |
| 167 | |
| 168 | set_current_state(TASK_INTERRUPTIBLE); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 169 | add_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait); |
| 170 | if (timer_pending(&EXT4_SB(sb)->turn_ro_timer)) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 171 | schedule(); |
| 172 | ret = 1; |
| 173 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 174 | remove_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 175 | return ret; |
| 176 | } |
| 177 | #endif |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 178 | case EXT4_IOC_GETRSVSZ: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 179 | if (test_opt(inode->i_sb, RESERVATION) |
| 180 | && S_ISREG(inode->i_mode) |
| 181 | && ei->i_block_alloc_info) { |
| 182 | rsv_window_size = ei->i_block_alloc_info->rsv_window_node.rsv_goal_size; |
| 183 | return put_user(rsv_window_size, (int __user *)arg); |
| 184 | } |
| 185 | return -ENOTTY; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 186 | case EXT4_IOC_SETRSVSZ: { |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 187 | int err; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 188 | |
| 189 | if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode)) |
| 190 | return -ENOTTY; |
| 191 | |
Satyam Sharma | 3bd858a | 2007-07-17 15:00:08 +0530 | [diff] [blame] | 192 | if (!is_owner_or_cap(inode)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 193 | return -EACCES; |
| 194 | |
| 195 | if (get_user(rsv_window_size, (int __user *)arg)) |
| 196 | return -EFAULT; |
| 197 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 198 | err = mnt_want_write(filp->f_path.mnt); |
| 199 | if (err) |
| 200 | return err; |
| 201 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 202 | if (rsv_window_size > EXT4_MAX_RESERVE_BLOCKS) |
| 203 | rsv_window_size = EXT4_MAX_RESERVE_BLOCKS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * need to allocate reservation structure for this inode |
| 207 | * before set the window size |
| 208 | */ |
Aneesh Kumar K.V | 0e855ac | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 209 | down_write(&ei->i_data_sem); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 210 | if (!ei->i_block_alloc_info) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 211 | ext4_init_block_alloc_info(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 212 | |
| 213 | if (ei->i_block_alloc_info){ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 214 | struct ext4_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 215 | rsv->rsv_goal_size = rsv_window_size; |
| 216 | } |
Aneesh Kumar K.V | 0e855ac | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 217 | up_write(&ei->i_data_sem); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 218 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 219 | return 0; |
| 220 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 221 | case EXT4_IOC_GROUP_EXTEND: { |
| 222 | ext4_fsblk_t n_blocks_count; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 223 | struct super_block *sb = inode->i_sb; |
| 224 | int err; |
| 225 | |
| 226 | if (!capable(CAP_SYS_RESOURCE)) |
| 227 | return -EPERM; |
| 228 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 229 | if (get_user(n_blocks_count, (__u32 __user *)arg)) |
| 230 | return -EFAULT; |
| 231 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 232 | err = mnt_want_write(filp->f_path.mnt); |
| 233 | if (err) |
| 234 | return err; |
| 235 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 236 | err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count); |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 237 | jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); |
| 238 | jbd2_journal_flush(EXT4_SB(sb)->s_journal); |
| 239 | jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 240 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 241 | |
| 242 | return err; |
| 243 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 244 | case EXT4_IOC_GROUP_ADD: { |
| 245 | struct ext4_new_group_data input; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 246 | struct super_block *sb = inode->i_sb; |
| 247 | int err; |
| 248 | |
| 249 | if (!capable(CAP_SYS_RESOURCE)) |
| 250 | return -EPERM; |
| 251 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 252 | if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 253 | sizeof(input))) |
| 254 | return -EFAULT; |
| 255 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 256 | err = mnt_want_write(filp->f_path.mnt); |
| 257 | if (err) |
| 258 | return err; |
| 259 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 260 | err = ext4_group_add(sb, &input); |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 261 | jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); |
| 262 | jbd2_journal_flush(EXT4_SB(sb)->s_journal); |
| 263 | jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 264 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 265 | |
| 266 | return err; |
| 267 | } |
| 268 | |
Aneesh Kumar K.V | c14c6fd | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 269 | case EXT4_IOC_MIGRATE: |
| 270 | return ext4_ext_migrate(inode, filp, cmd, arg); |
| 271 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 272 | default: |
| 273 | return -ENOTTY; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | #ifdef CONFIG_COMPAT |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 278 | long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 279 | { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 280 | /* These are just misnamed, they actually get/put from/to user an int */ |
| 281 | switch (cmd) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 282 | case EXT4_IOC32_GETFLAGS: |
| 283 | cmd = EXT4_IOC_GETFLAGS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 284 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 285 | case EXT4_IOC32_SETFLAGS: |
| 286 | cmd = EXT4_IOC_SETFLAGS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 287 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 288 | case EXT4_IOC32_GETVERSION: |
| 289 | cmd = EXT4_IOC_GETVERSION; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 290 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 291 | case EXT4_IOC32_SETVERSION: |
| 292 | cmd = EXT4_IOC_SETVERSION; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 293 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 294 | case EXT4_IOC32_GROUP_EXTEND: |
| 295 | cmd = EXT4_IOC_GROUP_EXTEND; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 296 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 297 | case EXT4_IOC32_GETVERSION_OLD: |
| 298 | cmd = EXT4_IOC_GETVERSION_OLD; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 299 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 300 | case EXT4_IOC32_SETVERSION_OLD: |
| 301 | cmd = EXT4_IOC_SETVERSION_OLD; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 302 | break; |
Jose R. Santos | e23291b | 2007-07-18 08:57:06 -0400 | [diff] [blame] | 303 | #ifdef CONFIG_JBD2_DEBUG |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 304 | case EXT4_IOC32_WAIT_FOR_READONLY: |
| 305 | cmd = EXT4_IOC_WAIT_FOR_READONLY; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 306 | break; |
| 307 | #endif |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 308 | case EXT4_IOC32_GETRSVSZ: |
| 309 | cmd = EXT4_IOC_GETRSVSZ; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 310 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 311 | case EXT4_IOC32_SETRSVSZ: |
| 312 | cmd = EXT4_IOC_SETRSVSZ; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 313 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 314 | case EXT4_IOC_GROUP_ADD: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 315 | break; |
| 316 | default: |
| 317 | return -ENOIOCTLCMD; |
| 318 | } |
Andi Kleen | 5cdd7b2 | 2008-04-29 22:03:54 -0400 | [diff] [blame] | 319 | return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 320 | } |
| 321 | #endif |