ioctl.c 17 KB

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