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