]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
cc08d43e | 2 | * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved. |
2bd0ea18 NS |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of version 2 of the GNU General Public License as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it would be useful, but | |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 | * | |
12 | * Further, this software is distributed without any warranty that it is | |
13 | * free of the rightful claim of any third person regarding infringement | |
14 | * or the like. Any license provided herein, whether implied or | |
15 | * otherwise, applies only to this software file. Patent licenses, if | |
16 | * any, provided herein do not apply to combinations of this program with | |
17 | * other software, or any other product whatsoever. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write the Free Software Foundation, Inc., 59 | |
21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
22 | * | |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, | |
24 | * Mountain View, CA 94043, or: | |
25 | * | |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ | |
31 | */ | |
32 | ||
33 | #include <libxfs.h> | |
34 | #include "agf.h" | |
35 | #include "command.h" | |
36 | #include "data.h" | |
37 | #include "type.h" | |
38 | #include "faddr.h" | |
39 | #include "fprint.h" | |
40 | #include "field.h" | |
41 | #include "io.h" | |
42 | #include "bit.h" | |
43 | #include "output.h" | |
44 | #include "mount.h" | |
45 | ||
46 | static int agf_f(int argc, char **argv); | |
47 | static void agf_help(void); | |
48 | ||
49 | static const cmdinfo_t agf_cmd = | |
50 | { "agf", NULL, agf_f, 0, 1, 1, "[agno]", | |
51 | "set address to agf header", agf_help }; | |
52 | ||
53 | const field_t agf_hfld[] = { | |
54 | { "", FLDT_AGF, OI(0), C1, 0, TYP_NONE }, | |
55 | { NULL } | |
56 | }; | |
57 | ||
58 | #define OFF(f) bitize(offsetof(xfs_agf_t, agf_ ## f)) | |
59 | #define SZ(f) bitszof(xfs_agf_t, agf_ ## f) | |
60 | const field_t agf_flds[] = { | |
61 | { "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE }, | |
62 | { "versionnum", FLDT_UINT32D, OI(OFF(versionnum)), C1, 0, TYP_NONE }, | |
63 | { "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE }, | |
64 | { "length", FLDT_AGBLOCK, OI(OFF(length)), C1, 0, TYP_NONE }, | |
65 | { "roots", FLDT_AGBLOCK, OI(OFF(roots)), CI(XFS_BTNUM_AGF), | |
66 | FLD_ARRAY|FLD_SKIPALL, TYP_NONE }, | |
67 | { "bnoroot", FLDT_AGBLOCK, | |
68 | OI(OFF(roots) + XFS_BTNUM_BNO * SZ(roots[XFS_BTNUM_BNO])), C1, 0, | |
69 | TYP_BNOBT }, | |
70 | { "cntroot", FLDT_AGBLOCK, | |
71 | OI(OFF(roots) + XFS_BTNUM_CNT * SZ(roots[XFS_BTNUM_CNT])), C1, 0, | |
72 | TYP_CNTBT }, | |
73 | { "levels", FLDT_UINT32D, OI(OFF(levels)), CI(XFS_BTNUM_AGF), | |
74 | FLD_ARRAY|FLD_SKIPALL, TYP_NONE }, | |
75 | { "bnolevel", FLDT_UINT32D, | |
76 | OI(OFF(levels) + XFS_BTNUM_BNO * SZ(levels[XFS_BTNUM_BNO])), C1, 0, | |
77 | TYP_NONE }, | |
78 | { "cntlevel", FLDT_UINT32D, | |
79 | OI(OFF(levels) + XFS_BTNUM_CNT * SZ(levels[XFS_BTNUM_CNT])), C1, 0, | |
80 | TYP_NONE }, | |
81 | { "flfirst", FLDT_UINT32D, OI(OFF(flfirst)), C1, 0, TYP_NONE }, | |
82 | { "fllast", FLDT_UINT32D, OI(OFF(fllast)), C1, 0, TYP_NONE }, | |
83 | { "flcount", FLDT_UINT32D, OI(OFF(flcount)), C1, 0, TYP_NONE }, | |
84 | { "freeblks", FLDT_EXTLEN, OI(OFF(freeblks)), C1, 0, TYP_NONE }, | |
85 | { "longest", FLDT_EXTLEN, OI(OFF(longest)), C1, 0, TYP_NONE }, | |
86 | { NULL } | |
87 | }; | |
88 | ||
89 | static void | |
90 | agf_help(void) | |
91 | { | |
92 | dbprintf( | |
93 | "\n" | |
94 | " set allocation group free block list\n" | |
95 | "\n" | |
96 | " Example:\n" | |
97 | "\n" | |
98 | " agf 2 - move location to AGF in 2nd filesystem allocation group\n" | |
99 | "\n" | |
100 | " Located in the 2nd 512 byte block of each allocation group,\n" | |
101 | " the AGF contains the root of two different freespace btrees:\n" | |
102 | " The 'cnt' btree keeps track freespace indexed on section size.\n" | |
103 | " The 'bno' btree tracks sections of freespace indexed on block number.\n" | |
104 | ); | |
105 | } | |
106 | ||
107 | static int | |
108 | agf_f( | |
109 | int argc, | |
110 | char **argv) | |
111 | { | |
112 | xfs_agnumber_t agno; | |
113 | char *p; | |
114 | ||
115 | if (argc > 1) { | |
116 | agno = (xfs_agnumber_t)strtoul(argv[1], &p, 0); | |
117 | if (*p != '\0' || agno >= mp->m_sb.sb_agcount) { | |
118 | dbprintf("bad allocation group number %s\n", argv[1]); | |
119 | return 0; | |
120 | } | |
121 | cur_agno = agno; | |
122 | } else if (cur_agno == NULLAGNUMBER) | |
123 | cur_agno = 0; | |
124 | ASSERT(typtab[TYP_AGF].typnm == TYP_AGF); | |
125 | set_cur(&typtab[TYP_AGF], XFS_AG_DADDR(mp, cur_agno, XFS_AGF_DADDR), 1, | |
126 | DB_RING_ADD, NULL); | |
127 | return 0; | |
128 | } | |
129 | ||
130 | void | |
131 | agf_init(void) | |
132 | { | |
133 | add_command(&agf_cmd); | |
134 | } | |
135 | ||
136 | int | |
137 | agf_size( | |
138 | void *obj, | |
139 | int startoff, | |
140 | int idx) | |
141 | { | |
142 | return bitize(mp->m_sb.sb_sectsize); | |
143 | } |