]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/type.c
xfs_db: update field printing for dir crc format changes.
[thirdparty/xfsprogs-dev.git] / db / type.c
1 /*
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <xfs/libxfs.h>
20 #include "block.h"
21 #include "command.h"
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"
29 #include "btblock.h"
30 #include "bmroot.h"
31 #include "agf.h"
32 #include "agfl.h"
33 #include "agi.h"
34 #include "io.h"
35 #include "output.h"
36 #include "write.h"
37 #include "attr.h"
38 #include "dquot.h"
39 #include "dir2.h"
40 #include "text.h"
41
42 static const typ_t *findtyp(char *name);
43 static int type_f(int argc, char **argv);
44
45 const typ_t *cur_typ;
46
47 static const cmdinfo_t type_cmd =
48 { "type", NULL, type_f, 0, 1, 1, N_("[newtype]"),
49 N_("set/show current data type"), NULL };
50
51 static const typ_t __typtab[] = {
52 { TYP_AGF, "agf", handle_struct, agf_hfld },
53 { TYP_AGFL, "agfl", handle_struct, agfl_hfld },
54 { TYP_AGI, "agi", handle_struct, agi_hfld },
55 { TYP_ATTR, "attr", handle_struct, attr_hfld },
56 { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_hfld },
57 { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_hfld },
58 { TYP_BNOBT, "bnobt", handle_struct, bnobt_hfld },
59 { TYP_CNTBT, "cntbt", handle_struct, cntbt_hfld },
60 { TYP_DATA, "data", handle_block, NULL },
61 { TYP_DIR2, "dir2", handle_struct, dir2_hfld },
62 { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld },
63 { TYP_INOBT, "inobt", handle_struct, inobt_hfld },
64 { TYP_INODATA, "inodata", NULL, NULL },
65 { TYP_INODE, "inode", handle_struct, inode_hfld },
66 { TYP_LOG, "log", NULL, NULL },
67 { TYP_RTBITMAP, "rtbitmap", NULL, NULL },
68 { TYP_RTSUMMARY, "rtsummary", NULL, NULL },
69 { TYP_SB, "sb", handle_struct, sb_hfld },
70 { TYP_SYMLINK, "symlink", handle_string, NULL },
71 { TYP_TEXT, "text", handle_text, NULL },
72 { TYP_NONE, NULL }
73 };
74
75 static const typ_t __typtab_crc[] = {
76 { TYP_AGF, "agf", handle_struct, agf_hfld },
77 { TYP_AGFL, "agfl", handle_struct, agfl_crc_hfld },
78 { TYP_AGI, "agi", handle_struct, agi_hfld },
79 { TYP_ATTR, "attr", handle_struct, attr_hfld },
80 { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_crc_hfld },
81 { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_crc_hfld },
82 { TYP_BNOBT, "bnobt", handle_struct, bnobt_crc_hfld },
83 { TYP_CNTBT, "cntbt", handle_struct, cntbt_crc_hfld },
84 { TYP_DATA, "data", handle_block, NULL },
85 { TYP_DIR2, "dir3", handle_struct, dir3_hfld },
86 { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld },
87 { TYP_INOBT, "inobt", handle_struct, inobt_crc_hfld },
88 { TYP_INODATA, "inodata", NULL, NULL },
89 { TYP_INODE, "inode", handle_struct, inode_crc_hfld },
90 { TYP_LOG, "log", NULL, NULL },
91 { TYP_RTBITMAP, "rtbitmap", NULL, NULL },
92 { TYP_RTSUMMARY, "rtsummary", NULL, NULL },
93 { TYP_SB, "sb", handle_struct, sb_hfld },
94 { TYP_SYMLINK, "symlink", handle_string, NULL },
95 { TYP_TEXT, "text", handle_text, NULL },
96 { TYP_NONE, NULL }
97 };
98
99 const typ_t *typtab = __typtab;
100
101 void
102 type_set_tab_crc(void)
103 {
104 typtab = __typtab_crc;
105 }
106
107 static const typ_t *
108 findtyp(
109 char *name)
110 {
111 const typ_t *tt;
112
113 for (tt = typtab; tt->typnm != TYP_NONE; tt++) {
114 ASSERT(tt->typnm == (typnm_t)(tt - typtab));
115 if (tt->name && strcmp(tt->name, name) == 0)
116 return tt;
117 }
118 return NULL;
119 }
120
121 static int
122 type_f(
123 int argc,
124 char **argv)
125 {
126 const typ_t *tt;
127 int count = 0;
128
129 if (argc == 1) {
130 if (cur_typ == NULL)
131 dbprintf(_("no current type\n"));
132 else
133 dbprintf(_("current type is \"%s\"\n"), cur_typ->name);
134
135 dbprintf(_("\n supported types are:\n "));
136 for (tt = typtab, count = 0; tt->typnm != TYP_NONE; tt++) {
137 if (tt->name == NULL)
138 continue;
139 if ((tt+1)->name != NULL) {
140 dbprintf("%s, ", tt->name);
141 if ((++count % 8) == 0)
142 dbprintf("\n ");
143 } else if ((tt+1)->typnm == TYP_NONE) {
144 dbprintf("%s\n", tt->name);
145 }
146 }
147
148
149 } else {
150 tt = findtyp(argv[1]);
151 if (tt == NULL) {
152 dbprintf(_("no such type %s\n"), argv[1]);
153 } else {
154 if (iocur_top->typ == NULL) {
155 dbprintf(_("no current object\n"));
156 } else {
157 iocur_top->typ = cur_typ = tt;
158 }
159 }
160 }
161 return 0;
162 }
163
164 void
165 type_init(void)
166 {
167 add_command(&type_cmd);
168 }
169
170 /* read/write selectors for each major data type */
171
172 void
173 handle_struct(
174 int action,
175 const field_t *fields,
176 int argc,
177 char **argv)
178 {
179 if (action == DB_WRITE)
180 write_struct(fields, argc, argv);
181 else
182 print_struct(fields, argc, argv);
183 }
184
185 void
186 handle_string(
187 int action,
188 const field_t *fields,
189 int argc,
190 char **argv)
191 {
192 if (action == DB_WRITE)
193 write_string(fields, argc, argv);
194 else
195 print_string(fields, argc, argv);
196 }
197
198 void
199 handle_block(
200 int action,
201 const field_t *fields,
202 int argc,
203 char **argv)
204 {
205 if (action == DB_WRITE)
206 write_block(fields, argc, argv);
207 else
208 print_block(fields, argc, argv);
209 }
210
211 void
212 handle_text(
213 int action,
214 const field_t *fields,
215 int argc,
216 char **argv)
217 {
218 if (action != DB_WRITE)
219 print_text(fields, argc, argv);
220 }