ioctl.c 17 KB

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