]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/agfl.c
xfs_db: add support for checking the refcount btree
[thirdparty/xfsprogs-dev.git] / db / agfl.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 "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 "agfl.h"
30
31 static int agfl_bno_size(void *obj, int startoff);
32 static int agfl_f(int argc, char **argv);
33 static void agfl_help(void);
34
35 static const cmdinfo_t agfl_cmd =
36 { "agfl", NULL, agfl_f, 0, 1, 1, N_("[agno]"),
37 N_("set address to agfl block"), agfl_help };
38
39 const field_t agfl_hfld[] = { {
40 "", FLDT_AGFL, OI(0), C1, 0, TYP_NONE, },
41 { NULL }
42 };
43
44 const field_t agfl_crc_hfld[] = { {
45 "", FLDT_AGFL_CRC, OI(0), C1, 0, TYP_NONE, },
46 { NULL }
47 };
48
49 #define OFF(f) bitize(offsetof(xfs_agfl_t, agfl_ ## f))
50 const field_t agfl_flds[] = {
51 { "bno", FLDT_AGBLOCKNZ, OI(OFF(magicnum)), agfl_bno_size,
52 FLD_ARRAY|FLD_COUNT, TYP_DATA },
53 { NULL }
54 };
55
56 const field_t agfl_crc_flds[] = {
57 { "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE },
58 { "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE },
59 { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
60 { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
61 { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
62 { "bno", FLDT_AGBLOCKNZ, OI(OFF(bno)), agfl_bno_size,
63 FLD_ARRAY|FLD_COUNT, TYP_DATA },
64 { NULL }
65 };
66
67 static int
68 agfl_bno_size(
69 void *obj,
70 int startoff)
71 {
72 return XFS_AGFL_SIZE(mp);
73 }
74
75 static void
76 agfl_help(void)
77 {
78 dbprintf(_(
79 "\n"
80 " set allocation group freelist\n"
81 "\n"
82 " Example:\n"
83 "\n"
84 " agfl 5"
85 "\n"
86 " Located in the fourth sector of each allocation group,\n"
87 " the agfl freelist for internal btree space allocation is maintained\n"
88 " for each allocation group. This acts as a reserved pool of space\n"
89 " separate from the general filesystem freespace (not used for user data).\n"
90 "\n"
91 ));
92
93 }
94
95 static int
96 agfl_f(
97 int argc,
98 char **argv)
99 {
100 xfs_agnumber_t agno;
101 char *p;
102
103 if (argc > 1) {
104 agno = (xfs_agnumber_t)strtoul(argv[1], &p, 0);
105 if (*p != '\0' || agno >= mp->m_sb.sb_agcount) {
106 dbprintf(_("bad allocation group number %s\n"), argv[1]);
107 return 0;
108 }
109 cur_agno = agno;
110 } else if (cur_agno == NULLAGNUMBER)
111 cur_agno = 0;
112 ASSERT(typtab[TYP_AGFL].typnm == TYP_AGFL);
113 set_cur(&typtab[TYP_AGFL],
114 XFS_AG_DADDR(mp, cur_agno, XFS_AGFL_DADDR(mp)),
115 XFS_FSS_TO_BB(mp, 1), DB_RING_ADD, NULL);
116 return 0;
117 }
118
119 void
120 agfl_init(void)
121 {
122 add_command(&agfl_cmd);
123 }
124
125 /*ARGSUSED*/
126 int
127 agfl_size(
128 void *obj,
129 int startoff,
130 int idx)
131 {
132 return bitize(mp->m_sb.sb_sectsize);
133 }