]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/agf.c
Userspace support for lazy superblock counters
[thirdparty/xfsprogs-dev.git] / db / agf.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 "command.h"
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"
28 #include "init.h"
29 #include "agf.h"
30
31 static int agf_f(int argc, char **argv);
32 static void agf_help(void);
33
34 static const cmdinfo_t agf_cmd =
35 { "agf", NULL, agf_f, 0, 1, 1, "[agno]",
36 "set address to agf header", agf_help };
37
38 const 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)
45 const 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 },
58 { "levels", FLDT_UINT32D, OI(OFF(levels)), CI(XFS_BTNUM_AGF),
59 FLD_ARRAY|FLD_SKIPALL, TYP_NONE },
60 { "bnolevel", FLDT_UINT32D,
61 OI(OFF(levels) + XFS_BTNUM_BNO * SZ(levels[XFS_BTNUM_BNO])), C1, 0,
62 TYP_NONE },
63 { "cntlevel", FLDT_UINT32D,
64 OI(OFF(levels) + XFS_BTNUM_CNT * SZ(levels[XFS_BTNUM_CNT])), C1, 0,
65 TYP_NONE },
66 { "flfirst", FLDT_UINT32D, OI(OFF(flfirst)), C1, 0, TYP_NONE },
67 { "fllast", FLDT_UINT32D, OI(OFF(fllast)), C1, 0, TYP_NONE },
68 { "flcount", FLDT_UINT32D, OI(OFF(flcount)), C1, 0, TYP_NONE },
69 { "freeblks", FLDT_EXTLEN, OI(OFF(freeblks)), C1, 0, TYP_NONE },
70 { "longest", FLDT_EXTLEN, OI(OFF(longest)), C1, 0, TYP_NONE },
71 { "btreeblks", FLDT_UINT32D, OI(OFF(btreeblks)), C1, 0, TYP_NONE },
72 { NULL }
73 };
74
75 static void
76 agf_help(void)
77 {
78 dbprintf(
79 "\n"
80 " set allocation group free block list\n"
81 "\n"
82 " Example:\n"
83 "\n"
84 " agf 2 - move location to AGF in 2nd filesystem allocation group\n"
85 "\n"
86 " Located in the second sector of each allocation group, the AGF\n"
87 " contains the root of two different freespace btrees:\n"
88 " The 'cnt' btree keeps track freespace indexed on section size.\n"
89 " The 'bno' btree tracks sections of freespace indexed on block number.\n"
90 );
91 }
92
93 static int
94 agf_f(
95 int argc,
96 char **argv)
97 {
98 xfs_agnumber_t agno;
99 char *p;
100
101 if (argc > 1) {
102 agno = (xfs_agnumber_t)strtoul(argv[1], &p, 0);
103 if (*p != '\0' || agno >= mp->m_sb.sb_agcount) {
104 dbprintf("bad allocation group number %s\n", argv[1]);
105 return 0;
106 }
107 cur_agno = agno;
108 } else if (cur_agno == NULLAGNUMBER)
109 cur_agno = 0;
110 ASSERT(typtab[TYP_AGF].typnm == TYP_AGF);
111 set_cur(&typtab[TYP_AGF],
112 XFS_AG_DADDR(mp, cur_agno, XFS_AGF_DADDR(mp)),
113 XFS_FSS_TO_BB(mp, 1), DB_RING_ADD, NULL);
114 return 0;
115 }
116
117 void
118 agf_init(void)
119 {
120 add_command(&agf_cmd);
121 }
122
123 int
124 agf_size(
125 void *obj,
126 int startoff,
127 int idx)
128 {
129 return bitize(mp->m_sb.sb_sectsize);
130 }