1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*
* quota.c --- code for handling ext4 quota inodes
*
*/
#ifdef HAVE_SYS_MOUNT_H
#include <sys/param.h>
#include <sys/mount.h>
#define MNT_FL (MS_MGC_VAL | MS_RDONLY)
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include "e2fsck.h"
#include "problem.h"
#include "quota/mkquota.h"
static void move_quota_inode(ext2_filsys fs, ext2_ino_t from_ino,
ext2_ino_t to_ino, int qtype)
{
struct ext2_super_block *sb = fs->super;
ext2_ino_t ino;
struct ext2_inode inode;
errcode_t retval;
char qf_name[255];
if (ext2fs_read_inode(fs, from_ino, &inode))
return;
inode.i_links_count = 1;
inode.i_mode = LINUX_S_IFREG | 0600;
inode.i_flags = EXT2_IMMUTABLE_FL;
if (fs->super->s_feature_incompat &
EXT3_FEATURE_INCOMPAT_EXTENTS)
inode.i_flags |= EXT4_EXTENTS_FL;
ext2fs_write_new_inode(fs, to_ino, &inode);
/* unlink the old inode */
get_qf_name(qtype, QFMT_VFS_V1, qf_name);
ext2fs_unlink(fs, EXT2_ROOT_INO, qf_name, from_ino, 0);
ext2fs_inode_alloc_stats(fs, from_ino, -1);
}
void e2fsck_hide_quota(e2fsck_t ctx)
{
struct ext2_super_block *sb = ctx->fs->super;
struct problem_context pctx;
ext2_filsys fs = ctx->fs;
clear_problem_context(&pctx);
if ((ctx->options & E2F_OPT_READONLY) ||
!(sb->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_QUOTA))
return;
/* We need the inode bitmap to be loaded */
if (ext2fs_read_bitmaps(fs))
return;
if (!sb->s_usr_quota_inum && !sb->s_grp_quota_inum)
/* nothing to do */
return;
if (sb->s_usr_quota_inum == EXT4_USR_QUOTA_INO &&
sb->s_grp_quota_inum == EXT4_GRP_QUOTA_INO)
/* nothing to do */
return;
if (!fix_problem(ctx, PR_0_HIDE_QUOTA, &pctx))
return;
if (sb->s_usr_quota_inum &&
sb->s_usr_quota_inum != EXT4_USR_QUOTA_INO) {
move_quota_inode(fs, sb->s_usr_quota_inum, EXT4_USR_QUOTA_INO,
USRQUOTA);
sb->s_usr_quota_inum = EXT4_USR_QUOTA_INO;
}
if (sb->s_grp_quota_inum &&
sb->s_grp_quota_inum != EXT4_GRP_QUOTA_INO) {
move_quota_inode(fs, sb->s_grp_quota_inum, EXT4_GRP_QUOTA_INO,
GRPQUOTA);
sb->s_grp_quota_inum = EXT4_GRP_QUOTA_INO;
}
return;
}
|