]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2bd0ea18 | 2 | /* |
da23017d NS |
3 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
2bd0ea18 NS |
5 | */ |
6 | ||
6b803e5a | 7 | #include "libxfs.h" |
2bd0ea18 NS |
8 | #include "block.h" |
9 | #include "command.h" | |
2bd0ea18 NS |
10 | #include "type.h" |
11 | #include "faddr.h" | |
12 | #include "fprint.h" | |
13 | #include "field.h" | |
14 | #include "print.h" | |
15 | #include "sb.h" | |
16 | #include "inode.h" | |
49b31417 | 17 | #include "btblock.h" |
2bd0ea18 NS |
18 | #include "bmroot.h" |
19 | #include "agf.h" | |
20 | #include "agfl.h" | |
21 | #include "agi.h" | |
2bd0ea18 NS |
22 | #include "io.h" |
23 | #include "output.h" | |
24 | #include "write.h" | |
25 | #include "attr.h" | |
26 | #include "dquot.h" | |
27 | #include "dir2.h" | |
c6b24b3b | 28 | #include "text.h" |
3cafd875 | 29 | #include "symlink.h" |
984af2e1 | 30 | #include "fuzz.h" |
ef420536 | 31 | #include "rtgroup.h" |
2bd0ea18 NS |
32 | |
33 | static const typ_t *findtyp(char *name); | |
34 | static int type_f(int argc, char **argv); | |
35 | ||
36 | const typ_t *cur_typ; | |
37 | ||
38 | static const cmdinfo_t type_cmd = | |
9ee7055c AM |
39 | { "type", NULL, type_f, 0, 1, 1, N_("[newtype]"), |
40 | N_("set/show current data type"), NULL }; | |
2bd0ea18 | 41 | |
c2907bd7 | 42 | static const typ_t __typtab[] = { |
86769b32 DC |
43 | { TYP_AGF, "agf", handle_struct, agf_hfld, NULL, TYP_F_NO_CRC_OFF }, |
44 | { TYP_AGFL, "agfl", handle_struct, agfl_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
45 | { TYP_AGI, "agi", handle_struct, agi_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
46 | { TYP_ATTR, "attr", handle_struct, attr_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
47 | { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_hfld, NULL, | |
48 | TYP_F_NO_CRC_OFF }, | |
49 | { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_hfld, NULL, | |
50 | TYP_F_NO_CRC_OFF }, | |
51 | { TYP_BNOBT, "bnobt", handle_struct, bnobt_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
52 | { TYP_CNTBT, "cntbt", handle_struct, cntbt_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
a9d7b986 | 53 | { TYP_RMAPBT, NULL }, |
fede3030 | 54 | { TYP_RTRMAPBT, NULL }, |
9fb2cb27 | 55 | { TYP_REFCBT, NULL }, |
97897d68 | 56 | { TYP_RTREFCBT, NULL }, |
86769b32 DC |
57 | { TYP_DATA, "data", handle_block, NULL, NULL, TYP_F_NO_CRC_OFF }, |
58 | { TYP_DIR2, "dir2", handle_struct, dir2_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
59 | { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
60 | { TYP_INOBT, "inobt", handle_struct, inobt_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
61 | { TYP_INODATA, "inodata", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
62 | { TYP_INODE, "inode", handle_struct, inode_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
63 | { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
87a271c2 DW |
64 | { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, |
65 | { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
ef420536 | 66 | { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, NULL, TYP_F_NO_CRC_OFF }, |
86769b32 DC |
67 | { TYP_SB, "sb", handle_struct, sb_hfld, NULL, TYP_F_NO_CRC_OFF }, |
68 | { TYP_SYMLINK, "symlink", handle_string, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
69 | { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
e229a59f | 70 | { TYP_FINOBT, "finobt", handle_struct, finobt_hfld, NULL, |
86769b32 | 71 | TYP_F_NO_CRC_OFF }, |
2be091fb | 72 | { TYP_RGBITMAP, NULL }, |
e5bd3d74 | 73 | { TYP_RGSUMMARY, NULL }, |
2bd0ea18 NS |
74 | { TYP_NONE, NULL } |
75 | }; | |
76 | ||
c2907bd7 | 77 | static const typ_t __typtab_crc[] = { |
86769b32 DC |
78 | { TYP_AGF, "agf", handle_struct, agf_hfld, &xfs_agf_buf_ops, |
79 | XFS_AGF_CRC_OFF }, | |
80 | { TYP_AGFL, "agfl", handle_struct, agfl_crc_hfld, &xfs_agfl_buf_ops, | |
81 | XFS_AGFL_CRC_OFF }, | |
82 | { TYP_AGI, "agi", handle_struct, agi_hfld, &xfs_agi_buf_ops, | |
83 | XFS_AGI_CRC_OFF }, | |
2847273f | 84 | { TYP_ATTR, "attr3", handle_struct, attr3_hfld, |
89baf918 | 85 | &xfs_attr3_db_buf_ops, TYP_F_CRC_FUNC, xfs_attr3_set_crc }, |
6fea8f83 | 86 | { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_crc_hfld, |
86769b32 | 87 | &xfs_bmbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, |
6fea8f83 | 88 | { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_crc_hfld, |
86769b32 | 89 | &xfs_bmbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, |
6fea8f83 | 90 | { TYP_BNOBT, "bnobt", handle_struct, bnobt_crc_hfld, |
fce74e98 | 91 | &xfs_bnobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
6fea8f83 | 92 | { TYP_CNTBT, "cntbt", handle_struct, cntbt_crc_hfld, |
fce74e98 | 93 | &xfs_cntbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
a9d7b986 DW |
94 | { TYP_RMAPBT, "rmapbt", handle_struct, rmapbt_crc_hfld, |
95 | &xfs_rmapbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, | |
fede3030 DW |
96 | { TYP_RTRMAPBT, "rtrmapbt", handle_struct, rtrmapbt_crc_hfld, |
97 | &xfs_rtrmapbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, | |
9fb2cb27 DW |
98 | { TYP_REFCBT, "refcntbt", handle_struct, refcbt_crc_hfld, |
99 | &xfs_refcountbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, | |
97897d68 DW |
100 | { TYP_RTREFCBT, "rtrefcntbt", handle_struct, rtrefcbt_crc_hfld, |
101 | &xfs_rtrefcountbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, | |
86769b32 | 102 | { TYP_DATA, "data", handle_block, NULL, NULL, TYP_F_NO_CRC_OFF }, |
fc068a19 | 103 | { TYP_DIR2, "dir3", handle_struct, dir3_hfld, |
89baf918 | 104 | &xfs_dir3_db_buf_ops, TYP_F_CRC_FUNC, xfs_dir3_set_crc }, |
6fea8f83 | 105 | { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld, |
1e9c13c5 | 106 | &xfs_dquot_buf_ops, TYP_F_CRC_FUNC, xfs_dquot_set_crc }, |
6fea8f83 | 107 | { TYP_INOBT, "inobt", handle_struct, inobt_crc_hfld, |
86769b32 DC |
108 | &xfs_inobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
109 | { TYP_INODATA, "inodata", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
6fea8f83 | 110 | { TYP_INODE, "inode", handle_struct, inode_crc_hfld, |
1e9c13c5 | 111 | &xfs_inode_buf_ops, TYP_F_CRC_FUNC, xfs_inode_set_crc }, |
86769b32 | 112 | { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, |
87a271c2 DW |
113 | { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, |
114 | { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
ef420536 DW |
115 | { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, &xfs_rtsb_buf_ops, |
116 | XFS_SB_CRC_OFF }, | |
86769b32 DC |
117 | { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, |
118 | XFS_SB_CRC_OFF }, | |
6fea8f83 | 119 | { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld, |
86769b32 DC |
120 | &xfs_symlink_buf_ops, XFS_SYMLINK_CRC_OFF }, |
121 | { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
e229a59f | 122 | { TYP_FINOBT, "finobt", handle_struct, finobt_crc_hfld, |
035ae96e | 123 | &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
2be091fb DW |
124 | { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, |
125 | &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, | |
e5bd3d74 DW |
126 | { TYP_RGSUMMARY, "rgsummary", handle_struct, rgsummary_hfld, |
127 | &xfs_rtsummary_buf_ops, XFS_RTBUF_CRC_OFF }, | |
c2907bd7 DC |
128 | { TYP_NONE, NULL } |
129 | }; | |
130 | ||
061e316e | 131 | static const typ_t __typtab_spcrc[] = { |
86769b32 DC |
132 | { TYP_AGF, "agf", handle_struct, agf_hfld, &xfs_agf_buf_ops, |
133 | XFS_AGF_CRC_OFF }, | |
134 | { TYP_AGFL, "agfl", handle_struct, agfl_crc_hfld, &xfs_agfl_buf_ops , | |
135 | XFS_AGFL_CRC_OFF }, | |
136 | { TYP_AGI, "agi", handle_struct, agi_hfld, &xfs_agi_buf_ops , | |
137 | XFS_AGI_CRC_OFF }, | |
061e316e | 138 | { TYP_ATTR, "attr3", handle_struct, attr3_hfld, |
89baf918 | 139 | &xfs_attr3_db_buf_ops, TYP_F_CRC_FUNC, xfs_attr3_set_crc }, |
061e316e | 140 | { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_crc_hfld, |
86769b32 | 141 | &xfs_bmbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, |
061e316e | 142 | { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_crc_hfld, |
86769b32 | 143 | &xfs_bmbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, |
061e316e | 144 | { TYP_BNOBT, "bnobt", handle_struct, bnobt_crc_hfld, |
fce74e98 | 145 | &xfs_bnobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
061e316e | 146 | { TYP_CNTBT, "cntbt", handle_struct, cntbt_crc_hfld, |
fce74e98 | 147 | &xfs_cntbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
a9d7b986 DW |
148 | { TYP_RMAPBT, "rmapbt", handle_struct, rmapbt_crc_hfld, |
149 | &xfs_rmapbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, | |
fede3030 DW |
150 | { TYP_RTRMAPBT, "rtrmapbt", handle_struct, rtrmapbt_crc_hfld, |
151 | &xfs_rtrmapbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, | |
9fb2cb27 DW |
152 | { TYP_REFCBT, "refcntbt", handle_struct, refcbt_crc_hfld, |
153 | &xfs_refcountbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, | |
97897d68 DW |
154 | { TYP_RTREFCBT, "rtrefcntbt", handle_struct, rtrefcbt_crc_hfld, |
155 | &xfs_rtrefcountbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, | |
86769b32 | 156 | { TYP_DATA, "data", handle_block, NULL, NULL, TYP_F_NO_CRC_OFF }, |
061e316e | 157 | { TYP_DIR2, "dir3", handle_struct, dir3_hfld, |
89baf918 | 158 | &xfs_dir3_db_buf_ops, TYP_F_CRC_FUNC, xfs_dir3_set_crc }, |
061e316e | 159 | { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld, |
1e9c13c5 | 160 | &xfs_dquot_buf_ops, TYP_F_CRC_FUNC, xfs_dquot_set_crc }, |
061e316e | 161 | { TYP_INOBT, "inobt", handle_struct, inobt_spcrc_hfld, |
86769b32 DC |
162 | &xfs_inobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
163 | { TYP_INODATA, "inodata", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
061e316e | 164 | { TYP_INODE, "inode", handle_struct, inode_crc_hfld, |
1e9c13c5 | 165 | &xfs_inode_buf_ops, TYP_F_CRC_FUNC, xfs_inode_set_crc }, |
86769b32 | 166 | { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, |
87a271c2 DW |
167 | { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, |
168 | { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
ef420536 DW |
169 | { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, &xfs_rtsb_buf_ops, |
170 | XFS_SB_CRC_OFF }, | |
86769b32 DC |
171 | { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, |
172 | XFS_SB_CRC_OFF }, | |
061e316e | 173 | { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld, |
86769b32 DC |
174 | &xfs_symlink_buf_ops, XFS_SYMLINK_CRC_OFF }, |
175 | { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
e229a59f | 176 | { TYP_FINOBT, "finobt", handle_struct, finobt_spcrc_hfld, |
035ae96e | 177 | &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
2be091fb DW |
178 | { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, |
179 | &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, | |
e5bd3d74 DW |
180 | { TYP_RGSUMMARY, "rgsummary", handle_struct, rgsummary_hfld, |
181 | &xfs_rtsummary_buf_ops, XFS_RTBUF_CRC_OFF }, | |
061e316e BF |
182 | { TYP_NONE, NULL } |
183 | }; | |
184 | ||
c2907bd7 DC |
185 | const typ_t *typtab = __typtab; |
186 | ||
187 | void | |
188 | type_set_tab_crc(void) | |
189 | { | |
190 | typtab = __typtab_crc; | |
191 | } | |
192 | ||
061e316e BF |
193 | void |
194 | type_set_tab_spcrc(void) | |
195 | { | |
196 | typtab = __typtab_spcrc; | |
197 | } | |
198 | ||
2bd0ea18 NS |
199 | static const typ_t * |
200 | findtyp( | |
201 | char *name) | |
202 | { | |
203 | const typ_t *tt; | |
204 | ||
a364668b | 205 | for (tt = typtab; tt->typnm != TYP_NONE; tt++) { |
2bd0ea18 | 206 | ASSERT(tt->typnm == (typnm_t)(tt - typtab)); |
a364668b | 207 | if (tt->name && strcmp(tt->name, name) == 0) |
2bd0ea18 NS |
208 | return tt; |
209 | } | |
210 | return NULL; | |
211 | } | |
212 | ||
213 | static int | |
214 | type_f( | |
215 | int argc, | |
216 | char **argv) | |
217 | { | |
218 | const typ_t *tt; | |
219 | int count = 0; | |
220 | ||
221 | if (argc == 1) { | |
222 | if (cur_typ == NULL) | |
9ee7055c | 223 | dbprintf(_("no current type\n")); |
2bd0ea18 | 224 | else |
9ee7055c | 225 | dbprintf(_("current type is \"%s\"\n"), cur_typ->name); |
2bd0ea18 | 226 | |
9ee7055c | 227 | dbprintf(_("\n supported types are:\n ")); |
a364668b DC |
228 | for (tt = typtab, count = 0; tt->typnm != TYP_NONE; tt++) { |
229 | if (tt->name == NULL) | |
230 | continue; | |
2bd0ea18 NS |
231 | if ((tt+1)->name != NULL) { |
232 | dbprintf("%s, ", tt->name); | |
233 | if ((++count % 8) == 0) | |
234 | dbprintf("\n "); | |
a364668b | 235 | } else if ((tt+1)->typnm == TYP_NONE) { |
2bd0ea18 NS |
236 | dbprintf("%s\n", tt->name); |
237 | } | |
238 | } | |
239 | ||
dfc130f3 | 240 | |
2bd0ea18 NS |
241 | } else { |
242 | tt = findtyp(argv[1]); | |
243 | if (tt == NULL) { | |
9ee7055c | 244 | dbprintf(_("no such type %s\n"), argv[1]); |
7b4a7b3f ES |
245 | } else if (iocur_top->typ == tt) { |
246 | return 0; | |
dfc130f3 | 247 | } else { |
9ba69ce2 DC |
248 | if (iocur_top->typ == NULL) |
249 | dbprintf(_("no current object\n")); | |
250 | else { | |
251 | cur_typ = tt; | |
252 | set_iocur_type(tt); | |
dfc130f3 RC |
253 | } |
254 | } | |
2bd0ea18 NS |
255 | } |
256 | return 0; | |
257 | } | |
258 | ||
259 | void | |
260 | type_init(void) | |
261 | { | |
262 | add_command(&type_cmd); | |
263 | } | |
264 | ||
265 | /* read/write selectors for each major data type */ | |
266 | ||
267 | void | |
268 | handle_struct( | |
269 | int action, | |
270 | const field_t *fields, | |
271 | int argc, | |
272 | char **argv) | |
273 | { | |
984af2e1 DW |
274 | switch (action) { |
275 | case DB_FUZZ: | |
276 | fuzz_struct(fields, argc, argv); | |
277 | break; | |
278 | case DB_WRITE: | |
2bd0ea18 | 279 | write_struct(fields, argc, argv); |
984af2e1 DW |
280 | break; |
281 | case DB_READ: | |
2bd0ea18 | 282 | print_struct(fields, argc, argv); |
984af2e1 DW |
283 | break; |
284 | } | |
2bd0ea18 NS |
285 | } |
286 | ||
287 | void | |
288 | handle_string( | |
289 | int action, | |
290 | const field_t *fields, | |
291 | int argc, | |
292 | char **argv) | |
293 | { | |
984af2e1 DW |
294 | switch (action) { |
295 | case DB_WRITE: | |
2bd0ea18 | 296 | write_string(fields, argc, argv); |
984af2e1 DW |
297 | break; |
298 | case DB_READ: | |
2bd0ea18 | 299 | print_string(fields, argc, argv); |
984af2e1 DW |
300 | break; |
301 | case DB_FUZZ: | |
302 | dbprintf(_("string fuzzing not supported.\n")); | |
303 | break; | |
304 | } | |
2bd0ea18 NS |
305 | } |
306 | ||
307 | void | |
308 | handle_block( | |
309 | int action, | |
310 | const field_t *fields, | |
311 | int argc, | |
312 | char **argv) | |
313 | { | |
984af2e1 DW |
314 | switch (action) { |
315 | case DB_WRITE: | |
2bd0ea18 | 316 | write_block(fields, argc, argv); |
984af2e1 DW |
317 | break; |
318 | case DB_READ: | |
2bd0ea18 | 319 | print_block(fields, argc, argv); |
984af2e1 DW |
320 | break; |
321 | case DB_FUZZ: | |
322 | dbprintf(_("use 'blocktrash' or 'write' to fuzz a block.\n")); | |
323 | break; | |
324 | } | |
2bd0ea18 | 325 | } |
c6b24b3b NS |
326 | |
327 | void | |
328 | handle_text( | |
329 | int action, | |
330 | const field_t *fields, | |
331 | int argc, | |
332 | char **argv) | |
333 | { | |
984af2e1 DW |
334 | switch (action) { |
335 | case DB_FUZZ: | |
7c432f77 | 336 | fallthrough; |
984af2e1 DW |
337 | case DB_WRITE: |
338 | dbprintf(_("text writing/fuzzing not supported.\n")); | |
339 | break; | |
340 | case DB_READ: | |
c6b24b3b | 341 | print_text(fields, argc, argv); |
984af2e1 DW |
342 | break; |
343 | } | |
c6b24b3b | 344 | } |