]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/dquot.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[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, "[projid|gid|uid]",
38 "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 { NULL }
52 };
53
54 #define DOFF(f) bitize(offsetof(xfs_disk_dquot_t, d_ ## f))
55 const field_t disk_dquot_flds[] = {
56 { "magic", FLDT_UINT16X, OI(DOFF(magic)), C1, 0, TYP_NONE },
57 { "version", FLDT_UINT8X, OI(DOFF(version)), C1, 0, TYP_NONE },
58 { "flags", FLDT_UINT8X, OI(DOFF(flags)), C1, 0, TYP_NONE },
59 { "id", FLDT_DQID, OI(DOFF(id)), C1, 0, TYP_NONE },
60 { "blk_hardlimit", FLDT_QCNT, OI(DOFF(blk_hardlimit)), C1, 0,
61 TYP_NONE },
62 { "blk_softlimit", FLDT_QCNT, OI(DOFF(blk_softlimit)), C1, 0,
63 TYP_NONE },
64 { "ino_hardlimit", FLDT_QCNT, OI(DOFF(ino_hardlimit)), C1, 0,
65 TYP_NONE },
66 { "ino_softlimit", FLDT_QCNT, OI(DOFF(ino_softlimit)), C1, 0,
67 TYP_NONE },
68 { "bcount", FLDT_QCNT, OI(DOFF(bcount)), C1, 0, TYP_NONE },
69 { "icount", FLDT_QCNT, OI(DOFF(icount)), C1, 0, TYP_NONE },
70 { "itimer", FLDT_INT32D, OI(DOFF(itimer)), C1, 0, TYP_NONE },
71 { "btimer", FLDT_INT32D, OI(DOFF(btimer)), C1, 0, TYP_NONE },
72 { "iwarns", FLDT_QWARNCNT, OI(DOFF(iwarns)), C1, 0, TYP_NONE },
73 { "bwarns", FLDT_QWARNCNT, OI(DOFF(bwarns)), C1, 0, TYP_NONE },
74 { "pad0", FLDT_INT32D, OI(DOFF(pad0)), C1, FLD_SKIPALL, TYP_NONE },
75 { "rtb_hardlimit", FLDT_QCNT, OI(DOFF(rtb_hardlimit)), C1, 0,
76 TYP_NONE },
77 { "rtb_softlimit", FLDT_QCNT, OI(DOFF(rtb_softlimit)), C1, 0,
78 TYP_NONE },
79 { "rtbcount", FLDT_QCNT, OI(DOFF(rtbcount)), C1, 0, TYP_NONE },
80 { "rtbtimer", FLDT_INT32D, OI(DOFF(rtbtimer)), C1, 0, TYP_NONE },
81 { "rtbwarns", FLDT_QWARNCNT, OI(DOFF(rtbwarns)), C1, 0, TYP_NONE },
82 { "pad", FLDT_UINT16X, OI(DOFF(pad)), C1, FLD_SKIPALL, TYP_NONE },
83 { NULL }
84 };
85
86 static void
87 dquot_help(void)
88 {
89 }
90
91 static int
92 dquot_f(
93 int argc,
94 char **argv)
95 {
96 bmap_ext_t bm;
97 int c;
98 int dogrp;
99 int doprj;
100 xfs_dqid_t id;
101 xfs_ino_t ino;
102 int nex;
103 char *p;
104 int perblock;
105 xfs_fileoff_t qbno;
106 int qoff;
107 char *s;
108
109 dogrp = doprj = optind = 0;
110 while ((c = getopt(argc, argv, "gpu")) != EOF) {
111 switch (c) {
112 case 'g':
113 dogrp = 1;
114 doprj = 0;
115 break;
116 case 'p':
117 doprj = 1;
118 dogrp = 0;
119 break;
120 case 'u':
121 dogrp = doprj = 0;
122 break;
123 default:
124 dbprintf("bad option for dquot command\n");
125 return 0;
126 }
127 }
128 s = doprj ? "project" : dogrp ? "group" : "user";
129 if (optind != argc - 1) {
130 dbprintf("dquot command requires one %s id argument\n", s);
131 return 0;
132 }
133 ino = (dogrp || doprj) ? mp->m_sb.sb_gquotino : mp->m_sb.sb_uquotino;
134 if (ino == 0 || ino == NULLFSINO ||
135 (dogrp && (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT)) ||
136 (doprj && (mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT))) {
137 dbprintf("no %s quota inode present\n", s);
138 return 0;
139 }
140 id = (xfs_dqid_t)strtol(argv[optind], &p, 0);
141 if (*p != '\0') {
142 dbprintf("bad %s id for dquot %s\n", s, argv[optind]);
143 return 0;
144 }
145 perblock = (int)(mp->m_sb.sb_blocksize / sizeof(xfs_dqblk_t));
146 qbno = (xfs_fileoff_t)id / perblock;
147 qoff = (int)(id % perblock);
148 push_cur();
149 set_cur_inode(ino);
150 nex = 1;
151 bmap(qbno, 1, XFS_DATA_FORK, &nex, &bm);
152 pop_cur();
153 if (nex == 0) {
154 dbprintf("no %s quota data for id %d\n", s, id);
155 return 0;
156 }
157 set_cur(&typtab[TYP_DQBLK], XFS_FSB_TO_DADDR(mp, bm.startblock), blkbb,
158 DB_RING_IGN, NULL);
159 off_cur(qoff * (int)sizeof(xfs_dqblk_t), sizeof(xfs_dqblk_t));
160 ring_add();
161 return 0;
162 }
163
164 void
165 dquot_init(void)
166 {
167 add_command(&dquot_cmd);
168 }