]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/addr.c
xfs: cache last bitmap block in realtime allocator
[thirdparty/xfsprogs-dev.git] / db / addr.c
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
2bd0ea18 2/*
da23017d
NS
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
2bd0ea18
NS
5 */
6
6b803e5a 7#include "libxfs.h"
2bd0ea18
NS
8#include "addr.h"
9#include "command.h"
10#include "type.h"
11#include "faddr.h"
12#include "fprint.h"
13#include "field.h"
14#include "io.h"
15#include "flist.h"
16#include "inode.h"
17#include "output.h"
18
19static int addr_f(int argc, char **argv);
20static void addr_help(void);
21
22static const cmdinfo_t addr_cmd =
9ee7055c
AM
23 { "addr", "a", addr_f, 0, 1, 1, N_("[field-expression]"),
24 N_("set current address"), addr_help };
2bd0ea18
NS
25
26static void
27addr_help(void)
28{
9ee7055c 29 dbprintf(_(
2bd0ea18
NS
30"\n"
31" 'addr' uses the given field to set the filesystem address and type\n"
32"\n"
33" Examples:\n"
34"\n"
35" sb\n"
36" a rootino - set the type to inode and set position to the root inode\n"
37" a u.bmx[0].startblock (for inode with blockmap)\n"
38"\n"
9ee7055c 39));
2bd0ea18
NS
40
41}
42
43static int
44addr_f(
45 int argc,
46 char **argv)
47{
48 adfnc_t adf;
49 const ftattr_t *fa;
50 flist_t *fl;
51 const field_t *fld;
52 typnm_t next;
53 flist_t *tfl;
54
55 if (argc == 1) {
56 print_iocur("current", iocur_top);
57 return 0;
58 }
59 if (cur_typ == NULL) {
9ee7055c 60 dbprintf(_("no current type\n"));
2bd0ea18
NS
61 return 0;
62 }
63 fld = cur_typ->fields;
64 if (fld != NULL && fld->name[0] == '\0') {
65 fa = &ftattrtab[fld->ftyp];
66 ASSERT(fa->ftyp == fld->ftyp);
67 fld = fa->subfld;
68 }
69 if (fld == NULL) {
9ee7055c 70 dbprintf(_("no fields for type %s\n"), cur_typ->name);
2bd0ea18
NS
71 return 0;
72 }
73 fl = flist_scan(argv[1]);
74 if (fl == NULL)
75 return 0;
355ac015
ES
76 if (!flist_parse(fld, fl, iocur_top->data, 0))
77 goto out;
78
2bd0ea18
NS
79 flist_print(fl);
80 for (tfl = fl; tfl->child != NULL; tfl = tfl->child) {
81 if ((tfl->flags & FL_OKLOW) && tfl->low < tfl->high) {
9ee7055c 82 dbprintf(_("array not allowed for addr command\n"));
355ac015 83 goto out;
2bd0ea18
NS
84 }
85 }
86 fld = tfl->fld;
87 next = fld->next;
88 if (next == TYP_INODATA)
89 next = inode_next_type();
90 if (next == TYP_NONE) {
9ee7055c 91 dbprintf(_("no next type for field %s\n"), fld->name);
355ac015 92 goto out;
2bd0ea18
NS
93 }
94 fa = &ftattrtab[fld->ftyp];
95 ASSERT(fa->ftyp == fld->ftyp);
96 adf = fa->adfunc;
97 if (adf == NULL) {
9ee7055c 98 dbprintf(_("no addr function for field %s (type %s)\n"),
2bd0ea18 99 fld->name, fa->name);
355ac015 100 goto out;
2bd0ea18
NS
101 }
102 (*adf)(iocur_top->data, tfl->offset, next);
355ac015 103out:
2bd0ea18
NS
104 flist_free(fl);
105 return 0;
106}
107
108void
109addr_init(void)
110{
111 add_command(&addr_cmd);
112}