]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/type.c
324f416a49cc4dbcd7fe6536aa35c91fd7ac73ce
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
33 static const typ_t
*findtyp(char *name
);
34 static int type_f(int argc
, char **argv
);
38 static const cmdinfo_t type_cmd
=
39 { "type", NULL
, type_f
, 0, 1, 1, N_("[newtype]"),
40 N_("set/show current data type"), NULL
};
42 static const typ_t __typtab
[] = {
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
,
49 { TYP_BMAPBTD
, "bmapbtd", handle_struct
, bmapbtd_hfld
, NULL
,
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
},
54 { TYP_RTRMAPBT
, NULL
},
56 { TYP_RTREFCBT
, NULL
},
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
},
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
},
66 { TYP_RTSB
, "rtsb", handle_struct
, rtsb_hfld
, NULL
, TYP_F_NO_CRC_OFF
},
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
},
70 { TYP_FINOBT
, "finobt", handle_struct
, finobt_hfld
, NULL
,
72 { TYP_RGBITMAP
, NULL
},
73 { TYP_RGSUMMARY
, NULL
},
77 static const typ_t __typtab_crc
[] = {
78 { TYP_AGF
, "agf", handle_struct
, agf_hfld
, &xfs_agf_buf_ops
,
80 { TYP_AGFL
, "agfl", handle_struct
, agfl_crc_hfld
, &xfs_agfl_buf_ops
,
82 { TYP_AGI
, "agi", handle_struct
, agi_hfld
, &xfs_agi_buf_ops
,
84 { TYP_ATTR
, "attr3", handle_struct
, attr3_hfld
,
85 &xfs_attr3_db_buf_ops
, TYP_F_CRC_FUNC
, xfs_attr3_set_crc
},
86 { TYP_BMAPBTA
, "bmapbta", handle_struct
, bmapbta_crc_hfld
,
87 &xfs_bmbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
88 { TYP_BMAPBTD
, "bmapbtd", handle_struct
, bmapbtd_crc_hfld
,
89 &xfs_bmbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
90 { TYP_BNOBT
, "bnobt", handle_struct
, bnobt_crc_hfld
,
91 &xfs_bnobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
92 { TYP_CNTBT
, "cntbt", handle_struct
, cntbt_crc_hfld
,
93 &xfs_cntbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
94 { TYP_RMAPBT
, "rmapbt", handle_struct
, rmapbt_crc_hfld
,
95 &xfs_rmapbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
96 { TYP_RTRMAPBT
, "rtrmapbt", handle_struct
, rtrmapbt_crc_hfld
,
97 &xfs_rtrmapbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
98 { TYP_REFCBT
, "refcntbt", handle_struct
, refcbt_crc_hfld
,
99 &xfs_refcountbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
100 { TYP_RTREFCBT
, "rtrefcntbt", handle_struct
, rtrefcbt_crc_hfld
,
101 &xfs_rtrefcountbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
102 { TYP_DATA
, "data", handle_block
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
103 { TYP_DIR2
, "dir3", handle_struct
, dir3_hfld
,
104 &xfs_dir3_db_buf_ops
, TYP_F_CRC_FUNC
, xfs_dir3_set_crc
},
105 { TYP_DQBLK
, "dqblk", handle_struct
, dqblk_hfld
,
106 &xfs_dquot_buf_ops
, TYP_F_CRC_FUNC
, xfs_dquot_set_crc
},
107 { TYP_INOBT
, "inobt", handle_struct
, inobt_crc_hfld
,
108 &xfs_inobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
109 { TYP_INODATA
, "inodata", NULL
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
110 { TYP_INODE
, "inode", handle_struct
, inode_crc_hfld
,
111 &xfs_inode_buf_ops
, TYP_F_CRC_FUNC
, xfs_inode_set_crc
},
112 { TYP_LOG
, "log", NULL
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
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
},
115 { TYP_RTSB
, "rtsb", handle_struct
, rtsb_hfld
, &xfs_rtsb_buf_ops
,
117 { TYP_SB
, "sb", handle_struct
, sb_hfld
, &xfs_sb_buf_ops
,
119 { TYP_SYMLINK
, "symlink", handle_struct
, symlink_crc_hfld
,
120 &xfs_symlink_buf_ops
, XFS_SYMLINK_CRC_OFF
},
121 { TYP_TEXT
, "text", handle_text
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
122 { TYP_FINOBT
, "finobt", handle_struct
, finobt_crc_hfld
,
123 &xfs_finobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
124 { TYP_RGBITMAP
, "rgbitmap", handle_struct
, rgbitmap_hfld
,
125 &xfs_rtbitmap_buf_ops
, XFS_RTBUF_CRC_OFF
},
126 { TYP_RGSUMMARY
, "rgsummary", handle_struct
, rgsummary_hfld
,
127 &xfs_rtsummary_buf_ops
, XFS_RTBUF_CRC_OFF
},
131 static const typ_t __typtab_spcrc
[] = {
132 { TYP_AGF
, "agf", handle_struct
, agf_hfld
, &xfs_agf_buf_ops
,
134 { TYP_AGFL
, "agfl", handle_struct
, agfl_crc_hfld
, &xfs_agfl_buf_ops
,
136 { TYP_AGI
, "agi", handle_struct
, agi_hfld
, &xfs_agi_buf_ops
,
138 { TYP_ATTR
, "attr3", handle_struct
, attr3_hfld
,
139 &xfs_attr3_db_buf_ops
, TYP_F_CRC_FUNC
, xfs_attr3_set_crc
},
140 { TYP_BMAPBTA
, "bmapbta", handle_struct
, bmapbta_crc_hfld
,
141 &xfs_bmbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
142 { TYP_BMAPBTD
, "bmapbtd", handle_struct
, bmapbtd_crc_hfld
,
143 &xfs_bmbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
144 { TYP_BNOBT
, "bnobt", handle_struct
, bnobt_crc_hfld
,
145 &xfs_bnobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
146 { TYP_CNTBT
, "cntbt", handle_struct
, cntbt_crc_hfld
,
147 &xfs_cntbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
148 { TYP_RMAPBT
, "rmapbt", handle_struct
, rmapbt_crc_hfld
,
149 &xfs_rmapbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
150 { TYP_RTRMAPBT
, "rtrmapbt", handle_struct
, rtrmapbt_crc_hfld
,
151 &xfs_rtrmapbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
152 { TYP_REFCBT
, "refcntbt", handle_struct
, refcbt_crc_hfld
,
153 &xfs_refcountbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
154 { TYP_RTREFCBT
, "rtrefcntbt", handle_struct
, rtrefcbt_crc_hfld
,
155 &xfs_rtrefcountbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
156 { TYP_DATA
, "data", handle_block
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
157 { TYP_DIR2
, "dir3", handle_struct
, dir3_hfld
,
158 &xfs_dir3_db_buf_ops
, TYP_F_CRC_FUNC
, xfs_dir3_set_crc
},
159 { TYP_DQBLK
, "dqblk", handle_struct
, dqblk_hfld
,
160 &xfs_dquot_buf_ops
, TYP_F_CRC_FUNC
, xfs_dquot_set_crc
},
161 { TYP_INOBT
, "inobt", handle_struct
, inobt_spcrc_hfld
,
162 &xfs_inobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
163 { TYP_INODATA
, "inodata", NULL
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
164 { TYP_INODE
, "inode", handle_struct
, inode_crc_hfld
,
165 &xfs_inode_buf_ops
, TYP_F_CRC_FUNC
, xfs_inode_set_crc
},
166 { TYP_LOG
, "log", NULL
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
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
},
169 { TYP_RTSB
, "rtsb", handle_struct
, rtsb_hfld
, &xfs_rtsb_buf_ops
,
171 { TYP_SB
, "sb", handle_struct
, sb_hfld
, &xfs_sb_buf_ops
,
173 { TYP_SYMLINK
, "symlink", handle_struct
, symlink_crc_hfld
,
174 &xfs_symlink_buf_ops
, XFS_SYMLINK_CRC_OFF
},
175 { TYP_TEXT
, "text", handle_text
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
176 { TYP_FINOBT
, "finobt", handle_struct
, finobt_spcrc_hfld
,
177 &xfs_finobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
178 { TYP_RGBITMAP
, "rgbitmap", handle_struct
, rgbitmap_hfld
,
179 &xfs_rtbitmap_buf_ops
, XFS_RTBUF_CRC_OFF
},
180 { TYP_RGSUMMARY
, "rgsummary", handle_struct
, rgsummary_hfld
,
181 &xfs_rtsummary_buf_ops
, XFS_RTBUF_CRC_OFF
},
185 const typ_t
*typtab
= __typtab
;
188 type_set_tab_crc(void)
190 typtab
= __typtab_crc
;
194 type_set_tab_spcrc(void)
196 typtab
= __typtab_spcrc
;
205 for (tt
= typtab
; tt
->typnm
!= TYP_NONE
; tt
++) {
206 ASSERT(tt
->typnm
== (typnm_t
)(tt
- typtab
));
207 if (tt
->name
&& strcmp(tt
->name
, name
) == 0)
223 dbprintf(_("no current type\n"));
225 dbprintf(_("current type is \"%s\"\n"), cur_typ
->name
);
227 dbprintf(_("\n supported types are:\n "));
228 for (tt
= typtab
, count
= 0; tt
->typnm
!= TYP_NONE
; tt
++) {
229 if (tt
->name
== NULL
)
231 if ((tt
+1)->name
!= NULL
) {
232 dbprintf("%s, ", tt
->name
);
233 if ((++count
% 8) == 0)
235 } else if ((tt
+1)->typnm
== TYP_NONE
) {
236 dbprintf("%s\n", tt
->name
);
242 tt
= findtyp(argv
[1]);
244 dbprintf(_("no such type %s\n"), argv
[1]);
245 } else if (iocur_top
->typ
== tt
) {
248 if (iocur_top
->typ
== NULL
)
249 dbprintf(_("no current object\n"));
262 add_command(&type_cmd
);
265 /* read/write selectors for each major data type */
270 const field_t
*fields
,
276 fuzz_struct(fields
, argc
, argv
);
279 write_struct(fields
, argc
, argv
);
282 print_struct(fields
, argc
, argv
);
290 const field_t
*fields
,
296 write_string(fields
, argc
, argv
);
299 print_string(fields
, argc
, argv
);
302 dbprintf(_("string fuzzing not supported.\n"));
310 const field_t
*fields
,
316 write_block(fields
, argc
, argv
);
319 print_block(fields
, argc
, argv
);
322 dbprintf(_("use 'blocktrash' or 'write' to fuzz a block.\n"));
330 const field_t
*fields
,
338 dbprintf(_("text writing/fuzzing not supported.\n"));
341 print_text(fields
, argc
, argv
);