ioctl.c 17 KB

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