2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
39 #include "attrshort.h"
41 static int attr_sf_entry_name_count(void *obj
, int startoff
);
42 static int attr_sf_entry_value_count(void *obj
, int startoff
);
43 static int attr_sf_entry_value_offset(void *obj
, int startoff
, int idx
);
44 static int attr_shortform_list_count(void *obj
, int startoff
);
45 static int attr_shortform_list_offset(void *obj
, int startoff
, int idx
);
47 #define OFF(f) bitize(offsetof(xfs_attr_shortform_t, f))
48 const field_t attr_shortform_flds
[] = {
49 { "hdr", FLDT_ATTR_SF_HDR
, OI(OFF(hdr
)), C1
, 0, TYP_NONE
},
50 { "list", FLDT_ATTR_SF_ENTRY
, attr_shortform_list_offset
,
51 attr_shortform_list_count
, FLD_ARRAY
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
55 #define HOFF(f) bitize(offsetof(xfs_attr_sf_hdr_t, f))
56 const field_t attr_sf_hdr_flds
[] = {
57 { "totsize", FLDT_UINT16D
, OI(HOFF(totsize
)), C1
, 0, TYP_NONE
},
58 { "count", FLDT_UINT8D
, OI(HOFF(count
)), C1
, 0, TYP_NONE
},
62 #define EOFF(f) bitize(offsetof(xfs_attr_sf_entry_t, f))
63 const field_t attr_sf_entry_flds
[] = {
64 { "namelen", FLDT_UINT8D
, OI(EOFF(namelen
)), C1
, 0, TYP_NONE
},
65 { "valuelen", FLDT_UINT8D
, OI(EOFF(valuelen
)), C1
, 0, TYP_NONE
},
66 { "flags", FLDT_UINT8X
, OI(EOFF(flags
)), C1
, FLD_SKIPALL
, TYP_NONE
},
68 OI(EOFF(flags
) + bitsz(__uint8_t
) - XFS_ATTR_ROOT_BIT
- 1), C1
, 0,
70 { "name", FLDT_CHARNS
, OI(EOFF(nameval
)), attr_sf_entry_name_count
,
71 FLD_COUNT
, TYP_NONE
},
72 { "value", FLDT_CHARNS
, attr_sf_entry_value_offset
,
73 attr_sf_entry_value_count
, FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
78 attr_sf_entry_name_count(
82 xfs_attr_sf_entry_t
*e
;
84 ASSERT(bitoffs(startoff
) == 0);
85 e
= (xfs_attr_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
95 xfs_attr_sf_entry_t
*e
;
97 xfs_attr_shortform_t
*sf
;
99 ASSERT(bitoffs(startoff
) == 0);
100 sf
= (xfs_attr_shortform_t
*)((char *)obj
+ byteize(startoff
));
102 for (i
= 0; i
< idx
; i
++)
103 e
= XFS_ATTR_SF_NEXTENTRY(e
);
104 return bitize((int)XFS_ATTR_SF_ENTSIZE(e
));
108 attr_sf_entry_value_count(
112 xfs_attr_sf_entry_t
*e
;
114 ASSERT(bitoffs(startoff
) == 0);
115 e
= (xfs_attr_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
121 attr_sf_entry_value_offset(
126 xfs_attr_sf_entry_t
*e
;
128 ASSERT(bitoffs(startoff
) == 0);
130 e
= (xfs_attr_sf_entry_t
*)((char *)obj
+ byteize(startoff
));
131 return bitize((int)((char *)&e
->nameval
[e
->namelen
] - (char *)e
));
135 attr_shortform_list_count(
139 xfs_attr_shortform_t
*sf
;
141 ASSERT(bitoffs(startoff
) == 0);
142 sf
= (xfs_attr_shortform_t
*)((char *)obj
+ byteize(startoff
));
143 return sf
->hdr
.count
;
147 attr_shortform_list_offset(
152 xfs_attr_sf_entry_t
*e
;
154 xfs_attr_shortform_t
*sf
;
156 ASSERT(bitoffs(startoff
) == 0);
157 sf
= (xfs_attr_shortform_t
*)((char *)obj
+ byteize(startoff
));
159 for (i
= 0; i
< idx
; i
++)
160 e
= XFS_ATTR_SF_NEXTENTRY(e
);
161 return bitize((int)((char *)e
- (char *)sf
));
171 xfs_attr_sf_entry_t
*e
;
173 xfs_attr_shortform_t
*sf
;
175 ASSERT(bitoffs(startoff
) == 0);
177 sf
= (xfs_attr_shortform_t
*)((char *)obj
+ byteize(startoff
));
179 for (i
= 0; i
< sf
->hdr
.count
; i
++)
180 e
= XFS_ATTR_SF_NEXTENTRY(e
);
181 return bitize((int)((char *)e
- (char *)sf
));