]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/type.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / db / type.c
CommitLineData
2bd0ea18 1/*
0d3e0b37 2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
dfc130f3 3 *
2bd0ea18
NS
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
dfc130f3 7 *
2bd0ea18
NS
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
dfc130f3 11 *
2bd0ea18
NS
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
dfc130f3 18 *
2bd0ea18
NS
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
dfc130f3 22 *
2bd0ea18
NS
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
dfc130f3
RC
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
2bd0ea18
NS
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33#include <libxfs.h>
34#include "agf.h"
35#include "agfl.h"
36#include "agi.h"
37#include "block.h"
38#include "command.h"
2bd0ea18
NS
39#include "type.h"
40#include "faddr.h"
41#include "fprint.h"
42#include "field.h"
43#include "print.h"
44#include "sb.h"
45#include "inode.h"
46#include "bnobt.h"
47#include "cntbt.h"
48#include "inobt.h"
49#include "bmapbt.h"
50#include "bmroot.h"
51#include "agf.h"
52#include "agfl.h"
53#include "agi.h"
54#include "dir.h"
55#include "dirshort.h"
56#include "io.h"
57#include "output.h"
58#include "write.h"
59#include "attr.h"
60#include "dquot.h"
61#include "dir2.h"
c6b24b3b 62#include "text.h"
2bd0ea18
NS
63
64static const typ_t *findtyp(char *name);
65static int type_f(int argc, char **argv);
66
67const typ_t *cur_typ;
68
69static const cmdinfo_t type_cmd =
70 { "type", NULL, type_f, 0, 1, 1, "[newtype]",
71 "set/show current data type", NULL };
72
73const typ_t typtab[] = {
74 { TYP_AGF, "agf", handle_struct, agf_hfld },
75 { TYP_AGFL, "agfl", handle_struct, agfl_hfld },
76 { TYP_AGI, "agi", handle_struct, agi_hfld },
77 { TYP_ATTR, "attr", handle_struct, attr_hfld },
78 { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_hfld },
79 { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_hfld },
80 { TYP_BNOBT, "bnobt", handle_struct, bnobt_hfld },
81 { TYP_CNTBT, "cntbt", handle_struct, cntbt_hfld },
82 { TYP_DATA, "data", handle_block, NULL },
83 { TYP_DIR, "dir", handle_struct, dir_hfld },
84 { TYP_DIR2, "dir2", handle_struct, dir2_hfld },
85 { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld },
86 { TYP_INOBT, "inobt", handle_struct, inobt_hfld },
87 { TYP_INODATA, "inodata", NULL, NULL },
88 { TYP_INODE, "inode", handle_struct, inode_hfld },
89 { TYP_LOG, "log", NULL, NULL },
90 { TYP_RTBITMAP, "rtbitmap", NULL, NULL },
91 { TYP_RTSUMMARY, "rtsummary", NULL, NULL },
92 { TYP_SB, "sb", handle_struct, sb_hfld },
93 { TYP_SYMLINK, "symlink", handle_string, NULL },
dfc130f3 94 { TYP_TEXT, "text", handle_text, NULL },
2bd0ea18
NS
95 { TYP_NONE, NULL }
96};
97
98static const typ_t *
99findtyp(
100 char *name)
101{
102 const typ_t *tt;
103
104 for (tt = typtab; tt->name != NULL; tt++) {
105 ASSERT(tt->typnm == (typnm_t)(tt - typtab));
106 if (strcmp(tt->name, name) == 0)
107 return tt;
108 }
109 return NULL;
110}
111
112static int
113type_f(
114 int argc,
115 char **argv)
116{
117 const typ_t *tt;
118 int count = 0;
119
120 if (argc == 1) {
121 if (cur_typ == NULL)
122 dbprintf("no current type\n");
123 else
124 dbprintf("current type is \"%s\"\n", cur_typ->name);
125
126 dbprintf("\n supported types are:\n ");
127 for (tt = typtab, count = 0; tt->name != NULL; tt++) {
128 if ((tt+1)->name != NULL) {
129 dbprintf("%s, ", tt->name);
130 if ((++count % 8) == 0)
131 dbprintf("\n ");
132 } else {
133 dbprintf("%s\n", tt->name);
134 }
135 }
136
dfc130f3 137
2bd0ea18
NS
138 } else {
139 tt = findtyp(argv[1]);
140 if (tt == NULL) {
141 dbprintf("no such type %s\n", argv[1]);
dfc130f3
RC
142 } else {
143 if (iocur_top->typ == NULL) {
144 dbprintf("no current object\n");
145 } else {
146 iocur_top->typ = cur_typ = tt;
147 }
148 }
2bd0ea18
NS
149 }
150 return 0;
151}
152
153void
154type_init(void)
155{
156 add_command(&type_cmd);
157}
158
159/* read/write selectors for each major data type */
160
161void
162handle_struct(
163 int action,
164 const field_t *fields,
165 int argc,
166 char **argv)
167{
168 if (action == DB_WRITE)
169 write_struct(fields, argc, argv);
170 else
171 print_struct(fields, argc, argv);
172}
173
174void
175handle_string(
176 int action,
177 const field_t *fields,
178 int argc,
179 char **argv)
180{
181 if (action == DB_WRITE)
182 write_string(fields, argc, argv);
183 else
184 print_string(fields, argc, argv);
185}
186
187void
188handle_block(
189 int action,
190 const field_t *fields,
191 int argc,
192 char **argv)
193{
194 if (action == DB_WRITE)
195 write_block(fields, argc, argv);
196 else
197 print_block(fields, argc, argv);
198}
c6b24b3b
NS
199
200void
201handle_text(
202 int action,
203 const field_t *fields,
204 int argc,
205 char **argv)
206{
207 if (action != DB_WRITE)
208 print_text(fields, argc, argv);
209}