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