]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - fs/ext4/ioctl.c
btrfs: don't print information about space cache or tree every remount
[mirror_ubuntu-jammy-kernel.git] / fs / ext4 / ioctl.c
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
11 #include <linux/fs.h>
12 #include <linux/capability.h>
13 #include <linux/time.h>
14 #include <linux/compat.h>
15 #include <linux/mount.h>
16 #include <linux/file.h>
17 #include <linux/quotaops.h>
18 #include <linux/random.h>
19 #include <linux/uuid.h>
20 #include <linux/uaccess.h>
21 #include <linux/delay.h>
22 #include <linux/iversion.h>
23 #include <linux/fileattr.h>
24 #include "ext4_jbd2.h"
25 #include "ext4.h"
26 #include <linux/fsmap.h>
27 #include "fsmap.h"
28 #include <trace/events/ext4.h>
29
30 /**
31 * Swap memory between @a and @b for @len bytes.
32 *
33 * @a: pointer to first memory area
34 * @b: pointer to second memory area
35 * @len: number of bytes to swap
36 *
37 */
38 static void memswap(void *a, void *b, size_t len)
39 {
40 unsigned char *ap, *bp;
41
42 ap = (unsigned char *)a;
43 bp = (unsigned char *)b;
44 while (len-- > 0) {
45 swap(*ap, *bp);
46 ap++;
47 bp++;
48 }
49 }
50
51 /**
52 * Swap i_data and associated attributes between @inode1 and @inode2.
53 * This function is used for the primary swap between inode1 and inode2
54 * and also to revert this primary swap in case of errors.
55 *
56 * Therefore you have to make sure, that calling this method twice
57 * will revert all changes.
58 *
59 * @inode1: pointer to first inode
60 * @inode2: pointer to second inode
61 */
62 static void swap_inode_data(struct inode *inode1, struct inode *inode2)
63 {
64 loff_t isize;
65 struct ext4_inode_info *ei1;
66 struct ext4_inode_info *ei2;
67 unsigned long tmp;
68
69 ei1 = EXT4_I(inode1);
70 ei2 = EXT4_I(inode2);
71
72 swap(inode1->i_version, inode2->i_version);
73 swap(inode1->i_atime, inode2->i_atime);
74 swap(inode1->i_mtime, inode2->i_mtime);
75
76 memswap(ei1->i_data, ei2->i_data, sizeof(ei1->i_data));
77 tmp = ei1->i_flags & EXT4_FL_SHOULD_SWAP;
78 ei1->i_flags = (ei2->i_flags & EXT4_FL_SHOULD_SWAP) |
79 (ei1->i_flags & ~EXT4_FL_SHOULD_SWAP);
80 ei2->i_flags = tmp | (ei2->i_flags & ~EXT4_FL_SHOULD_SWAP);
81 swap(ei1->i_disksize, ei2->i_disksize);
82 ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS);
83 ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS);
84
85 isize = i_size_read(inode1);
86 i_size_write(inode1, i_size_read(inode2));
87 i_size_write(inode2, isize);
88 }
89
90 void ext4_reset_inode_seed(struct inode *inode)
91 {
92 struct ext4_inode_info *ei = EXT4_I(inode);
93 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
94 __le32 inum = cpu_to_le32(inode->i_ino);
95 __le32 gen = cpu_to_le32(inode->i_generation);
96 __u32 csum;
97
98 if (!ext4_has_metadata_csum(inode->i_sb))
99 return;
100
101 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&inum, sizeof(inum));
102 ei->i_csum_seed = ext4_chksum(sbi, csum, (__u8 *)&gen, sizeof(gen));
103 }
104
105 /**
106 * Swap the information from the given @inode and the inode
107 * EXT4_BOOT_LOADER_INO. It will basically swap i_data and all other
108 * important fields of the inodes.
109 *
110 * @sb: the super block of the filesystem
111 * @mnt_userns: user namespace of the mount the inode was found from
112 * @inode: the inode to swap with EXT4_BOOT_LOADER_INO
113 *
114 */
115 static long swap_inode_boot_loader(struct super_block *sb,
116 struct user_namespace *mnt_userns,
117 struct inode *inode)
118 {
119 handle_t *handle;
120 int err;
121 struct inode *inode_bl;
122 struct ext4_inode_info *ei_bl;
123 qsize_t size, size_bl, diff;
124 blkcnt_t blocks;
125 unsigned short bytes;
126
127 inode_bl = ext4_iget(sb, EXT4_BOOT_LOADER_INO, EXT4_IGET_SPECIAL);
128 if (IS_ERR(inode_bl))
129 return PTR_ERR(inode_bl);
130 ei_bl = EXT4_I(inode_bl);
131
132 /* Protect orig inodes against a truncate and make sure,
133 * that only 1 swap_inode_boot_loader is running. */
134 lock_two_nondirectories(inode, inode_bl);
135
136 if (inode->i_nlink != 1 || !S_ISREG(inode->i_mode) ||
137 IS_SWAPFILE(inode) || IS_ENCRYPTED(inode) ||
138 (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) ||
139 ext4_has_inline_data(inode)) {
140 err = -EINVAL;
141 goto journal_err_out;
142 }
143
144 if (IS_RDONLY(inode) || IS_APPEND(inode) || IS_IMMUTABLE(inode) ||
145 !inode_owner_or_capable(mnt_userns, inode) ||
146 !capable(CAP_SYS_ADMIN)) {
147 err = -EPERM;
148 goto journal_err_out;
149 }
150
151 filemap_invalidate_lock(inode->i_mapping);
152 err = filemap_write_and_wait(inode->i_mapping);
153 if (err)
154 goto err_out;
155
156 err = filemap_write_and_wait(inode_bl->i_mapping);
157 if (err)
158 goto err_out;
159
160 /* Wait for all existing dio workers */
161 inode_dio_wait(inode);
162 inode_dio_wait(inode_bl);
163
164 truncate_inode_pages(&inode->i_data, 0);
165 truncate_inode_pages(&inode_bl->i_data, 0);
166
167 handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2);
168 if (IS_ERR(handle)) {
169 err = -EINVAL;
170 goto err_out;
171 }
172 ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_SWAP_BOOT, handle);
173
174 /* Protect extent tree against block allocations via delalloc */
175 ext4_double_down_write_data_sem(inode, inode_bl);
176
177 if (inode_bl->i_nlink == 0) {
178 /* this inode has never been used as a BOOT_LOADER */
179 set_nlink(inode_bl, 1);
180 i_uid_write(inode_bl, 0);
181 i_gid_write(inode_bl, 0);
182 inode_bl->i_flags = 0;
183 ei_bl->i_flags = 0;
184 inode_set_iversion(inode_bl, 1);
185 i_size_write(inode_bl, 0);
186 inode_bl->i_mode = S_IFREG;
187 if (ext4_has_feature_extents(sb)) {
188 ext4_set_inode_flag(inode_bl, EXT4_INODE_EXTENTS);
189 ext4_ext_tree_init(handle, inode_bl);
190 } else
191 memset(ei_bl->i_data, 0, sizeof(ei_bl->i_data));
192 }
193
194 err = dquot_initialize(inode);
195 if (err)
196 goto err_out1;
197
198 size = (qsize_t)(inode->i_blocks) * (1 << 9) + inode->i_bytes;
199 size_bl = (qsize_t)(inode_bl->i_blocks) * (1 << 9) + inode_bl->i_bytes;
200 diff = size - size_bl;
201 swap_inode_data(inode, inode_bl);
202
203 inode->i_ctime = inode_bl->i_ctime = current_time(inode);
204
205 inode->i_generation = prandom_u32();
206 inode_bl->i_generation = prandom_u32();
207 ext4_reset_inode_seed(inode);
208 ext4_reset_inode_seed(inode_bl);
209
210 ext4_discard_preallocations(inode, 0);
211
212 err = ext4_mark_inode_dirty(handle, inode);
213 if (err < 0) {
214 /* No need to update quota information. */
215 ext4_warning(inode->i_sb,
216 "couldn't mark inode #%lu dirty (err %d)",
217 inode->i_ino, err);
218 /* Revert all changes: */
219 swap_inode_data(inode, inode_bl);
220 ext4_mark_inode_dirty(handle, inode);
221 goto err_out1;
222 }
223
224 blocks = inode_bl->i_blocks;
225 bytes = inode_bl->i_bytes;
226 inode_bl->i_blocks = inode->i_blocks;
227 inode_bl->i_bytes = inode->i_bytes;
228 err = ext4_mark_inode_dirty(handle, inode_bl);
229 if (err < 0) {
230 /* No need to update quota information. */
231 ext4_warning(inode_bl->i_sb,
232 "couldn't mark inode #%lu dirty (err %d)",
233 inode_bl->i_ino, err);
234 goto revert;
235 }
236
237 /* Bootloader inode should not be counted into quota information. */
238 if (diff > 0)
239 dquot_free_space(inode, diff);
240 else
241 err = dquot_alloc_space(inode, -1 * diff);
242
243 if (err < 0) {
244 revert:
245 /* Revert all changes: */
246 inode_bl->i_blocks = blocks;
247 inode_bl->i_bytes = bytes;
248 swap_inode_data(inode, inode_bl);
249 ext4_mark_inode_dirty(handle, inode);
250 ext4_mark_inode_dirty(handle, inode_bl);
251 }
252
253 err_out1:
254 ext4_journal_stop(handle);
255 ext4_double_up_write_data_sem(inode, inode_bl);
256
257 err_out:
258 filemap_invalidate_unlock(inode->i_mapping);
259 journal_err_out:
260 unlock_two_nondirectories(inode, inode_bl);
261 iput(inode_bl);
262 return err;
263 }
264
265 #ifdef CONFIG_FS_ENCRYPTION
266 static int uuid_is_zero(__u8 u[16])
267 {
268 int i;
269
270 for (i = 0; i < 16; i++)
271 if (u[i])
272 return 0;
273 return 1;
274 }
275 #endif
276
277 /*
278 * If immutable is set and we are not clearing it, we're not allowed to change
279 * anything else in the inode. Don't error out if we're only trying to set
280 * immutable on an immutable file.
281 */
282 static int ext4_ioctl_check_immutable(struct inode *inode, __u32 new_projid,
283 unsigned int flags)
284 {
285 struct ext4_inode_info *ei = EXT4_I(inode);
286 unsigned int oldflags = ei->i_flags;
287
288 if (!(oldflags & EXT4_IMMUTABLE_FL) || !(flags & EXT4_IMMUTABLE_FL))
289 return 0;
290
291 if ((oldflags & ~EXT4_IMMUTABLE_FL) != (flags & ~EXT4_IMMUTABLE_FL))
292 return -EPERM;
293 if (ext4_has_feature_project(inode->i_sb) &&
294 __kprojid_val(ei->i_projid) != new_projid)
295 return -EPERM;
296
297 return 0;
298 }
299
300 static void ext4_dax_dontcache(struct inode *inode, unsigned int flags)
301 {
302 struct ext4_inode_info *ei = EXT4_I(inode);
303
304 if (S_ISDIR(inode->i_mode))
305 return;
306
307 if (test_opt2(inode->i_sb, DAX_NEVER) ||
308 test_opt(inode->i_sb, DAX_ALWAYS))
309 return;
310
311 if ((ei->i_flags ^ flags) & EXT4_DAX_FL)
312 d_mark_dontcache(inode);
313 }
314
315 static bool dax_compatible(struct inode *inode, unsigned int oldflags,
316 unsigned int flags)
317 {
318 /* Allow the DAX flag to be changed on inline directories */
319 if (S_ISDIR(inode->i_mode)) {
320 flags &= ~EXT4_INLINE_DATA_FL;
321 oldflags &= ~EXT4_INLINE_DATA_FL;
322 }
323
324 if (flags & EXT4_DAX_FL) {
325 if ((oldflags & EXT4_DAX_MUT_EXCL) ||
326 ext4_test_inode_state(inode,
327 EXT4_STATE_VERITY_IN_PROGRESS)) {
328 return false;
329 }
330 }
331
332 if ((flags & EXT4_DAX_MUT_EXCL) && (oldflags & EXT4_DAX_FL))
333 return false;
334
335 return true;
336 }
337
338 static int ext4_ioctl_setflags(struct inode *inode,
339 unsigned int flags)
340 {
341 struct ext4_inode_info *ei = EXT4_I(inode);
342 handle_t *handle = NULL;
343 int err = -EPERM, migrate = 0;
344 struct ext4_iloc iloc;
345 unsigned int oldflags, mask, i;
346 struct super_block *sb = inode->i_sb;
347
348 /* Is it quota file? Do not allow user to mess with it */
349 if (ext4_is_quota_file(inode))
350 goto flags_out;
351
352 oldflags = ei->i_flags;
353 /*
354 * The JOURNAL_DATA flag can only be changed by
355 * the relevant capability.
356 */
357 if ((flags ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
358 if (!capable(CAP_SYS_RESOURCE))
359 goto flags_out;
360 }
361
362 if (!dax_compatible(inode, oldflags, flags)) {
363 err = -EOPNOTSUPP;
364 goto flags_out;
365 }
366
367 if ((flags ^ oldflags) & EXT4_EXTENTS_FL)
368 migrate = 1;
369
370 if ((flags ^ oldflags) & EXT4_CASEFOLD_FL) {
371 if (!ext4_has_feature_casefold(sb)) {
372 err = -EOPNOTSUPP;
373 goto flags_out;
374 }
375
376 if (!S_ISDIR(inode->i_mode)) {
377 err = -ENOTDIR;
378 goto flags_out;
379 }
380
381 if (!ext4_empty_dir(inode)) {
382 err = -ENOTEMPTY;
383 goto flags_out;
384 }
385 }
386
387 /*
388 * Wait for all pending directio and then flush all the dirty pages
389 * for this file. The flush marks all the pages readonly, so any
390 * subsequent attempt to write to the file (particularly mmap pages)
391 * will come through the filesystem and fail.
392 */
393 if (S_ISREG(inode->i_mode) && !IS_IMMUTABLE(inode) &&
394 (flags & EXT4_IMMUTABLE_FL)) {
395 inode_dio_wait(inode);
396 err = filemap_write_and_wait(inode->i_mapping);
397 if (err)
398 goto flags_out;
399 }
400
401 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
402 if (IS_ERR(handle)) {
403 err = PTR_ERR(handle);
404 goto flags_out;
405 }
406 if (IS_SYNC(inode))
407 ext4_handle_sync(handle);
408 err = ext4_reserve_inode_write(handle, inode, &iloc);
409 if (err)
410 goto flags_err;
411
412 ext4_dax_dontcache(inode, flags);
413
414 for (i = 0, mask = 1; i < 32; i++, mask <<= 1) {
415 if (!(mask & EXT4_FL_USER_MODIFIABLE))
416 continue;
417 /* These flags get special treatment later */
418 if (mask == EXT4_JOURNAL_DATA_FL || mask == EXT4_EXTENTS_FL)
419 continue;
420 if (mask & flags)
421 ext4_set_inode_flag(inode, i);
422 else
423 ext4_clear_inode_flag(inode, i);
424 }
425
426 ext4_set_inode_flags(inode, false);
427
428 inode->i_ctime = current_time(inode);
429
430 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
431 flags_err:
432 ext4_journal_stop(handle);
433 if (err)
434 goto flags_out;
435
436 if ((flags ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
437 /*
438 * Changes to the journaling mode can cause unsafe changes to
439 * S_DAX if the inode is DAX
440 */
441 if (IS_DAX(inode)) {
442 err = -EBUSY;
443 goto flags_out;
444 }
445
446 err = ext4_change_inode_journal_flag(inode,
447 flags & EXT4_JOURNAL_DATA_FL);
448 if (err)
449 goto flags_out;
450 }
451 if (migrate) {
452 if (flags & EXT4_EXTENTS_FL)
453 err = ext4_ext_migrate(inode);
454 else
455 err = ext4_ind_migrate(inode);
456 }
457
458 flags_out:
459 return err;
460 }
461
462 #ifdef CONFIG_QUOTA
463 static int ext4_ioctl_setproject(struct inode *inode, __u32 projid)
464 {
465 struct super_block *sb = inode->i_sb;
466 struct ext4_inode_info *ei = EXT4_I(inode);
467 int err, rc;
468 handle_t *handle;
469 kprojid_t kprojid;
470 struct ext4_iloc iloc;
471 struct ext4_inode *raw_inode;
472 struct dquot *transfer_to[MAXQUOTAS] = { };
473
474 if (!ext4_has_feature_project(sb)) {
475 if (projid != EXT4_DEF_PROJID)
476 return -EOPNOTSUPP;
477 else
478 return 0;
479 }
480
481 if (EXT4_INODE_SIZE(sb) <= EXT4_GOOD_OLD_INODE_SIZE)
482 return -EOPNOTSUPP;
483
484 kprojid = make_kprojid(&init_user_ns, (projid_t)projid);
485
486 if (projid_eq(kprojid, EXT4_I(inode)->i_projid))
487 return 0;
488
489 err = -EPERM;
490 /* Is it quota file? Do not allow user to mess with it */
491 if (ext4_is_quota_file(inode))
492 return err;
493
494 err = ext4_get_inode_loc(inode, &iloc);
495 if (err)
496 return err;
497
498 raw_inode = ext4_raw_inode(&iloc);
499 if (!EXT4_FITS_IN_INODE(raw_inode, ei, i_projid)) {
500 err = ext4_expand_extra_isize(inode,
501 EXT4_SB(sb)->s_want_extra_isize,
502 &iloc);
503 if (err)
504 return err;
505 } else {
506 brelse(iloc.bh);
507 }
508
509 err = dquot_initialize(inode);
510 if (err)
511 return err;
512
513 handle = ext4_journal_start(inode, EXT4_HT_QUOTA,
514 EXT4_QUOTA_INIT_BLOCKS(sb) +
515 EXT4_QUOTA_DEL_BLOCKS(sb) + 3);
516 if (IS_ERR(handle))
517 return PTR_ERR(handle);
518
519 err = ext4_reserve_inode_write(handle, inode, &iloc);
520 if (err)
521 goto out_stop;
522
523 transfer_to[PRJQUOTA] = dqget(sb, make_kqid_projid(kprojid));
524 if (!IS_ERR(transfer_to[PRJQUOTA])) {
525
526 /* __dquot_transfer() calls back ext4_get_inode_usage() which
527 * counts xattr inode references.
528 */
529 down_read(&EXT4_I(inode)->xattr_sem);
530 err = __dquot_transfer(inode, transfer_to);
531 up_read(&EXT4_I(inode)->xattr_sem);
532 dqput(transfer_to[PRJQUOTA]);
533 if (err)
534 goto out_dirty;
535 }
536
537 EXT4_I(inode)->i_projid = kprojid;
538 inode->i_ctime = current_time(inode);
539 out_dirty:
540 rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
541 if (!err)
542 err = rc;
543 out_stop:
544 ext4_journal_stop(handle);
545 return err;
546 }
547 #else
548 static int ext4_ioctl_setproject(struct inode *inode, __u32 projid)
549 {
550 if (projid != EXT4_DEF_PROJID)
551 return -EOPNOTSUPP;
552 return 0;
553 }
554 #endif
555
556 static int ext4_shutdown(struct super_block *sb, unsigned long arg)
557 {
558 struct ext4_sb_info *sbi = EXT4_SB(sb);
559 __u32 flags;
560
561 if (!capable(CAP_SYS_ADMIN))
562 return -EPERM;
563
564 if (get_user(flags, (__u32 __user *)arg))
565 return -EFAULT;
566
567 if (flags > EXT4_GOING_FLAGS_NOLOGFLUSH)
568 return -EINVAL;
569
570 if (ext4_forced_shutdown(sbi))
571 return 0;
572
573 ext4_msg(sb, KERN_ALERT, "shut down requested (%d)", flags);
574 trace_ext4_shutdown(sb, flags);
575
576 switch (flags) {
577 case EXT4_GOING_FLAGS_DEFAULT:
578 freeze_bdev(sb->s_bdev);
579 set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
580 thaw_bdev(sb->s_bdev);
581 break;
582 case EXT4_GOING_FLAGS_LOGFLUSH:
583 set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
584 if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) {
585 (void) ext4_force_commit(sb);
586 jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
587 }
588 break;
589 case EXT4_GOING_FLAGS_NOLOGFLUSH:
590 set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
591 if (sbi->s_journal && !is_journal_aborted(sbi->s_journal))
592 jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
593 break;
594 default:
595 return -EINVAL;
596 }
597 clear_opt(sb, DISCARD);
598 return 0;
599 }
600
601 struct getfsmap_info {
602 struct super_block *gi_sb;
603 struct fsmap_head __user *gi_data;
604 unsigned int gi_idx;
605 __u32 gi_last_flags;
606 };
607
608 static int ext4_getfsmap_format(struct ext4_fsmap *xfm, void *priv)
609 {
610 struct getfsmap_info *info = priv;
611 struct fsmap fm;
612
613 trace_ext4_getfsmap_mapping(info->gi_sb, xfm);
614
615 info->gi_last_flags = xfm->fmr_flags;
616 ext4_fsmap_from_internal(info->gi_sb, &fm, xfm);
617 if (copy_to_user(&info->gi_data->fmh_recs[info->gi_idx++], &fm,
618 sizeof(struct fsmap)))
619 return -EFAULT;
620
621 return 0;
622 }
623
624 static int ext4_ioc_getfsmap(struct super_block *sb,
625 struct fsmap_head __user *arg)
626 {
627 struct getfsmap_info info = { NULL };
628 struct ext4_fsmap_head xhead = {0};
629 struct fsmap_head head;
630 bool aborted = false;
631 int error;
632
633 if (copy_from_user(&head, arg, sizeof(struct fsmap_head)))
634 return -EFAULT;
635 if (memchr_inv(head.fmh_reserved, 0, sizeof(head.fmh_reserved)) ||
636 memchr_inv(head.fmh_keys[0].fmr_reserved, 0,
637 sizeof(head.fmh_keys[0].fmr_reserved)) ||
638 memchr_inv(head.fmh_keys[1].fmr_reserved, 0,
639 sizeof(head.fmh_keys[1].fmr_reserved)))
640 return -EINVAL;
641 /*
642 * ext4 doesn't report file extents at all, so the only valid
643 * file offsets are the magic ones (all zeroes or all ones).
644 */
645 if (head.fmh_keys[0].fmr_offset ||
646 (head.fmh_keys[1].fmr_offset != 0 &&
647 head.fmh_keys[1].fmr_offset != -1ULL))
648 return -EINVAL;
649
650 xhead.fmh_iflags = head.fmh_iflags;
651 xhead.fmh_count = head.fmh_count;
652 ext4_fsmap_to_internal(sb, &xhead.fmh_keys[0], &head.fmh_keys[0]);
653 ext4_fsmap_to_internal(sb, &xhead.fmh_keys[1], &head.fmh_keys[1]);
654
655 trace_ext4_getfsmap_low_key(sb, &xhead.fmh_keys[0]);
656 trace_ext4_getfsmap_high_key(sb, &xhead.fmh_keys[1]);
657
658 info.gi_sb = sb;
659 info.gi_data = arg;
660 error = ext4_getfsmap(sb, &xhead, ext4_getfsmap_format, &info);
661 if (error == EXT4_QUERY_RANGE_ABORT)
662 aborted = true;
663 else if (error)
664 return error;
665
666 /* If we didn't abort, set the "last" flag in the last fmx */
667 if (!aborted && info.gi_idx) {
668 info.gi_last_flags |= FMR_OF_LAST;
669 if (copy_to_user(&info.gi_data->fmh_recs[info.gi_idx - 1].fmr_flags,
670 &info.gi_last_flags,
671 sizeof(info.gi_last_flags)))
672 return -EFAULT;
673 }
674
675 /* copy back header */
676 head.fmh_entries = xhead.fmh_entries;
677 head.fmh_oflags = xhead.fmh_oflags;
678 if (copy_to_user(arg, &head, sizeof(struct fsmap_head)))
679 return -EFAULT;
680
681 return 0;
682 }
683
684 static long ext4_ioctl_group_add(struct file *file,
685 struct ext4_new_group_data *input)
686 {
687 struct super_block *sb = file_inode(file)->i_sb;
688 int err, err2=0;
689
690 err = ext4_resize_begin(sb);
691 if (err)
692 return err;
693
694 if (ext4_has_feature_bigalloc(sb)) {
695 ext4_msg(sb, KERN_ERR,
696 "Online resizing not supported with bigalloc");
697 err = -EOPNOTSUPP;
698 goto group_add_out;
699 }
700
701 err = mnt_want_write_file(file);
702 if (err)
703 goto group_add_out;
704
705 err = ext4_group_add(sb, input);
706 if (EXT4_SB(sb)->s_journal) {
707 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
708 err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal, 0);
709 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
710 }
711 if (err == 0)
712 err = err2;
713 mnt_drop_write_file(file);
714 if (!err && ext4_has_group_desc_csum(sb) &&
715 test_opt(sb, INIT_INODE_TABLE))
716 err = ext4_register_li_request(sb, input->group);
717 group_add_out:
718 ext4_resize_end(sb);
719 return err;
720 }
721
722 int ext4_fileattr_get(struct dentry *dentry, struct fileattr *fa)
723 {
724 struct inode *inode = d_inode(dentry);
725 struct ext4_inode_info *ei = EXT4_I(inode);
726 u32 flags = ei->i_flags & EXT4_FL_USER_VISIBLE;
727
728 if (S_ISREG(inode->i_mode))
729 flags &= ~FS_PROJINHERIT_FL;
730
731 fileattr_fill_flags(fa, flags);
732 if (ext4_has_feature_project(inode->i_sb))
733 fa->fsx_projid = from_kprojid(&init_user_ns, ei->i_projid);
734
735 return 0;
736 }
737
738 int ext4_fileattr_set(struct user_namespace *mnt_userns,
739 struct dentry *dentry, struct fileattr *fa)
740 {
741 struct inode *inode = d_inode(dentry);
742 u32 flags = fa->flags;
743 int err = -EOPNOTSUPP;
744
745 ext4_fc_start_update(inode);
746 if (flags & ~EXT4_FL_USER_VISIBLE)
747 goto out;
748
749 /*
750 * chattr(1) grabs flags via GETFLAGS, modifies the result and
751 * passes that to SETFLAGS. So we cannot easily make SETFLAGS
752 * more restrictive than just silently masking off visible but
753 * not settable flags as we always did.
754 */
755 flags &= EXT4_FL_USER_MODIFIABLE;
756 if (ext4_mask_flags(inode->i_mode, flags) != flags)
757 goto out;
758 err = ext4_ioctl_check_immutable(inode, fa->fsx_projid, flags);
759 if (err)
760 goto out;
761 err = ext4_ioctl_setflags(inode, flags);
762 if (err)
763 goto out;
764 err = ext4_ioctl_setproject(inode, fa->fsx_projid);
765 out:
766 ext4_fc_stop_update(inode);
767 return err;
768 }
769
770 /* So that the fiemap access checks can't overflow on 32 bit machines. */
771 #define FIEMAP_MAX_EXTENTS (UINT_MAX / sizeof(struct fiemap_extent))
772
773 static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg)
774 {
775 struct fiemap fiemap;
776 struct fiemap __user *ufiemap = (struct fiemap __user *) arg;
777 struct fiemap_extent_info fieinfo = { 0, };
778 struct inode *inode = file_inode(filp);
779 int error;
780
781 if (copy_from_user(&fiemap, ufiemap, sizeof(fiemap)))
782 return -EFAULT;
783
784 if (fiemap.fm_extent_count > FIEMAP_MAX_EXTENTS)
785 return -EINVAL;
786
787 fieinfo.fi_flags = fiemap.fm_flags;
788 fieinfo.fi_extents_max = fiemap.fm_extent_count;
789 fieinfo.fi_extents_start = ufiemap->fm_extents;
790
791 error = ext4_get_es_cache(inode, &fieinfo, fiemap.fm_start,
792 fiemap.fm_length);
793 fiemap.fm_flags = fieinfo.fi_flags;
794 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
795 if (copy_to_user(ufiemap, &fiemap, sizeof(fiemap)))
796 error = -EFAULT;
797
798 return error;
799 }
800
801 static int ext4_ioctl_checkpoint(struct file *filp, unsigned long arg)
802 {
803 int err = 0;
804 __u32 flags = 0;
805 unsigned int flush_flags = 0;
806 struct super_block *sb = file_inode(filp)->i_sb;
807 struct request_queue *q;
808
809 if (copy_from_user(&flags, (__u32 __user *)arg,
810 sizeof(__u32)))
811 return -EFAULT;
812
813 if (!capable(CAP_SYS_ADMIN))
814 return -EPERM;
815
816 /* check for invalid bits set */
817 if ((flags & ~EXT4_IOC_CHECKPOINT_FLAG_VALID) ||
818 ((flags & JBD2_JOURNAL_FLUSH_DISCARD) &&
819 (flags & JBD2_JOURNAL_FLUSH_ZEROOUT)))
820 return -EINVAL;
821
822 if (!EXT4_SB(sb)->s_journal)
823 return -ENODEV;
824
825 if (flags & ~EXT4_IOC_CHECKPOINT_FLAG_VALID)
826 return -EINVAL;
827
828 q = bdev_get_queue(EXT4_SB(sb)->s_journal->j_dev);
829 if (!q)
830 return -ENXIO;
831 if ((flags & JBD2_JOURNAL_FLUSH_DISCARD) && !blk_queue_discard(q))
832 return -EOPNOTSUPP;
833
834 if (flags & EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN)
835 return 0;
836
837 if (flags & EXT4_IOC_CHECKPOINT_FLAG_DISCARD)
838 flush_flags |= JBD2_JOURNAL_FLUSH_DISCARD;
839
840 if (flags & EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT) {
841 flush_flags |= JBD2_JOURNAL_FLUSH_ZEROOUT;
842 pr_info_ratelimited("warning: checkpointing journal with EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT can be slow");
843 }
844
845 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
846 err = jbd2_journal_flush(EXT4_SB(sb)->s_journal, flush_flags);
847 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
848
849 return err;
850 }
851
852 static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
853 {
854 struct inode *inode = file_inode(filp);
855 struct super_block *sb = inode->i_sb;
856 struct user_namespace *mnt_userns = file_mnt_user_ns(filp);
857
858 ext4_debug("cmd = %u, arg = %lu\n", cmd, arg);
859
860 switch (cmd) {
861 case FS_IOC_GETFSMAP:
862 return ext4_ioc_getfsmap(sb, (void __user *)arg);
863 case EXT4_IOC_GETVERSION:
864 case EXT4_IOC_GETVERSION_OLD:
865 return put_user(inode->i_generation, (int __user *) arg);
866 case EXT4_IOC_SETVERSION:
867 case EXT4_IOC_SETVERSION_OLD: {
868 handle_t *handle;
869 struct ext4_iloc iloc;
870 __u32 generation;
871 int err;
872
873 if (!inode_owner_or_capable(mnt_userns, inode))
874 return -EPERM;
875
876 if (ext4_has_metadata_csum(inode->i_sb)) {
877 ext4_warning(sb, "Setting inode version is not "
878 "supported with metadata_csum enabled.");
879 return -ENOTTY;
880 }
881
882 err = mnt_want_write_file(filp);
883 if (err)
884 return err;
885 if (get_user(generation, (int __user *) arg)) {
886 err = -EFAULT;
887 goto setversion_out;
888 }
889
890 inode_lock(inode);
891 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
892 if (IS_ERR(handle)) {
893 err = PTR_ERR(handle);
894 goto unlock_out;
895 }
896 err = ext4_reserve_inode_write(handle, inode, &iloc);
897 if (err == 0) {
898 inode->i_ctime = current_time(inode);
899 inode->i_generation = generation;
900 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
901 }
902 ext4_journal_stop(handle);
903
904 unlock_out:
905 inode_unlock(inode);
906 setversion_out:
907 mnt_drop_write_file(filp);
908 return err;
909 }
910 case EXT4_IOC_GROUP_EXTEND: {
911 ext4_fsblk_t n_blocks_count;
912 int err, err2=0;
913
914 err = ext4_resize_begin(sb);
915 if (err)
916 return err;
917
918 if (get_user(n_blocks_count, (__u32 __user *)arg)) {
919 err = -EFAULT;
920 goto group_extend_out;
921 }
922
923 if (ext4_has_feature_bigalloc(sb)) {
924 ext4_msg(sb, KERN_ERR,
925 "Online resizing not supported with bigalloc");
926 err = -EOPNOTSUPP;
927 goto group_extend_out;
928 }
929
930 err = mnt_want_write_file(filp);
931 if (err)
932 goto group_extend_out;
933
934 err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count);
935 if (EXT4_SB(sb)->s_journal) {
936 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
937 err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal, 0);
938 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
939 }
940 if (err == 0)
941 err = err2;
942 mnt_drop_write_file(filp);
943 group_extend_out:
944 ext4_resize_end(sb);
945 return err;
946 }
947
948 case EXT4_IOC_MOVE_EXT: {
949 struct move_extent me;
950 struct fd donor;
951 int err;
952
953 if (!(filp->f_mode & FMODE_READ) ||
954 !(filp->f_mode & FMODE_WRITE))
955 return -EBADF;
956
957 if (copy_from_user(&me,
958 (struct move_extent __user *)arg, sizeof(me)))
959 return -EFAULT;
960 me.moved_len = 0;
961
962 donor = fdget(me.donor_fd);
963 if (!donor.file)
964 return -EBADF;
965
966 if (!(donor.file->f_mode & FMODE_WRITE)) {
967 err = -EBADF;
968 goto mext_out;
969 }
970
971 if (ext4_has_feature_bigalloc(sb)) {
972 ext4_msg(sb, KERN_ERR,
973 "Online defrag not supported with bigalloc");
974 err = -EOPNOTSUPP;
975 goto mext_out;
976 } else if (IS_DAX(inode)) {
977 ext4_msg(sb, KERN_ERR,
978 "Online defrag not supported with DAX");
979 err = -EOPNOTSUPP;
980 goto mext_out;
981 }
982
983 err = mnt_want_write_file(filp);
984 if (err)
985 goto mext_out;
986
987 err = ext4_move_extents(filp, donor.file, me.orig_start,
988 me.donor_start, me.len, &me.moved_len);
989 mnt_drop_write_file(filp);
990
991 if (copy_to_user((struct move_extent __user *)arg,
992 &me, sizeof(me)))
993 err = -EFAULT;
994 mext_out:
995 fdput(donor);
996 return err;
997 }
998
999 case EXT4_IOC_GROUP_ADD: {
1000 struct ext4_new_group_data input;
1001
1002 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
1003 sizeof(input)))
1004 return -EFAULT;
1005
1006 return ext4_ioctl_group_add(filp, &input);
1007 }
1008
1009 case EXT4_IOC_MIGRATE:
1010 {
1011 int err;
1012 if (!inode_owner_or_capable(mnt_userns, inode))
1013 return -EACCES;
1014
1015 err = mnt_want_write_file(filp);
1016 if (err)
1017 return err;
1018 /*
1019 * inode_mutex prevent write and truncate on the file.
1020 * Read still goes through. We take i_data_sem in
1021 * ext4_ext_swap_inode_data before we switch the
1022 * inode format to prevent read.
1023 */
1024 inode_lock((inode));
1025 err = ext4_ext_migrate(inode);
1026 inode_unlock((inode));
1027 mnt_drop_write_file(filp);
1028 return err;
1029 }
1030
1031 case EXT4_IOC_ALLOC_DA_BLKS:
1032 {
1033 int err;
1034 if (!inode_owner_or_capable(mnt_userns, inode))
1035 return -EACCES;
1036
1037 err = mnt_want_write_file(filp);
1038 if (err)
1039 return err;
1040 err = ext4_alloc_da_blocks(inode);
1041 mnt_drop_write_file(filp);
1042 return err;
1043 }
1044
1045 case EXT4_IOC_SWAP_BOOT:
1046 {
1047 int err;
1048 if (!(filp->f_mode & FMODE_WRITE))
1049 return -EBADF;
1050 err = mnt_want_write_file(filp);
1051 if (err)
1052 return err;
1053 err = swap_inode_boot_loader(sb, mnt_userns, inode);
1054 mnt_drop_write_file(filp);
1055 return err;
1056 }
1057
1058 case EXT4_IOC_RESIZE_FS: {
1059 ext4_fsblk_t n_blocks_count;
1060 int err = 0, err2 = 0;
1061 ext4_group_t o_group = EXT4_SB(sb)->s_groups_count;
1062
1063 if (copy_from_user(&n_blocks_count, (__u64 __user *)arg,
1064 sizeof(__u64))) {
1065 return -EFAULT;
1066 }
1067
1068 err = ext4_resize_begin(sb);
1069 if (err)
1070 return err;
1071
1072 err = mnt_want_write_file(filp);
1073 if (err)
1074 goto resizefs_out;
1075
1076 err = ext4_resize_fs(sb, n_blocks_count);
1077 if (EXT4_SB(sb)->s_journal) {
1078 ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_RESIZE, NULL);
1079 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
1080 err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal, 0);
1081 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
1082 }
1083 if (err == 0)
1084 err = err2;
1085 mnt_drop_write_file(filp);
1086 if (!err && (o_group < EXT4_SB(sb)->s_groups_count) &&
1087 ext4_has_group_desc_csum(sb) &&
1088 test_opt(sb, INIT_INODE_TABLE))
1089 err = ext4_register_li_request(sb, o_group);
1090
1091 resizefs_out:
1092 ext4_resize_end(sb);
1093 return err;
1094 }
1095
1096 case FITRIM:
1097 {
1098 struct request_queue *q = bdev_get_queue(sb->s_bdev);
1099 struct fstrim_range range;
1100 int ret = 0;
1101
1102 if (!capable(CAP_SYS_ADMIN))
1103 return -EPERM;
1104
1105 if (!blk_queue_discard(q))
1106 return -EOPNOTSUPP;
1107
1108 /*
1109 * We haven't replayed the journal, so we cannot use our
1110 * block-bitmap-guided storage zapping commands.
1111 */
1112 if (test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb))
1113 return -EROFS;
1114
1115 if (copy_from_user(&range, (struct fstrim_range __user *)arg,
1116 sizeof(range)))
1117 return -EFAULT;
1118
1119 ret = ext4_trim_fs(sb, &range);
1120 if (ret < 0)
1121 return ret;
1122
1123 if (copy_to_user((struct fstrim_range __user *)arg, &range,
1124 sizeof(range)))
1125 return -EFAULT;
1126
1127 return 0;
1128 }
1129 case EXT4_IOC_PRECACHE_EXTENTS:
1130 return ext4_ext_precache(inode);
1131
1132 case FS_IOC_SET_ENCRYPTION_POLICY:
1133 if (!ext4_has_feature_encrypt(sb))
1134 return -EOPNOTSUPP;
1135 return fscrypt_ioctl_set_policy(filp, (const void __user *)arg);
1136
1137 case FS_IOC_GET_ENCRYPTION_PWSALT: {
1138 #ifdef CONFIG_FS_ENCRYPTION
1139 int err, err2;
1140 struct ext4_sb_info *sbi = EXT4_SB(sb);
1141 handle_t *handle;
1142
1143 if (!ext4_has_feature_encrypt(sb))
1144 return -EOPNOTSUPP;
1145 if (uuid_is_zero(sbi->s_es->s_encrypt_pw_salt)) {
1146 err = mnt_want_write_file(filp);
1147 if (err)
1148 return err;
1149 handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1);
1150 if (IS_ERR(handle)) {
1151 err = PTR_ERR(handle);
1152 goto pwsalt_err_exit;
1153 }
1154 err = ext4_journal_get_write_access(handle, sb,
1155 sbi->s_sbh,
1156 EXT4_JTR_NONE);
1157 if (err)
1158 goto pwsalt_err_journal;
1159 lock_buffer(sbi->s_sbh);
1160 generate_random_uuid(sbi->s_es->s_encrypt_pw_salt);
1161 ext4_superblock_csum_set(sb);
1162 unlock_buffer(sbi->s_sbh);
1163 err = ext4_handle_dirty_metadata(handle, NULL,
1164 sbi->s_sbh);
1165 pwsalt_err_journal:
1166 err2 = ext4_journal_stop(handle);
1167 if (err2 && !err)
1168 err = err2;
1169 pwsalt_err_exit:
1170 mnt_drop_write_file(filp);
1171 if (err)
1172 return err;
1173 }
1174 if (copy_to_user((void __user *) arg,
1175 sbi->s_es->s_encrypt_pw_salt, 16))
1176 return -EFAULT;
1177 return 0;
1178 #else
1179 return -EOPNOTSUPP;
1180 #endif
1181 }
1182 case FS_IOC_GET_ENCRYPTION_POLICY:
1183 if (!ext4_has_feature_encrypt(sb))
1184 return -EOPNOTSUPP;
1185 return fscrypt_ioctl_get_policy(filp, (void __user *)arg);
1186
1187 case FS_IOC_GET_ENCRYPTION_POLICY_EX:
1188 if (!ext4_has_feature_encrypt(sb))
1189 return -EOPNOTSUPP;
1190 return fscrypt_ioctl_get_policy_ex(filp, (void __user *)arg);
1191
1192 case FS_IOC_ADD_ENCRYPTION_KEY:
1193 if (!ext4_has_feature_encrypt(sb))
1194 return -EOPNOTSUPP;
1195 return fscrypt_ioctl_add_key(filp, (void __user *)arg);
1196
1197 case FS_IOC_REMOVE_ENCRYPTION_KEY:
1198 if (!ext4_has_feature_encrypt(sb))
1199 return -EOPNOTSUPP;
1200 return fscrypt_ioctl_remove_key(filp, (void __user *)arg);
1201
1202 case FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
1203 if (!ext4_has_feature_encrypt(sb))
1204 return -EOPNOTSUPP;
1205 return fscrypt_ioctl_remove_key_all_users(filp,
1206 (void __user *)arg);
1207 case FS_IOC_GET_ENCRYPTION_KEY_STATUS:
1208 if (!ext4_has_feature_encrypt(sb))
1209 return -EOPNOTSUPP;
1210 return fscrypt_ioctl_get_key_status(filp, (void __user *)arg);
1211
1212 case FS_IOC_GET_ENCRYPTION_NONCE:
1213 if (!ext4_has_feature_encrypt(sb))
1214 return -EOPNOTSUPP;
1215 return fscrypt_ioctl_get_nonce(filp, (void __user *)arg);
1216
1217 case EXT4_IOC_CLEAR_ES_CACHE:
1218 {
1219 if (!inode_owner_or_capable(mnt_userns, inode))
1220 return -EACCES;
1221 ext4_clear_inode_es(inode);
1222 return 0;
1223 }
1224
1225 case EXT4_IOC_GETSTATE:
1226 {
1227 __u32 state = 0;
1228
1229 if (ext4_test_inode_state(inode, EXT4_STATE_EXT_PRECACHED))
1230 state |= EXT4_STATE_FLAG_EXT_PRECACHED;
1231 if (ext4_test_inode_state(inode, EXT4_STATE_NEW))
1232 state |= EXT4_STATE_FLAG_NEW;
1233 if (ext4_test_inode_state(inode, EXT4_STATE_NEWENTRY))
1234 state |= EXT4_STATE_FLAG_NEWENTRY;
1235 if (ext4_test_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE))
1236 state |= EXT4_STATE_FLAG_DA_ALLOC_CLOSE;
1237
1238 return put_user(state, (__u32 __user *) arg);
1239 }
1240
1241 case EXT4_IOC_GET_ES_CACHE:
1242 return ext4_ioctl_get_es_cache(filp, arg);
1243
1244 case EXT4_IOC_SHUTDOWN:
1245 return ext4_shutdown(sb, arg);
1246
1247 case FS_IOC_ENABLE_VERITY:
1248 if (!ext4_has_feature_verity(sb))
1249 return -EOPNOTSUPP;
1250 return fsverity_ioctl_enable(filp, (const void __user *)arg);
1251
1252 case FS_IOC_MEASURE_VERITY:
1253 if (!ext4_has_feature_verity(sb))
1254 return -EOPNOTSUPP;
1255 return fsverity_ioctl_measure(filp, (void __user *)arg);
1256
1257 case FS_IOC_READ_VERITY_METADATA:
1258 if (!ext4_has_feature_verity(sb))
1259 return -EOPNOTSUPP;
1260 return fsverity_ioctl_read_metadata(filp,
1261 (const void __user *)arg);
1262
1263 case EXT4_IOC_CHECKPOINT:
1264 return ext4_ioctl_checkpoint(filp, arg);
1265
1266 default:
1267 return -ENOTTY;
1268 }
1269 }
1270
1271 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1272 {
1273 long ret;
1274
1275 ext4_fc_start_update(file_inode(filp));
1276 ret = __ext4_ioctl(filp, cmd, arg);
1277 ext4_fc_stop_update(file_inode(filp));
1278
1279 return ret;
1280 }
1281
1282 #ifdef CONFIG_COMPAT
1283 long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1284 {
1285 /* These are just misnamed, they actually get/put from/to user an int */
1286 switch (cmd) {
1287 case EXT4_IOC32_GETVERSION:
1288 cmd = EXT4_IOC_GETVERSION;
1289 break;
1290 case EXT4_IOC32_SETVERSION:
1291 cmd = EXT4_IOC_SETVERSION;
1292 break;
1293 case EXT4_IOC32_GROUP_EXTEND:
1294 cmd = EXT4_IOC_GROUP_EXTEND;
1295 break;
1296 case EXT4_IOC32_GETVERSION_OLD:
1297 cmd = EXT4_IOC_GETVERSION_OLD;
1298 break;
1299 case EXT4_IOC32_SETVERSION_OLD:
1300 cmd = EXT4_IOC_SETVERSION_OLD;
1301 break;
1302 case EXT4_IOC32_GETRSVSZ:
1303 cmd = EXT4_IOC_GETRSVSZ;
1304 break;
1305 case EXT4_IOC32_SETRSVSZ:
1306 cmd = EXT4_IOC_SETRSVSZ;
1307 break;
1308 case EXT4_IOC32_GROUP_ADD: {
1309 struct compat_ext4_new_group_input __user *uinput;
1310 struct ext4_new_group_data input;
1311 int err;
1312
1313 uinput = compat_ptr(arg);
1314 err = get_user(input.group, &uinput->group);
1315 err |= get_user(input.block_bitmap, &uinput->block_bitmap);
1316 err |= get_user(input.inode_bitmap, &uinput->inode_bitmap);
1317 err |= get_user(input.inode_table, &uinput->inode_table);
1318 err |= get_user(input.blocks_count, &uinput->blocks_count);
1319 err |= get_user(input.reserved_blocks,
1320 &uinput->reserved_blocks);
1321 if (err)
1322 return -EFAULT;
1323 return ext4_ioctl_group_add(file, &input);
1324 }
1325 case EXT4_IOC_MOVE_EXT:
1326 case EXT4_IOC_RESIZE_FS:
1327 case FITRIM:
1328 case EXT4_IOC_PRECACHE_EXTENTS:
1329 case FS_IOC_SET_ENCRYPTION_POLICY:
1330 case FS_IOC_GET_ENCRYPTION_PWSALT:
1331 case FS_IOC_GET_ENCRYPTION_POLICY:
1332 case FS_IOC_GET_ENCRYPTION_POLICY_EX:
1333 case FS_IOC_ADD_ENCRYPTION_KEY:
1334 case FS_IOC_REMOVE_ENCRYPTION_KEY:
1335 case FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
1336 case FS_IOC_GET_ENCRYPTION_KEY_STATUS:
1337 case FS_IOC_GET_ENCRYPTION_NONCE:
1338 case EXT4_IOC_SHUTDOWN:
1339 case FS_IOC_GETFSMAP:
1340 case FS_IOC_ENABLE_VERITY:
1341 case FS_IOC_MEASURE_VERITY:
1342 case FS_IOC_READ_VERITY_METADATA:
1343 case EXT4_IOC_CLEAR_ES_CACHE:
1344 case EXT4_IOC_GETSTATE:
1345 case EXT4_IOC_GET_ES_CACHE:
1346 case EXT4_IOC_CHECKPOINT:
1347 break;
1348 default:
1349 return -ENOIOCTLCMD;
1350 }
1351 return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
1352 }
1353 #endif