]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/agi.c
xfs_db: btdump should avoid eval for push and pop of cursor
[thirdparty/xfsprogs-dev.git] / db / agi.c
CommitLineData
2bd0ea18 1/*
da23017d
NS
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
dfc130f3 4 *
da23017d
NS
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
2bd0ea18 7 * published by the Free Software Foundation.
dfc130f3 8 *
da23017d
NS
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.
dfc130f3 13 *
da23017d
NS
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
2bd0ea18
NS
17 */
18
6b803e5a 19#include "libxfs.h"
2bd0ea18 20#include "command.h"
2bd0ea18
NS
21#include "type.h"
22#include "faddr.h"
23#include "fprint.h"
24#include "field.h"
25#include "io.h"
26#include "bit.h"
27#include "output.h"
4ca431fc 28#include "init.h"
28d8e155 29#include "agi.h"
2bd0ea18
NS
30
31static int agi_f(int argc, char **argv);
32static void agi_help(void);
33
34static const cmdinfo_t agi_cmd =
9ee7055c
AM
35 { "agi", NULL, agi_f, 0, 1, 1, N_("[agno]"),
36 N_("set address to agi header"), agi_help };
2bd0ea18
NS
37
38const field_t agi_hfld[] = {
39 { "", FLDT_AGI, OI(0), C1, 0, TYP_NONE },
40 { NULL }
41};
42
43#define OFF(f) bitize(offsetof(xfs_agi_t, agi_ ## f))
44const field_t agi_flds[] = {
45 { "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE },
46 { "versionnum", FLDT_UINT32D, OI(OFF(versionnum)), C1, 0, TYP_NONE },
47 { "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE },
48 { "length", FLDT_AGBLOCK, OI(OFF(length)), C1, 0, TYP_NONE },
49 { "count", FLDT_AGINO, OI(OFF(count)), C1, 0, TYP_NONE },
50 { "root", FLDT_AGBLOCK, OI(OFF(root)), C1, 0, TYP_INOBT },
51 { "level", FLDT_UINT32D, OI(OFF(level)), C1, 0, TYP_NONE },
52 { "freecount", FLDT_AGINO, OI(OFF(freecount)), C1, 0, TYP_NONE },
53 { "newino", FLDT_AGINO, OI(OFF(newino)), C1, 0, TYP_INODE },
54 { "dirino", FLDT_AGINO, OI(OFF(dirino)), C1, 0, TYP_INODE },
55 { "unlinked", FLDT_AGINONN, OI(OFF(unlinked)),
56 CI(XFS_AGI_UNLINKED_BUCKETS), FLD_ARRAY, TYP_NONE },
c2907bd7
DC
57 { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
58 { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
0522f1cc 59 { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
61a15567 60 { "free_root", FLDT_AGBLOCK, OI(OFF(free_root)), C1, 0, TYP_FINOBT },
2a0cd7ad 61 { "free_level", FLDT_UINT32D, OI(OFF(free_level)), C1, 0, TYP_NONE },
2bd0ea18
NS
62 { NULL }
63};
64
65static void
66agi_help(void)
67{
9ee7055c 68 dbprintf(_(
2bd0ea18
NS
69"\n"
70" set allocation group inode btree\n"
71"\n"
72" Example:\n"
73"\n"
74" agi 3 (set location to 3rd allocation group inode btree and type to 'agi')\n"
75"\n"
76" Located in the 3rd 512 byte block of each allocation group,\n"
77" the agi inode btree tracks all used/free inodes in the allocation group.\n"
78" Inodes are allocated in 16k 'chunks', each btree entry tracks a 'chunk'.\n"
79"\n"
9ee7055c 80));
2bd0ea18
NS
81}
82
83static int
84agi_f(
85 int argc,
86 char **argv)
87{
88 xfs_agnumber_t agno;
89 char *p;
90
91 if (argc > 1) {
92 agno = (xfs_agnumber_t)strtoul(argv[1], &p, 0);
93 if (*p != '\0' || agno >= mp->m_sb.sb_agcount) {
9ee7055c 94 dbprintf(_("bad allocation group number %s\n"), argv[1]);
2bd0ea18
NS
95 return 0;
96 }
97 cur_agno = agno;
98 } else if (cur_agno == NULLAGNUMBER)
99 cur_agno = 0;
100 ASSERT(typtab[TYP_AGI].typnm == TYP_AGI);
9440d84d
NS
101 set_cur(&typtab[TYP_AGI],
102 XFS_AG_DADDR(mp, cur_agno, XFS_AGI_DADDR(mp)),
103 XFS_FSS_TO_BB(mp, 1), DB_RING_ADD, NULL);
2bd0ea18
NS
104 return 0;
105}
106
107void
108agi_init(void)
109{
110 add_command(&agi_cmd);
111}
112
113/*ARGSUSED*/
114int
115agi_size(
116 void *obj,
117 int startoff,
118 int idx)
119{
120 return bitize(mp->m_sb.sb_sectsize);
121}