]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/attrshort.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[thirdparty/xfsprogs-dev.git] / db / attrshort.c
1 /*
2 * Copyright (c) 2000-2001,2004-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <xfs/libxfs.h>
20 #include "type.h"
21 #include "faddr.h"
22 #include "fprint.h"
23 #include "field.h"
24 #include "bit.h"
25 #include "attrshort.h"
26
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);
32
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 },
38 { NULL }
39 };
40
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 },
45 { NULL }
46 };
47
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 },
53 { "root", FLDT_UINT1,
54 OI(EOFF(flags) + bitsz(__uint8_t) - XFS_ATTR_ROOT_BIT - 1), C1, 0,
55 TYP_NONE },
56 { "secure", FLDT_UINT1,
57 OI(EOFF(flags) + bitsz(__uint8_t) - XFS_ATTR_SECURE_BIT - 1), C1, 0,
58 TYP_NONE },
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 },
63 { NULL }
64 };
65
66 static int
67 attr_sf_entry_name_count(
68 void *obj,
69 int startoff)
70 {
71 xfs_attr_sf_entry_t *e;
72
73 ASSERT(bitoffs(startoff) == 0);
74 e = (xfs_attr_sf_entry_t *)((char *)obj + byteize(startoff));
75 return e->namelen;
76 }
77
78 int
79 attr_sf_entry_size(
80 void *obj,
81 int startoff,
82 int idx)
83 {
84 xfs_attr_sf_entry_t *e;
85 int i;
86 xfs_attr_shortform_t *sf;
87
88 ASSERT(bitoffs(startoff) == 0);
89 sf = (xfs_attr_shortform_t *)((char *)obj + byteize(startoff));
90 e = &sf->list[0];
91 for (i = 0; i < idx; i++)
92 e = XFS_ATTR_SF_NEXTENTRY(e);
93 return bitize((int)XFS_ATTR_SF_ENTSIZE(e));
94 }
95
96 static int
97 attr_sf_entry_value_count(
98 void *obj,
99 int startoff)
100 {
101 xfs_attr_sf_entry_t *e;
102
103 ASSERT(bitoffs(startoff) == 0);
104 e = (xfs_attr_sf_entry_t *)((char *)obj + byteize(startoff));
105 return e->valuelen;
106 }
107
108 /*ARGSUSED*/
109 static int
110 attr_sf_entry_value_offset(
111 void *obj,
112 int startoff,
113 int idx)
114 {
115 xfs_attr_sf_entry_t *e;
116
117 ASSERT(bitoffs(startoff) == 0);
118 ASSERT(idx == 0);
119 e = (xfs_attr_sf_entry_t *)((char *)obj + byteize(startoff));
120 return bitize((int)((char *)&e->nameval[e->namelen] - (char *)e));
121 }
122
123 static int
124 attr_shortform_list_count(
125 void *obj,
126 int startoff)
127 {
128 xfs_attr_shortform_t *sf;
129
130 ASSERT(bitoffs(startoff) == 0);
131 sf = (xfs_attr_shortform_t *)((char *)obj + byteize(startoff));
132 return sf->hdr.count;
133 }
134
135 static int
136 attr_shortform_list_offset(
137 void *obj,
138 int startoff,
139 int idx)
140 {
141 xfs_attr_sf_entry_t *e;
142 int i;
143 xfs_attr_shortform_t *sf;
144
145 ASSERT(bitoffs(startoff) == 0);
146 sf = (xfs_attr_shortform_t *)((char *)obj + byteize(startoff));
147 e = &sf->list[0];
148 for (i = 0; i < idx; i++)
149 e = XFS_ATTR_SF_NEXTENTRY(e);
150 return bitize((int)((char *)e - (char *)sf));
151 }
152
153 /*ARGSUSED*/
154 int
155 attrshort_size(
156 void *obj,
157 int startoff,
158 int idx)
159 {
160 xfs_attr_sf_entry_t *e;
161 int i;
162 xfs_attr_shortform_t *sf;
163
164 ASSERT(bitoffs(startoff) == 0);
165 ASSERT(idx == 0);
166 sf = (xfs_attr_shortform_t *)((char *)obj + byteize(startoff));
167 e = &sf->list[0];
168 for (i = 0; i < sf->hdr.count; i++)
169 e = XFS_ATTR_SF_NEXTENTRY(e);
170 return bitize((int)((char *)e - (char *)sf));
171 }