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