]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/type.c
Undoes mod: xfs-cmds:slinx:120772a
[thirdparty/xfsprogs-dev.git] / db / type.c
CommitLineData
2bd0ea18 1/*
9911e5dc 2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
2bd0ea18
NS
3 *
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.
7 *
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.
11 *
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.
18 *
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.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
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"
39#include "data.h"
40#include "type.h"
41#include "faddr.h"
42#include "fprint.h"
43#include "field.h"
44#include "print.h"
45#include "sb.h"
46#include "inode.h"
47#include "bnobt.h"
48#include "cntbt.h"
49#include "inobt.h"
50#include "bmapbt.h"
51#include "bmroot.h"
52#include "agf.h"
53#include "agfl.h"
54#include "agi.h"
55#include "dir.h"
56#include "dirshort.h"
57#include "io.h"
58#include "output.h"
59#include "write.h"
60#include "attr.h"
61#include "dquot.h"
62#include "dir2.h"
c6b24b3b 63#include "text.h"
2bd0ea18
NS
64
65static const typ_t *findtyp(char *name);
66static int type_f(int argc, char **argv);
67
68const typ_t *cur_typ;
69
70static const cmdinfo_t type_cmd =
71 { "type", NULL, type_f, 0, 1, 1, "[newtype]",
72 "set/show current data type", NULL };
73
74const typ_t typtab[] = {
75 { TYP_AGF, "agf", handle_struct, agf_hfld },
76 { TYP_AGFL, "agfl", handle_struct, agfl_hfld },
77 { TYP_AGI, "agi", handle_struct, agi_hfld },
78 { TYP_ATTR, "attr", handle_struct, attr_hfld },
79 { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_hfld },
80 { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_hfld },
81 { TYP_BNOBT, "bnobt", handle_struct, bnobt_hfld },
82 { TYP_CNTBT, "cntbt", handle_struct, cntbt_hfld },
83 { TYP_DATA, "data", handle_block, NULL },
84 { TYP_DIR, "dir", handle_struct, dir_hfld },
85 { TYP_DIR2, "dir2", handle_struct, dir2_hfld },
86 { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld },
87 { TYP_INOBT, "inobt", handle_struct, inobt_hfld },
88 { TYP_INODATA, "inodata", NULL, NULL },
89 { TYP_INODE, "inode", handle_struct, inode_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 },
c6b24b3b 95 { TYP_TEXT, "text", handle_text, NULL },
2bd0ea18
NS
96 { TYP_NONE, NULL }
97};
98
99static const typ_t *
100findtyp(
101 char *name)
102{
103 const typ_t *tt;
104
105 for (tt = typtab; tt->name != NULL; tt++) {
106 ASSERT(tt->typnm == (typnm_t)(tt - typtab));
107 if (strcmp(tt->name, name) == 0)
108 return tt;
109 }
110 return NULL;
111}
112
113static int
114type_f(
115 int argc,
116 char **argv)
117{
118 const typ_t *tt;
119 int count = 0;
120
121 if (argc == 1) {
122 if (cur_typ == NULL)
123 dbprintf("no current type\n");
124 else
125 dbprintf("current type is \"%s\"\n", cur_typ->name);
126
127 dbprintf("\n supported types are:\n ");
128 for (tt = typtab, count = 0; tt->name != NULL; tt++) {
129 if ((tt+1)->name != NULL) {
130 dbprintf("%s, ", tt->name);
131 if ((++count % 8) == 0)
132 dbprintf("\n ");
133 } else {
134 dbprintf("%s\n", tt->name);
135 }
136 }
137
138
139 } else {
140 tt = findtyp(argv[1]);
141 if (tt == NULL) {
142 dbprintf("no such type %s\n", argv[1]);
143 } else {
144 if (iocur_top->typ == NULL) {
145 dbprintf("no current object\n");
146 } else {
147 iocur_top->typ = cur_typ = tt;
148 }
149 }
150 }
151 return 0;
152}
153
154void
155type_init(void)
156{
157 add_command(&type_cmd);
158}
159
160/* read/write selectors for each major data type */
161
162void
163handle_struct(
164 int action,
165 const field_t *fields,
166 int argc,
167 char **argv)
168{
169 if (action == DB_WRITE)
170 write_struct(fields, argc, argv);
171 else
172 print_struct(fields, argc, argv);
173}
174
175void
176handle_string(
177 int action,
178 const field_t *fields,
179 int argc,
180 char **argv)
181{
182 if (action == DB_WRITE)
183 write_string(fields, argc, argv);
184 else
185 print_string(fields, argc, argv);
186}
187
188void
189handle_block(
190 int action,
191 const field_t *fields,
192 int argc,
193 char **argv)
194{
195 if (action == DB_WRITE)
196 write_block(fields, argc, argv);
197 else
198 print_block(fields, argc, argv);
199}
c6b24b3b
NS
200
201void
202handle_text(
203 int action,
204 const field_t *fields,
205 int argc,
206 char **argv)
207{
208 if (action != DB_WRITE)
209 print_text(fields, argc, argv);
210}
211