]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/type.c
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
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.
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.
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
44 static const typ_t
*findtyp(char *name
);
45 static int type_f(int argc
, char **argv
);
49 static const cmdinfo_t type_cmd
=
50 { "type", NULL
, type_f
, 0, 1, 1, N_("[newtype]"),
51 N_("set/show current data type"), NULL
};
53 static const typ_t __typtab
[] = {
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
,
60 { TYP_BMAPBTD
, "bmapbtd", handle_struct
, bmapbtd_hfld
, NULL
,
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
},
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
,
83 static const typ_t __typtab_crc
[] = {
84 { TYP_AGF
, "agf", handle_struct
, agf_hfld
, &xfs_agf_buf_ops
,
86 { TYP_AGFL
, "agfl", handle_struct
, agfl_crc_hfld
, &xfs_agfl_buf_ops
,
88 { TYP_AGI
, "agi", handle_struct
, agi_hfld
, &xfs_agi_buf_ops
,
90 { TYP_ATTR
, "attr3", handle_struct
, attr3_hfld
,
91 &xfs_attr3_db_buf_ops
, TYP_F_CRC_FUNC
, xfs_attr3_set_crc
},
92 { TYP_BMAPBTA
, "bmapbta", handle_struct
, bmapbta_crc_hfld
,
93 &xfs_bmbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
94 { TYP_BMAPBTD
, "bmapbtd", handle_struct
, bmapbtd_crc_hfld
,
95 &xfs_bmbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
96 { TYP_BNOBT
, "bnobt", handle_struct
, bnobt_crc_hfld
,
97 &xfs_allocbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
98 { TYP_CNTBT
, "cntbt", handle_struct
, cntbt_crc_hfld
,
99 &xfs_allocbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
100 { TYP_RMAPBT
, "rmapbt", handle_struct
, rmapbt_crc_hfld
,
101 &xfs_rmapbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
102 { TYP_REFCBT
, "refcntbt", handle_struct
, refcbt_crc_hfld
,
103 &xfs_refcountbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
104 { TYP_DATA
, "data", handle_block
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
105 { TYP_DIR2
, "dir3", handle_struct
, dir3_hfld
,
106 &xfs_dir3_db_buf_ops
, TYP_F_CRC_FUNC
, xfs_dir3_set_crc
},
107 { TYP_DQBLK
, "dqblk", handle_struct
, dqblk_hfld
,
108 &xfs_dquot_buf_ops
, TYP_F_CRC_FUNC
, xfs_dquot_set_crc
},
109 { TYP_INOBT
, "inobt", handle_struct
, inobt_crc_hfld
,
110 &xfs_inobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
111 { TYP_INODATA
, "inodata", NULL
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
112 { TYP_INODE
, "inode", handle_struct
, inode_crc_hfld
,
113 &xfs_inode_buf_ops
, TYP_F_CRC_FUNC
, xfs_inode_set_crc
},
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
,
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
, inobt_crc_hfld
,
123 &xfs_inobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
127 static const typ_t __typtab_spcrc
[] = {
128 { TYP_AGF
, "agf", handle_struct
, agf_hfld
, &xfs_agf_buf_ops
,
130 { TYP_AGFL
, "agfl", handle_struct
, agfl_crc_hfld
, &xfs_agfl_buf_ops
,
132 { TYP_AGI
, "agi", handle_struct
, agi_hfld
, &xfs_agi_buf_ops
,
134 { TYP_ATTR
, "attr3", handle_struct
, attr3_hfld
,
135 &xfs_attr3_db_buf_ops
, TYP_F_CRC_FUNC
, xfs_attr3_set_crc
},
136 { TYP_BMAPBTA
, "bmapbta", handle_struct
, bmapbta_crc_hfld
,
137 &xfs_bmbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
138 { TYP_BMAPBTD
, "bmapbtd", handle_struct
, bmapbtd_crc_hfld
,
139 &xfs_bmbt_buf_ops
, XFS_BTREE_LBLOCK_CRC_OFF
},
140 { TYP_BNOBT
, "bnobt", handle_struct
, bnobt_crc_hfld
,
141 &xfs_allocbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
142 { TYP_CNTBT
, "cntbt", handle_struct
, cntbt_crc_hfld
,
143 &xfs_allocbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
144 { TYP_RMAPBT
, "rmapbt", handle_struct
, rmapbt_crc_hfld
,
145 &xfs_rmapbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
146 { TYP_REFCBT
, "refcntbt", handle_struct
, refcbt_crc_hfld
,
147 &xfs_refcountbt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
148 { TYP_DATA
, "data", handle_block
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
149 { TYP_DIR2
, "dir3", handle_struct
, dir3_hfld
,
150 &xfs_dir3_db_buf_ops
, TYP_F_CRC_FUNC
, xfs_dir3_set_crc
},
151 { TYP_DQBLK
, "dqblk", handle_struct
, dqblk_hfld
,
152 &xfs_dquot_buf_ops
, TYP_F_CRC_FUNC
, xfs_dquot_set_crc
},
153 { TYP_INOBT
, "inobt", handle_struct
, inobt_spcrc_hfld
,
154 &xfs_inobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
155 { TYP_INODATA
, "inodata", NULL
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
156 { TYP_INODE
, "inode", handle_struct
, inode_crc_hfld
,
157 &xfs_inode_buf_ops
, TYP_F_CRC_FUNC
, xfs_inode_set_crc
},
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
,
163 { TYP_SYMLINK
, "symlink", handle_struct
, symlink_crc_hfld
,
164 &xfs_symlink_buf_ops
, XFS_SYMLINK_CRC_OFF
},
165 { TYP_TEXT
, "text", handle_text
, NULL
, NULL
, TYP_F_NO_CRC_OFF
},
166 { TYP_FINOBT
, "finobt", handle_struct
, inobt_crc_hfld
,
167 &xfs_inobt_buf_ops
, XFS_BTREE_SBLOCK_CRC_OFF
},
171 const typ_t
*typtab
= __typtab
;
174 type_set_tab_crc(void)
176 typtab
= __typtab_crc
;
180 type_set_tab_spcrc(void)
182 typtab
= __typtab_spcrc
;
191 for (tt
= typtab
; tt
->typnm
!= TYP_NONE
; tt
++) {
192 ASSERT(tt
->typnm
== (typnm_t
)(tt
- typtab
));
193 if (tt
->name
&& strcmp(tt
->name
, name
) == 0)
209 dbprintf(_("no current type\n"));
211 dbprintf(_("current type is \"%s\"\n"), cur_typ
->name
);
213 dbprintf(_("\n supported types are:\n "));
214 for (tt
= typtab
, count
= 0; tt
->typnm
!= TYP_NONE
; tt
++) {
215 if (tt
->name
== NULL
)
217 if ((tt
+1)->name
!= NULL
) {
218 dbprintf("%s, ", tt
->name
);
219 if ((++count
% 8) == 0)
221 } else if ((tt
+1)->typnm
== TYP_NONE
) {
222 dbprintf("%s\n", tt
->name
);
228 tt
= findtyp(argv
[1]);
230 dbprintf(_("no such type %s\n"), argv
[1]);
232 if (iocur_top
->typ
== NULL
)
233 dbprintf(_("no current object\n"));
246 add_command(&type_cmd
);
249 /* read/write selectors for each major data type */
254 const field_t
*fields
,
260 fuzz_struct(fields
, argc
, argv
);
263 write_struct(fields
, argc
, argv
);
266 print_struct(fields
, argc
, argv
);
274 const field_t
*fields
,
280 write_string(fields
, argc
, argv
);
283 print_string(fields
, argc
, argv
);
286 dbprintf(_("string fuzzing not supported.\n"));
294 const field_t
*fields
,
300 write_block(fields
, argc
, argv
);
303 print_block(fields
, argc
, argv
);
306 dbprintf(_("use 'blocktrash' or 'write' to fuzz a block.\n"));
314 const field_t
*fields
,
322 dbprintf(_("text writing/fuzzing not supported.\n"));
325 print_text(fields
, argc
, argv
);