]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/btdump.c
2 * Copyright (C) 2017 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
33 " If the cursor points to a btree block, 'btdump' dumps the btree\n"
34 " downward from that block. If the cursor points to an inode,\n"
35 " the data fork btree root is selected by default.\n"
38 " -a -- Display an inode's extended attribute fork btree.\n"
39 " -i -- Print internal btree nodes.\n"
56 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
59 v
= breakline(buf
, &c
);
67 struct xfs_btree_block
*block
,
71 return block
->bb_u
.l
.bb_rightsib
!= cpu_to_be64(NULLFSBLOCK
);
72 return block
->bb_u
.s
.bb_rightsib
!= cpu_to_be32(NULLAGBLOCK
);
80 xfs_daddr_t orig_daddr
= iocur_top
->bb
;
81 xfs_daddr_t last_daddr
;
91 last_daddr
= iocur_top
->bb
;
92 dbprintf(_("%s level %u block %u daddr %llu\n"),
93 iocur_top
->typ
->name
, level
, nr
, last_daddr
);
95 ret
= eval("print keys");
98 ret
= eval("print ptrs");
100 ret
= eval("print recs");
104 if (btblock_has_rightsib(iocur_top
->data
, long_format
)) {
105 ret
= eval("addr rightsib");
110 } while (iocur_top
->bb
!= orig_daddr
&& iocur_top
->bb
!= last_daddr
);
121 bool dump_node_blocks
,
124 xfs_daddr_t orig_daddr
= iocur_top
->bb
;
125 xfs_daddr_t last_daddr
;
133 cur_agno
= XFS_FSB_TO_AGNO(mp
, XFS_DADDR_TO_FSB(mp
, iocur_top
->bb
));
134 level
= xfs_btree_get_level(iocur_top
->data
);
136 last_daddr
= iocur_top
->bb
;
138 if (dump_node_blocks
) {
139 ret
= dump_btlevel(level
, long_format
);
143 ret
= eval("addr ptrs[1]");
145 ret
= dump_btlevel(level
, long_format
);
150 } while (level
>= 0 &&
151 iocur_top
->bb
!= orig_daddr
&&
152 iocur_top
->bb
!= last_daddr
);
161 static inline int dump_btree_short(bool dump_node_blocks
)
163 return dump_btree(dump_node_blocks
, false);
166 static inline int dump_btree_long(bool dump_node_blocks
)
168 return dump_btree(dump_node_blocks
, true);
173 bool dump_node_blocks
,
177 struct xfs_dinode
*dip
;
182 else if (xfs_sb_version_hascrc(&mp
->m_sb
))
187 dip
= iocur_top
->data
;
189 if (!dip
->di_anextents
||
190 dip
->di_aformat
!= XFS_DINODE_FMT_BTREE
) {
191 dbprintf(_("attr fork not in btree format\n"));
195 if (!dip
->di_nextents
||
196 dip
->di_format
!= XFS_DINODE_FMT_BTREE
) {
197 dbprintf(_("data fork not in btree format\n"));
206 if (dump_node_blocks
) {
207 ret
= eval("print %s.keys", prefix
);
210 ret
= eval("print %s.ptrs", prefix
);
215 ret
= eval("addr %s.ptrs[1]", prefix
);
219 ret
= dump_btree_long(dump_node_blocks
);
239 if (cur_typ
== NULL
) {
240 dbprintf(_("no current type\n"));
243 while ((c
= getopt(argc
, argv
, "ai")) != EOF
) {
252 dbprintf(_("bad option for btdump command\n"));
257 if (optind
!= argc
) {
258 dbprintf(_("bad options for btdump command\n"));
261 if (aflag
&& cur_typ
->typnm
!= TYP_INODE
) {
262 dbprintf(_("attrfork flag doesn't apply here\n"));
266 switch (cur_typ
->typnm
) {
273 return dump_btree_short(iflag
);
276 return dump_btree_long(iflag
);
278 return dump_inode(iflag
, aflag
);
280 dbprintf(_("type \"%s\" is not a btree type or inode\n"),
286 static const cmdinfo_t btdump_cmd
=
287 { "btdump", "b", btdump_f
, 0, 2, 0, "[-a] [-i]",
288 N_("dump btree"), btdump_help
};
293 add_command(&btdump_cmd
);