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