ioctl.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/fs/ext4/ioctl.c
  4. *
  5. * Copyright (C) 1993, 1994, 1995
  6. * Remy Card (card@masi.ibp.fr)
  7. * Laboratoire MASI - Institut Blaise Pascal
  8. * Universite Pierre et Marie Curie (Paris VI)
  9. */
  10. #include <linux/fs.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 <linux/quotaops.h>
  17. #include <linux/random.h>
  18. #include <linux/uuid.h>
  19. #include <linux/uaccess.h>
  20. #include <linux/delay.h>
  21. #include <linux/iversion.h>
  22. #include "ext4_jbd2.h"
  23. #include "ext4.h"
  24. #include <linux/fsmap.h>
  25. #include "fsmap.h"
  26. #include <trace/events/ext4.h>
  27. /**
  28. * Swap memory between @a and @b for @len bytes.
  29. *
  30. * @a: pointer to first memory area
  31. * @b: pointer to second memory area
  32. * @len: number of bytes to swap
  33. *
  34. */
  35. static void memswap(void *a, void *b, size_t len)
  36. {
  37. unsigned char *ap, *bp;
  38. ap = (unsigned char *)a;
  39. bp = (unsigned char *)b;
  40. while (len-- > 0) {
  41. swap(*ap, *bp);
  42. ap++;
  43. bp++;
  44. }
  45. }
  46. /**
  47. * Swap i_data and associated attributes between @inode1 and @inode2.
  48. * This function is used for the primary swap between inode1 and inode2
  49. * and also to revert this primary swap in case of errors.
  50. *
  51. * Therefore you have to make sure, that calling this method twice
  52. * will revert all changes.
  53. *
  54. * @inode1: pointer to first inode
  55. * @inode2: pointer to second inode
  56. */
  57. static void swap_inode_data(struct inode *inode1, struct inode *inode2)
  58. {
  59. loff_t isize;
  60. struct ext4_inode_info *ei1;
  61. struct ext4_inode_info *ei2;
  62. unsigned long tmp;
  63. ei1 = EXT4_I(inode1);
  64. ei2 = EXT4_I(inode2);
  65. swap(inode1->i_version, inode2->i_version);
  66. swap(inode1->i_atime, inode2->i_atime);
  67. swap(inode1->i_mtime, inode2->i_mtime);
  68. memswap(ei1->i_data, ei2->i_data, sizeof(ei1->i_data));
  69. tmp = ei1->i_flags & EXT4_FL_SHOULD_SWAP;
  70. ei1->i_flags = (ei2->i_flags & EXT4_FL_SHOULD_SWAP) |
  71. (ei1->i_flags & ~EXT4_FL_SHOULD_SWAP);
  72. ei2->i_flags = tmp | (ei2->i_flags & ~EXT4_FL_SHOULD_SWAP);
  73. swap(ei1->i_disksize, ei2->i_disksize);
  74. ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS);
  75. ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS);
  76. isize = i_size_read(inode1);
  77. i_size_write(inode1, i_size_read(inode2));
  78. i_size_write(inode2, isize);
  79. }
  80. static void reset_inode_seed(struct inode *inode)
  81. {
  82. struct ext4_inode_info *ei = EXT4_I(inode);
  83. struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
  84. __le32 inum = cpu_to_le32(inode->i_ino);
  85. __le32 gen = cpu_to_le32(inode->i_generation);
  86. __u32 csum;
  87. if (!ext4_has_metadata_csum(inode->i_sb))
  88. return;
  89. csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&inum, sizeof(inum));
  90. ei->i_csum_seed = ext4_chksum(sbi, csum, (__u8 *)&gen, sizeof(gen));
  91. }
  92. /**
  93. * Swap the information from the given @inode and the inode
  94. * EXT4_BOOT_LOADER_INO. It will basically swap i_data and all other
  95. * important fields of the inodes.
  96. *
  97. * @sb: the super block of the filesystem
  98. * @inode: the inode to swap with EXT4_BOOT_LOADER_INO
  99. *
  100. */
  101. static long swap_inode_boot_loader(struct super_block *sb,
  102. struct inode *inode)
  103. {
  104. handle_t *handle;
  105. int err;
  106. struct inode *inode_bl;
  107. struct ext4_inode_info *ei_bl;
  108. qsize_t size, size_bl, diff;
  109. blkcnt_t blocks;
  110. unsigned short bytes;
  111. inode_bl = ext4_iget(sb, EXT4_BOOT_LOADER_INO, EXT4_IGET_SPECIAL);
  112. if (IS_ERR(inode_bl))
  113. return PTR_ERR(inode_bl);
  114. ei_bl = EXT4_I(inode_bl);
  115. /* Protect orig inodes against a truncate and make sure,
  116. * that only 1 swap_inode_boot_loader is running. */
  117. lock_two_nondirectories(inode, inode_bl);
  118. if (inode->i_nlink != 1 || !S_ISREG(inode->i_mode) ||
  119. IS_SWAPFILE(inode) || IS_ENCRYPTED(inode) ||
  120. (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) ||
  121. ext4_has_inline_data(inode)) {
  122. err = -EINVAL;
  123. goto journal_err_out;
  124. }
  125. if (IS_RDONLY(inode) || IS_APPEND(inode) || IS_IMMUTABLE(inode) ||
  126. !inode_owner_or_capable(inode) || !capable(CAP_SYS_ADMIN)) {
  127. err = -EPERM;
  128. goto journal_err_out;
  129. }
  130. down_write(&EXT4_I(inode)->i_mmap_sem);
  131. err = filemap_write_and_wait(inode->i_mapping);
  132. if (err)
  133. goto err_out;
  134. err = filemap_write_and_wait(inode_bl->i_mapping);
  135. if (err)
  136. goto err_out;
  137. /* Wait for all existing dio workers */
  138. inode_dio_wait(inode);
  139. inode_dio_wait(inode_bl);
  140. truncate_inode_pages(&inode->i_data, 0);
  141. truncate_inode_pages(&inode_bl->i_data, 0);
  142. handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2);
  143. if (IS_ERR(handle)) {
  144. err = -EINVAL;
  145. goto err_out;
  146. }
  147. /* Protect extent tree against block allocations via delalloc */
  148. ext4_double_down_write_data_sem(inode, inode_bl);
  149. if (inode_bl->i_nlink == 0) {
  150. /* this inode has never been used as a BOOT_LOADER */
  151. set_nlink(inode_bl, 1);
  152. i_uid_write(inode_bl, 0);
  153. i_gid_write(inode_bl, 0);
  154. inode_bl->i_flags = 0;
  155. ei_bl->i_flags = 0;
  156. inode_set_iversion(inode_bl, 1);
  157. i_size_write(inode_bl, 0);
  158. inode_bl->i_mode = S_IFREG;
  159. if (ext4_has_feature_extents(sb)) {
  160. ext4_set_inode_flag(inode_bl, EXT4_INODE_EXTENTS);
  161. ext4_ext_tree_init(handle, inode_bl);
  162. } else
  163. memset(ei_bl->i_data, 0, sizeof(ei_bl->i_data));
  164. }
  165. err = dquot_initialize(inode);
  166. if (err)
  167. goto err_out1;
  168. size = (qsize_t)(inode->i_blocks) * (1 << 9) + inode->i_bytes;
  169. size_bl = (qsize_t)(inode_bl->i_blocks) * (1 << 9) + inode_bl->i_bytes;
  170. diff = size - size_bl;
  171. swap_inode_data(inode, inode_bl);
  172. inode->i_ctime = inode_bl->i_ctime = current_time(inode);
  173. inode->i_generation = prandom_u32();
  174. inode_bl->i_generation = prandom_u32();
  175. reset_inode_seed(inode);
  176. reset_inode_seed(inode_bl);
  177. ext4_discard_preallocations(inode);
  178. err = ext4_mark_inode_dirty(handle, inode);
  179. if (err < 0) {
  180. /* No need to update quota information. */
  181. ext4_warning(inode->i_sb,
  182. "couldn't mark inode #%lu dirty (err %d)",
  183. inode->i_ino, err);
  184. /* Revert all changes: */
  185. swap_inode_data(inode, inode_bl);
  186. ext4_mark_inode_dirty(handle, inode);
  187. goto err_out1;
  188. }
  189. blocks = inode_bl->i_blocks;
  190. bytes = inode_bl->i_bytes;
  191. inode_bl->i_blocks = inode->i_blocks;
  192. inode_bl->i_bytes = inode->i_bytes;
  193. err = ext4_mark_inode_dirty(handle, inode_bl);
  194. if (err < 0) {
  195. /* No need to update quota information. */
  196. ext4_warning(inode_bl->i_sb,
  197. "couldn't mark inode #%lu dirty (err %d)",
  198. inode_bl->i_ino, err);
  199. goto revert;
  200. }
  201. /* Bootloader inode should not be counted into quota information. */
  202. if (diff > 0)
  203. dquot_free_space(inode, diff);
  204. else
  205. err = dquot_alloc_space(inode, -1 * diff);
  206. if (err < 0) {
  207. revert:
  208. /* Revert all changes: */
  209. inode_bl->i_blocks = blocks;
  210. inode_bl->i_bytes = bytes;
  211. swap_inode_data(inode, inode_bl);
  212. ext4_mark_inode_dirty(handle, inode);
  213. ext4_mark_inode_dirty(handle, inode_bl);
  214. }
  215. err_out1:
  216. ext4_journal_stop(handle);
  217. ext4_double_up_write_data_sem(inode, inode_bl);
  218. err_out:
  219. up_write(&EXT4_I(inode)->i_mmap_sem);
  220. journal_err_out:
  221. unlock_two_nondirectories(inode, inode_bl);
  222. iput(inode_bl);
  223. return err;
  224. }
  225. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  226. static int uuid_is_zero(__u8 u[16])
  227. {
  228. int i;
  229. for (i = 0; i < 16; i++)
  230. if (u[i])
  231. return 0;
  232. return 1;
  233. }
  234. #endif
  235. /*
  236. * If immutable is set and we are not clearing it, we're not allowed to change
  237. * anything else in the inode. Don't error out if we're only trying to set
  238. * immutable on an immutable file.
  239. */
  240. static int ext4_ioctl_check_immutable(struct inode *inode, __u32 new_projid,
  241. unsigned int flags)
  242. {
  243. struct ext4_inode_info *ei = EXT4_I(inode);
  244. unsigned int oldflags = ei->i_flags;
  245. if (!(oldflags & EXT4_IMMUTABLE_FL) || !(flags & EXT4_IMMUTABLE_FL))
  246. return 0;
  247. if ((oldflags & ~EXT4_IMMUTABLE_FL) != (flags & ~EXT4_IMMUTABLE_FL))
  248. return -EPERM;
  249. if (ext4_has_feature_project(inode->i_sb) &&
  250. __kprojid_val(ei->i_projid) != new_projid)
  251. return -EPERM;
  252. return 0;
  253. }
  254. static int ext4_ioctl_setflags(struct inode *inode,
  255. unsigned int flags)
  256. {
  257. struct ext4_inode_info *ei = EXT4_I(inode);
  258. handle_t *handle = NULL;
  259. int err = -EPERM, migrate = 0;
  260. struct ext4_iloc iloc;
  261. unsigned int oldflags, mask, i;
  262. unsigned int jflag;
  263. /* Is it quota file? Do not allow user to mess with it */
  264. if (ext4_is_quota_file(inode))
  265. goto flags_out;
  266. oldflags = ei->i_flags;
  267. /* The JOURNAL_DATA flag is modifiable only by root */
  268. jflag = flags & EXT4_JOURNAL_DATA_FL;
  269. /*
  270. * The IMMUTABLE and APPEND_ONLY flags can only be changed by
  271. * the relevant capability.
  272. *
  273. * This test looks nicer. Thanks to Pauline Middelink
  274. */
  275. if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
  276. if (!capable(CAP_LINUX_IMMUTABLE))
  277. goto flags_out;
  278. }
  279. /*
  280. * The JOURNAL_DATA flag can only be changed by
  281. * the relevant capability.
  282. */
  283. if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
  284. if (!capable(CAP_SYS_RESOURCE))
  285. goto flags_out;
  286. }
  287. if ((flags ^ oldflags) & EXT4_EXTENTS_FL)
  288. migrate = 1;
  289. if (flags & EXT4_EOFBLOCKS_FL) {
  290. /* we don't support adding EOFBLOCKS flag */
  291. if (!(oldflags & EXT4_EOFBLOCKS_FL)) {
  292. err = -EOPNOTSUPP;
  293. goto flags_out;
  294. }
  295. } else if (oldflags & EXT4_EOFBLOCKS_FL) {
  296. err = ext4_truncate(inode);
  297. if (err)
  298. goto flags_out;
  299. }
  300. /*
  301. * Wait for all pending directio and then flush all the dirty pages
  302. * for this file. The flush marks all the pages readonly, so any
  303. * subsequent attempt to write to the file (particularly mmap pages)
  304. * will come through the filesystem and fail.
  305. */
  306. if (S_ISREG(inode->i_mode) && !IS_IMMUTABLE(inode) &&
  307. (flags & EXT4_IMMUTABLE_FL)) {
  308. inode_dio_wait(inode);
  309. err = filemap_write_and_wait(inode->i_mapping);
  310. if (err)
  311. goto flags_out;
  312. }
  313. handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
  314. if (IS_ERR(handle)) {
  315. err = PTR_ERR(handle);
  316. goto flags_out;
  317. }
  318. if (IS_SYNC(inode))
  319. ext4_handle_sync(handle);
  320. err = ext4_reserve_inode_write(handle, inode, &iloc);
  321. if (err)
  322. goto flags_err;
  323. for (i = 0, mask = 1; i < 32; i++, mask <<= 1) {
  324. if (!(mask & EXT4_FL_USER_MODIFIABLE))
  325. continue;
  326. /* These flags get special treatment later */
  327. if (mask == EXT4_JOURNAL_DATA_FL || mask == EXT4_EXTENTS_FL)
  328. continue;
  329. if (mask & flags)
  330. ext4_set_inode_flag(inode, i);
  331. else
  332. ext4_clear_inode_flag(inode, i);
  333. }
  334. ext4_set_inode_flags(inode);
  335. inode->i_ctime = current_time(inode);
  336. err = ext4_mark_iloc_dirty(handle, inode, &iloc);
  337. flags_err:
  338. ext4_journal_stop(handle);
  339. if (err)
  340. goto flags_out;
  341. if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
  342. /*
  343. * Changes to the journaling mode can cause unsafe changes to
  344. * S_DAX if we are using the DAX mount option.
  345. */
  346. if (test_opt(inode->i_sb, DAX)) {
  347. err = -EBUSY;
  348. goto flags_out;
  349. }
  350. err = ext4_change_inode_journal_flag(inode, jflag);
  351. if (err)
  352. goto flags_out;
  353. }
  354. if (migrate) {
  355. if (flags & EXT4_EXTENTS_FL)
  356. err = ext4_ext_migrate(inode);
  357. else
  358. err = ext4_ind_migrate(inode);
  359. }
  360. flags_out:
  361. return err;
  362. }
  363. #ifdef CONFIG_QUOTA
  364. static int ext4_ioctl_setproject(struct file *filp, __u32 projid)
  365. {
  366. struct inode *inode = file_inode(filp);
  367. struct super_block *sb = inode->i_sb;
  368. struct ext4_inode_info *ei = EXT4_I(inode);
  369. int err, rc;
  370. handle_t *handle;
  371. kprojid_t kprojid;
  372. struct ext4_iloc iloc;
  373. struct ext4_inode *raw_inode;
  374. struct dquot *transfer_to[MAXQUOTAS] = { };
  375. if (!ext4_has_feature_project(sb)) {
  376. if (projid != EXT4_DEF_PROJID)
  377. return -EOPNOTSUPP;
  378. else
  379. return 0;
  380. }
  381. if (EXT4_INODE_SIZE(sb) <= EXT4_GOOD_OLD_INODE_SIZE)
  382. return -EOPNOTSUPP;
  383. kprojid = make_kprojid(&init_user_ns, (projid_t)projid);
  384. if (projid_eq(kprojid, EXT4_I(inode)->i_projid))
  385. return 0;
  386. err = -EPERM;
  387. /* Is it quota file? Do not allow user to mess with it */
  388. if (ext4_is_quota_file(inode))
  389. return err;
  390. err = ext4_get_inode_loc(inode, &iloc);
  391. if (err)
  392. return err;
  393. raw_inode = ext4_raw_inode(&iloc);
  394. if (!EXT4_FITS_IN_INODE(raw_inode, ei, i_projid)) {
  395. err = ext4_expand_extra_isize(inode,
  396. EXT4_SB(sb)->s_want_extra_isize,
  397. &iloc);
  398. if (err)
  399. return err;
  400. } else {
  401. brelse(iloc.bh);
  402. }
  403. err = dquot_initialize(inode);
  404. if (err)
  405. return err;
  406. handle = ext4_journal_start(inode, EXT4_HT_QUOTA,
  407. EXT4_QUOTA_INIT_BLOCKS(sb) +
  408. EXT4_QUOTA_DEL_BLOCKS(sb) + 3);
  409. if (IS_ERR(handle))
  410. return PTR_ERR(handle);
  411. err = ext4_reserve_inode_write(handle, inode, &iloc);
  412. if (err)
  413. goto out_stop;
  414. transfer_to[PRJQUOTA] = dqget(sb, make_kqid_projid(kprojid));
  415. if (!IS_ERR(transfer_to[PRJQUOTA])) {
  416. /* __dquot_transfer() calls back ext4_get_inode_usage() which
  417. * counts xattr inode references.
  418. */
  419. down_read(&EXT4_I(inode)->xattr_sem);
  420. err = __dquot_transfer(inode, transfer_to);
  421. up_read(&EXT4_I(inode)->xattr_sem);
  422. dqput(transfer_to[PRJQUOTA]);
  423. if (err)
  424. goto out_dirty;
  425. }
  426. EXT4_I(inode)->i_projid = kprojid;
  427. inode->i_ctime = current_time(inode);
  428. out_dirty:
  429. rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
  430. if (!err)
  431. err = rc;
  432. out_stop:
  433. ext4_journal_stop(handle);
  434. return err;
  435. }
  436. #else
  437. static int ext4_ioctl_setproject(struct file *filp, __u32 projid)
  438. {
  439. if (projid != EXT4_DEF_PROJID)
  440. return -EOPNOTSUPP;
  441. return 0;
  442. }
  443. #endif
  444. /* Transfer internal flags to xflags */
  445. static inline __u32 ext4_iflags_to_xflags(unsigned long iflags)
  446. {
  447. __u32 xflags = 0;
  448. if (iflags & EXT4_SYNC_FL)
  449. xflags |= FS_XFLAG_SYNC;
  450. if (iflags & EXT4_IMMUTABLE_FL)
  451. xflags |= FS_XFLAG_IMMUTABLE;
  452. if (iflags & EXT4_APPEND_FL)
  453. xflags |= FS_XFLAG_APPEND;
  454. if (iflags & EXT4_NODUMP_FL)
  455. xflags |= FS_XFLAG_NODUMP;
  456. if (iflags & EXT4_NOATIME_FL)
  457. xflags |= FS_XFLAG_NOATIME;
  458. if (iflags & EXT4_PROJINHERIT_FL)
  459. xflags |= FS_XFLAG_PROJINHERIT;
  460. return xflags;
  461. }
  462. #define EXT4_SUPPORTED_FS_XFLAGS (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | \
  463. FS_XFLAG_APPEND | FS_XFLAG_NODUMP | \
  464. FS_XFLAG_NOATIME | FS_XFLAG_PROJINHERIT)
  465. /* Transfer xflags flags to internal */
  466. static inline unsigned long ext4_xflags_to_iflags(__u32 xflags)
  467. {
  468. unsigned long iflags = 0;
  469. if (xflags & FS_XFLAG_SYNC)
  470. iflags |= EXT4_SYNC_FL;
  471. if (xflags & FS_XFLAG_IMMUTABLE)
  472. iflags |= EXT4_IMMUTABLE_FL;
  473. if (xflags & FS_XFLAG_APPEND)
  474. iflags |= EXT4_APPEND_FL;
  475. if (xflags & FS_XFLAG_NODUMP)
  476. iflags |= EXT4_NODUMP_FL;
  477. if (xflags & FS_XFLAG_NOATIME)
  478. iflags |= EXT4_NOATIME_FL;
  479. if (xflags & FS_XFLAG_PROJINHERIT)
  480. iflags |= EXT4_PROJINHERIT_FL;
  481. return iflags;
  482. }
  483. static int ext4_shutdown(struct super_block *sb, unsigned long arg)
  484. {
  485. struct ext4_sb_info *sbi = EXT4_SB(sb);
  486. __u32 flags;
  487. if (!capable(CAP_SYS_ADMIN))
  488. return -EPERM;
  489. if (get_user(flags, (__u32 __user *)arg))
  490. return -EFAULT;
  491. if (flags > EXT4_GOING_FLAGS_NOLOGFLUSH)
  492. return -EINVAL;
  493. if (ext4_forced_shutdown(sbi))
  494. return 0;
  495. ext4_msg(sb, KERN_ALERT, "shut down requested (%d)", flags);
  496. trace_ext4_shutdown(sb, flags);
  497. switch (flags) {
  498. case EXT4_GOING_FLAGS_DEFAULT:
  499. freeze_bdev(sb->s_bdev);
  500. set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
  501. thaw_bdev(sb->s_bdev, sb);
  502. break;
  503. case EXT4_GOING_FLAGS_LOGFLUSH:
  504. set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
  505. if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) {
  506. (void) ext4_force_commit(sb);
  507. jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
  508. }
  509. break;
  510. case EXT4_GOING_FLAGS_NOLOGFLUSH:
  511. set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
  512. if (sbi->s_journal && !is_journal_aborted(sbi->s_journal))
  513. jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
  514. break;
  515. default:
  516. return -EINVAL;
  517. }
  518. clear_opt(sb, DISCARD);
  519. return 0;
  520. }
  521. struct getfsmap_info {
  522. struct super_block *gi_sb;
  523. struct fsmap_head __user *gi_data;
  524. unsigned int gi_idx;
  525. __u32 gi_last_flags;
  526. };
  527. static int ext4_getfsmap_format(struct ext4_fsmap *xfm, void *priv)
  528. {
  529. struct getfsmap_info *info = priv;
  530. struct fsmap fm;
  531. trace_ext4_getfsmap_mapping(info->gi_sb, xfm);
  532. info->gi_last_flags = xfm->fmr_flags;
  533. ext4_fsmap_from_internal(info->gi_sb, &fm, xfm);
  534. if (copy_to_user(&info->gi_data->fmh_recs[info->gi_idx++], &fm,
  535. sizeof(struct fsmap)))
  536. return -EFAULT;
  537. return 0;
  538. }
  539. static int ext4_ioc_getfsmap(struct super_block *sb,
  540. struct fsmap_head __user *arg)
  541. {
  542. struct getfsmap_info info = {0};
  543. struct ext4_fsmap_head xhead = {0};
  544. struct fsmap_head head;
  545. bool aborted = false;
  546. int error;
  547. if (copy_from_user(&head, arg, sizeof(struct fsmap_head)))
  548. return -EFAULT;
  549. if (memchr_inv(head.fmh_reserved, 0, sizeof(head.fmh_reserved)) ||
  550. memchr_inv(head.fmh_keys[0].fmr_reserved, 0,
  551. sizeof(head.fmh_keys[0].fmr_reserved)) ||
  552. memchr_inv(head.fmh_keys[1].fmr_reserved, 0,
  553. sizeof(head.fmh_keys[1].fmr_reserved)))
  554. return -EINVAL;
  555. /*
  556. * ext4 doesn't report file extents at all, so the only valid
  557. * file offsets are the magic ones (all zeroes or all ones).
  558. */
  559. if (head.fmh_keys[0].fmr_offset ||
  560. (head.fmh_keys[1].fmr_offset != 0 &&
  561. head.fmh_keys[1].fmr_offset != -1ULL))
  562. return -EINVAL;
  563. xhead.fmh_iflags = head.fmh_iflags;
  564. xhead.fmh_count = head.fmh_count;
  565. ext4_fsmap_to_internal(sb, &xhead.fmh_keys[0], &head.fmh_keys[0]);
  566. ext4_fsmap_to_internal(sb, &xhead.fmh_keys[1], &head.fmh_keys[1]);
  567. trace_ext4_getfsmap_low_key(sb, &xhead.fmh_keys[0]);
  568. trace_ext4_getfsmap_high_key(sb, &xhead.fmh_keys[1]);
  569. info.gi_sb = sb;
  570. info.gi_data = arg;
  571. error = ext4_getfsmap(sb, &xhead, ext4_getfsmap_format, &info);
  572. if (error == EXT4_QUERY_RANGE_ABORT) {
  573. error = 0;
  574. aborted = true;
  575. } else if (error)
  576. return error;
  577. /* If we didn't abort, set the "last" flag in the last fmx */
  578. if (!aborted && info.gi_idx) {
  579. info.gi_last_flags |= FMR_OF_LAST;
  580. if (copy_to_user(&info.gi_data->fmh_recs[info.gi_idx - 1].fmr_flags,
  581. &info.gi_last_flags,
  582. sizeof(info.gi_last_flags)))
  583. return -EFAULT;
  584. }
  585. /* copy back header */
  586. head.fmh_entries = xhead.fmh_entries;
  587. head.fmh_oflags = xhead.fmh_oflags;
  588. if (copy_to_user(arg, &head, sizeof(struct fsmap_head)))
  589. return -EFAULT;
  590. return 0;
  591. }
  592. static long ext4_ioctl_group_add(struct file *file,
  593. struct ext4_new_group_data *input)
  594. {
  595. struct super_block *sb = file_inode(file)->i_sb;
  596. int err, err2=0;
  597. err = ext4_resize_begin(sb);
  598. if (err)
  599. return err;
  600. if (ext4_has_feature_bigalloc(sb)) {
  601. ext4_msg(sb, KERN_ERR,
  602. "Online resizing not supported with bigalloc");
  603. err = -EOPNOTSUPP;
  604. goto group_add_out;
  605. }
  606. err = mnt_want_write_file(file);
  607. if (err)
  608. goto group_add_out;
  609. err = ext4_group_add(sb, input);
  610. if (EXT4_SB(sb)->s_journal) {
  611. jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
  612. err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
  613. jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
  614. }
  615. if (err == 0)
  616. err = err2;
  617. mnt_drop_write_file(file);
  618. if (!err && ext4_has_group_desc_csum(sb) &&
  619. test_opt(sb, INIT_INODE_TABLE))
  620. err = ext4_register_li_request(sb, input->group);
  621. group_add_out:
  622. ext4_resize_end(sb);
  623. return err;
  624. }
  625. static int ext4_ioctl_check_project(struct inode *inode, struct fsxattr *fa)
  626. {
  627. /*
  628. * Project Quota ID state is only allowed to change from within the init
  629. * namespace. Enforce that restriction only if we are trying to change
  630. * the quota ID state. Everything else is allowed in user namespaces.
  631. */
  632. if (current_user_ns() == &init_user_ns)
  633. return 0;
  634. if (__kprojid_val(EXT4_I(inode)->i_projid) != fa->fsx_projid)
  635. return -EINVAL;
  636. if (ext4_test_inode_flag(inode, EXT4_INODE_PROJINHERIT)) {
  637. if (!(fa->fsx_xflags & FS_XFLAG_PROJINHERIT))
  638. return -EINVAL;
  639. } else {
  640. if (fa->fsx_xflags & FS_XFLAG_PROJINHERIT)
  641. return -EINVAL;
  642. }
  643. return 0;
  644. }
  645. long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  646. {
  647. struct inode *inode = file_inode(filp);
  648. struct super_block *sb = inode->i_sb;
  649. struct ext4_inode_info *ei = EXT4_I(inode);
  650. unsigned int flags;
  651. ext4_debug("cmd = %u, arg = %lu\n", cmd, arg);
  652. switch (cmd) {
  653. case FS_IOC_GETFSMAP:
  654. return ext4_ioc_getfsmap(sb, (void __user *)arg);
  655. case EXT4_IOC_GETFLAGS:
  656. flags = ei->i_flags & EXT4_FL_USER_VISIBLE;
  657. return put_user(flags, (int __user *) arg);
  658. case EXT4_IOC_SETFLAGS: {
  659. int err;
  660. if (!inode_owner_or_capable(inode))
  661. return -EACCES;
  662. if (get_user(flags, (int __user *) arg))
  663. return -EFAULT;
  664. if (flags & ~EXT4_FL_USER_VISIBLE)
  665. return -EOPNOTSUPP;
  666. /*
  667. * chattr(1) grabs flags via GETFLAGS, modifies the result and
  668. * passes that to SETFLAGS. So we cannot easily make SETFLAGS
  669. * more restrictive than just silently masking off visible but
  670. * not settable flags as we always did.
  671. */
  672. flags &= EXT4_FL_USER_MODIFIABLE;
  673. if (ext4_mask_flags(inode->i_mode, flags) != flags)
  674. return -EOPNOTSUPP;
  675. err = mnt_want_write_file(filp);
  676. if (err)
  677. return err;
  678. inode_lock(inode);
  679. err = ext4_ioctl_check_immutable(inode,
  680. from_kprojid(&init_user_ns, ei->i_projid),
  681. flags);
  682. if (!err)
  683. err = ext4_ioctl_setflags(inode, flags);
  684. inode_unlock(inode);
  685. mnt_drop_write_file(filp);
  686. return err;
  687. }
  688. case EXT4_IOC_GETVERSION:
  689. case EXT4_IOC_GETVERSION_OLD:
  690. return put_user(inode->i_generation, (int __user *) arg);
  691. case EXT4_IOC_SETVERSION:
  692. case EXT4_IOC_SETVERSION_OLD: {
  693. handle_t *handle;
  694. struct ext4_iloc iloc;
  695. __u32 generation;
  696. int err;
  697. if (!inode_owner_or_capable(inode))
  698. return -EPERM;
  699. if (ext4_has_metadata_csum(inode->i_sb)) {
  700. ext4_warning(sb, "Setting inode version is not "
  701. "supported with metadata_csum enabled.");
  702. return -ENOTTY;
  703. }
  704. err = mnt_want_write_file(filp);
  705. if (err)
  706. return err;
  707. if (get_user(generation, (int __user *) arg)) {
  708. err = -EFAULT;
  709. goto setversion_out;
  710. }
  711. inode_lock(inode);
  712. handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
  713. if (IS_ERR(handle)) {
  714. err = PTR_ERR(handle);
  715. goto unlock_out;
  716. }
  717. err = ext4_reserve_inode_write(handle, inode, &iloc);
  718. if (err == 0) {
  719. inode->i_ctime = current_time(inode);
  720. inode->i_generation = generation;
  721. err = ext4_mark_iloc_dirty(handle, inode, &iloc);
  722. }
  723. ext4_journal_stop(handle);
  724. unlock_out:
  725. inode_unlock(inode);
  726. setversion_out:
  727. mnt_drop_write_file(filp);
  728. return err;
  729. }
  730. case EXT4_IOC_GROUP_EXTEND: {
  731. ext4_fsblk_t n_blocks_count;
  732. int err, err2=0;
  733. err = ext4_resize_begin(sb);
  734. if (err)
  735. return err;
  736. if (get_user(n_blocks_count, (__u32 __user *)arg)) {
  737. err = -EFAULT;
  738. goto group_extend_out;
  739. }
  740. if (ext4_has_feature_bigalloc(sb)) {
  741. ext4_msg(sb, KERN_ERR,
  742. "Online resizing not supported with bigalloc");
  743. err = -EOPNOTSUPP;
  744. goto group_extend_out;
  745. }
  746. err = mnt_want_write_file(filp);
  747. if (err)
  748. goto group_extend_out;
  749. err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count);
  750. if (EXT4_SB(sb)->s_journal) {
  751. jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
  752. err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
  753. jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
  754. }
  755. if (err == 0)
  756. err = err2;
  757. mnt_drop_write_file(filp);
  758. group_extend_out:
  759. ext4_resize_end(sb);
  760. return err;
  761. }
  762. case EXT4_IOC_MOVE_EXT: {
  763. struct move_extent me;
  764. struct fd donor;
  765. int err;
  766. if (!(filp->f_mode & FMODE_READ) ||
  767. !(filp->f_mode & FMODE_WRITE))
  768. return -EBADF;
  769. if (copy_from_user(&me,
  770. (struct move_extent __user *)arg, sizeof(me)))
  771. return -EFAULT;
  772. me.moved_len = 0;
  773. donor = fdget(me.donor_fd);
  774. if (!donor.file)
  775. return -EBADF;
  776. if (!(donor.file->f_mode & FMODE_WRITE)) {
  777. err = -EBADF;
  778. goto mext_out;
  779. }
  780. if (ext4_has_feature_bigalloc(sb)) {
  781. ext4_msg(sb, KERN_ERR,
  782. "Online defrag not supported with bigalloc");
  783. err = -EOPNOTSUPP;
  784. goto mext_out;
  785. } else if (IS_DAX(inode)) {
  786. ext4_msg(sb, KERN_ERR,
  787. "Online defrag not supported with DAX");
  788. err = -EOPNOTSUPP;
  789. goto mext_out;
  790. }
  791. err = mnt_want_write_file(filp);
  792. if (err)
  793. goto mext_out;
  794. err = ext4_move_extents(filp, donor.file, me.orig_start,
  795. me.donor_start, me.len, &me.moved_len);
  796. mnt_drop_write_file(filp);
  797. if (copy_to_user((struct move_extent __user *)arg,
  798. &me, sizeof(me)))
  799. err = -EFAULT;
  800. mext_out:
  801. fdput(donor);
  802. return err;
  803. }
  804. case EXT4_IOC_GROUP_ADD: {
  805. struct ext4_new_group_data input;
  806. if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
  807. sizeof(input)))
  808. return -EFAULT;
  809. return ext4_ioctl_group_add(filp, &input);
  810. }
  811. case EXT4_IOC_MIGRATE:
  812. {
  813. int err;
  814. if (!inode_owner_or_capable(inode))
  815. return -EACCES;
  816. err = mnt_want_write_file(filp);
  817. if (err)
  818. return err;
  819. /*
  820. * inode_mutex prevent write and truncate on the file.
  821. * Read still goes through. We take i_data_sem in
  822. * ext4_ext_swap_inode_data before we switch the
  823. * inode format to prevent read.
  824. */
  825. inode_lock((inode));
  826. err = ext4_ext_migrate(inode);
  827. inode_unlock((inode));
  828. mnt_drop_write_file(filp);
  829. return err;
  830. }
  831. case EXT4_IOC_ALLOC_DA_BLKS:
  832. {
  833. int err;
  834. if (!inode_owner_or_capable(inode))
  835. return -EACCES;
  836. err = mnt_want_write_file(filp);
  837. if (err)
  838. return err;
  839. err = ext4_alloc_da_blocks(inode);
  840. mnt_drop_write_file(filp);
  841. return err;
  842. }
  843. case EXT4_IOC_SWAP_BOOT:
  844. {
  845. int err;
  846. if (!(filp->f_mode & FMODE_WRITE))
  847. return -EBADF;
  848. err = mnt_want_write_file(filp);
  849. if (err)
  850. return err;
  851. err = swap_inode_boot_loader(sb, inode);
  852. mnt_drop_write_file(filp);
  853. return err;
  854. }
  855. case EXT4_IOC_RESIZE_FS: {
  856. ext4_fsblk_t n_blocks_count;
  857. int err = 0, err2 = 0;
  858. ext4_group_t o_group = EXT4_SB(sb)->s_groups_count;
  859. if (copy_from_user(&n_blocks_count, (__u64 __user *)arg,
  860. sizeof(__u64))) {
  861. return -EFAULT;
  862. }
  863. err = ext4_resize_begin(sb);
  864. if (err)
  865. return err;
  866. err = mnt_want_write_file(filp);
  867. if (err)
  868. goto resizefs_out;
  869. err = ext4_resize_fs(sb, n_blocks_count);
  870. if (EXT4_SB(sb)->s_journal) {
  871. jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
  872. err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
  873. jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
  874. }
  875. if (err == 0)
  876. err = err2;
  877. mnt_drop_write_file(filp);
  878. if (!err && (o_group < EXT4_SB(sb)->s_groups_count) &&
  879. ext4_has_group_desc_csum(sb) &&
  880. test_opt(sb, INIT_INODE_TABLE))
  881. err = ext4_register_li_request(sb, o_group);
  882. resizefs_out:
  883. ext4_resize_end(sb);
  884. return err;
  885. }
  886. case FITRIM:
  887. {
  888. struct request_queue *q = bdev_get_queue(sb->s_bdev);
  889. struct fstrim_range range;
  890. int ret = 0;
  891. if (!capable(CAP_SYS_ADMIN))
  892. return -EPERM;
  893. if (!blk_queue_discard(q))
  894. return -EOPNOTSUPP;
  895. /*
  896. * We haven't replayed the journal, so we cannot use our
  897. * block-bitmap-guided storage zapping commands.
  898. */
  899. if (test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb))
  900. return -EROFS;
  901. if (copy_from_user(&range, (struct fstrim_range __user *)arg,
  902. sizeof(range)))
  903. return -EFAULT;
  904. range.minlen = max((unsigned int)range.minlen,
  905. q->limits.discard_granularity);
  906. ret = ext4_trim_fs(sb, &range);
  907. if (ret < 0)
  908. return ret;
  909. if (copy_to_user((struct fstrim_range __user *)arg, &range,
  910. sizeof(range)))
  911. return -EFAULT;
  912. return 0;
  913. }
  914. case EXT4_IOC_PRECACHE_EXTENTS:
  915. return ext4_ext_precache(inode);
  916. case EXT4_IOC_SET_ENCRYPTION_POLICY:
  917. if (!ext4_has_feature_encrypt(sb))
  918. return -EOPNOTSUPP;
  919. return fscrypt_ioctl_set_policy(filp, (const void __user *)arg);
  920. case EXT4_IOC_GET_ENCRYPTION_PWSALT: {
  921. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  922. int err, err2;
  923. struct ext4_sb_info *sbi = EXT4_SB(sb);
  924. handle_t *handle;
  925. if (!ext4_has_feature_encrypt(sb))
  926. return -EOPNOTSUPP;
  927. if (uuid_is_zero(sbi->s_es->s_encrypt_pw_salt)) {
  928. err = mnt_want_write_file(filp);
  929. if (err)
  930. return err;
  931. handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1);
  932. if (IS_ERR(handle)) {
  933. err = PTR_ERR(handle);
  934. goto pwsalt_err_exit;
  935. }
  936. err = ext4_journal_get_write_access(handle, sbi->s_sbh);
  937. if (err)
  938. goto pwsalt_err_journal;
  939. generate_random_uuid(sbi->s_es->s_encrypt_pw_salt);
  940. err = ext4_handle_dirty_metadata(handle, NULL,
  941. sbi->s_sbh);
  942. pwsalt_err_journal:
  943. err2 = ext4_journal_stop(handle);
  944. if (err2 && !err)
  945. err = err2;
  946. pwsalt_err_exit:
  947. mnt_drop_write_file(filp);
  948. if (err)
  949. return err;
  950. }
  951. if (copy_to_user((void __user *) arg,
  952. sbi->s_es->s_encrypt_pw_salt, 16))
  953. return -EFAULT;
  954. return 0;
  955. #else
  956. return -EOPNOTSUPP;
  957. #endif
  958. }
  959. case EXT4_IOC_GET_ENCRYPTION_POLICY:
  960. return fscrypt_ioctl_get_policy(filp, (void __user *)arg);
  961. case EXT4_IOC_FSGETXATTR:
  962. {
  963. struct fsxattr fa;
  964. memset(&fa, 0, sizeof(struct fsxattr));
  965. fa.fsx_xflags = ext4_iflags_to_xflags(ei->i_flags & EXT4_FL_USER_VISIBLE);
  966. if (ext4_has_feature_project(inode->i_sb)) {
  967. fa.fsx_projid = (__u32)from_kprojid(&init_user_ns,
  968. EXT4_I(inode)->i_projid);
  969. }
  970. if (copy_to_user((struct fsxattr __user *)arg,
  971. &fa, sizeof(fa)))
  972. return -EFAULT;
  973. return 0;
  974. }
  975. case EXT4_IOC_FSSETXATTR:
  976. {
  977. struct fsxattr fa;
  978. int err;
  979. if (copy_from_user(&fa, (struct fsxattr __user *)arg,
  980. sizeof(fa)))
  981. return -EFAULT;
  982. /* Make sure caller has proper permission */
  983. if (!inode_owner_or_capable(inode))
  984. return -EACCES;
  985. if (fa.fsx_xflags & ~EXT4_SUPPORTED_FS_XFLAGS)
  986. return -EOPNOTSUPP;
  987. flags = ext4_xflags_to_iflags(fa.fsx_xflags);
  988. if (ext4_mask_flags(inode->i_mode, flags) != flags)
  989. return -EOPNOTSUPP;
  990. err = mnt_want_write_file(filp);
  991. if (err)
  992. return err;
  993. inode_lock(inode);
  994. err = ext4_ioctl_check_project(inode, &fa);
  995. if (err)
  996. goto out;
  997. flags = (ei->i_flags & ~EXT4_FL_XFLAG_VISIBLE) |
  998. (flags & EXT4_FL_XFLAG_VISIBLE);
  999. err = ext4_ioctl_check_immutable(inode, fa.fsx_projid, flags);
  1000. if (err)
  1001. goto out;
  1002. err = ext4_ioctl_setflags(inode, flags);
  1003. if (err)
  1004. goto out;
  1005. err = ext4_ioctl_setproject(filp, fa.fsx_projid);
  1006. out:
  1007. inode_unlock(inode);
  1008. mnt_drop_write_file(filp);
  1009. return err;
  1010. }
  1011. case EXT4_IOC_SHUTDOWN:
  1012. return ext4_shutdown(sb, arg);
  1013. default:
  1014. return -ENOTTY;
  1015. }
  1016. }
  1017. #ifdef CONFIG_COMPAT
  1018. long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  1019. {
  1020. /* These are just misnamed, they actually get/put from/to user an int */
  1021. switch (cmd) {
  1022. case EXT4_IOC32_GETFLAGS:
  1023. cmd = EXT4_IOC_GETFLAGS;
  1024. break;
  1025. case EXT4_IOC32_SETFLAGS:
  1026. cmd = EXT4_IOC_SETFLAGS;
  1027. break;
  1028. case EXT4_IOC32_GETVERSION:
  1029. cmd = EXT4_IOC_GETVERSION;
  1030. break;
  1031. case EXT4_IOC32_SETVERSION:
  1032. cmd = EXT4_IOC_SETVERSION;
  1033. break;
  1034. case EXT4_IOC32_GROUP_EXTEND:
  1035. cmd = EXT4_IOC_GROUP_EXTEND;
  1036. break;
  1037. case EXT4_IOC32_GETVERSION_OLD:
  1038. cmd = EXT4_IOC_GETVERSION_OLD;
  1039. break;
  1040. case EXT4_IOC32_SETVERSION_OLD:
  1041. cmd = EXT4_IOC_SETVERSION_OLD;
  1042. break;
  1043. case EXT4_IOC32_GETRSVSZ:
  1044. cmd = EXT4_IOC_GETRSVSZ;
  1045. break;
  1046. case EXT4_IOC32_SETRSVSZ:
  1047. cmd = EXT4_IOC_SETRSVSZ;
  1048. break;
  1049. case EXT4_IOC32_GROUP_ADD: {
  1050. struct compat_ext4_new_group_input __user *uinput;
  1051. struct ext4_new_group_data input;
  1052. int err;
  1053. uinput = compat_ptr(arg);
  1054. err = get_user(input.group, &uinput->group);
  1055. err |= get_user(input.block_bitmap, &uinput->block_bitmap);
  1056. err |= get_user(input.inode_bitmap, &uinput->inode_bitmap);
  1057. err |= get_user(input.inode_table, &uinput->inode_table);
  1058. err |= get_user(input.blocks_count, &uinput->blocks_count);
  1059. err |= get_user(input.reserved_blocks,
  1060. &uinput->reserved_blocks);
  1061. if (err)
  1062. return -EFAULT;
  1063. return ext4_ioctl_group_add(file, &input);
  1064. }
  1065. case EXT4_IOC_MOVE_EXT:
  1066. case EXT4_IOC_RESIZE_FS:
  1067. case EXT4_IOC_PRECACHE_EXTENTS:
  1068. case EXT4_IOC_SET_ENCRYPTION_POLICY:
  1069. case EXT4_IOC_GET_ENCRYPTION_PWSALT:
  1070. case EXT4_IOC_GET_ENCRYPTION_POLICY:
  1071. case EXT4_IOC_SHUTDOWN:
  1072. case FS_IOC_GETFSMAP:
  1073. break;
  1074. default:
  1075. return -ENOIOCTLCMD;
  1076. }
  1077. return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
  1078. }
  1079. #endif