blob: 2046d699b4a7456139e31ec03553ccdbea474209 [file] [log] [blame]
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001/*
Mingming Cao617ba132006-10-11 01:20:53 -07002 * linux/fs/ext4/ioctl.c
Dave Kleikampac27a0e2006-10-11 01:20:50 -07003 *
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 Caodab291a2006-10-11 01:21:01 -070011#include <linux/jbd2.h>
Dave Kleikampac27a0e2006-10-11 01:20:50 -070012#include <linux/capability.h>
Dave Kleikampac27a0e2006-10-11 01:20:50 -070013#include <linux/time.h>
14#include <linux/compat.h>
Dave Hansen42a74f22008-02-15 14:37:46 -080015#include <linux/mount.h>
Akira Fujita748de672009-06-17 19:24:03 -040016#include <linux/file.h>
Dave Kleikampac27a0e2006-10-11 01:20:50 -070017#include <asm/uaccess.h>
Christoph Hellwig3dcf5452008-04-29 18:13:32 -040018#include "ext4_jbd2.h"
19#include "ext4.h"
Dave Kleikampac27a0e2006-10-11 01:20:50 -070020
Andi Kleen5cdd7b22008-04-29 22:03:54 -040021long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070022{
Andi Kleen5cdd7b22008-04-29 22:03:54 -040023 struct inode *inode = filp->f_dentry->d_inode;
Theodore Ts'obab08ab2011-09-09 18:36:51 -040024 struct super_block *sb = inode->i_sb;
Mingming Cao617ba132006-10-11 01:20:53 -070025 struct ext4_inode_info *ei = EXT4_I(inode);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070026 unsigned int flags;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070027
Theodore Ts'oaf5bc922008-09-08 22:25:24 -040028 ext4_debug("cmd = %u, arg = %lu\n", cmd, arg);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070029
30 switch (cmd) {
Mingming Cao617ba132006-10-11 01:20:53 -070031 case EXT4_IOC_GETFLAGS:
Jan Karaff9ddf72007-07-18 09:24:20 -040032 ext4_get_inode_flags(ei);
Mingming Cao617ba132006-10-11 01:20:53 -070033 flags = ei->i_flags & EXT4_FL_USER_VISIBLE;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070034 return put_user(flags, (int __user *) arg);
Mingming Cao617ba132006-10-11 01:20:53 -070035 case EXT4_IOC_SETFLAGS: {
Dave Kleikampac27a0e2006-10-11 01:20:50 -070036 handle_t *handle = NULL;
Aneesh Kumar K.V4db46fc2008-10-08 23:34:06 -040037 int err, migrate = 0;
Mingming Cao617ba132006-10-11 01:20:53 -070038 struct ext4_iloc iloc;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070039 unsigned int oldflags;
40 unsigned int jflag;
41
Serge E. Hallyn2e149672011-03-23 16:43:26 -070042 if (!inode_owner_or_capable(inode))
Dave Kleikampac27a0e2006-10-11 01:20:50 -070043 return -EACCES;
44
45 if (get_user(flags, (int __user *) arg))
46 return -EFAULT;
47
Dave Hansen42a74f22008-02-15 14:37:46 -080048 err = mnt_want_write(filp->f_path.mnt);
49 if (err)
50 return err;
51
Duane Griffin2dc6b0d2009-02-15 18:09:20 -050052 flags = ext4_mask_flags(inode->i_mode, flags);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070053
Dave Hansen42a74f22008-02-15 14:37:46 -080054 err = -EPERM;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070055 mutex_lock(&inode->i_mutex);
Jan Karae47776a2007-11-14 16:58:56 -080056 /* Is it quota file? Do not allow user to mess with it */
Dave Hansen42a74f22008-02-15 14:37:46 -080057 if (IS_NOQUOTA(inode))
58 goto flags_out;
59
Dave Kleikampac27a0e2006-10-11 01:20:50 -070060 oldflags = ei->i_flags;
61
62 /* The JOURNAL_DATA flag is modifiable only by root */
Mingming Cao617ba132006-10-11 01:20:53 -070063 jflag = flags & EXT4_JOURNAL_DATA_FL;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070064
65 /*
66 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
67 * the relevant capability.
68 *
69 * This test looks nicer. Thanks to Pauline Middelink
70 */
Mingming Cao617ba132006-10-11 01:20:53 -070071 if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
Dave Hansen42a74f22008-02-15 14:37:46 -080072 if (!capable(CAP_LINUX_IMMUTABLE))
73 goto flags_out;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070074 }
75
76 /*
77 * The JOURNAL_DATA flag can only be changed by
78 * the relevant capability.
79 */
Mingming Cao617ba132006-10-11 01:20:53 -070080 if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
Dave Hansen42a74f22008-02-15 14:37:46 -080081 if (!capable(CAP_SYS_RESOURCE))
82 goto flags_out;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070083 }
Aneesh Kumar K.V4db46fc2008-10-08 23:34:06 -040084 if (oldflags & EXT4_EXTENTS_FL) {
85 /* We don't support clearning extent flags */
86 if (!(flags & EXT4_EXTENTS_FL)) {
87 err = -EOPNOTSUPP;
88 goto flags_out;
89 }
90 } else if (flags & EXT4_EXTENTS_FL) {
91 /* migrate the file */
92 migrate = 1;
93 flags &= ~EXT4_EXTENTS_FL;
94 }
Dave Kleikampac27a0e2006-10-11 01:20:50 -070095
Jiaying Zhangc8d46e42010-02-24 09:52:53 -050096 if (flags & EXT4_EOFBLOCKS_FL) {
97 /* we don't support adding EOFBLOCKS flag */
98 if (!(oldflags & EXT4_EOFBLOCKS_FL)) {
99 err = -EOPNOTSUPP;
100 goto flags_out;
101 }
102 } else if (oldflags & EXT4_EOFBLOCKS_FL)
103 ext4_truncate(inode);
104
Mingming Cao617ba132006-10-11 01:20:53 -0700105 handle = ext4_journal_start(inode, 1);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700106 if (IS_ERR(handle)) {
Dave Hansen42a74f22008-02-15 14:37:46 -0800107 err = PTR_ERR(handle);
108 goto flags_out;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700109 }
110 if (IS_SYNC(inode))
Frank Mayhar03901312009-01-07 00:06:22 -0500111 ext4_handle_sync(handle);
Mingming Cao617ba132006-10-11 01:20:53 -0700112 err = ext4_reserve_inode_write(handle, inode, &iloc);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700113 if (err)
114 goto flags_err;
115
Mingming Cao617ba132006-10-11 01:20:53 -0700116 flags = flags & EXT4_FL_USER_MODIFIABLE;
117 flags |= oldflags & ~EXT4_FL_USER_MODIFIABLE;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700118 ei->i_flags = flags;
119
Mingming Cao617ba132006-10-11 01:20:53 -0700120 ext4_set_inode_flags(inode);
Kalpak Shahef7f3832007-07-18 09:15:20 -0400121 inode->i_ctime = ext4_current_time(inode);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700122
Mingming Cao617ba132006-10-11 01:20:53 -0700123 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700124flags_err:
Mingming Cao617ba132006-10-11 01:20:53 -0700125 ext4_journal_stop(handle);
Dave Hansen42a74f22008-02-15 14:37:46 -0800126 if (err)
127 goto flags_out;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700128
Mingming Cao617ba132006-10-11 01:20:53 -0700129 if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL))
130 err = ext4_change_inode_journal_flag(inode, jflag);
Aneesh Kumar K.V4db46fc2008-10-08 23:34:06 -0400131 if (err)
132 goto flags_out;
133 if (migrate)
134 err = ext4_ext_migrate(inode);
Dave Hansen42a74f22008-02-15 14:37:46 -0800135flags_out:
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700136 mutex_unlock(&inode->i_mutex);
Dave Hansen42a74f22008-02-15 14:37:46 -0800137 mnt_drop_write(filp->f_path.mnt);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700138 return err;
139 }
Mingming Cao617ba132006-10-11 01:20:53 -0700140 case EXT4_IOC_GETVERSION:
141 case EXT4_IOC_GETVERSION_OLD:
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700142 return put_user(inode->i_generation, (int __user *) arg);
Mingming Cao617ba132006-10-11 01:20:53 -0700143 case EXT4_IOC_SETVERSION:
144 case EXT4_IOC_SETVERSION_OLD: {
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700145 handle_t *handle;
Mingming Cao617ba132006-10-11 01:20:53 -0700146 struct ext4_iloc iloc;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700147 __u32 generation;
148 int err;
149
Serge E. Hallyn2e149672011-03-23 16:43:26 -0700150 if (!inode_owner_or_capable(inode))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700151 return -EPERM;
Dave Hansen42a74f22008-02-15 14:37:46 -0800152
153 err = mnt_want_write(filp->f_path.mnt);
154 if (err)
155 return err;
156 if (get_user(generation, (int __user *) arg)) {
157 err = -EFAULT;
158 goto setversion_out;
159 }
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700160
Mingming Cao617ba132006-10-11 01:20:53 -0700161 handle = ext4_journal_start(inode, 1);
Dave Hansen42a74f22008-02-15 14:37:46 -0800162 if (IS_ERR(handle)) {
163 err = PTR_ERR(handle);
164 goto setversion_out;
165 }
Mingming Cao617ba132006-10-11 01:20:53 -0700166 err = ext4_reserve_inode_write(handle, inode, &iloc);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700167 if (err == 0) {
Kalpak Shahef7f3832007-07-18 09:15:20 -0400168 inode->i_ctime = ext4_current_time(inode);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700169 inode->i_generation = generation;
Mingming Cao617ba132006-10-11 01:20:53 -0700170 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700171 }
Mingming Cao617ba132006-10-11 01:20:53 -0700172 ext4_journal_stop(handle);
Dave Hansen42a74f22008-02-15 14:37:46 -0800173setversion_out:
174 mnt_drop_write(filp->f_path.mnt);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700175 return err;
176 }
Jose R. Santose23291b2007-07-18 08:57:06 -0400177#ifdef CONFIG_JBD2_DEBUG
Mingming Cao617ba132006-10-11 01:20:53 -0700178 case EXT4_IOC_WAIT_FOR_READONLY:
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700179 /*
180 * This is racy - by the time we're woken up and running,
181 * the superblock could be released. And the module could
182 * have been unloaded. So sue me.
183 *
184 * Returns 1 if it slept, else zero.
185 */
186 {
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700187 DECLARE_WAITQUEUE(wait, current);
188 int ret = 0;
189
190 set_current_state(TASK_INTERRUPTIBLE);
Mingming Cao617ba132006-10-11 01:20:53 -0700191 add_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait);
192 if (timer_pending(&EXT4_SB(sb)->turn_ro_timer)) {
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700193 schedule();
194 ret = 1;
195 }
Mingming Cao617ba132006-10-11 01:20:53 -0700196 remove_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700197 return ret;
198 }
199#endif
Mingming Cao617ba132006-10-11 01:20:53 -0700200 case EXT4_IOC_GROUP_EXTEND: {
201 ext4_fsblk_t n_blocks_count;
Peng Taoac046f12009-07-13 09:30:17 -0400202 int err, err2=0;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700203
Yongqiang Yang8f82f842011-07-26 21:35:44 -0400204 err = ext4_resize_begin(sb);
205 if (err)
206 return err;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700207
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700208 if (get_user(n_blocks_count, (__u32 __user *)arg))
209 return -EFAULT;
210
Theodore Ts'obab08ab2011-09-09 18:36:51 -0400211 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
212 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
213 ext4_msg(sb, KERN_ERR,
214 "Online resizing not supported with bigalloc");
215 return -EOPNOTSUPP;
216 }
217
Dave Hansen42a74f22008-02-15 14:37:46 -0800218 err = mnt_want_write(filp->f_path.mnt);
219 if (err)
220 return err;
221
Mingming Cao617ba132006-10-11 01:20:53 -0700222 err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count);
Peng Taoac046f12009-07-13 09:30:17 -0400223 if (EXT4_SB(sb)->s_journal) {
224 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
225 err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
226 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
227 }
Hidehiro Kawai7ffe1ea2008-10-10 20:29:21 -0400228 if (err == 0)
229 err = err2;
Dave Hansen42a74f22008-02-15 14:37:46 -0800230 mnt_drop_write(filp->f_path.mnt);
Yongqiang Yang8f82f842011-07-26 21:35:44 -0400231 ext4_resize_end(sb);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700232
233 return err;
234 }
Akira Fujita748de672009-06-17 19:24:03 -0400235
236 case EXT4_IOC_MOVE_EXT: {
237 struct move_extent me;
238 struct file *donor_filp;
239 int err;
240
Akira Fujita4a585792009-12-06 23:38:31 -0500241 if (!(filp->f_mode & FMODE_READ) ||
242 !(filp->f_mode & FMODE_WRITE))
243 return -EBADF;
244
Akira Fujita748de672009-06-17 19:24:03 -0400245 if (copy_from_user(&me,
246 (struct move_extent __user *)arg, sizeof(me)))
247 return -EFAULT;
Akira Fujita4a585792009-12-06 23:38:31 -0500248 me.moved_len = 0;
Akira Fujita748de672009-06-17 19:24:03 -0400249
250 donor_filp = fget(me.donor_fd);
251 if (!donor_filp)
252 return -EBADF;
253
Akira Fujita4a585792009-12-06 23:38:31 -0500254 if (!(donor_filp->f_mode & FMODE_WRITE)) {
255 err = -EBADF;
256 goto mext_out;
Akira Fujita748de672009-06-17 19:24:03 -0400257 }
258
Theodore Ts'obab08ab2011-09-09 18:36:51 -0400259 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
260 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
261 ext4_msg(sb, KERN_ERR,
262 "Online defrag not supported with bigalloc");
263 return -EOPNOTSUPP;
264 }
265
Akira Fujita4a585792009-12-06 23:38:31 -0500266 err = mnt_want_write(filp->f_path.mnt);
267 if (err)
268 goto mext_out;
269
Akira Fujita748de672009-06-17 19:24:03 -0400270 err = ext4_move_extents(filp, donor_filp, me.orig_start,
271 me.donor_start, me.len, &me.moved_len);
Akira Fujita4a585792009-12-06 23:38:31 -0500272 mnt_drop_write(filp->f_path.mnt);
273 if (me.moved_len > 0)
274 file_remove_suid(donor_filp);
Akira Fujita748de672009-06-17 19:24:03 -0400275
Theodore Ts'o60e66792010-05-17 07:00:00 -0400276 if (copy_to_user((struct move_extent __user *)arg,
Akira Fujitac437b272010-03-04 00:39:24 -0500277 &me, sizeof(me)))
Akira Fujita4a585792009-12-06 23:38:31 -0500278 err = -EFAULT;
279mext_out:
280 fput(donor_filp);
Akira Fujita748de672009-06-17 19:24:03 -0400281 return err;
282 }
283
Mingming Cao617ba132006-10-11 01:20:53 -0700284 case EXT4_IOC_GROUP_ADD: {
285 struct ext4_new_group_data input;
Peng Taoac046f12009-07-13 09:30:17 -0400286 int err, err2=0;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700287
Yongqiang Yang8f82f842011-07-26 21:35:44 -0400288 err = ext4_resize_begin(sb);
289 if (err)
290 return err;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700291
Mingming Cao617ba132006-10-11 01:20:53 -0700292 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700293 sizeof(input)))
294 return -EFAULT;
295
Theodore Ts'obab08ab2011-09-09 18:36:51 -0400296 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
297 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
298 ext4_msg(sb, KERN_ERR,
299 "Online resizing not supported with bigalloc");
300 return -EOPNOTSUPP;
301 }
302
Dave Hansen42a74f22008-02-15 14:37:46 -0800303 err = mnt_want_write(filp->f_path.mnt);
304 if (err)
305 return err;
306
Mingming Cao617ba132006-10-11 01:20:53 -0700307 err = ext4_group_add(sb, &input);
Peng Taoac046f12009-07-13 09:30:17 -0400308 if (EXT4_SB(sb)->s_journal) {
309 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
310 err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
311 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
312 }
Hidehiro Kawai7ffe1ea2008-10-10 20:29:21 -0400313 if (err == 0)
314 err = err2;
Dave Hansen42a74f22008-02-15 14:37:46 -0800315 mnt_drop_write(filp->f_path.mnt);
Yongqiang Yang8f82f842011-07-26 21:35:44 -0400316 ext4_resize_end(sb);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700317
318 return err;
319 }
320
Aneesh Kumar K.Vc14c6fd2008-01-28 23:58:26 -0500321 case EXT4_IOC_MIGRATE:
Aneesh Kumar K.V2a43a872008-09-13 12:52:26 -0400322 {
323 int err;
Serge E. Hallyn2e149672011-03-23 16:43:26 -0700324 if (!inode_owner_or_capable(inode))
Aneesh Kumar K.V2a43a872008-09-13 12:52:26 -0400325 return -EACCES;
326
327 err = mnt_want_write(filp->f_path.mnt);
328 if (err)
329 return err;
330 /*
331 * inode_mutex prevent write and truncate on the file.
332 * Read still goes through. We take i_data_sem in
333 * ext4_ext_swap_inode_data before we switch the
334 * inode format to prevent read.
335 */
336 mutex_lock(&(inode->i_mutex));
337 err = ext4_ext_migrate(inode);
338 mutex_unlock(&(inode->i_mutex));
339 mnt_drop_write(filp->f_path.mnt);
340 return err;
341 }
Aneesh Kumar K.Vc14c6fd2008-01-28 23:58:26 -0500342
Theodore Ts'occd25062009-02-26 01:04:07 -0500343 case EXT4_IOC_ALLOC_DA_BLKS:
344 {
345 int err;
Serge E. Hallyn2e149672011-03-23 16:43:26 -0700346 if (!inode_owner_or_capable(inode))
Theodore Ts'occd25062009-02-26 01:04:07 -0500347 return -EACCES;
348
349 err = mnt_want_write(filp->f_path.mnt);
350 if (err)
351 return err;
352 err = ext4_alloc_da_blocks(inode);
353 mnt_drop_write(filp->f_path.mnt);
354 return err;
355 }
356
Lukas Czernere681c042010-11-19 21:47:07 -0500357 case FITRIM:
358 {
Lukas Czerner41431792011-02-23 12:42:32 -0500359 struct request_queue *q = bdev_get_queue(sb->s_bdev);
Lukas Czernere681c042010-11-19 21:47:07 -0500360 struct fstrim_range range;
361 int ret = 0;
362
363 if (!capable(CAP_SYS_ADMIN))
364 return -EPERM;
365
Lukas Czerner41431792011-02-23 12:42:32 -0500366 if (!blk_queue_discard(q))
367 return -EOPNOTSUPP;
368
Theodore Ts'obab08ab2011-09-09 18:36:51 -0400369 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
370 EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
371 ext4_msg(sb, KERN_ERR,
372 "FITRIM not supported with bigalloc");
373 return -EOPNOTSUPP;
374 }
375
Lukas Czernere681c042010-11-19 21:47:07 -0500376 if (copy_from_user(&range, (struct fstrim_range *)arg,
377 sizeof(range)))
378 return -EFAULT;
379
Lukas Czerner5c2ed622011-02-23 17:49:51 -0500380 range.minlen = max((unsigned int)range.minlen,
381 q->limits.discard_granularity);
Lukas Czernere681c042010-11-19 21:47:07 -0500382 ret = ext4_trim_fs(sb, &range);
383 if (ret < 0)
384 return ret;
385
386 if (copy_to_user((struct fstrim_range *)arg, &range,
387 sizeof(range)))
388 return -EFAULT;
389
390 return 0;
391 }
392
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700393 default:
394 return -ENOTTY;
395 }
396}
397
398#ifdef CONFIG_COMPAT
Mingming Cao617ba132006-10-11 01:20:53 -0700399long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700400{
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700401 /* These are just misnamed, they actually get/put from/to user an int */
402 switch (cmd) {
Mingming Cao617ba132006-10-11 01:20:53 -0700403 case EXT4_IOC32_GETFLAGS:
404 cmd = EXT4_IOC_GETFLAGS;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700405 break;
Mingming Cao617ba132006-10-11 01:20:53 -0700406 case EXT4_IOC32_SETFLAGS:
407 cmd = EXT4_IOC_SETFLAGS;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700408 break;
Mingming Cao617ba132006-10-11 01:20:53 -0700409 case EXT4_IOC32_GETVERSION:
410 cmd = EXT4_IOC_GETVERSION;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700411 break;
Mingming Cao617ba132006-10-11 01:20:53 -0700412 case EXT4_IOC32_SETVERSION:
413 cmd = EXT4_IOC_SETVERSION;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700414 break;
Mingming Cao617ba132006-10-11 01:20:53 -0700415 case EXT4_IOC32_GROUP_EXTEND:
416 cmd = EXT4_IOC_GROUP_EXTEND;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700417 break;
Mingming Cao617ba132006-10-11 01:20:53 -0700418 case EXT4_IOC32_GETVERSION_OLD:
419 cmd = EXT4_IOC_GETVERSION_OLD;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700420 break;
Mingming Cao617ba132006-10-11 01:20:53 -0700421 case EXT4_IOC32_SETVERSION_OLD:
422 cmd = EXT4_IOC_SETVERSION_OLD;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700423 break;
Jose R. Santose23291b2007-07-18 08:57:06 -0400424#ifdef CONFIG_JBD2_DEBUG
Mingming Cao617ba132006-10-11 01:20:53 -0700425 case EXT4_IOC32_WAIT_FOR_READONLY:
426 cmd = EXT4_IOC_WAIT_FOR_READONLY;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700427 break;
428#endif
Mingming Cao617ba132006-10-11 01:20:53 -0700429 case EXT4_IOC32_GETRSVSZ:
430 cmd = EXT4_IOC_GETRSVSZ;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700431 break;
Mingming Cao617ba132006-10-11 01:20:53 -0700432 case EXT4_IOC32_SETRSVSZ:
433 cmd = EXT4_IOC_SETRSVSZ;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700434 break;
Ben Hutchings4d92dc02010-05-17 06:00:00 -0400435 case EXT4_IOC32_GROUP_ADD: {
436 struct compat_ext4_new_group_input __user *uinput;
437 struct ext4_new_group_input input;
438 mm_segment_t old_fs;
439 int err;
440
441 uinput = compat_ptr(arg);
442 err = get_user(input.group, &uinput->group);
443 err |= get_user(input.block_bitmap, &uinput->block_bitmap);
444 err |= get_user(input.inode_bitmap, &uinput->inode_bitmap);
445 err |= get_user(input.inode_table, &uinput->inode_table);
446 err |= get_user(input.blocks_count, &uinput->blocks_count);
447 err |= get_user(input.reserved_blocks,
448 &uinput->reserved_blocks);
449 if (err)
450 return -EFAULT;
451 old_fs = get_fs();
452 set_fs(KERNEL_DS);
453 err = ext4_ioctl(file, EXT4_IOC_GROUP_ADD,
454 (unsigned long) &input);
455 set_fs(old_fs);
456 return err;
457 }
Christian Borntraegerb684b2e2010-05-15 00:00:00 -0400458 case EXT4_IOC_MOVE_EXT:
Tao Maa56e69c2011-03-20 23:16:58 -0400459 case FITRIM:
Christian Borntraegerb684b2e2010-05-15 00:00:00 -0400460 break;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700461 default:
462 return -ENOIOCTLCMD;
463 }
Andi Kleen5cdd7b22008-04-29 22:03:54 -0400464 return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700465}
466#endif