]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/dquot.c
progs: clean up libxfs.h includes
[thirdparty/xfsprogs-dev.git] / db / dquot.c
1 /*
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "xfs/libxfs.h"
20 #include "bit.h"
21 #include "bmap.h"
22 #include "command.h"
23 #include "type.h"
24 #include "faddr.h"
25 #include "fprint.h"
26 #include "field.h"
27 #include "inode.h"
28 #include "io.h"
29 #include "init.h"
30 #include "output.h"
31 #include "dquot.h"
32
33 static int dquot_f(int argc, char **argv);
34 static void dquot_help(void);
35
36 static const cmdinfo_t dquot_cmd =
37 { "dquot", NULL, dquot_f, 1, 2, 1, N_("[projid|gid|uid]"),
38 N_("set current address to project, group or user quota block"), dquot_help };
39
40 const field_t dqblk_hfld[] = {
41 { "", FLDT_DQBLK, OI(0), C1, 0, TYP_NONE },
42 { NULL }
43 };
44
45 #define DDOFF(f) bitize(offsetof(xfs_dqblk_t, dd_ ## f))
46 #define DDSZC(f) szcount(xfs_dqblk_t, dd_ ## f)
47 const field_t dqblk_flds[] = {
48 { "diskdq", FLDT_DISK_DQUOT, OI(DDOFF(diskdq)), C1, 0, TYP_NONE },
49 { "fill", FLDT_CHARS, OI(DDOFF(fill)), CI(DDSZC(fill)), FLD_SKIPALL,
50 TYP_NONE },
51 { "crc", FLDT_CRC, OI(DDOFF(crc)), C1, 0, TYP_NONE },
52 { "lsn", FLDT_UINT64X, OI(DDOFF(lsn)), C1, 0, TYP_NONE },
53 { "uuid", FLDT_UUID, OI(DDOFF(uuid)), C1, 0, TYP_NONE },
54 { NULL }
55 };
56
57 #define DOFF(f) bitize(offsetof(xfs_disk_dquot_t, d_ ## f))
58 const field_t disk_dquot_flds[] = {
59 { "magic", FLDT_UINT16X, OI(DOFF(magic)), C1, 0, TYP_NONE },
60 { "version", FLDT_UINT8X, OI(DOFF(version)), C1, 0, TYP_NONE },
61 { "flags", FLDT_UINT8X, OI(DOFF(flags)), C1, 0, TYP_NONE },
62 { "id", FLDT_DQID, OI(DOFF(id)), C1, 0, TYP_NONE },
63 { "blk_hardlimit", FLDT_QCNT, OI(DOFF(blk_hardlimit)), C1, 0,
64 TYP_NONE },
65 { "blk_softlimit", FLDT_QCNT, OI(DOFF(blk_softlimit)), C1, 0,
66 TYP_NONE },
67 { "ino_hardlimit", FLDT_QCNT, OI(DOFF(ino_hardlimit)), C1, 0,
68 TYP_NONE },
69 { "ino_softlimit", FLDT_QCNT, OI(DOFF(ino_softlimit)), C1, 0,
70 TYP_NONE },
71 { "bcount", FLDT_QCNT, OI(DOFF(bcount)), C1, 0, TYP_NONE },
72 { "icount", FLDT_QCNT, OI(DOFF(icount)), C1, 0, TYP_NONE },
73 { "itimer", FLDT_INT32D, OI(DOFF(itimer)), C1, 0, TYP_NONE },
74 { "btimer", FLDT_INT32D, OI(DOFF(btimer)), C1, 0, TYP_NONE },
75 { "iwarns", FLDT_QWARNCNT, OI(DOFF(iwarns)), C1, 0, TYP_NONE },
76 { "bwarns", FLDT_QWARNCNT, OI(DOFF(bwarns)), C1, 0, TYP_NONE },
77 { "pad0", FLDT_INT32D, OI(DOFF(pad0)), C1, FLD_SKIPALL, TYP_NONE },
78 { "rtb_hardlimit", FLDT_QCNT, OI(DOFF(rtb_hardlimit)), C1, 0,
79 TYP_NONE },
80 { "rtb_softlimit", FLDT_QCNT, OI(DOFF(rtb_softlimit)), C1, 0,
81 TYP_NONE },
82 { "rtbcount", FLDT_QCNT, OI(DOFF(rtbcount)), C1, 0, TYP_NONE },
83 { "rtbtimer", FLDT_INT32D, OI(DOFF(rtbtimer)), C1, 0, TYP_NONE },
84 { "rtbwarns", FLDT_QWARNCNT, OI(DOFF(rtbwarns)), C1, 0, TYP_NONE },
85 { "pad", FLDT_UINT16X, OI(DOFF(pad)), C1, FLD_SKIPALL, TYP_NONE },
86 { NULL }
87 };
88
89 static void
90 dquot_help(void)
91 {
92 }
93
94 static int
95 dquot_f(
96 int argc,
97 char **argv)
98 {
99 bmap_ext_t bm;
100 int c;
101 int dogrp;
102 int doprj;
103 xfs_dqid_t id;
104 xfs_ino_t ino;
105 int nex;
106 char *p;
107 int perblock;
108 xfs_fileoff_t qbno;
109 int qoff;
110 char *s;
111
112 dogrp = doprj = optind = 0;
113 while ((c = getopt(argc, argv, "gpu")) != EOF) {
114 switch (c) {
115 case 'g':
116 dogrp = 1;
117 doprj = 0;
118 break;
119 case 'p':
120 doprj = 1;
121 dogrp = 0;
122 break;
123 case 'u':
124 dogrp = doprj = 0;
125 break;
126 default:
127 dbprintf(_("bad option for dquot command\n"));
128 return 0;
129 }
130 }
131 s = doprj ? _("project") : dogrp ? _("group") : _("user");
132 if (optind != argc - 1) {
133 dbprintf(_("dquot command requires one %s id argument\n"), s);
134 return 0;
135 }
136 ino = mp->m_sb.sb_uquotino;
137 if (doprj)
138 ino = mp->m_sb.sb_pquotino;
139 else if (dogrp)
140 ino = mp->m_sb.sb_gquotino;
141
142 if (ino == 0 || ino == NULLFSINO) {
143 dbprintf(_("no %s quota inode present\n"), s);
144 return 0;
145 }
146 id = (xfs_dqid_t)strtol(argv[optind], &p, 0);
147 if (*p != '\0') {
148 dbprintf(_("bad %s id for dquot %s\n"), s, argv[optind]);
149 return 0;
150 }
151 perblock = (int)(mp->m_sb.sb_blocksize / sizeof(xfs_dqblk_t));
152 qbno = (xfs_fileoff_t)id / perblock;
153 qoff = (int)(id % perblock);
154 push_cur();
155 set_cur_inode(ino);
156 nex = 1;
157 bmap(qbno, 1, XFS_DATA_FORK, &nex, &bm);
158 pop_cur();
159 if (nex == 0) {
160 dbprintf(_("no %s quota data for id %d\n"), s, id);
161 return 0;
162 }
163 set_cur(&typtab[TYP_DQBLK], XFS_FSB_TO_DADDR(mp, bm.startblock), blkbb,
164 DB_RING_IGN, NULL);
165 off_cur(qoff * (int)sizeof(xfs_dqblk_t), sizeof(xfs_dqblk_t));
166 ring_add();
167 return 0;
168 }
169
170 void
171 dquot_init(void)
172 {
173 add_command(&dquot_cmd);
174 }