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