]>
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 "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" |
2bd0ea18 NS |
42 | |
43 | static const typ_t *findtyp(char *name); | |
44 | static int type_f(int argc, char **argv); | |
45 | ||
46 | const typ_t *cur_typ; | |
47 | ||
48 | static const cmdinfo_t type_cmd = | |
9ee7055c AM |
49 | { "type", NULL, type_f, 0, 1, 1, N_("[newtype]"), |
50 | N_("set/show current data type"), NULL }; | |
2bd0ea18 | 51 | |
c2907bd7 | 52 | static const typ_t __typtab[] = { |
86769b32 DC |
53 | { TYP_AGF, "agf", handle_struct, agf_hfld, NULL, TYP_F_NO_CRC_OFF }, |
54 | { TYP_AGFL, "agfl", handle_struct, agfl_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
55 | { TYP_AGI, "agi", handle_struct, agi_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
56 | { TYP_ATTR, "attr", handle_struct, attr_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
57 | { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_hfld, NULL, | |
58 | TYP_F_NO_CRC_OFF }, | |
59 | { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_hfld, NULL, | |
60 | TYP_F_NO_CRC_OFF }, | |
61 | { TYP_BNOBT, "bnobt", handle_struct, bnobt_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
62 | { TYP_CNTBT, "cntbt", handle_struct, cntbt_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
a9d7b986 | 63 | { TYP_RMAPBT, NULL }, |
86769b32 DC |
64 | { TYP_DATA, "data", handle_block, NULL, NULL, TYP_F_NO_CRC_OFF }, |
65 | { TYP_DIR2, "dir2", handle_struct, dir2_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
66 | { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
67 | { TYP_INOBT, "inobt", handle_struct, inobt_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
68 | { TYP_INODATA, "inodata", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
69 | { TYP_INODE, "inode", handle_struct, inode_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
70 | { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
71 | { TYP_RTBITMAP, "rtbitmap", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
72 | { TYP_RTSUMMARY, "rtsummary", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
73 | { TYP_SB, "sb", handle_struct, sb_hfld, NULL, TYP_F_NO_CRC_OFF }, | |
74 | { TYP_SYMLINK, "symlink", handle_string, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
75 | { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
76 | { TYP_FINOBT, "finobt", handle_struct, inobt_hfld, NULL, | |
77 | TYP_F_NO_CRC_OFF }, | |
2bd0ea18 NS |
78 | { TYP_NONE, NULL } |
79 | }; | |
80 | ||
c2907bd7 | 81 | static const typ_t __typtab_crc[] = { |
86769b32 DC |
82 | { TYP_AGF, "agf", handle_struct, agf_hfld, &xfs_agf_buf_ops, |
83 | XFS_AGF_CRC_OFF }, | |
84 | { TYP_AGFL, "agfl", handle_struct, agfl_crc_hfld, &xfs_agfl_buf_ops, | |
85 | XFS_AGFL_CRC_OFF }, | |
86 | { TYP_AGI, "agi", handle_struct, agi_hfld, &xfs_agi_buf_ops, | |
87 | XFS_AGI_CRC_OFF }, | |
2847273f | 88 | { TYP_ATTR, "attr3", handle_struct, attr3_hfld, |
86769b32 | 89 | &xfs_attr3_db_buf_ops, TYP_F_NO_CRC_OFF }, |
6fea8f83 | 90 | { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_crc_hfld, |
86769b32 | 91 | &xfs_bmbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, |
6fea8f83 | 92 | { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_crc_hfld, |
86769b32 | 93 | &xfs_bmbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, |
6fea8f83 | 94 | { TYP_BNOBT, "bnobt", handle_struct, bnobt_crc_hfld, |
86769b32 | 95 | &xfs_allocbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
6fea8f83 | 96 | { TYP_CNTBT, "cntbt", handle_struct, cntbt_crc_hfld, |
86769b32 | 97 | &xfs_allocbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
a9d7b986 DW |
98 | { TYP_RMAPBT, "rmapbt", handle_struct, rmapbt_crc_hfld, |
99 | &xfs_rmapbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, | |
86769b32 | 100 | { TYP_DATA, "data", handle_block, NULL, NULL, TYP_F_NO_CRC_OFF }, |
fc068a19 | 101 | { TYP_DIR2, "dir3", handle_struct, dir3_hfld, |
86769b32 | 102 | &xfs_dir3_db_buf_ops, TYP_F_NO_CRC_OFF }, |
6fea8f83 | 103 | { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld, |
86769b32 | 104 | &xfs_dquot_buf_ops, TYP_F_NO_CRC_OFF }, |
6fea8f83 | 105 | { TYP_INOBT, "inobt", handle_struct, inobt_crc_hfld, |
86769b32 DC |
106 | &xfs_inobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
107 | { TYP_INODATA, "inodata", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
6fea8f83 | 108 | { TYP_INODE, "inode", handle_struct, inode_crc_hfld, |
86769b32 DC |
109 | &xfs_inode_buf_ops, TYP_F_NO_CRC_OFF }, |
110 | { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
111 | { TYP_RTBITMAP, "rtbitmap", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
112 | { TYP_RTSUMMARY, "rtsummary", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
113 | { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, | |
114 | XFS_SB_CRC_OFF }, | |
6fea8f83 | 115 | { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld, |
86769b32 DC |
116 | &xfs_symlink_buf_ops, XFS_SYMLINK_CRC_OFF }, |
117 | { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
20f35ef4 | 118 | { TYP_FINOBT, "finobt", handle_struct, inobt_crc_hfld, |
86769b32 | 119 | &xfs_inobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
c2907bd7 DC |
120 | { TYP_NONE, NULL } |
121 | }; | |
122 | ||
061e316e | 123 | static const typ_t __typtab_spcrc[] = { |
86769b32 DC |
124 | { TYP_AGF, "agf", handle_struct, agf_hfld, &xfs_agf_buf_ops, |
125 | XFS_AGF_CRC_OFF }, | |
126 | { TYP_AGFL, "agfl", handle_struct, agfl_crc_hfld, &xfs_agfl_buf_ops , | |
127 | XFS_AGFL_CRC_OFF }, | |
128 | { TYP_AGI, "agi", handle_struct, agi_hfld, &xfs_agi_buf_ops , | |
129 | XFS_AGI_CRC_OFF }, | |
061e316e | 130 | { TYP_ATTR, "attr3", handle_struct, attr3_hfld, |
86769b32 | 131 | &xfs_attr3_db_buf_ops, TYP_F_NO_CRC_OFF }, |
061e316e | 132 | { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_crc_hfld, |
86769b32 | 133 | &xfs_bmbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, |
061e316e | 134 | { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_crc_hfld, |
86769b32 | 135 | &xfs_bmbt_buf_ops, XFS_BTREE_LBLOCK_CRC_OFF }, |
061e316e | 136 | { TYP_BNOBT, "bnobt", handle_struct, bnobt_crc_hfld, |
86769b32 | 137 | &xfs_allocbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
061e316e | 138 | { TYP_CNTBT, "cntbt", handle_struct, cntbt_crc_hfld, |
86769b32 | 139 | &xfs_allocbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
a9d7b986 DW |
140 | { TYP_RMAPBT, "rmapbt", handle_struct, rmapbt_crc_hfld, |
141 | &xfs_rmapbt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, | |
86769b32 | 142 | { TYP_DATA, "data", handle_block, NULL, NULL, TYP_F_NO_CRC_OFF }, |
061e316e | 143 | { TYP_DIR2, "dir3", handle_struct, dir3_hfld, |
86769b32 | 144 | &xfs_dir3_db_buf_ops, TYP_F_NO_CRC_OFF }, |
061e316e | 145 | { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld, |
86769b32 | 146 | &xfs_dquot_buf_ops, TYP_F_NO_CRC_OFF }, |
061e316e | 147 | { TYP_INOBT, "inobt", handle_struct, inobt_spcrc_hfld, |
86769b32 DC |
148 | &xfs_inobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
149 | { TYP_INODATA, "inodata", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
061e316e | 150 | { TYP_INODE, "inode", handle_struct, inode_crc_hfld, |
86769b32 DC |
151 | &xfs_inode_buf_ops, TYP_F_NO_CRC_OFF }, |
152 | { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
153 | { TYP_RTBITMAP, "rtbitmap", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
154 | { TYP_RTSUMMARY, "rtsummary", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
155 | { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, | |
156 | XFS_SB_CRC_OFF }, | |
061e316e | 157 | { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld, |
86769b32 DC |
158 | &xfs_symlink_buf_ops, XFS_SYMLINK_CRC_OFF }, |
159 | { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, | |
e96864ff | 160 | { TYP_FINOBT, "finobt", handle_struct, inobt_crc_hfld, |
86769b32 | 161 | &xfs_inobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, |
061e316e BF |
162 | { TYP_NONE, NULL } |
163 | }; | |
164 | ||
c2907bd7 DC |
165 | const typ_t *typtab = __typtab; |
166 | ||
167 | void | |
168 | type_set_tab_crc(void) | |
169 | { | |
170 | typtab = __typtab_crc; | |
171 | } | |
172 | ||
061e316e BF |
173 | void |
174 | type_set_tab_spcrc(void) | |
175 | { | |
176 | typtab = __typtab_spcrc; | |
177 | } | |
178 | ||
2bd0ea18 NS |
179 | static const typ_t * |
180 | findtyp( | |
181 | char *name) | |
182 | { | |
183 | const typ_t *tt; | |
184 | ||
a364668b | 185 | for (tt = typtab; tt->typnm != TYP_NONE; tt++) { |
2bd0ea18 | 186 | ASSERT(tt->typnm == (typnm_t)(tt - typtab)); |
a364668b | 187 | if (tt->name && strcmp(tt->name, name) == 0) |
2bd0ea18 NS |
188 | return tt; |
189 | } | |
190 | return NULL; | |
191 | } | |
192 | ||
193 | static int | |
194 | type_f( | |
195 | int argc, | |
196 | char **argv) | |
197 | { | |
198 | const typ_t *tt; | |
199 | int count = 0; | |
200 | ||
201 | if (argc == 1) { | |
202 | if (cur_typ == NULL) | |
9ee7055c | 203 | dbprintf(_("no current type\n")); |
2bd0ea18 | 204 | else |
9ee7055c | 205 | dbprintf(_("current type is \"%s\"\n"), cur_typ->name); |
2bd0ea18 | 206 | |
9ee7055c | 207 | dbprintf(_("\n supported types are:\n ")); |
a364668b DC |
208 | for (tt = typtab, count = 0; tt->typnm != TYP_NONE; tt++) { |
209 | if (tt->name == NULL) | |
210 | continue; | |
2bd0ea18 NS |
211 | if ((tt+1)->name != NULL) { |
212 | dbprintf("%s, ", tt->name); | |
213 | if ((++count % 8) == 0) | |
214 | dbprintf("\n "); | |
a364668b | 215 | } else if ((tt+1)->typnm == TYP_NONE) { |
2bd0ea18 NS |
216 | dbprintf("%s\n", tt->name); |
217 | } | |
218 | } | |
219 | ||
dfc130f3 | 220 | |
2bd0ea18 NS |
221 | } else { |
222 | tt = findtyp(argv[1]); | |
223 | if (tt == NULL) { | |
9ee7055c | 224 | dbprintf(_("no such type %s\n"), argv[1]); |
dfc130f3 | 225 | } else { |
9ba69ce2 DC |
226 | if (iocur_top->typ == NULL) |
227 | dbprintf(_("no current object\n")); | |
228 | else { | |
229 | cur_typ = tt; | |
230 | set_iocur_type(tt); | |
dfc130f3 RC |
231 | } |
232 | } | |
2bd0ea18 NS |
233 | } |
234 | return 0; | |
235 | } | |
236 | ||
237 | void | |
238 | type_init(void) | |
239 | { | |
240 | add_command(&type_cmd); | |
241 | } | |
242 | ||
243 | /* read/write selectors for each major data type */ | |
244 | ||
245 | void | |
246 | handle_struct( | |
247 | int action, | |
248 | const field_t *fields, | |
249 | int argc, | |
250 | char **argv) | |
251 | { | |
252 | if (action == DB_WRITE) | |
253 | write_struct(fields, argc, argv); | |
254 | else | |
255 | print_struct(fields, argc, argv); | |
256 | } | |
257 | ||
258 | void | |
259 | handle_string( | |
260 | int action, | |
261 | const field_t *fields, | |
262 | int argc, | |
263 | char **argv) | |
264 | { | |
265 | if (action == DB_WRITE) | |
266 | write_string(fields, argc, argv); | |
267 | else | |
268 | print_string(fields, argc, argv); | |
269 | } | |
270 | ||
271 | void | |
272 | handle_block( | |
273 | int action, | |
274 | const field_t *fields, | |
275 | int argc, | |
276 | char **argv) | |
277 | { | |
278 | if (action == DB_WRITE) | |
279 | write_block(fields, argc, argv); | |
280 | else | |
281 | print_block(fields, argc, argv); | |
282 | } | |
c6b24b3b NS |
283 | |
284 | void | |
285 | handle_text( | |
286 | int action, | |
287 | const field_t *fields, | |
288 | int argc, | |
289 | char **argv) | |
290 | { | |
291 | if (action != DB_WRITE) | |
292 | print_text(fields, argc, argv); | |
293 | } |