]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/agi.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / db / agi.c
1 /*
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
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 "agi.h"
35 #include "command.h"
36 #include "type.h"
37 #include "faddr.h"
38 #include "fprint.h"
39 #include "field.h"
40 #include "io.h"
41 #include "bit.h"
42 #include "output.h"
43 #include "init.h"
44
45 static int agi_f(int argc, char **argv);
46 static void agi_help(void);
47
48 static const cmdinfo_t agi_cmd =
49 { "agi", NULL, agi_f, 0, 1, 1, "[agno]",
50 "set address to agi header", agi_help };
51
52 const field_t agi_hfld[] = {
53 { "", FLDT_AGI, OI(0), C1, 0, TYP_NONE },
54 { NULL }
55 };
56
57 #define OFF(f) bitize(offsetof(xfs_agi_t, agi_ ## f))
58 const field_t agi_flds[] = {
59 { "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE },
60 { "versionnum", FLDT_UINT32D, OI(OFF(versionnum)), C1, 0, TYP_NONE },
61 { "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE },
62 { "length", FLDT_AGBLOCK, OI(OFF(length)), C1, 0, TYP_NONE },
63 { "count", FLDT_AGINO, OI(OFF(count)), C1, 0, TYP_NONE },
64 { "root", FLDT_AGBLOCK, OI(OFF(root)), C1, 0, TYP_INOBT },
65 { "level", FLDT_UINT32D, OI(OFF(level)), C1, 0, TYP_NONE },
66 { "freecount", FLDT_AGINO, OI(OFF(freecount)), C1, 0, TYP_NONE },
67 { "newino", FLDT_AGINO, OI(OFF(newino)), C1, 0, TYP_INODE },
68 { "dirino", FLDT_AGINO, OI(OFF(dirino)), C1, 0, TYP_INODE },
69 { "unlinked", FLDT_AGINONN, OI(OFF(unlinked)),
70 CI(XFS_AGI_UNLINKED_BUCKETS), FLD_ARRAY, TYP_NONE },
71 { NULL }
72 };
73
74 static void
75 agi_help(void)
76 {
77 dbprintf(
78 "\n"
79 " set allocation group inode btree\n"
80 "\n"
81 " Example:\n"
82 "\n"
83 " agi 3 (set location to 3rd allocation group inode btree and type to 'agi')\n"
84 "\n"
85 " Located in the 3rd 512 byte block of each allocation group,\n"
86 " the agi inode btree tracks all used/free inodes in the allocation group.\n"
87 " Inodes are allocated in 16k 'chunks', each btree entry tracks a 'chunk'.\n"
88 "\n"
89 );
90 }
91
92 static int
93 agi_f(
94 int argc,
95 char **argv)
96 {
97 xfs_agnumber_t agno;
98 char *p;
99
100 if (argc > 1) {
101 agno = (xfs_agnumber_t)strtoul(argv[1], &p, 0);
102 if (*p != '\0' || agno >= mp->m_sb.sb_agcount) {
103 dbprintf("bad allocation group number %s\n", argv[1]);
104 return 0;
105 }
106 cur_agno = agno;
107 } else if (cur_agno == NULLAGNUMBER)
108 cur_agno = 0;
109 ASSERT(typtab[TYP_AGI].typnm == TYP_AGI);
110 set_cur(&typtab[TYP_AGI],
111 XFS_AG_DADDR(mp, cur_agno, XFS_AGI_DADDR(mp)),
112 XFS_FSS_TO_BB(mp, 1), DB_RING_ADD, NULL);
113 return 0;
114 }
115
116 void
117 agi_init(void)
118 {
119 add_command(&agi_cmd);
120 }
121
122 /*ARGSUSED*/
123 int
124 agi_size(
125 void *obj,
126 int startoff,
127 int idx)
128 {
129 return bitize(mp->m_sb.sb_sectsize);
130 }