ioctl.c 17 KB

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