]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/type.c
cmd/xfs/bmap/Makefile 1.8 Renamed to cmd/xfsprogs/bmap/Makefile
[thirdparty/xfsprogs-dev.git] / db / type.c
CommitLineData
2bd0ea18
NS
1/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
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"
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 },
94 { TYP_NONE, NULL }
95};
96
97static const typ_t *
98findtyp(
99 char *name)
100{
101 const typ_t *tt;
102
103 for (tt = typtab; tt->name != NULL; tt++) {
104 ASSERT(tt->typnm == (typnm_t)(tt - typtab));
105 if (strcmp(tt->name, name) == 0)
106 return tt;
107 }
108 return NULL;
109}
110
111static int
112type_f(
113 int argc,
114 char **argv)
115{
116 const typ_t *tt;
117 int count = 0;
118
119 if (argc == 1) {
120 if (cur_typ == NULL)
121 dbprintf("no current type\n");
122 else
123 dbprintf("current type is \"%s\"\n", cur_typ->name);
124
125 dbprintf("\n supported types are:\n ");
126 for (tt = typtab, count = 0; tt->name != NULL; tt++) {
127 if ((tt+1)->name != NULL) {
128 dbprintf("%s, ", tt->name);
129 if ((++count % 8) == 0)
130 dbprintf("\n ");
131 } else {
132 dbprintf("%s\n", tt->name);
133 }
134 }
135
136
137 } else {
138 tt = findtyp(argv[1]);
139 if (tt == NULL) {
140 dbprintf("no such type %s\n", argv[1]);
141 } else {
142 if (iocur_top->typ == NULL) {
143 dbprintf("no current object\n");
144 } else {
145 iocur_top->typ = cur_typ = tt;
146 }
147 }
148 }
149 return 0;
150}
151
152void
153type_init(void)
154{
155 add_command(&type_cmd);
156}
157
158/* read/write selectors for each major data type */
159
160void
161handle_struct(
162 int action,
163 const field_t *fields,
164 int argc,
165 char **argv)
166{
167 if (action == DB_WRITE)
168 write_struct(fields, argc, argv);
169 else
170 print_struct(fields, argc, argv);
171}
172
173void
174handle_string(
175 int action,
176 const field_t *fields,
177 int argc,
178 char **argv)
179{
180 if (action == DB_WRITE)
181 write_string(fields, argc, argv);
182 else
183 print_string(fields, argc, argv);
184}
185
186void
187handle_block(
188 int action,
189 const field_t *fields,
190 int argc,
191 char **argv)
192{
193 if (action == DB_WRITE)
194 write_block(fields, argc, argv);
195 else
196 print_block(fields, argc, argv);
197}