]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/dquot.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / db / dquot.c
1 /*
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
3 *
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.
7 *
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.
11 *
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.
18 *
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.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <libxfs.h>
34 #include "bit.h"
35 #include "bmap.h"
36 #include "command.h"
37 #include "dquot.h"
38 #include "type.h"
39 #include "faddr.h"
40 #include "fprint.h"
41 #include "field.h"
42 #include "inode.h"
43 #include "io.h"
44 #include "init.h"
45 #include "output.h"
46
47 static int dquot_f(int argc, char **argv);
48 static void dquot_help(void);
49
50 static const cmdinfo_t dquot_cmd =
51 { "dquot", NULL, dquot_f, 1, 2, 1, "[gid|uid]",
52 "set current address to group or user quota block", dquot_help };
53
54 const field_t dqblk_hfld[] = {
55 { "", FLDT_DQBLK, OI(0), C1, 0, TYP_NONE },
56 { NULL }
57 };
58
59 #define DDOFF(f) bitize(offsetof(xfs_dqblk_t, dd_ ## f))
60 #define DDSZC(f) szcount(xfs_dqblk_t, dd_ ## f)
61 const field_t dqblk_flds[] = {
62 { "diskdq", FLDT_DISK_DQUOT, OI(DDOFF(diskdq)), C1, 0, TYP_NONE },
63 { "fill", FLDT_CHARS, OI(DDOFF(fill)), CI(DDSZC(fill)), FLD_SKIPALL,
64 TYP_NONE },
65 { NULL }
66 };
67
68 #define DOFF(f) bitize(offsetof(xfs_disk_dquot_t, d_ ## f))
69 const field_t disk_dquot_flds[] = {
70 { "magic", FLDT_UINT16X, OI(DOFF(magic)), C1, 0, TYP_NONE },
71 { "version", FLDT_UINT8X, OI(DOFF(version)), C1, 0, TYP_NONE },
72 { "flags", FLDT_UINT8X, OI(DOFF(flags)), C1, 0, TYP_NONE },
73 { "id", FLDT_DQID, OI(DOFF(id)), C1, 0, TYP_NONE },
74 { "blk_hardlimit", FLDT_QCNT, OI(DOFF(blk_hardlimit)), C1, 0,
75 TYP_NONE },
76 { "blk_softlimit", FLDT_QCNT, OI(DOFF(blk_softlimit)), C1, 0,
77 TYP_NONE },
78 { "ino_hardlimit", FLDT_QCNT, OI(DOFF(ino_hardlimit)), C1, 0,
79 TYP_NONE },
80 { "ino_softlimit", FLDT_QCNT, OI(DOFF(ino_softlimit)), C1, 0,
81 TYP_NONE },
82 { "bcount", FLDT_QCNT, OI(DOFF(bcount)), C1, 0, TYP_NONE },
83 { "icount", FLDT_QCNT, OI(DOFF(icount)), C1, 0, TYP_NONE },
84 { "itimer", FLDT_INT32D, OI(DOFF(itimer)), C1, 0, TYP_NONE },
85 { "btimer", FLDT_INT32D, OI(DOFF(btimer)), C1, 0, TYP_NONE },
86 { "iwarns", FLDT_QWARNCNT, OI(DOFF(iwarns)), C1, 0, TYP_NONE },
87 { "bwarns", FLDT_QWARNCNT, OI(DOFF(bwarns)), C1, 0, TYP_NONE },
88 { "pad0", FLDT_INT32D, OI(DOFF(pad0)), C1, FLD_SKIPALL, TYP_NONE },
89 { "rtb_hardlimit", FLDT_QCNT, OI(DOFF(rtb_hardlimit)), C1, 0,
90 TYP_NONE },
91 { "rtb_softlimit", FLDT_QCNT, OI(DOFF(rtb_softlimit)), C1, 0,
92 TYP_NONE },
93 { "rtbcount", FLDT_QCNT, OI(DOFF(rtbcount)), C1, 0, TYP_NONE },
94 { "rtbtimer", FLDT_INT32D, OI(DOFF(rtbtimer)), C1, 0, TYP_NONE },
95 { "rtbwarns", FLDT_QWARNCNT, OI(DOFF(rtbwarns)), C1, 0, TYP_NONE },
96 { "pad", FLDT_UINT16X, OI(DOFF(pad)), C1, FLD_SKIPALL, TYP_NONE },
97 { NULL }
98 };
99
100 static void
101 dquot_help(void)
102 {
103 }
104
105 static int
106 dquot_f(
107 int argc,
108 char **argv)
109 {
110 bmap_ext_t bm;
111 int c;
112 int dogrp;
113 xfs_dqid_t id;
114 xfs_ino_t ino;
115 int nex;
116 char *p;
117 int perblock;
118 xfs_fileoff_t qbno;
119 int qoff;
120 char *s;
121
122 dogrp = optind = 0;
123 while ((c = getopt(argc, argv, "gu")) != EOF) {
124 switch (c) {
125 case 'g':
126 dogrp = 1;
127 break;
128 case 'u':
129 dogrp = 0;
130 break;
131 default:
132 dbprintf("bad option for dquot command\n");
133 return 0;
134 }
135 }
136 s = dogrp ? "group" : "user";
137 if (optind != argc - 1) {
138 dbprintf("dquot command requires one %s id argument\n", s);
139 return 0;
140 }
141 ino = dogrp ? mp->m_sb.sb_gquotino : mp->m_sb.sb_uquotino;
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 }