]>
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
19 #include <xfs/command.h>
26 static cmdinfo_t quota_cmd
;
33 " display usage and quota information\n"
35 " -g -- display group quota information\n"
36 " -p -- display project quota information\n"
37 " -u -- display user quota information\n"
38 " -b -- display number of blocks used\n"
39 " -i -- display number of inodes used\n"
40 " -r -- display number of realtime blocks used\n"
41 " -h -- report in a human-readable format\n"
42 " -n -- skip identifier-to-name translations, just report IDs\n"
43 " -N -- suppress the initial header\n"
44 " -v -- increase verbosity in reporting (also dumps zero values)\n"
45 " -f -- send output to a file\n"
46 " The (optional) user/group/project can be specified either by name or by\n"
47 " number (i.e. uid/gid/projid).\n"
62 char *dev
= mount
->fs_name
;
63 char c
[8], h
[8], s
[8];
67 xfsquotactl(XFS_QSYNC
, dev
, type
, 0, NULL
);
68 if (xfsquotactl(XFS_GETQUOTA
, dev
, type
, id
, (void *)&d
) < 0)
71 if (!(flags
& VERBOSE_FLAG
)) {
73 if ((form
& XFS_BLOCK_QUOTA
) && d
.d_bcount
)
75 if ((form
& XFS_INODE_QUOTA
) && d
.d_icount
)
77 if ((form
& XFS_RTBLOCK_QUOTA
) && d
.d_rtbcount
)
83 if (!(flags
& NO_HEADER_FLAG
)) {
85 _("Disk quotas for %s %s (%u)\nFilesystem%s"),
86 type_to_string(type
), name
, id
,
87 (flags
& HUMAN_FLAG
) ? " " : " ");
88 if (form
& XFS_BLOCK_QUOTA
)
89 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
90 _(" Blocks Quota Limit Warn/Time ") :
91 _(" Blocks Quota Limit Warn/Time "));
92 if (form
& XFS_INODE_QUOTA
)
93 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
94 _(" Files Quota Limit Warn/Time ") :
95 _(" Files Quota Limit Warn/Time "));
96 if (form
& XFS_RTBLOCK_QUOTA
)
97 fprintf(fp
, (flags
& HUMAN_FLAG
) ?
98 _("Realtime Quota Limit Warn/Time ") :
99 _(" Realtime Quota Limit Warn/Time "));
100 fputs("Mounted on\n", fp
);
103 if (flags
& HUMAN_FLAG
) {
104 count
= fprintf(fp
, "%-12s", dev
);
106 fprintf(fp
, "\n%12s", " ");
108 count
= fprintf(fp
, "%-19s", dev
);
110 fprintf(fp
, "\n%19s", " ");
113 if (form
& XFS_BLOCK_QUOTA
) {
114 qflags
= (flags
& HUMAN_FLAG
);
115 if (d
.d_blk_hardlimit
&& d
.d_bcount
> d
.d_blk_hardlimit
)
116 qflags
|= LIMIT_FLAG
;
117 if (d
.d_blk_softlimit
&& d
.d_bcount
> d
.d_blk_softlimit
)
118 qflags
|= QUOTA_FLAG
;
119 if (flags
& HUMAN_FLAG
)
120 fprintf(fp
, " %6s %6s %6s %02d %8s ",
121 bbs_to_string(d
.d_bcount
, c
, sizeof(c
)),
122 bbs_to_string(d
.d_blk_softlimit
, s
, sizeof(s
)),
123 bbs_to_string(d
.d_blk_hardlimit
, h
, sizeof(h
)),
125 time_to_string(d
.d_btimer
, qflags
));
127 fprintf(fp
, " %10llu %10llu %10llu %02d %9s ",
128 (unsigned long long)d
.d_bcount
>> 1,
129 (unsigned long long)d
.d_blk_softlimit
>> 1,
130 (unsigned long long)d
.d_blk_hardlimit
>> 1,
132 time_to_string(d
.d_btimer
, qflags
));
134 if (form
& XFS_INODE_QUOTA
) {
135 qflags
= (flags
& HUMAN_FLAG
);
136 if (d
.d_ino_hardlimit
&& d
.d_icount
> d
.d_ino_hardlimit
)
137 qflags
|= LIMIT_FLAG
;
138 if (d
.d_ino_softlimit
&& d
.d_icount
> d
.d_ino_softlimit
)
139 qflags
|= QUOTA_FLAG
;
140 if (flags
& HUMAN_FLAG
)
141 fprintf(fp
, " %6s %6s %6s %02d %8s ",
142 num_to_string(d
.d_icount
, c
, sizeof(c
)),
143 num_to_string(d
.d_ino_softlimit
, s
, sizeof(s
)),
144 num_to_string(d
.d_ino_hardlimit
, h
, sizeof(h
)),
146 time_to_string(d
.d_itimer
, qflags
));
148 fprintf(fp
, " %10llu %10llu %10llu %02d %9s ",
149 (unsigned long long)d
.d_icount
,
150 (unsigned long long)d
.d_ino_softlimit
,
151 (unsigned long long)d
.d_ino_hardlimit
,
153 time_to_string(d
.d_itimer
, qflags
));
155 if (form
& XFS_RTBLOCK_QUOTA
) {
156 qflags
= (flags
& HUMAN_FLAG
);
157 if (d
.d_rtb_hardlimit
&& d
.d_rtbcount
> d
.d_rtb_hardlimit
)
158 qflags
|= LIMIT_FLAG
;
159 if (d
.d_rtb_softlimit
&& d
.d_rtbcount
> d
.d_rtb_softlimit
)
160 qflags
|= QUOTA_FLAG
;
161 if (flags
& HUMAN_FLAG
)
162 fprintf(fp
, " %6s %6s %6s %02d %8s ",
163 bbs_to_string(d
.d_rtbcount
, c
, sizeof(c
)),
164 bbs_to_string(d
.d_rtb_softlimit
, s
, sizeof(s
)),
165 bbs_to_string(d
.d_rtb_hardlimit
, h
, sizeof(h
)),
167 time_to_string(d
.d_rtbtimer
, qflags
));
169 fprintf(fp
, " %10llu %10llu %10llu %02d %9s ",
170 (unsigned long long)d
.d_rtbcount
>> 1,
171 (unsigned long long)d
.d_rtb_softlimit
>> 1,
172 (unsigned long long)d
.d_rtb_hardlimit
>> 1,
174 time_to_string(d
.d_rtbtimer
, qflags
));
176 fprintf(fp
, "%s\n", mount
->fs_dir
);
192 fs_cursor_initialise(NULL
, FS_MOUNT_POINT
, &cursor
);
193 while ((path
= fs_cursor_next_entry(&cursor
))) {
194 if (quota_mount(fp
, id
, name
, form
, type
, path
, flags
))
195 flags
|= NO_HEADER_FLAG
;
204 static char buffer
[32];
207 struct passwd
*u
= getpwuid(uid
);
211 snprintf(buffer
, sizeof(buffer
), "#%u", uid
);
227 if (isdigit(name
[0])) {
229 name
= getusername(id
, flags
& NO_LOOKUP_FLAG
);
230 } else if ((u
= getpwnam(name
))) {
235 fprintf(stderr
, _("%s: cannot find user %s\n"),
241 name
= getusername(id
, flags
& NO_LOOKUP_FLAG
);
244 quota(fp
, id
, name
, form
, type
, flags
);
252 static char buffer
[32];
255 struct group
*g
= getgrgid(gid
);
259 snprintf(buffer
, sizeof(buffer
), "#%u", gid
);
272 gid_t gid
, *gids
= NULL
;
273 int i
, ngroups
, dofree
= 0;
276 if (isdigit(name
[0])) {
278 name
= getgroupname(gid
, flags
& NO_LOOKUP_FLAG
);
280 if ((g
= getgrnam(name
))) {
285 fprintf(stderr
, _("%s: cannot find group %s\n"),
292 } else if ( ((ngroups
= sysconf(_SC_NGROUPS_MAX
)) < 0) ||
293 ((gids
= malloc(ngroups
* sizeof(gid_t
))) == NULL
) ||
294 ((ngroups
= getgroups(ngroups
, gids
)) < 0)) {
295 dofree
= (gids
!= NULL
);
300 dofree
= (gids
!= NULL
);
303 for (i
= 0; i
< ngroups
; i
++, name
= NULL
) {
305 name
= getgroupname(gids
[i
], flags
& NO_LOOKUP_FLAG
);
306 quota(fp
, gids
[i
], name
, form
, type
, flags
);
318 static char buffer
[32];
321 fs_project_t
*p
= getprprid(prid
);
325 snprintf(buffer
, sizeof(buffer
), "#%u", (unsigned int)prid
);
342 fprintf(stderr
, _("%s: must specify a project name/ID\n"),
347 if (isdigit(name
[0])) {
349 name
= getprojectname(id
, flags
& NO_LOOKUP_FLAG
);
350 } else if ((p
= getprnam(name
))) {
355 fprintf(stderr
, _("%s: cannot find project %s\n"),
360 quota(fp
, id
, name
, form
, type
, flags
);
373 quota_user_type(fp
, name
, form
, type
, flags
);
375 case XFS_GROUP_QUOTA
:
376 quota_group_type(fp
, name
, form
, type
, flags
);
379 quota_proj_type(fp
, name
, form
, type
, flags
);
391 int c
, flags
= 0, type
= 0, form
= 0;
393 while ((c
= getopt(argc
, argv
, "bf:ghnNipruv")) != EOF
) {
399 form
|= XFS_BLOCK_QUOTA
;
402 form
|= XFS_INODE_QUOTA
;
405 form
|= XFS_RTBLOCK_QUOTA
;
408 type
= XFS_GROUP_QUOTA
;
411 type
= XFS_PROJ_QUOTA
;
414 type
= XFS_USER_QUOTA
;
420 flags
|= NO_LOOKUP_FLAG
;
423 flags
|= NO_HEADER_FLAG
;
426 flags
|= VERBOSE_FLAG
;
429 return command_usage("a_cmd
);
434 form
= XFS_BLOCK_QUOTA
;
437 type
= XFS_USER_QUOTA
;
439 if ((fp
= fopen_write_secure(fname
)) == NULL
)
443 quota_any_type(fp
, NULL
, form
, type
, flags
);
444 else while (argc
> optind
)
445 quota_any_type(fp
, argv
[optind
++], form
, type
, flags
);
455 quota_cmd
.name
= "quota";
456 quota_cmd
.altname
= "l";
457 quota_cmd
.cfunc
= quota_f
;
458 quota_cmd
.argmin
= 0;
459 quota_cmd
.argmax
= -1;
460 quota_cmd
.args
= _("[-bir] [-gpu] [-hnNv] [-f file] [id|name]...");
461 quota_cmd
.oneline
= _("show usage and limits");
462 quota_cmd
.help
= quota_help
;
464 add_command("a_cmd
);