1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
17 static int dir2_inou_i4_count(void *obj
, int startoff
);
18 static int dir2_inou_i8_count(void *obj
, int startoff
);
19 static int dir2_sf_entry_inumber_offset(void *obj
, int startoff
, int idx
);
20 static int dir2_sf_entry_name_count(void *obj
, int startoff
);
21 static int dir2_sf_list_count(void *obj
, int startoff
);
22 static int dir2_sf_list_offset(void *obj
, int startoff
, int idx
);
24 #define OFF(f) bitize(offsetof(struct xfs_dir2_sf_hdr, f))
25 const field_t dir2sf_flds
[] = {
26 { "hdr", FLDT_DIR2_SF_HDR
, OI(OFF(count
)), C1
, 0, TYP_NONE
},
27 { "list", FLDT_DIR2_SF_ENTRY
, dir2_sf_list_offset
, dir2_sf_list_count
,
28 FLD_ARRAY
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
32 const field_t dir2_inou_flds
[] = {
33 { "i8", FLDT_DIR2_INO8
, NULL
, dir2_inou_i8_count
, FLD_COUNT
, TYP_INODE
},
34 { "i4", FLDT_DIR2_INO4
, NULL
, dir2_inou_i4_count
, FLD_COUNT
, TYP_INODE
},
38 #define HOFF(f) bitize(offsetof(xfs_dir2_sf_hdr_t, f))
39 const field_t dir2_sf_hdr_flds
[] = {
40 { "count", FLDT_UINT8D
, OI(HOFF(count
)), C1
, 0, TYP_NONE
},
41 { "i8count", FLDT_UINT8D
, OI(HOFF(i8count
)), C1
, 0, TYP_NONE
},
42 { "parent", FLDT_DIR2_INOU
, OI(HOFF(parent
)), C1
, 0, TYP_NONE
},
46 #define EOFF(f) bitize(offsetof(xfs_dir2_sf_entry_t, f))
47 const field_t dir2_sf_entry_flds
[] = {
48 { "namelen", FLDT_UINT8D
, OI(EOFF(namelen
)), C1
, 0, TYP_NONE
},
49 { "offset", FLDT_DIR2_SF_OFF
, OI(EOFF(offset
)), C1
, 0, TYP_NONE
},
50 { "name", FLDT_CHARNS
, OI(EOFF(name
)), dir2_sf_entry_name_count
,
51 FLD_COUNT
, TYP_NONE
},
52 { "inumber", FLDT_DIR2_INOU
, dir2_sf_entry_inumber_offset
, C1
,
53 FLD_OFFSET
, TYP_NONE
},
63 struct xfs_dinode
*dip
= obj
;
64 struct xfs_dir2_sf_hdr
*sf
;
66 ASSERT(bitoffs(startoff
) == 0);
67 sf
= (struct xfs_dir2_sf_hdr
*)XFS_DFORK_DPTR(dip
);
68 return sf
->i8count
== 0;
77 struct xfs_dinode
*dip
= obj
;
78 struct xfs_dir2_sf_hdr
*sf
;
80 ASSERT(bitoffs(startoff
) == 0);
81 sf
= (struct xfs_dir2_sf_hdr
*)XFS_DFORK_DPTR(dip
);
82 return sf
->i8count
!= 0;
92 struct xfs_dinode
*dip
= obj
;
93 struct xfs_dir2_sf_hdr
*sf
;
95 ASSERT(bitoffs(startoff
) == 0);
97 sf
= (struct xfs_dir2_sf_hdr
*)XFS_DFORK_DPTR(dip
);
98 return bitize(sf
->i8count
? XFS_INO64_SIZE
: XFS_INO32_SIZE
);
102 dir2_sf_entry_name_count(
106 xfs_dir2_sf_entry_t
*e
;
108 ASSERT(bitoffs(startoff
) == 0);
109 e
= (xfs_dir2_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
114 dir2_sf_entry_inumber_offset(
119 xfs_dir2_sf_entry_t
*e
;
121 ASSERT(bitoffs(startoff
) == 0);
123 e
= (xfs_dir2_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
124 return bitize((int)((char *)xfs_dir2_sf_inumberp(e
) - (char *)e
));
128 dir3_sf_entry_inumber_offset(
133 xfs_dir2_sf_entry_t
*e
;
135 ASSERT(bitoffs(startoff
) == 0);
137 e
= (xfs_dir2_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
138 /* plus 1 to skip the ftype entry */
139 return bitize((int)((char *)xfs_dir2_sf_inumberp(e
) + 1 - (char *)e
));
143 dir3_sf_entry_ftype_offset(
148 xfs_dir2_sf_entry_t
*e
;
150 ASSERT(bitoffs(startoff
) == 0);
152 e
= (xfs_dir2_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
153 return bitize((int)((char *)&e
->name
[e
->namelen
] - (char *)e
));
162 xfs_dir2_sf_entry_t
*e
;
164 struct xfs_dir2_sf_hdr
*sf
;
166 ASSERT(bitoffs(startoff
) == 0);
167 sf
= (struct xfs_dir2_sf_hdr
*)((char *)obj
+ byteize(startoff
));
168 e
= xfs_dir2_sf_firstentry(sf
);
169 for (i
= 0; i
< idx
; i
++)
170 e
= libxfs_dir2_sf_nextentry(mp
, sf
, e
);
171 return bitize((int)libxfs_dir2_sf_entsize(mp
, sf
, e
->namelen
));
181 struct xfs_dir2_sf_hdr
*sf
;
183 ASSERT(bitoffs(startoff
) == 0);
185 sf
= (struct xfs_dir2_sf_hdr
*)((char *)obj
+ byteize(startoff
));
186 return bitize(xfs_dir2_sf_hdr_size(sf
->i8count
));
194 struct xfs_dir2_sf_hdr
*sf
;
196 ASSERT(bitoffs(startoff
) == 0);
197 sf
= (struct xfs_dir2_sf_hdr
*)((char *)obj
+ byteize(startoff
));
207 xfs_dir2_sf_entry_t
*e
;
209 struct xfs_dir2_sf_hdr
*sf
;
211 ASSERT(bitoffs(startoff
) == 0);
212 sf
= (struct xfs_dir2_sf_hdr
*)((char *)obj
+ byteize(startoff
));
213 e
= xfs_dir2_sf_firstentry(sf
);
214 for (i
= 0; i
< idx
; i
++)
215 e
= libxfs_dir2_sf_nextentry(mp
, sf
, e
);
216 return bitize((int)((char *)e
- (char *)sf
));
226 xfs_dir2_sf_entry_t
*e
;
228 struct xfs_dir2_sf_hdr
*sf
;
230 ASSERT(bitoffs(startoff
) == 0);
232 sf
= (struct xfs_dir2_sf_hdr
*)((char *)obj
+ byteize(startoff
));
233 e
= xfs_dir2_sf_firstentry(sf
);
234 for (i
= 0; i
< sf
->count
; i
++)
235 e
= libxfs_dir2_sf_nextentry(mp
, sf
, e
);
236 return bitize((int)((char *)e
- (char *)sf
));
239 #define OFF(f) bitize(offsetof(struct xfs_dir2_sf_hdr, f))
240 const field_t dir3sf_flds
[] = {
241 { "hdr", FLDT_DIR2_SF_HDR
, OI(OFF(count
)), C1
, 0, TYP_NONE
},
242 { "list", FLDT_DIR3_SF_ENTRY
, dir2_sf_list_offset
, dir2_sf_list_count
,
243 FLD_ARRAY
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
247 #define E3OFF(f) bitize(offsetof(xfs_dir2_sf_entry_t, f))
248 const field_t dir3_sf_entry_flds
[] = {
249 { "namelen", FLDT_UINT8D
, OI(E3OFF(namelen
)), C1
, 0, TYP_NONE
},
250 { "offset", FLDT_DIR2_SF_OFF
, OI(E3OFF(offset
)), C1
, 0, TYP_NONE
},
251 { "name", FLDT_CHARNS
, OI(E3OFF(name
)), dir2_sf_entry_name_count
,
252 FLD_COUNT
, TYP_NONE
},
253 { "inumber", FLDT_DIR2_INOU
, dir3_sf_entry_inumber_offset
, C1
,
254 FLD_OFFSET
, TYP_NONE
},
255 { "filetype", FLDT_UINT8D
, dir3_sf_entry_ftype_offset
, C1
,
256 FLD_OFFSET
, TYP_NONE
},