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