2 * Copyright (c) 2016 Red Hat, 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
21 #include <sys/quota.h>
22 #include <sys/types.h>
26 * Exercise the Q_GETNEXTQUOTA and Q_XGETNEXTQUOTA quotactls.
27 * Really only returns a bare minimum of quota information,
28 * just enough to be sure we got a sane answer back.
30 * These quotactls take a quota ID as input, and return the
31 * next active quota >= that ID.
34 * test-nextquota [-v] -[u|g|p] -i id -d device
41 #ifndef Q_GETNEXTQUOTA
42 #define Q_GETNEXTQUOTA 0x800009 /* get disk limits and usage >= ID */
46 u_int64_t dqb_bhardlimit; /* absolute limit on disk quota blocks alloc */
47 u_int64_t dqb_bsoftlimit; /* preferred limit on disk quota blocks */
48 u_int64_t dqb_curspace; /* current quota block count */
49 u_int64_t dqb_ihardlimit; /* maximum # allocated inodes */
50 u_int64_t dqb_isoftlimit; /* preferred inode limit */
51 u_int64_t dqb_curinodes; /* current # allocated inodes */
52 u_int64_t dqb_btime; /* time limit for excessive disk use */
53 u_int64_t dqb_itime; /* time limit for excessive files */
54 u_int32_t dqb_valid; /* bitmask of QIF_* constants */
55 u_int32_t dqb_id; /* id for this quota info*/
59 #ifndef Q_XGETNEXTQUOTA
60 #define Q_XGETNEXTQUOTA XQM_CMD(9)
63 void usage(char *progname)
65 printf("usage: %s [-v] -[u|g|p] -i id -d device\n", progname);
69 int main(int argc, char *argv[])
73 int type = -1, typeflag = 0;
75 uint id = 0, idflag = 0;
78 struct fs_disk_quota xqb;
80 while ((c = getopt(argc,argv,"ugpi:d:v")) != EOF) {
110 printf("No id specified\n");
114 printf("No type specified\n");
118 printf("Multiple types specified\n");
121 if (device == NULL) {
122 printf("No device specified\n");
127 printf("asking for quota type %d for id %u on %s\n", type, id, device);
129 memset(&dqb, 0, sizeof(struct nextdqblk));
130 memset(&xqb, 0, sizeof(struct fs_disk_quota));
133 printf("====Q_GETNEXTQUOTA====\n");
134 cmd = QCMD(Q_GETNEXTQUOTA, type);
135 if (quotactl(cmd, device, id, (void *)&dqb) < 0) {
136 perror("Q_GETNEXTQUOTA");
141 * We only print id and inode limits because
142 * block count varies depending on fs block size, etc;
143 * this is just a sanity test that we can retrieve the quota,
144 * and inode limits have the same units across both calls.
146 printf("id %u\n", dqb.dqb_id);
147 printf("ihard %llu\n", (unsigned long long)dqb.dqb_ihardlimit);
148 printf("isoft %llu\n", (unsigned long long)dqb.dqb_isoftlimit);
151 printf("====Q_XGETNEXTQUOTA====\n");
152 cmd = QCMD(Q_XGETNEXTQUOTA, USRQUOTA);
153 if (quotactl(cmd, device, id, (void *)&xqb) < 0) {
154 perror("Q_XGETNEXTQUOTA");
158 printf("id %u\n", xqb.d_id);
159 printf("ihard %llu\n", xqb.d_ino_hardlimit);
160 printf("isoft %llu\n", xqb.d_ino_softlimit);