]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/agfl.c
xfsprogs: Release v6.8.0
[thirdparty/xfsprogs-dev.git] / db / agfl.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include "libxfs.h"
8 #include "command.h"
9 #include "type.h"
10 #include "faddr.h"
11 #include "fprint.h"
12 #include "field.h"
13 #include "io.h"
14 #include "bit.h"
15 #include "output.h"
16 #include "init.h"
17 #include "agfl.h"
18
19 static int agfl_bno_size(void *obj, int startoff);
20 static int agfl_f(int argc, char **argv);
21 static void agfl_help(void);
22
23 static const cmdinfo_t agfl_cmd =
24 { "agfl", NULL, agfl_f, 0, 1, 1, N_("[agno]"),
25 N_("set address to agfl block"), agfl_help };
26
27 const field_t agfl_hfld[] = { {
28 "", FLDT_AGFL, OI(0), C1, 0, TYP_NONE, },
29 { NULL }
30 };
31
32 const field_t agfl_crc_hfld[] = { {
33 "", FLDT_AGFL_CRC, OI(0), C1, 0, TYP_NONE, },
34 { NULL }
35 };
36
37 #define OFF(f) bitize(offsetof(struct xfs_agfl, agfl_ ## f))
38 const field_t agfl_flds[] = {
39 { "bno", FLDT_AGBLOCKNZ, OI(OFF(magicnum)), agfl_bno_size,
40 FLD_ARRAY|FLD_COUNT, TYP_DATA },
41 { NULL }
42 };
43
44 const field_t agfl_crc_flds[] = {
45 { "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE },
46 { "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE },
47 { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
48 { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
49 { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
50 /* the bno array is after the actual structure */
51 { "bno", FLDT_AGBLOCKNZ, OI(bitize(sizeof(struct xfs_agfl))),
52 agfl_bno_size, FLD_ARRAY|FLD_COUNT, TYP_DATA },
53 { NULL }
54 };
55
56 static int
57 agfl_bno_size(
58 void *obj,
59 int startoff)
60 {
61 return libxfs_agfl_size(mp);
62 }
63
64 static void
65 agfl_help(void)
66 {
67 dbprintf(_(
68 "\n"
69 " set allocation group freelist\n"
70 "\n"
71 " Example:\n"
72 "\n"
73 " agfl 5"
74 "\n"
75 " Located in the fourth sector of each allocation group,\n"
76 " the agfl freelist for internal btree space allocation is maintained\n"
77 " for each allocation group. This acts as a reserved pool of space\n"
78 " separate from the general filesystem freespace (not used for user data).\n"
79 "\n"
80 ));
81
82 }
83
84 static int
85 agfl_f(
86 int argc,
87 char **argv)
88 {
89 xfs_agnumber_t agno;
90 char *p;
91
92 if (argc > 1) {
93 agno = (xfs_agnumber_t)strtoul(argv[1], &p, 0);
94 if (*p != '\0' || agno >= mp->m_sb.sb_agcount) {
95 dbprintf(_("bad allocation group number %s\n"), argv[1]);
96 return 0;
97 }
98 cur_agno = agno;
99 } else if (cur_agno == NULLAGNUMBER)
100 cur_agno = 0;
101 ASSERT(typtab[TYP_AGFL].typnm == TYP_AGFL);
102 set_cur(&typtab[TYP_AGFL],
103 XFS_AG_DADDR(mp, cur_agno, XFS_AGFL_DADDR(mp)),
104 XFS_FSS_TO_BB(mp, 1), DB_RING_ADD, NULL);
105 return 0;
106 }
107
108 void
109 agfl_init(void)
110 {
111 add_command(&agfl_cmd);
112 }
113
114 /*ARGSUSED*/
115 int
116 agfl_size(
117 void *obj,
118 int startoff,
119 int idx)
120 {
121 return bitize(mp->m_sb.sb_sectsize);
122 }