2 * quota.c --- debugfs quota commands
4 * Copyright (C) 2014 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
18 #include <sys/types.h>
28 const char *quota_type
[] = { "user", "group", "project", NULL
};
30 static int load_quota_ctx(char *progname
)
34 if (check_fs_open(progname
))
37 if (!ext2fs_has_feature_quota(current_fs
->super
)) {
38 com_err(progname
, 0, "quota feature not enabled");
45 retval
= quota_init_context(¤t_qctx
, current_fs
, 0);
47 com_err(current_fs
->device_name
, retval
,
48 "while trying to load quota information");
54 static int parse_quota_type(const char *cmdname
, const char *str
)
61 for (i
= 0; i
< MAXQUOTAS
; i
++) {
62 if (strcasecmp(str
, quota_type
[i
]) == 0)
66 i
= strtol(str
, &t
, 0);
70 if (i
< 0 || i
>= MAXQUOTAS
) {
71 com_err(0, 0, "Invalid quota type: %s", str
);
72 printf("Valid quota types are: ");
73 for (i
= 0; i
< MAXQUOTAS
; i
++)
74 printf("%s ", quota_type
[i
]);
79 if (current_fs
->flags
& EXT2_FLAG_RW
)
80 flags
|= EXT2_FILE_WRITE
;
82 retval
= quota_file_open(current_qctx
, NULL
, 0, i
, -1, flags
);
84 com_err(cmdname
, retval
,
85 "while opening quota inode (type %d)", i
);
92 static int list_quota_callback(struct dquot
*dq
,
93 void *cb_data
EXT2FS_ATTR((unused
)))
95 printf("%10u %8lld %8lld %8lld %8lld %8lld %8lld\n",
96 dq
->dq_id
, (long long)dq
->dq_dqb
.dqb_curspace
,
97 (long long)dq
->dq_dqb
.dqb_bsoftlimit
,
98 (long long)dq
->dq_dqb
.dqb_bhardlimit
,
99 (long long)dq
->dq_dqb
.dqb_curinodes
,
100 (long long)dq
->dq_dqb
.dqb_isoftlimit
,
101 (long long)dq
->dq_dqb
.dqb_ihardlimit
);
105 void do_list_quota(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
106 void *infop
EXT2FS_ATTR((unused
)))
110 struct quota_handle
*qh
;
112 if (load_quota_ctx(argv
[0]))
116 com_err(0, 0, "Usage: list_quota <quota_type>\n");
120 type
= parse_quota_type(argv
[0], argv
[1]);
124 printf("%7s %2s %8s %8s %8s %8s %8s %8s\n",
125 quota_type
[type
], "id",
126 "blocks", "quota", "limit", "inodes", "quota", "limit");
127 qh
= current_qctx
->quota_file
[type
];
128 retval
= qh
->qh_ops
->scan_dquots(qh
, list_quota_callback
, NULL
);
130 com_err(argv
[0], retval
, "while scanning dquots");
135 void do_get_quota(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
136 void *infop
EXT2FS_ATTR((unused
)))
139 struct quota_handle
*qh
;
143 if (load_quota_ctx(argv
[0]))
147 com_err(0, 0, "Usage: get_quota <quota_type> <id>\n");
151 type
= parse_quota_type(argv
[0], argv
[1]);
155 id
= parse_ulong(argv
[2], argv
[0], "id", &err
);
159 printf("%7s %2s %8s %8s %8s %8s %8s %8s\n",
160 quota_type
[type
], "id",
161 "blocks", "quota", "limit", "inodes", "quota", "limit");
163 qh
= current_qctx
->quota_file
[type
];
165 dq
= qh
->qh_ops
->read_dquot(qh
, id
);
167 list_quota_callback(dq
, NULL
);
168 ext2fs_free_mem(&dq
);
170 com_err(argv
[0], 0, "couldn't read quota record");