]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/attrshort.c
cmd/xfs/bmap/Makefile 1.8 Renamed to cmd/xfsprogs/bmap/Makefile
[thirdparty/xfsprogs-dev.git] / db / attrshort.c
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
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.
7 *
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.
11 *
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.
18 *
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.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <libxfs.h>
34 #include "type.h"
35 #include "faddr.h"
36 #include "fprint.h"
37 #include "field.h"
38 #include "bit.h"
39 #include "attrshort.h"
40
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);
46
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 },
52 { NULL }
53 };
54
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 },
59 { NULL }
60 };
61
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 },
67 { "root", FLDT_UINT1,
68 OI(EOFF(flags) + bitsz(__uint8_t) - XFS_ATTR_ROOT_BIT - 1), C1, 0,
69 TYP_NONE },
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 },
74 { NULL }
75 };
76
77 static int
78 attr_sf_entry_name_count(
79 void *obj,
80 int startoff)
81 {
82 xfs_attr_sf_entry_t *e;
83
84 ASSERT(bitoffs(startoff) == 0);
85 e = (xfs_attr_sf_entry_t *)((char *)obj + byteize(startoff));
86 return e->namelen;
87 }
88
89 int
90 attr_sf_entry_size(
91 void *obj,
92 int startoff,
93 int idx)
94 {
95 xfs_attr_sf_entry_t *e;
96 int i;
97 xfs_attr_shortform_t *sf;
98
99 ASSERT(bitoffs(startoff) == 0);
100 sf = (xfs_attr_shortform_t *)((char *)obj + byteize(startoff));
101 e = &sf->list[0];
102 for (i = 0; i < idx; i++)
103 e = XFS_ATTR_SF_NEXTENTRY(e);
104 return bitize((int)XFS_ATTR_SF_ENTSIZE(e));
105 }
106
107 static int
108 attr_sf_entry_value_count(
109 void *obj,
110 int startoff)
111 {
112 xfs_attr_sf_entry_t *e;
113
114 ASSERT(bitoffs(startoff) == 0);
115 e = (xfs_attr_sf_entry_t *)((char *)obj + byteize(startoff));
116 return e->valuelen;
117 }
118
119 /*ARGSUSED*/
120 static int
121 attr_sf_entry_value_offset(
122 void *obj,
123 int startoff,
124 int idx)
125 {
126 xfs_attr_sf_entry_t *e;
127
128 ASSERT(bitoffs(startoff) == 0);
129 ASSERT(idx == 0);
130 e = (xfs_attr_sf_entry_t *)((char *)obj + byteize(startoff));
131 return bitize((int)((char *)&e->nameval[e->namelen] - (char *)e));
132 }
133
134 static int
135 attr_shortform_list_count(
136 void *obj,
137 int startoff)
138 {
139 xfs_attr_shortform_t *sf;
140
141 ASSERT(bitoffs(startoff) == 0);
142 sf = (xfs_attr_shortform_t *)((char *)obj + byteize(startoff));
143 return sf->hdr.count;
144 }
145
146 static int
147 attr_shortform_list_offset(
148 void *obj,
149 int startoff,
150 int idx)
151 {
152 xfs_attr_sf_entry_t *e;
153 int i;
154 xfs_attr_shortform_t *sf;
155
156 ASSERT(bitoffs(startoff) == 0);
157 sf = (xfs_attr_shortform_t *)((char *)obj + byteize(startoff));
158 e = &sf->list[0];
159 for (i = 0; i < idx; i++)
160 e = XFS_ATTR_SF_NEXTENTRY(e);
161 return bitize((int)((char *)e - (char *)sf));
162 }
163
164 /*ARGSUSED*/
165 int
166 attrshort_size(
167 void *obj,
168 int startoff,
169 int idx)
170 {
171 xfs_attr_sf_entry_t *e;
172 int i;
173 xfs_attr_shortform_t *sf;
174
175 ASSERT(bitoffs(startoff) == 0);
176 ASSERT(idx == 0);
177 sf = (xfs_attr_shortform_t *)((char *)obj + byteize(startoff));
178 e = &sf->list[0];
179 for (i = 0; i < sf->hdr.count; i++)
180 e = XFS_ATTR_SF_NEXTENTRY(e);
181 return bitize((int)((char *)e - (char *)sf));
182 }