]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - quota/quota.c
2 * Copyright (c) 2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 static cmdinfo_t quota_cmd
;
34 " display usage and quota information\n"
36 " -g -- display group quota information\n"
37 " -p -- display project quota information\n"
38 " -u -- display user quota information\n"
39 " -b -- display number of blocks used\n"
40 " -i -- display number of inodes used\n"
41 " -r -- display number of realtime blocks used\n"
42 " -h -- report in a human-readable format\n"
43 " -n -- skip identifier-to-name translations, just report IDs\n"
44 " -N -- suppress the initial header\n"
45 " -v -- increase verbosity in reporting (also dumps zero values)\n"
46 " -f -- send output to a file\n"
47 " The (optional) user/group/project can be specified either by name or by\n"
48 " number (i.e. uid/gid/projid).\n"
63 char *dev
= mount
->fs_name
;
64 char c
[8], h
[8], s
[8];
68 xfsquotactl(XFS_QSYNC
, dev
, type
, 0, NULL
);
69 if (xfsquotactl(XFS_GETQUOTA
, dev
, type
, id
, (void *)&d
) < 0)
72 if (!(flags
& VERBOSE_FLAG
)) {
74 if ((form
& XFS_BLOCK_QUOTA
) && d
.d_bcount
)
76 if ((form
& XFS_INODE_QUOTA
) && d
.d_icount
)
78 if ((form
& XFS_RTBLOCK_QUOTA
) && d
.d_rtbcount
)
84 if (!(flags
& NO_HEADER_FLAG
)) {
86 _("Disk quotas for %s %s (%u)\nFilesystem%s"),
87 type_to_string(type
), name
, id
,
88 (flags
& HUMAN_FLAG
) ? " " : " ");
89 if (form
& XFS_BLOCK_QUOTA
)
90 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
91 _(" Blocks Quota Limit Warn/Time ") :
92 _(" Blocks Quota Limit Warn/Time "));
93 if (form
& XFS_INODE_QUOTA
)
94 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
95 _(" Files Quota Limit Warn/Time ") :
96 _(" Files Quota Limit Warn/Time "));
97 if (form
& XFS_RTBLOCK_QUOTA
)
98 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
99 _("Realtime Quota Limit Warn/Time ") :
100 _(" Realtime Quota Limit Warn/Time "));
101 fputs("Mounted on\n", fp
);
104 if (flags
& HUMAN_FLAG
) {
105 count
= fprintf(fp
, "%-12s", dev
);
107 fprintf(fp
, "\n%12s", " ");
109 count
= fprintf(fp
, "%-19s", dev
);
111 fprintf(fp
, "\n%19s", " ");
114 if (form
& XFS_BLOCK_QUOTA
) {
115 qflags
= (flags
& HUMAN_FLAG
);
116 if (d
.d_blk_hardlimit
&& d
.d_bcount
> d
.d_blk_hardlimit
)
117 qflags
|= LIMIT_FLAG
;
118 if (d
.d_blk_softlimit
&& d
.d_bcount
> d
.d_blk_softlimit
)
119 qflags
|= QUOTA_FLAG
;
120 if (flags
& HUMAN_FLAG
)
121 fprintf(fp
, " %6s %6s %6s %02d %8s ",
122 bbs_to_string(d
.d_bcount
, c
, sizeof(c
)),
123 bbs_to_string(d
.d_blk_softlimit
, s
, sizeof(s
)),
124 bbs_to_string(d
.d_blk_hardlimit
, h
, sizeof(h
)),
126 time_to_string(d
.d_btimer
, qflags
));
128 fprintf(fp
, " %10llu %10llu %10llu %02d %9s ",
129 (unsigned long long)d
.d_bcount
>> 1,
130 (unsigned long long)d
.d_blk_softlimit
>> 1,
131 (unsigned long long)d
.d_blk_hardlimit
>> 1,
133 time_to_string(d
.d_btimer
, qflags
));
135 if (form
& XFS_INODE_QUOTA
) {
136 qflags
= (flags
& HUMAN_FLAG
);
137 if (d
.d_ino_hardlimit
&& d
.d_icount
> d
.d_ino_hardlimit
)
138 qflags
|= LIMIT_FLAG
;
139 if (d
.d_ino_softlimit
&& d
.d_icount
> d
.d_ino_softlimit
)
140 qflags
|= QUOTA_FLAG
;
141 if (flags
& HUMAN_FLAG
)
142 fprintf(fp
, " %6s %6s %6s %02d %8s ",
143 num_to_string(d
.d_icount
, c
, sizeof(c
)),
144 num_to_string(d
.d_ino_softlimit
, s
, sizeof(s
)),
145 num_to_string(d
.d_ino_hardlimit
, h
, sizeof(h
)),
147 time_to_string(d
.d_itimer
, qflags
));
149 fprintf(fp
, " %10llu %10llu %10llu %02d %9s ",
150 (unsigned long long)d
.d_icount
,
151 (unsigned long long)d
.d_ino_softlimit
,
152 (unsigned long long)d
.d_ino_hardlimit
,
154 time_to_string(d
.d_itimer
, qflags
));
156 if (form
& XFS_RTBLOCK_QUOTA
) {
157 qflags
= (flags
& HUMAN_FLAG
);
158 if (d
.d_rtb_hardlimit
&& d
.d_rtbcount
> d
.d_rtb_hardlimit
)
159 qflags
|= LIMIT_FLAG
;
160 if (d
.d_rtb_softlimit
&& d
.d_rtbcount
> d
.d_rtb_softlimit
)
161 qflags
|= QUOTA_FLAG
;
162 if (flags
& HUMAN_FLAG
)
163 fprintf(fp
, " %6s %6s %6s %02d %8s ",
164 bbs_to_string(d
.d_rtbcount
, c
, sizeof(c
)),
165 bbs_to_string(d
.d_rtb_softlimit
, s
, sizeof(s
)),
166 bbs_to_string(d
.d_rtb_hardlimit
, h
, sizeof(h
)),
168 time_to_string(d
.d_rtbtimer
, qflags
));
170 fprintf(fp
, " %10llu %10llu %10llu %02d %9s ",
171 (unsigned long long)d
.d_rtbcount
>> 1,
172 (unsigned long long)d
.d_rtb_softlimit
>> 1,
173 (unsigned long long)d
.d_rtb_hardlimit
>> 1,
175 time_to_string(d
.d_rtbtimer
, qflags
));
177 fprintf(fp
, "%s\n", mount
->fs_dir
);
193 fs_cursor_initialise(NULL
, FS_MOUNT_POINT
, &cursor
);
194 while ((path
= fs_cursor_next_entry(&cursor
))) {
195 if (quota_mount(fp
, id
, name
, form
, type
, path
, flags
))
196 flags
|= NO_HEADER_FLAG
;
205 static char buffer
[32];
208 struct passwd
*u
= getpwuid(uid
);
212 snprintf(buffer
, sizeof(buffer
), "#%u", uid
);
228 if (isdigits_only(name
)) {
230 name
= getusername(id
, flags
& NO_LOOKUP_FLAG
);
231 } else if ((u
= getpwnam(name
))) {
236 fprintf(stderr
, _("%s: cannot find user %s\n"),
242 name
= getusername(id
, flags
& NO_LOOKUP_FLAG
);
245 quota(fp
, id
, name
, form
, type
, flags
);
253 static char buffer
[32];
256 struct group
*g
= getgrgid(gid
);
260 snprintf(buffer
, sizeof(buffer
), "#%u", gid
);
273 gid_t gid
, *gids
= NULL
;
274 int i
, ngroups
, dofree
= 0;
277 if (isdigits_only(name
)) {
279 name
= getgroupname(gid
, flags
& NO_LOOKUP_FLAG
);
281 if ((g
= getgrnam(name
))) {
286 fprintf(stderr
, _("%s: cannot find group %s\n"),
294 if ( ((ngroups
= sysconf(_SC_NGROUPS_MAX
)) < 0) ||
295 ((gids
= malloc(ngroups
* sizeof(gid_t
))) == NULL
) ||
296 ((ngroups
= getgroups(ngroups
, gids
)) < 0)) {
297 /* something failed. Fall back to 1 group */
303 /* It all worked, and we allocated memory */
308 for (i
= 0; i
< ngroups
; i
++, name
= NULL
) {
310 name
= getgroupname(gids
[i
], flags
& NO_LOOKUP_FLAG
);
311 quota(fp
, gids
[i
], name
, form
, type
, flags
);
323 static char buffer
[32];
326 fs_project_t
*p
= getprprid(prid
);
330 snprintf(buffer
, sizeof(buffer
), "#%u", (unsigned int)prid
);
347 fprintf(stderr
, _("%s: must specify a project name/ID\n"),
352 if (isdigits_only(name
)) {
354 name
= getprojectname(id
, flags
& NO_LOOKUP_FLAG
);
355 } else if ((p
= getprnam(name
))) {
360 fprintf(stderr
, _("%s: cannot find project %s\n"),
365 quota(fp
, id
, name
, form
, type
, flags
);
378 quota_user_type(fp
, name
, form
, type
, flags
);
380 case XFS_GROUP_QUOTA
:
381 quota_group_type(fp
, name
, form
, type
, flags
);
384 quota_proj_type(fp
, name
, form
, type
, flags
);
396 int c
, flags
= 0, type
= 0, form
= 0;
398 while ((c
= getopt(argc
, argv
, "bf:ghnNipruv")) != EOF
) {
404 form
|= XFS_BLOCK_QUOTA
;
407 form
|= XFS_INODE_QUOTA
;
410 form
|= XFS_RTBLOCK_QUOTA
;
413 type
|= XFS_GROUP_QUOTA
;
416 type
|= XFS_PROJ_QUOTA
;
419 type
|= XFS_USER_QUOTA
;
425 flags
|= NO_LOOKUP_FLAG
;
428 flags
|= NO_HEADER_FLAG
;
431 flags
|= VERBOSE_FLAG
;
434 return command_usage("a_cmd
);
439 form
= XFS_BLOCK_QUOTA
;
442 type
= XFS_USER_QUOTA
;
443 } else if (type
!= XFS_GROUP_QUOTA
&&
444 type
!= XFS_PROJ_QUOTA
&&
445 type
!= XFS_USER_QUOTA
) {
446 return command_usage("a_cmd
);
449 if ((fp
= fopen_write_secure(fname
)) == NULL
)
453 quota_any_type(fp
, NULL
, form
, type
, flags
);
454 else while (argc
> optind
)
455 quota_any_type(fp
, argv
[optind
++], form
, type
, flags
);
465 quota_cmd
.name
= "quota";
466 quota_cmd
.altname
= "l";
467 quota_cmd
.cfunc
= quota_f
;
468 quota_cmd
.argmin
= 0;
469 quota_cmd
.argmax
= -1;
470 quota_cmd
.args
= _("[-bir] [-g|-p|-u] [-hnNv] [-f file] [id|name]...");
471 quota_cmd
.oneline
= _("show usage and limits");
472 quota_cmd
.help
= quota_help
;
473 quota_cmd
.flags
= CMD_FLAG_FOREIGN_OK
;
475 add_command("a_cmd
);