]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/addr.c
Undoes mod: xfs-cmds:slinx:120772a
[thirdparty/xfsprogs-dev.git] / db / addr.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 "addr.h"
35#include "command.h"
36#include "type.h"
37#include "faddr.h"
38#include "fprint.h"
39#include "field.h"
40#include "io.h"
41#include "flist.h"
42#include "inode.h"
43#include "output.h"
44
45static int addr_f(int argc, char **argv);
46static void addr_help(void);
47
48static const cmdinfo_t addr_cmd =
49 { "addr", "a", addr_f, 0, 1, 1, "[field-expression]",
50 "set current address", addr_help };
51
52static void
53addr_help(void)
54{
55 dbprintf(
56"\n"
57" 'addr' uses the given field to set the filesystem address and type\n"
58"\n"
59" Examples:\n"
60"\n"
61" sb\n"
62" a rootino - set the type to inode and set position to the root inode\n"
63" a u.bmx[0].startblock (for inode with blockmap)\n"
64"\n"
65);
66
67}
68
69static int
70addr_f(
71 int argc,
72 char **argv)
73{
74 adfnc_t adf;
75 const ftattr_t *fa;
76 flist_t *fl;
77 const field_t *fld;
78 typnm_t next;
79 flist_t *tfl;
80
81 if (argc == 1) {
82 print_iocur("current", iocur_top);
83 return 0;
84 }
85 if (cur_typ == NULL) {
86 dbprintf("no current type\n");
87 return 0;
88 }
89 fld = cur_typ->fields;
90 if (fld != NULL && fld->name[0] == '\0') {
91 fa = &ftattrtab[fld->ftyp];
92 ASSERT(fa->ftyp == fld->ftyp);
93 fld = fa->subfld;
94 }
95 if (fld == NULL) {
96 dbprintf("no fields for type %s\n", cur_typ->name);
97 return 0;
98 }
99 fl = flist_scan(argv[1]);
100 if (fl == NULL)
101 return 0;
102 if (!flist_parse(fld, fl, iocur_top->data, 0)) {
103 flist_free(fl);
104 return 0;
105 }
106 flist_print(fl);
107 for (tfl = fl; tfl->child != NULL; tfl = tfl->child) {
108 if ((tfl->flags & FL_OKLOW) && tfl->low < tfl->high) {
109 dbprintf("array not allowed for addr command\n");
110 flist_free(fl);
111 return 0;
112 }
113 }
114 fld = tfl->fld;
115 next = fld->next;
116 if (next == TYP_INODATA)
117 next = inode_next_type();
118 if (next == TYP_NONE) {
119 dbprintf("no next type for field %s\n", fld->name);
120 return 0;
121 }
122 fa = &ftattrtab[fld->ftyp];
123 ASSERT(fa->ftyp == fld->ftyp);
124 adf = fa->adfunc;
125 if (adf == NULL) {
126 dbprintf("no addr function for field %s (type %s)\n",
127 fld->name, fa->name);
128 return 0;
129 }
130 (*adf)(iocur_top->data, tfl->offset, next);
131 flist_free(fl);
132 return 0;
133}
134
135void
136addr_init(void)
137{
138 add_command(&addr_cmd);
139}