]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
cc08d43e | 2 | * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved. |
2bd0ea18 NS |
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 "dir2sf.h" | |
40 | ||
41 | static int dir2_inou_i4_count(void *obj, int startoff); | |
42 | static int dir2_inou_i8_count(void *obj, int startoff); | |
43 | static int dir2_sf_entry_inumber_offset(void *obj, int startoff, int idx); | |
44 | static int dir2_sf_entry_name_count(void *obj, int startoff); | |
45 | static int dir2_sf_list_count(void *obj, int startoff); | |
46 | static int dir2_sf_list_offset(void *obj, int startoff, int idx); | |
47 | ||
48 | #define OFF(f) bitize(offsetof(xfs_dir2_sf_t, f)) | |
49 | const field_t dir2sf_flds[] = { | |
50 | { "hdr", FLDT_DIR2_SF_HDR, OI(OFF(hdr)), C1, 0, TYP_NONE }, | |
51 | { "list", FLDT_DIR2_SF_ENTRY, dir2_sf_list_offset, dir2_sf_list_count, | |
52 | FLD_ARRAY|FLD_COUNT|FLD_OFFSET, TYP_NONE }, | |
53 | { NULL } | |
54 | }; | |
55 | ||
56 | #define UOFF(f) bitize(offsetof(xfs_dir2_inou_t, f)) | |
57 | const field_t dir2_inou_flds[] = { | |
58 | { "i8", FLDT_DIR2_INO8, OI(UOFF(i8)), dir2_inou_i8_count, FLD_COUNT, | |
59 | TYP_INODE }, | |
60 | { "i4", FLDT_DIR2_INO4, OI(UOFF(i4)), dir2_inou_i4_count, FLD_COUNT, | |
61 | TYP_INODE }, | |
62 | { NULL } | |
63 | }; | |
64 | ||
65 | #define HOFF(f) bitize(offsetof(xfs_dir2_sf_hdr_t, f)) | |
66 | const field_t dir2_sf_hdr_flds[] = { | |
67 | { "count", FLDT_UINT8D, OI(HOFF(count)), C1, 0, TYP_NONE }, | |
68 | { "i8count", FLDT_UINT8D, OI(HOFF(i8count)), C1, 0, TYP_NONE }, | |
69 | { "parent", FLDT_DIR2_INOU, OI(HOFF(parent)), C1, 0, TYP_NONE }, | |
70 | { NULL } | |
71 | }; | |
72 | ||
73 | #define EOFF(f) bitize(offsetof(xfs_dir2_sf_entry_t, f)) | |
74 | const field_t dir2_sf_entry_flds[] = { | |
75 | { "namelen", FLDT_UINT8D, OI(EOFF(namelen)), C1, 0, TYP_NONE }, | |
76 | { "offset", FLDT_DIR2_SF_OFF, OI(EOFF(offset)), C1, 0, TYP_NONE }, | |
77 | { "name", FLDT_CHARNS, OI(EOFF(name)), dir2_sf_entry_name_count, | |
78 | FLD_COUNT, TYP_NONE }, | |
79 | { "inumber", FLDT_DIR2_INOU, dir2_sf_entry_inumber_offset, C1, | |
80 | FLD_OFFSET, TYP_NONE }, | |
81 | { NULL } | |
82 | }; | |
83 | ||
84 | /*ARGSUSED*/ | |
85 | static int | |
86 | dir2_inou_i4_count( | |
87 | void *obj, | |
88 | int startoff) | |
89 | { | |
90 | xfs_dir2_sf_t *sf; | |
91 | ||
92 | ASSERT(bitoffs(startoff) == 0); | |
93 | sf = &((xfs_dinode_t *)obj)->di_u.di_dir2sf; | |
94 | return sf->hdr.i8count == 0; | |
95 | } | |
96 | ||
97 | /*ARGSUSED*/ | |
98 | static int | |
99 | dir2_inou_i8_count( | |
100 | void *obj, | |
101 | int startoff) | |
102 | { | |
103 | xfs_dir2_sf_t *sf; | |
104 | ||
105 | ASSERT(bitoffs(startoff) == 0); | |
106 | sf = &((xfs_dinode_t *)obj)->di_u.di_dir2sf; | |
107 | return sf->hdr.i8count != 0; | |
108 | } | |
109 | ||
110 | /*ARGSUSED*/ | |
111 | int | |
112 | dir2_inou_size( | |
113 | void *obj, | |
114 | int startoff, | |
115 | int idx) | |
116 | { | |
117 | xfs_dir2_sf_t *sf; | |
118 | ||
119 | ASSERT(bitoffs(startoff) == 0); | |
120 | ASSERT(idx == 0); | |
121 | sf = &((xfs_dinode_t *)obj)->di_u.di_dir2sf; | |
122 | return bitize(sf->hdr.i8count ? | |
123 | (uint)sizeof(xfs_dir2_ino8_t) : | |
124 | (uint)sizeof(xfs_dir2_ino4_t)); | |
125 | } | |
126 | ||
127 | static int | |
128 | dir2_sf_entry_name_count( | |
129 | void *obj, | |
130 | int startoff) | |
131 | { | |
132 | xfs_dir2_sf_entry_t *e; | |
133 | ||
134 | ASSERT(bitoffs(startoff) == 0); | |
135 | e = (xfs_dir2_sf_entry_t *)((char *)obj + byteize(startoff)); | |
136 | return e->namelen; | |
137 | } | |
138 | ||
139 | /*ARGSUSED*/ | |
140 | static int | |
141 | dir2_sf_entry_inumber_offset( | |
142 | void *obj, | |
143 | int startoff, | |
144 | int idx) | |
145 | { | |
146 | xfs_dir2_sf_entry_t *e; | |
147 | ||
148 | ASSERT(bitoffs(startoff) == 0); | |
149 | ASSERT(idx == 0); | |
150 | e = (xfs_dir2_sf_entry_t *)((char *)obj + byteize(startoff)); | |
151 | return bitize((int)((char *)XFS_DIR2_SF_INUMBERP(e) - (char *)e)); | |
152 | } | |
153 | ||
154 | int | |
155 | dir2_sf_entry_size( | |
156 | void *obj, | |
157 | int startoff, | |
158 | int idx) | |
159 | { | |
160 | xfs_dir2_sf_entry_t *e; | |
161 | int i; | |
162 | xfs_dir2_sf_t *sf; | |
163 | ||
164 | ASSERT(bitoffs(startoff) == 0); | |
165 | sf = (xfs_dir2_sf_t *)((char *)obj + byteize(startoff)); | |
166 | e = XFS_DIR2_SF_FIRSTENTRY(sf); | |
167 | for (i = 0; i < idx; i++) | |
168 | e = XFS_DIR2_SF_NEXTENTRY(sf, e); | |
169 | return bitize((int)XFS_DIR2_SF_ENTSIZE_BYENTRY(sf, e)); | |
170 | } | |
171 | ||
172 | /*ARGSUSED*/ | |
173 | int | |
174 | dir2_sf_hdr_size( | |
175 | void *obj, | |
176 | int startoff, | |
177 | int idx) | |
178 | { | |
179 | xfs_dir2_sf_t *sf; | |
180 | ||
181 | ASSERT(bitoffs(startoff) == 0); | |
182 | ASSERT(idx == 0); | |
183 | sf = (xfs_dir2_sf_t *)((char *)obj + byteize(startoff)); | |
184 | return bitize(XFS_DIR2_SF_HDR_SIZE(sf->hdr.i8count)); | |
185 | } | |
186 | ||
187 | static int | |
188 | dir2_sf_list_count( | |
189 | void *obj, | |
190 | int startoff) | |
191 | { | |
192 | xfs_dir2_sf_t *sf; | |
193 | ||
194 | ASSERT(bitoffs(startoff) == 0); | |
195 | sf = (xfs_dir2_sf_t *)((char *)obj + byteize(startoff)); | |
196 | return sf->hdr.count; | |
197 | } | |
198 | ||
199 | static int | |
200 | dir2_sf_list_offset( | |
201 | void *obj, | |
202 | int startoff, | |
203 | int idx) | |
204 | { | |
205 | xfs_dir2_sf_entry_t *e; | |
206 | int i; | |
207 | xfs_dir2_sf_t *sf; | |
208 | ||
209 | ASSERT(bitoffs(startoff) == 0); | |
210 | sf = (xfs_dir2_sf_t *)((char *)obj + byteize(startoff)); | |
211 | e = XFS_DIR2_SF_FIRSTENTRY(sf); | |
212 | for (i = 0; i < idx; i++) | |
213 | e = XFS_DIR2_SF_NEXTENTRY(sf, e); | |
214 | return bitize((int)((char *)e - (char *)sf)); | |
215 | } | |
216 | ||
217 | /*ARGSUSED*/ | |
218 | int | |
219 | dir2sf_size( | |
220 | void *obj, | |
221 | int startoff, | |
222 | int idx) | |
223 | { | |
224 | xfs_dir2_sf_entry_t *e; | |
225 | int i; | |
226 | xfs_dir2_sf_t *sf; | |
227 | ||
228 | ASSERT(bitoffs(startoff) == 0); | |
229 | ASSERT(idx == 0); | |
230 | sf = (xfs_dir2_sf_t *)((char *)obj + byteize(startoff)); | |
231 | e = XFS_DIR2_SF_FIRSTENTRY(sf); | |
232 | for (i = 0; i < sf->hdr.count; i++) | |
233 | e = XFS_DIR2_SF_NEXTENTRY(sf, e); | |
234 | return bitize((int)((char *)e - (char *)sf)); | |
235 | } |