2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <xfs/libxfs.h>
29 static int dir_leaf_entries_count(void *obj
, int startoff
);
30 static int dir_leaf_hdr_count(void *obj
, int startoff
);
31 static int dir_leaf_name_count(void *obj
, int startoff
);
32 static int dir_leaf_namelist_count(void *obj
, int startoff
);
33 static int dir_leaf_namelist_offset(void *obj
, int startoff
, int idx
);
34 static int dir_node_btree_count(void *obj
, int startoff
);
35 static int dir_node_hdr_count(void *obj
, int startoff
);
37 const field_t dir_hfld
[] = {
38 { "", FLDT_DIR
, OI(0), C1
, 0, TYP_NONE
},
42 #define LOFF(f) bitize(offsetof(xfs_dir_leafblock_t, f))
43 #define NOFF(f) bitize(offsetof(xfs_da_intnode_t, f))
44 const field_t dir_flds
[] = {
45 { "lhdr", FLDT_DIR_LEAF_HDR
, OI(LOFF(hdr
)), dir_leaf_hdr_count
,
46 FLD_COUNT
, TYP_NONE
},
47 { "nhdr", FLDT_DIR_NODE_HDR
, OI(NOFF(hdr
)), dir_node_hdr_count
,
48 FLD_COUNT
, TYP_NONE
},
49 { "entries", FLDT_DIR_LEAF_ENTRY
, OI(LOFF(entries
)),
50 dir_leaf_entries_count
, FLD_ARRAY
|FLD_COUNT
, TYP_NONE
},
51 { "btree", FLDT_DIR_NODE_ENTRY
, OI(NOFF(btree
)),
52 dir_node_btree_count
, FLD_ARRAY
|FLD_COUNT
, TYP_NONE
},
53 { "namelist", FLDT_DIR_LEAF_NAME
, dir_leaf_namelist_offset
,
54 dir_leaf_namelist_count
, FLD_ARRAY
|FLD_OFFSET
|FLD_COUNT
, TYP_NONE
},
58 #define BOFF(f) bitize(offsetof(xfs_da_blkinfo_t, f))
59 const field_t dir_blkinfo_flds
[] = {
60 { "forw", FLDT_DIRBLOCK
, OI(BOFF(forw
)), C1
, 0, TYP_INODATA
},
61 { "back", FLDT_DIRBLOCK
, OI(BOFF(back
)), C1
, 0, TYP_INODATA
},
62 { "magic", FLDT_UINT16X
, OI(BOFF(magic
)), C1
, 0, TYP_NONE
},
63 { "pad", FLDT_UINT16X
, OI(BOFF(pad
)), C1
, FLD_SKIPALL
, TYP_NONE
},
67 #define LEOFF(f) bitize(offsetof(xfs_dir_leaf_entry_t, f))
68 const field_t dir_leaf_entry_flds
[] = {
69 { "hashval", FLDT_UINT32X
, OI(LEOFF(hashval
)), C1
, 0, TYP_NONE
},
70 { "nameidx", FLDT_UINT16D
, OI(LEOFF(nameidx
)), C1
, 0, TYP_NONE
},
71 { "namelen", FLDT_UINT8D
, OI(LEOFF(namelen
)), C1
, 0, TYP_NONE
},
72 { "pad2", FLDT_UINT8X
, OI(LEOFF(pad2
)), C1
, FLD_SKIPALL
, TYP_NONE
},
76 #define LHOFF(f) bitize(offsetof(xfs_dir_leaf_hdr_t, f))
77 const field_t dir_leaf_hdr_flds
[] = {
78 { "info", FLDT_DIR_BLKINFO
, OI(LHOFF(info
)), C1
, 0, TYP_NONE
},
79 { "count", FLDT_UINT16D
, OI(LHOFF(count
)), C1
, 0, TYP_NONE
},
80 { "namebytes", FLDT_UINT16D
, OI(LHOFF(namebytes
)), C1
, 0, TYP_NONE
},
81 { "firstused", FLDT_UINT16D
, OI(LHOFF(firstused
)), C1
, 0, TYP_NONE
},
82 { "holes", FLDT_UINT8D
, OI(LHOFF(holes
)), C1
, 0, TYP_NONE
},
83 { "pad1", FLDT_UINT8X
, OI(LHOFF(pad1
)), C1
, FLD_SKIPALL
, TYP_NONE
},
84 { "freemap", FLDT_DIR_LEAF_MAP
, OI(LHOFF(freemap
)),
85 CI(XFS_DIR_LEAF_MAPSIZE
), FLD_ARRAY
, TYP_NONE
},
89 #define LMOFF(f) bitize(offsetof(xfs_dir_leaf_map_t, f))
90 const field_t dir_leaf_map_flds
[] = {
91 { "base", FLDT_UINT16D
, OI(LMOFF(base
)), C1
, 0, TYP_NONE
},
92 { "size", FLDT_UINT16D
, OI(LMOFF(size
)), C1
, 0, TYP_NONE
},
96 #define LNOFF(f) bitize(offsetof(xfs_dir_leaf_name_t, f))
97 const field_t dir_leaf_name_flds
[] = {
98 { "inumber", FLDT_DIR_INO
, OI(LNOFF(inumber
)), C1
, 0, TYP_INODE
},
99 { "name", FLDT_CHARNS
, OI(LNOFF(name
)), dir_leaf_name_count
, FLD_COUNT
,
104 #define EOFF(f) bitize(offsetof(xfs_da_node_entry_t, f))
105 const field_t dir_node_entry_flds
[] = {
106 { "hashval", FLDT_UINT32X
, OI(EOFF(hashval
)), C1
, 0, TYP_NONE
},
107 { "before", FLDT_DIRBLOCK
, OI(EOFF(before
)), C1
, 0, TYP_INODATA
},
111 #define HOFF(f) bitize(offsetof(xfs_da_node_hdr_t, f))
112 const field_t dir_node_hdr_flds
[] = {
113 { "info", FLDT_DIR_BLKINFO
, OI(HOFF(info
)), C1
, 0, TYP_NONE
},
114 { "count", FLDT_UINT16D
, OI(HOFF(count
)), C1
, 0, TYP_NONE
},
115 { "level", FLDT_UINT16D
, OI(HOFF(level
)), C1
, 0, TYP_NONE
},
121 dir_leaf_entries_count(
125 xfs_dir_leafblock_t
*block
;
127 ASSERT(startoff
== 0);
129 if (be16_to_cpu(block
->hdr
.info
.magic
) != XFS_DIR_LEAF_MAGIC
)
131 return be16_to_cpu(block
->hdr
.count
);
140 xfs_dir_leafblock_t
*block
;
142 ASSERT(startoff
== 0);
144 return be16_to_cpu(block
->hdr
.info
.magic
) == XFS_DIR_LEAF_MAGIC
;
152 xfs_dir_leafblock_t
*block
;
153 xfs_dir_leaf_entry_t
*e
;
157 ASSERT(bitoffs(startoff
) == 0);
158 off
= byteize(startoff
);
160 if (be16_to_cpu(block
->hdr
.info
.magic
) != XFS_DIR_LEAF_MAGIC
)
162 for (i
= 0; i
< be16_to_cpu(block
->hdr
.count
); i
++) {
163 e
= &block
->entries
[i
];
164 if (be16_to_cpu(e
->nameidx
) == off
)
177 xfs_dir_leafblock_t
*block
;
178 xfs_dir_leaf_entry_t
*e
;
180 ASSERT(startoff
== 0);
182 if (be16_to_cpu(block
->hdr
.info
.magic
) != XFS_DIR_LEAF_MAGIC
)
184 e
= &block
->entries
[idx
];
185 return bitize((int)xfs_dir_leaf_entsize_byentry(e
));
190 dir_leaf_namelist_count(
194 xfs_dir_leafblock_t
*block
;
196 ASSERT(startoff
== 0);
198 if (be16_to_cpu(block
->hdr
.info
.magic
) != XFS_DIR_LEAF_MAGIC
)
200 return be16_to_cpu(block
->hdr
.count
);
205 dir_leaf_namelist_offset(
210 xfs_dir_leafblock_t
*block
;
211 xfs_dir_leaf_entry_t
*e
;
213 ASSERT(startoff
== 0);
215 e
= &block
->entries
[idx
];
216 return bitize(be16_to_cpu(e
->nameidx
));
221 dir_node_btree_count(
225 xfs_da_intnode_t
*block
;
227 ASSERT(startoff
== 0); /* this is a base structure */
229 if (be16_to_cpu(block
->hdr
.info
.magic
) != XFS_DA_NODE_MAGIC
)
231 return be16_to_cpu(block
->hdr
.count
);
240 xfs_da_intnode_t
*block
;
242 ASSERT(startoff
== 0);
244 return be16_to_cpu(block
->hdr
.info
.magic
) == XFS_DA_NODE_MAGIC
;
254 return bitize(mp
->m_sb
.sb_blocksize
);