]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - quota/report.c
2 * Copyright (c) 2005 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #include <xfs/command.h>
39 static cmdinfo_t dump_cmd
;
40 static cmdinfo_t report_cmd
;
45 dump_cmd
.args
= _("[-gpu] [-f file]");
46 dump_cmd
.oneline
= _("dump quota information for backup utilities");
49 " create a backup file which contains quota limits information\n"
50 " -g -- dump out group quota limits\n"
51 " -p -- dump out project quota limits\n"
52 " -u -- dump out user quota limits (default)\n"
53 " -f -- write the dump out to the specified file\n"
60 report_cmd
.args
= _("[-bir] [-gpu] [-ahnt] [-f file]");
61 report_cmd
.oneline
= _("report filesystem quota information");
64 " report used space and inodes, and quota limits, for a filesystem\n"
67 " (reports inode usage for all groups, in an easy-to-read format)\n"
68 " This command is the equivalent of the traditional repquota command, which\n"
69 " prints a summary of the disk usage and quotas for the current filesystem,\n"
70 " or all filesystems.\n"
71 " -a -- report for all mounted filesystems with quota enabled\n"
72 " -h -- report in a human-readable format\n"
73 " -n -- suppress the header from the output\n"
74 " -t -- terse output format, hides rows which are all zero\n"
75 " -g -- report group usage and quota information\n"
76 " -p -- report project usage and quota information\n"
77 " -u -- report user usage and quota information\n"
78 " -b -- report blocks-used information only\n"
79 " -i -- report inodes-used information only\n"
80 " -r -- report realtime-blocks-used information only\n"
93 if (xfsquotactl(XFS_GETQUOTA
, dev
, type
, id
, (void *)&d
) < 0)
95 fprintf(fp
, "fs = %s\n", dev
);
96 fprintf(fp
, "%-10d %7llu %7llu %7llu %7llu %7llu %7llu\n", id
,
97 (unsigned long long)d
.d_blk_softlimit
,
98 (unsigned long long)d
.d_blk_hardlimit
,
99 (unsigned long long)d
.d_ino_softlimit
,
100 (unsigned long long)d
.d_ino_hardlimit
,
101 (unsigned long long)d
.d_rtb_softlimit
,
102 (unsigned long long)d
.d_rtb_hardlimit
);
106 dump_limits_any_type(
113 if ((mount
= fs_table_lookup(dir
, FS_MOUNT_POINT
)) == NULL
) {
114 fprintf(stderr
, "%s: cannot find mount point %s\n",
120 case XFS_GROUP_QUOTA
: {
123 while ((g
= getgrent()) != NULL
)
124 dump_file(fp
, g
->gr_gid
, type
, mount
->fs_name
);
128 case XFS_PROJ_QUOTA
: {
129 struct fs_project
*p
;
131 while ((p
= getprent()) != NULL
)
132 dump_file(fp
, p
->pr_prid
, type
, mount
->fs_name
);
136 case XFS_USER_QUOTA
: {
139 while ((u
= getpwent()) != NULL
)
140 dump_file(fp
, u
->pw_uid
, type
, mount
->fs_name
);
154 int c
, type
= XFS_USER_QUOTA
;
156 while ((c
= getopt(argc
, argv
, "f:gpu")) != EOF
) {
162 type
= XFS_GROUP_QUOTA
;
165 type
= XFS_PROJ_QUOTA
;
168 type
= XFS_USER_QUOTA
;
171 return command_usage(&dump_cmd
);
176 return command_usage(&dump_cmd
);
178 if ((fp
= fopen_write_secure(fname
)) == NULL
)
181 dump_limits_any_type(fp
, type
, fs_path
->fs_dir
);
197 char *typename
= type_to_string(type
);
201 if (flags
& NO_HEADER_FLAG
)
205 fprintf(fp
, _("%s quota on %s (%s)\n"),
206 typename
, mount
->fs_dir
, mount
->fs_name
);
209 for (i
= 0; i
< 10; i
++)
211 if (form
& XFS_BLOCK_QUOTA
)
212 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
213 "%13c %s %13c" : "%20c %s %20c",
214 ' ', form_to_string(XFS_BLOCK_QUOTA
), ' ');
215 if (form
& XFS_INODE_QUOTA
)
216 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
217 "%13c %s %13c" : "%20c %s %20c",
218 ' ', form_to_string(XFS_INODE_QUOTA
), ' ');
219 if (form
& XFS_RTBLOCK_QUOTA
)
220 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
221 "%9c %s %9c" : "%15c %s %15c",
222 ' ', form_to_string(XFS_RTBLOCK_QUOTA
), ' ');
226 snprintf(scratch
, sizeof(scratch
), "%s ID", typename
);
227 fprintf(fp
, "%-10s ", scratch
);
228 if (form
& XFS_BLOCK_QUOTA
)
229 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
230 _(" Used Soft Hard Warn/Grace ") :
231 _(" Used Soft Hard Warn/Grace "));
232 if (form
& XFS_INODE_QUOTA
)
233 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
234 _(" Used Soft Hard Warn/Grace ") :
235 _(" Used Soft Hard Warn/ Grace "));
236 if (form
& XFS_RTBLOCK_QUOTA
)
237 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
238 _(" Used Soft Hard Warn/Grace ") :
239 _(" Used Soft Hard Warn/Grace "));
243 for (i
= 0; i
< 10; i
++)
246 count
= (flags
& HUMAN_FLAG
) ? 33 : 50;
247 if (form
& XFS_BLOCK_QUOTA
) {
248 for (i
= 0; i
< count
; i
++)
252 if (form
& XFS_INODE_QUOTA
) {
253 for (i
= 0; i
< count
; i
++)
257 if (form
& XFS_RTBLOCK_QUOTA
) {
258 for (i
= 0; i
< count
; i
++)
276 char *dev
= mount
->fs_name
;
277 char c
[8], h
[8], s
[8];
281 if (xfsquotactl(XFS_GETQUOTA
, dev
, type
, id
, (void *)&d
) < 0)
284 if (flags
& TERSE_FLAG
) {
286 if ((form
& XFS_BLOCK_QUOTA
) && d
.d_bcount
)
288 if ((form
& XFS_INODE_QUOTA
) && d
.d_icount
)
290 if ((form
& XFS_RTBLOCK_QUOTA
) && d
.d_rtbcount
)
296 if (!(flags
& NO_HEADER_FLAG
))
297 report_header(fp
, form
, type
, mount
, flags
);
299 fprintf(fp
, "%-10s", name
);
300 if (form
& XFS_BLOCK_QUOTA
) {
301 qflags
= (flags
& HUMAN_FLAG
);
302 if (d
.d_blk_hardlimit
&& d
.d_bcount
> d
.d_blk_hardlimit
)
303 qflags
|= LIMIT_FLAG
;
304 if (d
.d_blk_softlimit
&& d
.d_bcount
> d
.d_blk_softlimit
)
305 qflags
|= QUOTA_FLAG
;
306 if (flags
& HUMAN_FLAG
)
307 fprintf(fp
, " %6s %6s %6s %02d %8s",
308 bbs_to_string(d
.d_bcount
, c
, sizeof(c
)),
309 bbs_to_string(d
.d_blk_softlimit
, s
, sizeof(s
)),
310 bbs_to_string(d
.d_blk_hardlimit
, h
, sizeof(h
)),
312 time_to_string(d
.d_btimer
, qflags
));
314 fprintf(fp
, " %10llu %10llu %10llu %02d %9s",
315 (unsigned long long)d
.d_bcount
>> 1,
316 (unsigned long long)d
.d_blk_softlimit
>> 1,
317 (unsigned long long)d
.d_blk_hardlimit
>> 1,
319 time_to_string(d
.d_btimer
, qflags
));
321 if (form
& XFS_INODE_QUOTA
) {
322 qflags
= (flags
& HUMAN_FLAG
);
323 if (d
.d_ino_hardlimit
&& d
.d_icount
> d
.d_ino_hardlimit
)
324 qflags
|= LIMIT_FLAG
;
325 if (d
.d_ino_softlimit
&& d
.d_icount
> d
.d_ino_softlimit
)
326 qflags
|= QUOTA_FLAG
;
327 if (flags
& HUMAN_FLAG
)
328 fprintf(fp
, " %6s %6s %6s %02d %8s",
329 num_to_string(d
.d_icount
, c
, sizeof(c
)),
330 num_to_string(d
.d_ino_softlimit
, s
, sizeof(s
)),
331 num_to_string(d
.d_ino_hardlimit
, h
, sizeof(h
)),
333 time_to_string(d
.d_itimer
, qflags
));
335 fprintf(fp
, " %10llu %10llu %10llu %02d %9s",
336 (unsigned long long)d
.d_icount
,
337 (unsigned long long)d
.d_ino_softlimit
,
338 (unsigned long long)d
.d_ino_hardlimit
,
340 time_to_string(d
.d_itimer
, qflags
));
342 if (form
& XFS_RTBLOCK_QUOTA
) {
343 qflags
= (flags
& HUMAN_FLAG
);
344 if (d
.d_rtb_hardlimit
&& d
.d_rtbcount
> d
.d_rtb_hardlimit
)
345 qflags
|= LIMIT_FLAG
;
346 if (d
.d_rtb_softlimit
&& d
.d_rtbcount
> d
.d_rtb_softlimit
)
347 qflags
|= QUOTA_FLAG
;
348 if (flags
& HUMAN_FLAG
)
349 fprintf(fp
, " %6s %6s %6s %02d %8s",
350 bbs_to_string(d
.d_rtbcount
, c
, sizeof(c
)),
351 bbs_to_string(d
.d_rtb_softlimit
, s
, sizeof(s
)),
352 bbs_to_string(d
.d_rtb_hardlimit
, h
, sizeof(h
)),
354 time_to_string(d
.d_rtbtimer
, qflags
));
356 fprintf(fp
, " %10llu %10llu %10llu %02d %9s",
357 (unsigned long long)d
.d_rtbcount
>> 1,
358 (unsigned long long)d
.d_rtb_softlimit
>> 1,
359 (unsigned long long)d
.d_rtb_hardlimit
>> 1,
361 time_to_string(d
.d_rtbtimer
, qflags
));
377 while ((u
= getpwent()) != NULL
)
378 if (report_mount(fp
, u
->pw_uid
, u
->pw_name
,
379 form
, XFS_USER_QUOTA
, mount
, flags
))
380 flags
|= NO_HEADER_FLAG
;
381 if (flags
& NO_HEADER_FLAG
)
396 while ((g
= getgrent()) != NULL
)
397 if (report_mount(fp
, g
->gr_gid
, g
->gr_name
,
398 form
, XFS_GROUP_QUOTA
, mount
, flags
))
399 flags
|= NO_HEADER_FLAG
;
400 if (flags
& NO_HEADER_FLAG
)
406 report_project_mount(
415 while ((p
= getprent()) != NULL
)
416 if (report_mount(fp
, p
->pr_prid
, p
->pr_name
,
417 form
, XFS_PROJ_QUOTA
, mount
, flags
))
418 flags
|= NO_HEADER_FLAG
;
419 if (flags
& NO_HEADER_FLAG
)
435 if (type
& XFS_USER_QUOTA
) {
436 fs_cursor_initialise(dir
, FS_MOUNT_POINT
, &cursor
);
437 while ((mount
= fs_cursor_next_entry(&cursor
)))
438 report_user_mount(fp
, form
, mount
, flags
);
440 if (type
& XFS_GROUP_QUOTA
) {
441 fs_cursor_initialise(dir
, FS_MOUNT_POINT
, &cursor
);
442 while ((mount
= fs_cursor_next_entry(&cursor
)))
443 report_group_mount(fp
, form
, mount
, flags
);
445 if (type
& XFS_PROJ_QUOTA
) {
446 fs_cursor_initialise(dir
, FS_MOUNT_POINT
, &cursor
);
447 while ((mount
= fs_cursor_next_entry(&cursor
)))
448 report_project_mount(fp
, form
, mount
, flags
);
459 int c
, flags
= 0, type
= 0, form
= 0;
461 while ((c
= getopt(argc
, argv
, "abf:hgniprtu")) != EOF
) {
467 form
|= XFS_BLOCK_QUOTA
;
470 form
|= XFS_INODE_QUOTA
;
473 form
|= XFS_RTBLOCK_QUOTA
;
476 type
|= XFS_GROUP_QUOTA
;
479 type
|= XFS_PROJ_QUOTA
;
482 type
|= XFS_USER_QUOTA
;
485 flags
|= ALL_MOUNTS_FLAG
;
491 flags
|= NO_HEADER_FLAG
;
497 return command_usage(&report_cmd
);
502 form
= XFS_BLOCK_QUOTA
;
505 type
= XFS_USER_QUOTA
| XFS_GROUP_QUOTA
| XFS_PROJ_QUOTA
;
507 if ((fp
= fopen_write_secure(fname
)) == NULL
)
511 report_any_type(fp
, form
, type
, (flags
& ALL_MOUNTS_FLAG
) ?
512 NULL
: fs_path
->fs_dir
, flags
);
513 else while (argc
> optind
)
514 report_any_type(fp
, form
, type
, argv
[optind
++], flags
);
524 dump_cmd
.name
= _("dump");
525 dump_cmd
.cfunc
= dump_f
;
527 dump_cmd
.argmax
= -1;
528 dump_cmd
.args
= _("[-gpu] [-f file]");
529 dump_cmd
.oneline
= _("dump quota information for backup utilities");
530 dump_cmd
.help
= dump_help
;
532 report_cmd
.name
= _("report");
533 report_cmd
.altname
= _("repquota");
534 report_cmd
.cfunc
= report_f
;
535 report_cmd
.argmin
= 0;
536 report_cmd
.argmax
= -1;
537 report_cmd
.args
= _("[-bir] [-gpu] [-ahnt] [-f file]");
538 report_cmd
.oneline
= _("report filesystem quota information");
539 report_cmd
.help
= report_help
;
542 add_command(&dump_cmd
);
543 add_command(&report_cmd
);