]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/agf.c
libxfs: sanitize agcount on load
[thirdparty/xfsprogs-dev.git] / db / agf.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 "agf.h"
2bd0ea18
NS
30
31static int agf_f(int argc, char **argv);
32static void agf_help(void);
33
34static const cmdinfo_t agf_cmd =
9ee7055c
AM
35 { "agf", NULL, agf_f, 0, 1, 1, N_("[agno]"),
36 N_("set address to agf header"), agf_help };
2bd0ea18
NS
37
38const field_t agf_hfld[] = {
39 { "", FLDT_AGF, OI(0), C1, 0, TYP_NONE },
40 { NULL }
41};
42
43#define OFF(f) bitize(offsetof(xfs_agf_t, agf_ ## f))
44#define SZ(f) bitszof(xfs_agf_t, agf_ ## f)
45const field_t agf_flds[] = {
46 { "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE },
47 { "versionnum", FLDT_UINT32D, OI(OFF(versionnum)), C1, 0, TYP_NONE },
48 { "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE },
49 { "length", FLDT_AGBLOCK, OI(OFF(length)), C1, 0, TYP_NONE },
50 { "roots", FLDT_AGBLOCK, OI(OFF(roots)), CI(XFS_BTNUM_AGF),
51 FLD_ARRAY|FLD_SKIPALL, TYP_NONE },
52 { "bnoroot", FLDT_AGBLOCK,
53 OI(OFF(roots) + XFS_BTNUM_BNO * SZ(roots[XFS_BTNUM_BNO])), C1, 0,
54 TYP_BNOBT },
55 { "cntroot", FLDT_AGBLOCK,
56 OI(OFF(roots) + XFS_BTNUM_CNT * SZ(roots[XFS_BTNUM_CNT])), C1, 0,
57 TYP_CNTBT },
a9d7b986
DW
58 { "rmaproot", FLDT_AGBLOCKNZ,
59 OI(OFF(roots) + XFS_BTNUM_RMAP * SZ(roots[XFS_BTNUM_RMAP])), C1, 0,
60 TYP_RMAPBT },
9fb2cb27
DW
61 { "refcntroot", FLDT_AGBLOCKNZ,
62 OI(OFF(refcount_root)), C1, 0,
63 TYP_REFCBT },
2bd0ea18
NS
64 { "levels", FLDT_UINT32D, OI(OFF(levels)), CI(XFS_BTNUM_AGF),
65 FLD_ARRAY|FLD_SKIPALL, TYP_NONE },
66 { "bnolevel", FLDT_UINT32D,
67 OI(OFF(levels) + XFS_BTNUM_BNO * SZ(levels[XFS_BTNUM_BNO])), C1, 0,
68 TYP_NONE },
69 { "cntlevel", FLDT_UINT32D,
70 OI(OFF(levels) + XFS_BTNUM_CNT * SZ(levels[XFS_BTNUM_CNT])), C1, 0,
71 TYP_NONE },
a9d7b986
DW
72 { "rmaplevel", FLDT_UINT32D,
73 OI(OFF(levels) + XFS_BTNUM_RMAP * SZ(levels[XFS_BTNUM_RMAP])), C1, 0,
74 TYP_NONE },
9fb2cb27
DW
75 { "refcntlevel", FLDT_UINT32D,
76 OI(OFF(refcount_level)), C1, 0,
77 TYP_NONE },
a9d7b986
DW
78 { "rmapblocks", FLDT_UINT32D,
79 OI(OFF(rmap_blocks)), C1, 0,
80 TYP_NONE },
9fb2cb27
DW
81 { "refcntblocks", FLDT_UINT32D,
82 OI(OFF(refcount_blocks)), C1, 0,
83 TYP_NONE },
2bd0ea18
NS
84 { "flfirst", FLDT_UINT32D, OI(OFF(flfirst)), C1, 0, TYP_NONE },
85 { "fllast", FLDT_UINT32D, OI(OFF(fllast)), C1, 0, TYP_NONE },
86 { "flcount", FLDT_UINT32D, OI(OFF(flcount)), C1, 0, TYP_NONE },
87 { "freeblks", FLDT_EXTLEN, OI(OFF(freeblks)), C1, 0, TYP_NONE },
88 { "longest", FLDT_EXTLEN, OI(OFF(longest)), C1, 0, TYP_NONE },
cdded3d8 89 { "btreeblks", FLDT_UINT32D, OI(OFF(btreeblks)), C1, 0, TYP_NONE },
c2907bd7
DC
90 { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
91 { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
0522f1cc 92 { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
2bd0ea18
NS
93 { NULL }
94};
95
96static void
97agf_help(void)
98{
9ee7055c 99 dbprintf(_(
2bd0ea18
NS
100"\n"
101" set allocation group free block list\n"
102"\n"
103" Example:\n"
104"\n"
105" agf 2 - move location to AGF in 2nd filesystem allocation group\n"
106"\n"
9440d84d
NS
107" Located in the second sector of each allocation group, the AGF\n"
108" contains the root of two different freespace btrees:\n"
2bd0ea18
NS
109" The 'cnt' btree keeps track freespace indexed on section size.\n"
110" The 'bno' btree tracks sections of freespace indexed on block number.\n"
9ee7055c 111));
2bd0ea18
NS
112}
113
114static int
115agf_f(
116 int argc,
117 char **argv)
118{
119 xfs_agnumber_t agno;
120 char *p;
121
122 if (argc > 1) {
123 agno = (xfs_agnumber_t)strtoul(argv[1], &p, 0);
124 if (*p != '\0' || agno >= mp->m_sb.sb_agcount) {
9ee7055c 125 dbprintf(_("bad allocation group number %s\n"), argv[1]);
2bd0ea18
NS
126 return 0;
127 }
128 cur_agno = agno;
129 } else if (cur_agno == NULLAGNUMBER)
130 cur_agno = 0;
131 ASSERT(typtab[TYP_AGF].typnm == TYP_AGF);
9440d84d
NS
132 set_cur(&typtab[TYP_AGF],
133 XFS_AG_DADDR(mp, cur_agno, XFS_AGF_DADDR(mp)),
134 XFS_FSS_TO_BB(mp, 1), DB_RING_ADD, NULL);
2bd0ea18
NS
135 return 0;
136}
137
138void
139agf_init(void)
140{
141 add_command(&agf_cmd);
142}
143
144int
145agf_size(
146 void *obj,
147 int startoff,
148 int idx)
149{
150 return bitize(mp->m_sb.sb_sectsize);
151}