2 * quota.c --- code for handling ext4 quota inodes
7 #ifdef HAVE_SYS_MOUNT_H
10 #define MNT_FL (MS_MGC_VAL | MS_RDONLY)
12 #ifdef HAVE_SYS_STAT_H
19 static void move_quota_inode(ext2_filsys fs, ext2_ino_t from_ino,
20 ext2_ino_t to_ino, enum quota_type qtype)
22 struct ext2_inode inode;
24 char qf_name[QUOTA_NAME_LEN];
26 /* We need the inode bitmap to be loaded */
27 if (ext2fs_read_bitmaps(fs))
30 retval = ext2fs_read_inode(fs, from_ino, &inode);
32 com_err("ext2fs_read_inode", retval, "%s",
33 _("in move_quota_inode"));
37 inode.i_links_count = 1;
38 inode.i_mode = LINUX_S_IFREG | 0600;
39 inode.i_flags = EXT2_IMMUTABLE_FL;
40 if (ext2fs_has_feature_extents(fs->super))
41 inode.i_flags |= EXT4_EXTENTS_FL;
43 retval = ext2fs_write_new_inode(fs, to_ino, &inode);
45 com_err("ext2fs_write_new_inode", retval, "%s",
46 _("in move_quota_inode"));
50 /* unlink the old inode */
51 quota_get_qf_name(qtype, QFMT_VFS_V1, qf_name);
52 ext2fs_unlink(fs, EXT2_ROOT_INO, qf_name, from_ino, 0);
53 ext2fs_inode_alloc_stats(fs, from_ino, -1);
54 /* Clear out the original inode in the inode-table block. */
55 memset(&inode, 0, sizeof(struct ext2_inode));
56 ext2fs_write_inode(fs, from_ino, &inode);
59 void e2fsck_hide_quota(e2fsck_t ctx)
61 struct ext2_super_block *sb = ctx->fs->super;
62 struct problem_context pctx;
63 ext2_filsys fs = ctx->fs;
64 enum quota_type qtype;
67 clear_problem_context(&pctx);
69 if ((ctx->options & E2F_OPT_READONLY) ||
70 !ext2fs_has_feature_quota(sb))
73 for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
74 pctx.dir = 2; /* This is a guess, but it's a good one */
75 pctx.ino = *quota_sb_inump(sb, qtype);
77 quota_ino = quota_type2inum(qtype, fs->super);
78 if (pctx.ino && (pctx.ino != quota_ino) &&
79 fix_problem(ctx, PR_0_HIDE_QUOTA, &pctx)) {
80 move_quota_inode(fs, pctx.ino, quota_ino, qtype);
81 *quota_sb_inump(sb, qtype) = quota_ino;
82 ext2fs_mark_super_dirty(fs);
89 void e2fsck_validate_quota_inodes(e2fsck_t ctx)
91 struct ext2_super_block *sb = ctx->fs->super;
92 struct problem_context pctx;
93 ext2_filsys fs = ctx->fs;
94 enum quota_type qtype;
96 clear_problem_context(&pctx);
98 for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
99 pctx.ino = *quota_sb_inump(sb, qtype);
102 ((pctx.ino == EXT2_BAD_INO) ||
103 (pctx.ino == EXT2_ROOT_INO) ||
104 (pctx.ino == EXT2_BOOT_LOADER_INO) ||
105 (pctx.ino == EXT2_UNDEL_DIR_INO) ||
106 (pctx.ino == EXT2_RESIZE_INO) ||
107 (pctx.ino == EXT2_JOURNAL_INO) ||
108 (pctx.ino == EXT2_EXCLUDE_INO) ||
109 (pctx.ino == EXT4_REPLICA_INO) ||
110 (pctx.ino > fs->super->s_inodes_count)) &&
111 fix_problem(ctx, PR_0_INVALID_QUOTA_INO, &pctx)) {
112 *quota_sb_inump(sb, qtype) = 0;
113 ext2fs_mark_super_dirty(fs);