Merge remote-tracking branch 'lsk/v3.10/topic/gator' into linux-linaro-lsk
[firefly-linux-kernel-4.4.55.git] / fs / ext4 / ioctl.c
1 /*
2  * linux/fs/ext4/ioctl.c
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>
11 #include <linux/jbd2.h>
12 #include <linux/capability.h>
13 #include <linux/time.h>
14 #include <linux/compat.h>
15 #include <linux/mount.h>
16 #include <linux/file.h>
17 #include <asm/uaccess.h>
18 #include "ext4_jbd2.h"
19 #include "ext4.h"
20 #include "ext4_extents.h"
21
22 #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
23
24 /**
25  * Swap memory between @a and @b for @len bytes.
26  *
27  * @a:          pointer to first memory area
28  * @b:          pointer to second memory area
29  * @len:        number of bytes to swap
30  *
31  */
32 static void memswap(void *a, void *b, size_t len)
33 {
34         unsigned char *ap, *bp;
35         unsigned char tmp;
36
37         ap = (unsigned char *)a;
38         bp = (unsigned char *)b;
39         while (len-- > 0) {
40                 tmp = *ap;
41                 *ap = *bp;
42                 *bp = tmp;
43                 ap++;
44                 bp++;
45         }
46 }
47
48 /**
49  * Swap i_data and associated attributes between @inode1 and @inode2.
50  * This function is used for the primary swap between inode1 and inode2
51  * and also to revert this primary swap in case of errors.
52  *
53  * Therefore you have to make sure, that calling this method twice
54  * will revert all changes.
55  *
56  * @inode1:     pointer to first inode
57  * @inode2:     pointer to second inode
58  */
59 static void swap_inode_data(struct inode *inode1, struct inode *inode2)
60 {
61         loff_t isize;
62         struct ext4_inode_info *ei1;
63         struct ext4_inode_info *ei2;
64
65         ei1 = EXT4_I(inode1);
66         ei2 = EXT4_I(inode2);
67
68         memswap(&inode1->i_flags, &inode2->i_flags, sizeof(inode1->i_flags));
69         memswap(&inode1->i_version, &inode2->i_version,
70                   sizeof(inode1->i_version));
71         memswap(&inode1->i_blocks, &inode2->i_blocks,
72                   sizeof(inode1->i_blocks));
73         memswap(&inode1->i_bytes, &inode2->i_bytes, sizeof(inode1->i_bytes));
74         memswap(&inode1->i_atime, &inode2->i_atime, sizeof(inode1->i_atime));
75         memswap(&inode1->i_mtime, &inode2->i_mtime, sizeof(inode1->i_mtime));
76
77         memswap(ei1->i_data, ei2->i_data, sizeof(ei1->i_data));
78         memswap(&ei1->i_flags, &ei2->i_flags, sizeof(ei1->i_flags));
79         memswap(&ei1->i_disksize, &ei2->i_disksize, sizeof(ei1->i_disksize));
80         ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS);
81         ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS);
82         ext4_es_lru_del(inode1);
83         ext4_es_lru_del(inode2);
84
85         isize = i_size_read(inode1);
86         i_size_write(inode1, i_size_read(inode2));
87         i_size_write(inode2, isize);
88 }
89
90 /**
91  * Swap the information from the given @inode and the inode
92  * EXT4_BOOT_LOADER_INO. It will basically swap i_data and all other
93  * important fields of the inodes.
94  *
95  * @sb:         the super block of the filesystem
96  * @inode:      the inode to swap with EXT4_BOOT_LOADER_INO
97  *
98  */
99 static long swap_inode_boot_loader(struct super_block *sb,
100                                 struct inode *inode)
101 {
102         handle_t *handle;
103         int err;
104         struct inode *inode_bl;
105         struct ext4_inode_info *ei;
106         struct ext4_inode_info *ei_bl;
107         struct ext4_sb_info *sbi;
108
109         if (inode->i_nlink != 1 || !S_ISREG(inode->i_mode)) {
110                 err = -EINVAL;
111                 goto swap_boot_out;
112         }
113
114         if (!inode_owner_or_capable(inode) || !capable(CAP_SYS_ADMIN)) {
115                 err = -EPERM;
116                 goto swap_boot_out;
117         }
118
119         sbi = EXT4_SB(sb);
120         ei = EXT4_I(inode);
121
122         inode_bl = ext4_iget(sb, EXT4_BOOT_LOADER_INO);
123         if (IS_ERR(inode_bl)) {
124                 err = PTR_ERR(inode_bl);
125                 goto swap_boot_out;
126         }
127         ei_bl = EXT4_I(inode_bl);
128
129         filemap_flush(inode->i_mapping);
130         filemap_flush(inode_bl->i_mapping);
131
132         /* Protect orig inodes against a truncate and make sure,
133          * that only 1 swap_inode_boot_loader is running. */
134         ext4_inode_double_lock(inode, inode_bl);
135
136         truncate_inode_pages(&inode->i_data, 0);
137         truncate_inode_pages(&inode_bl->i_data, 0);
138
139         /* Wait for all existing dio workers */
140         ext4_inode_block_unlocked_dio(inode);
141         ext4_inode_block_unlocked_dio(inode_bl);
142         inode_dio_wait(inode);
143         inode_dio_wait(inode_bl);
144
145         handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2);
146         if (IS_ERR(handle)) {
147                 err = -EINVAL;
148                 goto journal_err_out;
149         }
150
151         /* Protect extent tree against block allocations via delalloc */
152         ext4_double_down_write_data_sem(inode, inode_bl);
153
154         if (inode_bl->i_nlink == 0) {
155                 /* this inode has never been used as a BOOT_LOADER */
156                 set_nlink(inode_bl, 1);
157                 i_uid_write(inode_bl, 0);
158                 i_gid_write(inode_bl, 0);
159                 inode_bl->i_flags = 0;
160                 ei_bl->i_flags = 0;
161                 inode_bl->i_version = 1;
162                 i_size_write(inode_bl, 0);
163                 inode_bl->i_mode = S_IFREG;
164                 if (EXT4_HAS_INCOMPAT_FEATURE(sb,
165                                               EXT4_FEATURE_INCOMPAT_EXTENTS)) {
166                         ext4_set_inode_flag(inode_bl, EXT4_INODE_EXTENTS);
167                         ext4_ext_tree_init(handle, inode_bl);
168                 } else
169                         memset(ei_bl->i_data, 0, sizeof(ei_bl->i_data));
170         }
171
172         swap_inode_data(inode, inode_bl);
173
174         inode->i_ctime = inode_bl->i_ctime = ext4_current_time(inode);
175
176         spin_lock(&sbi->s_next_gen_lock);
177         inode->i_generation = sbi->s_next_generation++;
178         inode_bl->i_generation = sbi->s_next_generation++;
179         spin_unlock(&sbi->s_next_gen_lock);
180
181         ext4_discard_preallocations(inode);
182
183         err = ext4_mark_inode_dirty(handle, inode);
184         if (err < 0) {
185                 ext4_warning(inode->i_sb,
186                         "couldn't mark inode #%lu dirty (err %d)",
187                         inode->i_ino, err);
188                 /* Revert all changes: */
189                 swap_inode_data(inode, inode_bl);
190         } else {
191                 err = ext4_mark_inode_dirty(handle, inode_bl);
192                 if (err < 0) {
193                         ext4_warning(inode_bl->i_sb,
194                                 "couldn't mark inode #%lu dirty (err %d)",
195                                 inode_bl->i_ino, err);
196                         /* Revert all changes: */
197                         swap_inode_data(inode, inode_bl);
198                         ext4_mark_inode_dirty(handle, inode);
199                 }
200         }
201
202         ext4_journal_stop(handle);
203
204         ext4_double_up_write_data_sem(inode, inode_bl);
205
206 journal_err_out:
207         ext4_inode_resume_unlocked_dio(inode);
208         ext4_inode_resume_unlocked_dio(inode_bl);
209
210         ext4_inode_double_unlock(inode, inode_bl);
211
212         iput(inode_bl);
213
214 swap_boot_out:
215         return err;
216 }
217
218 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
219 {
220         struct inode *inode = file_inode(filp);
221         struct super_block *sb = inode->i_sb;
222         struct ext4_inode_info *ei = EXT4_I(inode);
223         unsigned int flags;
224
225         ext4_debug("cmd = %u, arg = %lu\n", cmd, arg);
226
227         switch (cmd) {
228         case EXT4_IOC_GETFLAGS:
229                 ext4_get_inode_flags(ei);
230                 flags = ei->i_flags & EXT4_FL_USER_VISIBLE;
231                 return put_user(flags, (int __user *) arg);
232         case EXT4_IOC_SETFLAGS: {
233                 handle_t *handle = NULL;
234                 int err, migrate = 0;
235                 struct ext4_iloc iloc;
236                 unsigned int oldflags, mask, i;
237                 unsigned int jflag;
238
239                 if (!inode_owner_or_capable(inode))
240                         return -EACCES;
241
242                 if (get_user(flags, (int __user *) arg))
243                         return -EFAULT;
244
245                 err = mnt_want_write_file(filp);
246                 if (err)
247                         return err;
248
249                 flags = ext4_mask_flags(inode->i_mode, flags);
250
251                 err = -EPERM;
252                 mutex_lock(&inode->i_mutex);
253                 /* Is it quota file? Do not allow user to mess with it */
254                 if (IS_NOQUOTA(inode))
255                         goto flags_out;
256
257                 oldflags = ei->i_flags;
258
259                 /* The JOURNAL_DATA flag is modifiable only by root */
260                 jflag = flags & EXT4_JOURNAL_DATA_FL;
261
262                 /*
263                  * The IMMUTABLE and APPEND_ONLY flags can only be changed by
264                  * the relevant capability.
265                  *
266                  * This test looks nicer. Thanks to Pauline Middelink
267                  */
268                 if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
269                         if (!capable(CAP_LINUX_IMMUTABLE))
270                                 goto flags_out;
271                 }
272
273                 /*
274                  * The JOURNAL_DATA flag can only be changed by
275                  * the relevant capability.
276                  */
277                 if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
278                         if (!capable(CAP_SYS_RESOURCE))
279                                 goto flags_out;
280                 }
281                 if ((flags ^ oldflags) & EXT4_EXTENTS_FL)
282                         migrate = 1;
283
284                 if (flags & EXT4_EOFBLOCKS_FL) {
285                         /* we don't support adding EOFBLOCKS flag */
286                         if (!(oldflags & EXT4_EOFBLOCKS_FL)) {
287                                 err = -EOPNOTSUPP;
288                                 goto flags_out;
289                         }
290                 } else if (oldflags & EXT4_EOFBLOCKS_FL)
291                         ext4_truncate(inode);
292
293                 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
294                 if (IS_ERR(handle)) {
295                         err = PTR_ERR(handle);
296                         goto flags_out;
297                 }
298                 if (IS_SYNC(inode))
299                         ext4_handle_sync(handle);
300                 err = ext4_reserve_inode_write(handle, inode, &iloc);
301                 if (err)
302                         goto flags_err;
303
304                 for (i = 0, mask = 1; i < 32; i++, mask <<= 1) {
305                         if (!(mask & EXT4_FL_USER_MODIFIABLE))
306                                 continue;
307                         if (mask & flags)
308                                 ext4_set_inode_flag(inode, i);
309                         else
310                                 ext4_clear_inode_flag(inode, i);
311                 }
312
313                 ext4_set_inode_flags(inode);
314                 inode->i_ctime = ext4_current_time(inode);
315
316                 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
317 flags_err:
318                 ext4_journal_stop(handle);
319                 if (err)
320                         goto flags_out;
321
322                 if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL))
323                         err = ext4_change_inode_journal_flag(inode, jflag);
324                 if (err)
325                         goto flags_out;
326                 if (migrate) {
327                         if (flags & EXT4_EXTENTS_FL)
328                                 err = ext4_ext_migrate(inode);
329                         else
330                                 err = ext4_ind_migrate(inode);
331                 }
332
333 flags_out:
334                 mutex_unlock(&inode->i_mutex);
335                 mnt_drop_write_file(filp);
336                 return err;
337         }
338         case EXT4_IOC_GETVERSION:
339         case EXT4_IOC_GETVERSION_OLD:
340                 return put_user(inode->i_generation, (int __user *) arg);
341         case EXT4_IOC_SETVERSION:
342         case EXT4_IOC_SETVERSION_OLD: {
343                 handle_t *handle;
344                 struct ext4_iloc iloc;
345                 __u32 generation;
346                 int err;
347
348                 if (!inode_owner_or_capable(inode))
349                         return -EPERM;
350
351                 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
352                                 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
353                         ext4_warning(sb, "Setting inode version is not "
354                                      "supported with metadata_csum enabled.");
355                         return -ENOTTY;
356                 }
357
358                 err = mnt_want_write_file(filp);
359                 if (err)
360                         return err;
361                 if (get_user(generation, (int __user *) arg)) {
362                         err = -EFAULT;
363                         goto setversion_out;
364                 }
365
366                 mutex_lock(&inode->i_mutex);
367                 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
368                 if (IS_ERR(handle)) {
369                         err = PTR_ERR(handle);
370                         goto unlock_out;
371                 }
372                 err = ext4_reserve_inode_write(handle, inode, &iloc);
373                 if (err == 0) {
374                         inode->i_ctime = ext4_current_time(inode);
375                         inode->i_generation = generation;
376                         err = ext4_mark_iloc_dirty(handle, inode, &iloc);
377                 }
378                 ext4_journal_stop(handle);
379
380 unlock_out:
381                 mutex_unlock(&inode->i_mutex);
382 setversion_out:
383                 mnt_drop_write_file(filp);
384                 return err;
385         }
386         case EXT4_IOC_GROUP_EXTEND: {
387                 ext4_fsblk_t n_blocks_count;
388                 int err, err2=0;
389
390                 err = ext4_resize_begin(sb);
391                 if (err)
392                         return err;
393
394                 if (get_user(n_blocks_count, (__u32 __user *)arg)) {
395                         err = -EFAULT;
396                         goto group_extend_out;
397                 }
398
399                 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
400                                EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
401                         ext4_msg(sb, KERN_ERR,
402                                  "Online resizing not supported with bigalloc");
403                         err = -EOPNOTSUPP;
404                         goto group_extend_out;
405                 }
406
407                 err = mnt_want_write_file(filp);
408                 if (err)
409                         goto group_extend_out;
410
411                 err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count);
412                 if (EXT4_SB(sb)->s_journal) {
413                         jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
414                         err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
415                         jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
416                 }
417                 if (err == 0)
418                         err = err2;
419                 mnt_drop_write_file(filp);
420 group_extend_out:
421                 ext4_resize_end(sb);
422                 return err;
423         }
424
425         case EXT4_IOC_MOVE_EXT: {
426                 struct move_extent me;
427                 struct fd donor;
428                 int err;
429
430                 if (!(filp->f_mode & FMODE_READ) ||
431                     !(filp->f_mode & FMODE_WRITE))
432                         return -EBADF;
433
434                 if (copy_from_user(&me,
435                         (struct move_extent __user *)arg, sizeof(me)))
436                         return -EFAULT;
437                 me.moved_len = 0;
438
439                 donor = fdget(me.donor_fd);
440                 if (!donor.file)
441                         return -EBADF;
442
443                 if (!(donor.file->f_mode & FMODE_WRITE)) {
444                         err = -EBADF;
445                         goto mext_out;
446                 }
447
448                 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
449                                EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
450                         ext4_msg(sb, KERN_ERR,
451                                  "Online defrag not supported with bigalloc");
452                         err = -EOPNOTSUPP;
453                         goto mext_out;
454                 }
455
456                 err = mnt_want_write_file(filp);
457                 if (err)
458                         goto mext_out;
459
460                 err = ext4_move_extents(filp, donor.file, me.orig_start,
461                                         me.donor_start, me.len, &me.moved_len);
462                 mnt_drop_write_file(filp);
463
464                 if (copy_to_user((struct move_extent __user *)arg,
465                                  &me, sizeof(me)))
466                         err = -EFAULT;
467 mext_out:
468                 fdput(donor);
469                 return err;
470         }
471
472         case EXT4_IOC_GROUP_ADD: {
473                 struct ext4_new_group_data input;
474                 int err, err2=0;
475
476                 err = ext4_resize_begin(sb);
477                 if (err)
478                         return err;
479
480                 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
481                                 sizeof(input))) {
482                         err = -EFAULT;
483                         goto group_add_out;
484                 }
485
486                 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
487                                EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
488                         ext4_msg(sb, KERN_ERR,
489                                  "Online resizing not supported with bigalloc");
490                         err = -EOPNOTSUPP;
491                         goto group_add_out;
492                 }
493
494                 err = mnt_want_write_file(filp);
495                 if (err)
496                         goto group_add_out;
497
498                 err = ext4_group_add(sb, &input);
499                 if (EXT4_SB(sb)->s_journal) {
500                         jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
501                         err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
502                         jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
503                 }
504                 if (err == 0)
505                         err = err2;
506                 mnt_drop_write_file(filp);
507                 if (!err && ext4_has_group_desc_csum(sb) &&
508                     test_opt(sb, INIT_INODE_TABLE))
509                         err = ext4_register_li_request(sb, input.group);
510 group_add_out:
511                 ext4_resize_end(sb);
512                 return err;
513         }
514
515         case EXT4_IOC_MIGRATE:
516         {
517                 int err;
518                 if (!inode_owner_or_capable(inode))
519                         return -EACCES;
520
521                 err = mnt_want_write_file(filp);
522                 if (err)
523                         return err;
524                 /*
525                  * inode_mutex prevent write and truncate on the file.
526                  * Read still goes through. We take i_data_sem in
527                  * ext4_ext_swap_inode_data before we switch the
528                  * inode format to prevent read.
529                  */
530                 mutex_lock(&(inode->i_mutex));
531                 err = ext4_ext_migrate(inode);
532                 mutex_unlock(&(inode->i_mutex));
533                 mnt_drop_write_file(filp);
534                 return err;
535         }
536
537         case EXT4_IOC_ALLOC_DA_BLKS:
538         {
539                 int err;
540                 if (!inode_owner_or_capable(inode))
541                         return -EACCES;
542
543                 err = mnt_want_write_file(filp);
544                 if (err)
545                         return err;
546                 err = ext4_alloc_da_blocks(inode);
547                 mnt_drop_write_file(filp);
548                 return err;
549         }
550
551         case EXT4_IOC_SWAP_BOOT:
552                 if (!(filp->f_mode & FMODE_WRITE))
553                         return -EBADF;
554                 return swap_inode_boot_loader(sb, inode);
555
556         case EXT4_IOC_RESIZE_FS: {
557                 ext4_fsblk_t n_blocks_count;
558                 int err = 0, err2 = 0;
559                 ext4_group_t o_group = EXT4_SB(sb)->s_groups_count;
560
561                 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
562                                EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
563                         ext4_msg(sb, KERN_ERR,
564                                  "Online resizing not (yet) supported with bigalloc");
565                         return -EOPNOTSUPP;
566                 }
567
568                 if (copy_from_user(&n_blocks_count, (__u64 __user *)arg,
569                                    sizeof(__u64))) {
570                         return -EFAULT;
571                 }
572
573                 err = ext4_resize_begin(sb);
574                 if (err)
575                         return err;
576
577                 err = mnt_want_write_file(filp);
578                 if (err)
579                         goto resizefs_out;
580
581                 err = ext4_resize_fs(sb, n_blocks_count);
582                 if (EXT4_SB(sb)->s_journal) {
583                         jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
584                         err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
585                         jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
586                 }
587                 if (err == 0)
588                         err = err2;
589                 mnt_drop_write_file(filp);
590                 if (!err && (o_group > EXT4_SB(sb)->s_groups_count) &&
591                     ext4_has_group_desc_csum(sb) &&
592                     test_opt(sb, INIT_INODE_TABLE))
593                         err = ext4_register_li_request(sb, o_group);
594
595 resizefs_out:
596                 ext4_resize_end(sb);
597                 return err;
598         }
599
600         case FITRIM:
601         {
602                 struct request_queue *q = bdev_get_queue(sb->s_bdev);
603                 struct fstrim_range range;
604                 int ret = 0;
605
606                 if (!capable(CAP_SYS_ADMIN))
607                         return -EPERM;
608
609                 if (!blk_queue_discard(q))
610                         return -EOPNOTSUPP;
611
612                 if (copy_from_user(&range, (struct fstrim_range __user *)arg,
613                     sizeof(range)))
614                         return -EFAULT;
615
616                 range.minlen = max((unsigned int)range.minlen,
617                                    q->limits.discard_granularity);
618                 ret = ext4_trim_fs(sb, &range);
619                 if (ret < 0)
620                         return ret;
621
622                 if (copy_to_user((struct fstrim_range __user *)arg, &range,
623                     sizeof(range)))
624                         return -EFAULT;
625
626                 return 0;
627         }
628
629         default:
630                 return -ENOTTY;
631         }
632 }
633
634 #ifdef CONFIG_COMPAT
635 long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
636 {
637         /* These are just misnamed, they actually get/put from/to user an int */
638         switch (cmd) {
639         case EXT4_IOC32_GETFLAGS:
640                 cmd = EXT4_IOC_GETFLAGS;
641                 break;
642         case EXT4_IOC32_SETFLAGS:
643                 cmd = EXT4_IOC_SETFLAGS;
644                 break;
645         case EXT4_IOC32_GETVERSION:
646                 cmd = EXT4_IOC_GETVERSION;
647                 break;
648         case EXT4_IOC32_SETVERSION:
649                 cmd = EXT4_IOC_SETVERSION;
650                 break;
651         case EXT4_IOC32_GROUP_EXTEND:
652                 cmd = EXT4_IOC_GROUP_EXTEND;
653                 break;
654         case EXT4_IOC32_GETVERSION_OLD:
655                 cmd = EXT4_IOC_GETVERSION_OLD;
656                 break;
657         case EXT4_IOC32_SETVERSION_OLD:
658                 cmd = EXT4_IOC_SETVERSION_OLD;
659                 break;
660         case EXT4_IOC32_GETRSVSZ:
661                 cmd = EXT4_IOC_GETRSVSZ;
662                 break;
663         case EXT4_IOC32_SETRSVSZ:
664                 cmd = EXT4_IOC_SETRSVSZ;
665                 break;
666         case EXT4_IOC32_GROUP_ADD: {
667                 struct compat_ext4_new_group_input __user *uinput;
668                 struct ext4_new_group_input input;
669                 mm_segment_t old_fs;
670                 int err;
671
672                 uinput = compat_ptr(arg);
673                 err = get_user(input.group, &uinput->group);
674                 err |= get_user(input.block_bitmap, &uinput->block_bitmap);
675                 err |= get_user(input.inode_bitmap, &uinput->inode_bitmap);
676                 err |= get_user(input.inode_table, &uinput->inode_table);
677                 err |= get_user(input.blocks_count, &uinput->blocks_count);
678                 err |= get_user(input.reserved_blocks,
679                                 &uinput->reserved_blocks);
680                 if (err)
681                         return -EFAULT;
682                 old_fs = get_fs();
683                 set_fs(KERNEL_DS);
684                 err = ext4_ioctl(file, EXT4_IOC_GROUP_ADD,
685                                  (unsigned long) &input);
686                 set_fs(old_fs);
687                 return err;
688         }
689         case EXT4_IOC_MOVE_EXT:
690         case FITRIM:
691         case EXT4_IOC_RESIZE_FS:
692                 break;
693         default:
694                 return -ENOIOCTLCMD;
695         }
696         return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
697 }
698 #endif