ioctl.c 31 KB

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