2 * Copyright (c) 2000-2001,2004-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
25 #include "attrshort.h"
27 static int attr_sf_entry_name_count(void *obj
, int startoff
);
28 static int attr_sf_entry_value_count(void *obj
, int startoff
);
29 static int attr_sf_entry_value_offset(void *obj
, int startoff
, int idx
);
30 static int attr_shortform_list_count(void *obj
, int startoff
);
31 static int attr_shortform_list_offset(void *obj
, int startoff
, int idx
);
33 #define OFF(f) bitize(offsetof(xfs_attr_shortform_t, f))
34 const field_t attr_shortform_flds
[] = {
35 { "hdr", FLDT_ATTR_SF_HDR
, OI(OFF(hdr
)), C1
, 0, TYP_NONE
},
36 { "list", FLDT_ATTR_SF_ENTRY
, attr_shortform_list_offset
,
37 attr_shortform_list_count
, FLD_ARRAY
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
41 #define HOFF(f) bitize(offsetof(xfs_attr_sf_hdr_t, f))
42 const field_t attr_sf_hdr_flds
[] = {
43 { "totsize", FLDT_UINT16D
, OI(HOFF(totsize
)), C1
, 0, TYP_NONE
},
44 { "count", FLDT_UINT8D
, OI(HOFF(count
)), C1
, 0, TYP_NONE
},
48 #define EOFF(f) bitize(offsetof(xfs_attr_sf_entry_t, f))
49 const field_t attr_sf_entry_flds
[] = {
50 { "namelen", FLDT_UINT8D
, OI(EOFF(namelen
)), C1
, 0, TYP_NONE
},
51 { "valuelen", FLDT_UINT8D
, OI(EOFF(valuelen
)), C1
, 0, TYP_NONE
},
52 { "flags", FLDT_UINT8X
, OI(EOFF(flags
)), C1
, FLD_SKIPALL
, TYP_NONE
},
54 OI(EOFF(flags
) + bitsz(uint8_t) - XFS_ATTR_ROOT_BIT
- 1), C1
, 0,
56 { "secure", FLDT_UINT1
,
57 OI(EOFF(flags
) + bitsz(uint8_t) - XFS_ATTR_SECURE_BIT
- 1), C1
, 0,
59 { "name", FLDT_CHARNS
, OI(EOFF(nameval
)), attr_sf_entry_name_count
,
60 FLD_COUNT
, TYP_NONE
},
61 { "value", FLDT_CHARNS
, attr_sf_entry_value_offset
,
62 attr_sf_entry_value_count
, FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
67 attr_sf_entry_name_count(
71 xfs_attr_sf_entry_t
*e
;
73 ASSERT(bitoffs(startoff
) == 0);
74 e
= (xfs_attr_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
84 xfs_attr_sf_entry_t
*e
;
86 xfs_attr_shortform_t
*sf
;
88 ASSERT(bitoffs(startoff
) == 0);
89 sf
= (xfs_attr_shortform_t
*)((char *)obj
+ byteize(startoff
));
91 for (i
= 0; i
< idx
; i
++)
92 e
= XFS_ATTR_SF_NEXTENTRY(e
);
93 return bitize((int)XFS_ATTR_SF_ENTSIZE(e
));
97 attr_sf_entry_value_count(
101 xfs_attr_sf_entry_t
*e
;
103 ASSERT(bitoffs(startoff
) == 0);
104 e
= (xfs_attr_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
110 attr_sf_entry_value_offset(
115 xfs_attr_sf_entry_t
*e
;
117 ASSERT(bitoffs(startoff
) == 0);
119 e
= (xfs_attr_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
120 return bitize((int)((char *)&e
->nameval
[e
->namelen
] - (char *)e
));
124 attr_shortform_list_count(
128 xfs_attr_shortform_t
*sf
;
130 ASSERT(bitoffs(startoff
) == 0);
131 sf
= (xfs_attr_shortform_t
*)((char *)obj
+ byteize(startoff
));
132 return sf
->hdr
.count
;
136 attr_shortform_list_offset(
141 xfs_attr_sf_entry_t
*e
;
143 xfs_attr_shortform_t
*sf
;
145 ASSERT(bitoffs(startoff
) == 0);
146 sf
= (xfs_attr_shortform_t
*)((char *)obj
+ byteize(startoff
));
148 for (i
= 0; i
< idx
; i
++)
149 e
= XFS_ATTR_SF_NEXTENTRY(e
);
150 return bitize((int)((char *)e
- (char *)sf
));
160 xfs_attr_sf_entry_t
*e
;
162 xfs_attr_shortform_t
*sf
;
164 ASSERT(bitoffs(startoff
) == 0);
166 sf
= (xfs_attr_shortform_t
*)((char *)obj
+ byteize(startoff
));
168 for (i
= 0; i
< sf
->hdr
.count
; i
++)
169 e
= XFS_ATTR_SF_NEXTENTRY(e
);
170 return bitize((int)((char *)e
- (char *)sf
));