ioctl.c 17 KB

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