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 | |
Theodore Ts'o | af5bc92 | 2008-09-08 22:25:24 -0400 | [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; |
Aneesh Kumar K.V | 4db46fc | 2008-10-08 23:34:06 -0400 | [diff] [blame^] | 37 | int err, migrate = 0; |
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 | } |
Aneesh Kumar K.V | 4db46fc | 2008-10-08 23:34:06 -0400 | [diff] [blame^] | 85 | if (oldflags & EXT4_EXTENTS_FL) { |
| 86 | /* We don't support clearning extent flags */ |
| 87 | if (!(flags & EXT4_EXTENTS_FL)) { |
| 88 | err = -EOPNOTSUPP; |
| 89 | goto flags_out; |
| 90 | } |
| 91 | } else if (flags & EXT4_EXTENTS_FL) { |
| 92 | /* migrate the file */ |
| 93 | migrate = 1; |
| 94 | flags &= ~EXT4_EXTENTS_FL; |
| 95 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 96 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 97 | handle = ext4_journal_start(inode, 1); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 98 | if (IS_ERR(handle)) { |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 99 | err = PTR_ERR(handle); |
| 100 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 101 | } |
| 102 | if (IS_SYNC(inode)) |
| 103 | handle->h_sync = 1; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 104 | err = ext4_reserve_inode_write(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 105 | if (err) |
| 106 | goto flags_err; |
| 107 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 108 | flags = flags & EXT4_FL_USER_MODIFIABLE; |
| 109 | flags |= oldflags & ~EXT4_FL_USER_MODIFIABLE; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 110 | ei->i_flags = flags; |
| 111 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 112 | ext4_set_inode_flags(inode); |
Kalpak Shah | ef7f383 | 2007-07-18 09:15:20 -0400 | [diff] [blame] | 113 | inode->i_ctime = ext4_current_time(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 114 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 115 | err = ext4_mark_iloc_dirty(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 116 | flags_err: |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 117 | ext4_journal_stop(handle); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 118 | if (err) |
| 119 | goto flags_out; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 120 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 121 | if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) |
| 122 | err = ext4_change_inode_journal_flag(inode, jflag); |
Aneesh Kumar K.V | 4db46fc | 2008-10-08 23:34:06 -0400 | [diff] [blame^] | 123 | if (err) |
| 124 | goto flags_out; |
| 125 | if (migrate) |
| 126 | err = ext4_ext_migrate(inode); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 127 | flags_out: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 128 | mutex_unlock(&inode->i_mutex); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 129 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 130 | return err; |
| 131 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 132 | case EXT4_IOC_GETVERSION: |
| 133 | case EXT4_IOC_GETVERSION_OLD: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 134 | return put_user(inode->i_generation, (int __user *) arg); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 135 | case EXT4_IOC_SETVERSION: |
| 136 | case EXT4_IOC_SETVERSION_OLD: { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 137 | handle_t *handle; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 138 | struct ext4_iloc iloc; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 139 | __u32 generation; |
| 140 | int err; |
| 141 | |
Satyam Sharma | 3bd858a | 2007-07-17 15:00:08 +0530 | [diff] [blame] | 142 | if (!is_owner_or_cap(inode)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 143 | return -EPERM; |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 144 | |
| 145 | err = mnt_want_write(filp->f_path.mnt); |
| 146 | if (err) |
| 147 | return err; |
| 148 | if (get_user(generation, (int __user *) arg)) { |
| 149 | err = -EFAULT; |
| 150 | goto setversion_out; |
| 151 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 152 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 153 | handle = ext4_journal_start(inode, 1); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 154 | if (IS_ERR(handle)) { |
| 155 | err = PTR_ERR(handle); |
| 156 | goto setversion_out; |
| 157 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 158 | err = ext4_reserve_inode_write(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 159 | if (err == 0) { |
Kalpak Shah | ef7f383 | 2007-07-18 09:15:20 -0400 | [diff] [blame] | 160 | inode->i_ctime = ext4_current_time(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 161 | inode->i_generation = generation; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 162 | err = ext4_mark_iloc_dirty(handle, inode, &iloc); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 163 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 164 | ext4_journal_stop(handle); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 165 | setversion_out: |
| 166 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 167 | return err; |
| 168 | } |
Jose R. Santos | e23291b | 2007-07-18 08:57:06 -0400 | [diff] [blame] | 169 | #ifdef CONFIG_JBD2_DEBUG |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 170 | case EXT4_IOC_WAIT_FOR_READONLY: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 171 | /* |
| 172 | * This is racy - by the time we're woken up and running, |
| 173 | * the superblock could be released. And the module could |
| 174 | * have been unloaded. So sue me. |
| 175 | * |
| 176 | * Returns 1 if it slept, else zero. |
| 177 | */ |
| 178 | { |
| 179 | struct super_block *sb = inode->i_sb; |
| 180 | DECLARE_WAITQUEUE(wait, current); |
| 181 | int ret = 0; |
| 182 | |
| 183 | set_current_state(TASK_INTERRUPTIBLE); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 184 | add_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait); |
| 185 | if (timer_pending(&EXT4_SB(sb)->turn_ro_timer)) { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 186 | schedule(); |
| 187 | ret = 1; |
| 188 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 189 | remove_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 190 | return ret; |
| 191 | } |
| 192 | #endif |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 193 | case EXT4_IOC_GETRSVSZ: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 194 | if (test_opt(inode->i_sb, RESERVATION) |
| 195 | && S_ISREG(inode->i_mode) |
| 196 | && ei->i_block_alloc_info) { |
| 197 | rsv_window_size = ei->i_block_alloc_info->rsv_window_node.rsv_goal_size; |
| 198 | return put_user(rsv_window_size, (int __user *)arg); |
| 199 | } |
| 200 | return -ENOTTY; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 201 | case EXT4_IOC_SETRSVSZ: { |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 202 | int err; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 203 | |
Theodore Ts'o | af5bc92 | 2008-09-08 22:25:24 -0400 | [diff] [blame] | 204 | if (!test_opt(inode->i_sb, RESERVATION) || !S_ISREG(inode->i_mode)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 205 | return -ENOTTY; |
| 206 | |
Satyam Sharma | 3bd858a | 2007-07-17 15:00:08 +0530 | [diff] [blame] | 207 | if (!is_owner_or_cap(inode)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 208 | return -EACCES; |
| 209 | |
| 210 | if (get_user(rsv_window_size, (int __user *)arg)) |
| 211 | return -EFAULT; |
| 212 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 213 | err = mnt_want_write(filp->f_path.mnt); |
| 214 | if (err) |
| 215 | return err; |
| 216 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 217 | if (rsv_window_size > EXT4_MAX_RESERVE_BLOCKS) |
| 218 | rsv_window_size = EXT4_MAX_RESERVE_BLOCKS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * need to allocate reservation structure for this inode |
| 222 | * before set the window size |
| 223 | */ |
Aneesh Kumar K.V | 0e855ac | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 224 | down_write(&ei->i_data_sem); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 225 | if (!ei->i_block_alloc_info) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 226 | ext4_init_block_alloc_info(inode); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 227 | |
| 228 | if (ei->i_block_alloc_info){ |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 229 | 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] | 230 | rsv->rsv_goal_size = rsv_window_size; |
| 231 | } |
Aneesh Kumar K.V | 0e855ac | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 232 | up_write(&ei->i_data_sem); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 233 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 234 | return 0; |
| 235 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 236 | case EXT4_IOC_GROUP_EXTEND: { |
| 237 | ext4_fsblk_t n_blocks_count; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 238 | struct super_block *sb = inode->i_sb; |
| 239 | int err; |
| 240 | |
| 241 | if (!capable(CAP_SYS_RESOURCE)) |
| 242 | return -EPERM; |
| 243 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 244 | if (get_user(n_blocks_count, (__u32 __user *)arg)) |
| 245 | return -EFAULT; |
| 246 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 247 | err = mnt_want_write(filp->f_path.mnt); |
| 248 | if (err) |
| 249 | return err; |
| 250 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 251 | 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] | 252 | jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); |
| 253 | jbd2_journal_flush(EXT4_SB(sb)->s_journal); |
| 254 | jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 255 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 256 | |
| 257 | return err; |
| 258 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 259 | case EXT4_IOC_GROUP_ADD: { |
| 260 | struct ext4_new_group_data input; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 261 | struct super_block *sb = inode->i_sb; |
| 262 | int err; |
| 263 | |
| 264 | if (!capable(CAP_SYS_RESOURCE)) |
| 265 | return -EPERM; |
| 266 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 267 | if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 268 | sizeof(input))) |
| 269 | return -EFAULT; |
| 270 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 271 | err = mnt_want_write(filp->f_path.mnt); |
| 272 | if (err) |
| 273 | return err; |
| 274 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 275 | err = ext4_group_add(sb, &input); |
Mingming Cao | dab291a | 2006-10-11 01:21:01 -0700 | [diff] [blame] | 276 | jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); |
| 277 | jbd2_journal_flush(EXT4_SB(sb)->s_journal); |
| 278 | jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 279 | mnt_drop_write(filp->f_path.mnt); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 280 | |
| 281 | return err; |
| 282 | } |
| 283 | |
Aneesh Kumar K.V | c14c6fd | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 284 | case EXT4_IOC_MIGRATE: |
Aneesh Kumar K.V | 2a43a87 | 2008-09-13 12:52:26 -0400 | [diff] [blame] | 285 | { |
| 286 | int err; |
| 287 | if (!is_owner_or_cap(inode)) |
| 288 | return -EACCES; |
| 289 | |
| 290 | err = mnt_want_write(filp->f_path.mnt); |
| 291 | if (err) |
| 292 | return err; |
| 293 | /* |
| 294 | * inode_mutex prevent write and truncate on the file. |
| 295 | * Read still goes through. We take i_data_sem in |
| 296 | * ext4_ext_swap_inode_data before we switch the |
| 297 | * inode format to prevent read. |
| 298 | */ |
| 299 | mutex_lock(&(inode->i_mutex)); |
| 300 | err = ext4_ext_migrate(inode); |
| 301 | mutex_unlock(&(inode->i_mutex)); |
| 302 | mnt_drop_write(filp->f_path.mnt); |
| 303 | return err; |
| 304 | } |
Aneesh Kumar K.V | c14c6fd | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 305 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 306 | default: |
| 307 | return -ENOTTY; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | #ifdef CONFIG_COMPAT |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 312 | 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] | 313 | { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 314 | /* These are just misnamed, they actually get/put from/to user an int */ |
| 315 | switch (cmd) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 316 | case EXT4_IOC32_GETFLAGS: |
| 317 | cmd = EXT4_IOC_GETFLAGS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 318 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 319 | case EXT4_IOC32_SETFLAGS: |
| 320 | cmd = EXT4_IOC_SETFLAGS; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 321 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 322 | case EXT4_IOC32_GETVERSION: |
| 323 | cmd = EXT4_IOC_GETVERSION; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 324 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 325 | case EXT4_IOC32_SETVERSION: |
| 326 | cmd = EXT4_IOC_SETVERSION; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 327 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 328 | case EXT4_IOC32_GROUP_EXTEND: |
| 329 | cmd = EXT4_IOC_GROUP_EXTEND; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 330 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 331 | case EXT4_IOC32_GETVERSION_OLD: |
| 332 | cmd = EXT4_IOC_GETVERSION_OLD; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 333 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 334 | case EXT4_IOC32_SETVERSION_OLD: |
| 335 | cmd = EXT4_IOC_SETVERSION_OLD; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 336 | break; |
Jose R. Santos | e23291b | 2007-07-18 08:57:06 -0400 | [diff] [blame] | 337 | #ifdef CONFIG_JBD2_DEBUG |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 338 | case EXT4_IOC32_WAIT_FOR_READONLY: |
| 339 | cmd = EXT4_IOC_WAIT_FOR_READONLY; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 340 | break; |
| 341 | #endif |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 342 | case EXT4_IOC32_GETRSVSZ: |
| 343 | cmd = EXT4_IOC_GETRSVSZ; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 344 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 345 | case EXT4_IOC32_SETRSVSZ: |
| 346 | cmd = EXT4_IOC_SETRSVSZ; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 347 | break; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 348 | case EXT4_IOC_GROUP_ADD: |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 349 | break; |
| 350 | default: |
| 351 | return -ENOIOCTLCMD; |
| 352 | } |
Andi Kleen | 5cdd7b2 | 2008-04-29 22:03:54 -0400 | [diff] [blame] | 353 | return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 354 | } |
| 355 | #endif |