ioctl.c 17 KB

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