hfs_subr.c revision 1.3.12.2 1 1.3.12.2 yamt /* $NetBSD: hfs_subr.c,v 1.3.12.2 2007/09/03 14:40:20 yamt Exp $ */
2 1.3.12.2 yamt
3 1.3.12.2 yamt /*-
4 1.3.12.2 yamt * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
5 1.3.12.2 yamt * All rights reserved.
6 1.3.12.2 yamt *
7 1.3.12.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.3.12.2 yamt * by Yevgeny Binder and Dieter Baron.
9 1.3.12.2 yamt *
10 1.3.12.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.3.12.2 yamt * modification, are permitted provided that the following conditions
12 1.3.12.2 yamt * are met:
13 1.3.12.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.3.12.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.3.12.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.12.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.3.12.2 yamt * documentation and/or other materials provided with the distribution.
18 1.3.12.2 yamt *
19 1.3.12.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.3.12.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.3.12.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.3.12.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.3.12.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.3.12.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.3.12.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.3.12.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.3.12.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.3.12.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.3.12.2 yamt * POSSIBILITY OF SUCH DAMAGE.
30 1.3.12.2 yamt */
31 1.3.12.2 yamt
32 1.3.12.2 yamt #include <sys/cdefs.h>
33 1.3.12.2 yamt __KERNEL_RCSID(0, "$NetBSD: hfs_subr.c,v 1.3.12.2 2007/09/03 14:40:20 yamt Exp $");
34 1.3.12.2 yamt
35 1.3.12.2 yamt #include <sys/param.h>
36 1.3.12.2 yamt #include <sys/systm.h>
37 1.3.12.2 yamt #include <sys/time.h>
38 1.3.12.2 yamt #include <sys/kernel.h>
39 1.3.12.2 yamt #include <sys/proc.h>
40 1.3.12.2 yamt #include <sys/vnode.h>
41 1.3.12.2 yamt #include <sys/malloc.h>
42 1.3.12.2 yamt #include <sys/stat.h>
43 1.3.12.2 yamt #include <sys/file.h>
44 1.3.12.2 yamt #include <sys/filedesc.h>
45 1.3.12.2 yamt #include <sys/mount.h>
46 1.3.12.2 yamt #include <sys/disklabel.h>
47 1.3.12.2 yamt #include <sys/conf.h>
48 1.3.12.2 yamt #include <sys/kauth.h>
49 1.3.12.2 yamt
50 1.3.12.2 yamt #include <fs/hfs/hfs.h>
51 1.3.12.2 yamt
52 1.3.12.2 yamt /*
53 1.3.12.2 yamt * Initialize the vnode associated with a new hfsnode.
54 1.3.12.2 yamt */
55 1.3.12.2 yamt void
56 1.3.12.2 yamt hfs_vinit(struct mount *mp, int (**specops)(void *), int (**fifoops)(void *),
57 1.3.12.2 yamt struct vnode **vpp)
58 1.3.12.2 yamt {
59 1.3.12.2 yamt struct hfsnode *hp;
60 1.3.12.2 yamt struct vnode *vp;
61 1.3.12.2 yamt struct vnode *nvp;
62 1.3.12.2 yamt
63 1.3.12.2 yamt vp = *vpp;
64 1.3.12.2 yamt hp = VTOH(vp);
65 1.3.12.2 yamt
66 1.3.12.2 yamt vp->v_type = hfs_catalog_keyed_record_vtype(
67 1.3.12.2 yamt (hfs_catalog_keyed_record_t *)&hp->h_rec);
68 1.3.12.2 yamt
69 1.3.12.2 yamt switch(vp->v_type) {
70 1.3.12.2 yamt case VCHR:
71 1.3.12.2 yamt case VBLK:
72 1.3.12.2 yamt vp->v_op = specops;
73 1.3.12.2 yamt if ((nvp = checkalias(vp,
74 1.3.12.2 yamt HFS_CONVERT_RDEV(hp->h_rec.file.bsd.special.raw_device),
75 1.3.12.2 yamt mp)) != NULL) {
76 1.3.12.2 yamt /*
77 1.3.12.2 yamt * Discard unneeded vnode, but save its inode.
78 1.3.12.2 yamt */
79 1.3.12.2 yamt nvp->v_data = vp->v_data;
80 1.3.12.2 yamt vp->v_data = NULL;
81 1.3.12.2 yamt /* XXX spec_vnodeops has no locking,
82 1.3.12.2 yamt do it explicitly */
83 1.3.12.2 yamt VOP_UNLOCK(vp, 0);
84 1.3.12.2 yamt vp->v_op = specops;
85 1.3.12.2 yamt vp->v_flag &= ~VLOCKSWORK;
86 1.3.12.2 yamt vrele(vp);
87 1.3.12.2 yamt vgone(vp);
88 1.3.12.2 yamt lockmgr(&nvp->v_lock, LK_EXCLUSIVE,
89 1.3.12.2 yamt &nvp->v_interlock);
90 1.3.12.2 yamt /*
91 1.3.12.2 yamt * Reinitialize aliased inode.
92 1.3.12.2 yamt */
93 1.3.12.2 yamt vp = nvp;
94 1.3.12.2 yamt hp->h_vnode = vp;
95 1.3.12.2 yamt }
96 1.3.12.2 yamt break;
97 1.3.12.2 yamt case VFIFO:
98 1.3.12.2 yamt vp->v_op = fifoops;
99 1.3.12.2 yamt break;
100 1.3.12.2 yamt
101 1.3.12.2 yamt case VNON:
102 1.3.12.2 yamt case VBAD:
103 1.3.12.2 yamt case VSOCK:
104 1.3.12.2 yamt case VDIR:
105 1.3.12.2 yamt case VREG:
106 1.3.12.2 yamt case VLNK:
107 1.3.12.2 yamt break;
108 1.3.12.2 yamt }
109 1.3.12.2 yamt
110 1.3.12.2 yamt if (hp->h_rec.cnid == HFS_CNID_ROOT_FOLDER)
111 1.3.12.2 yamt vp->v_flag |= VROOT;
112 1.3.12.2 yamt
113 1.3.12.2 yamt *vpp = vp;
114 1.3.12.2 yamt }
115 1.3.12.2 yamt
116 1.3.12.2 yamt /*
117 1.3.12.2 yamt * Callbacks for libhfs
118 1.3.12.2 yamt */
119 1.3.12.2 yamt
120 1.3.12.2 yamt void
121 1.3.12.2 yamt hfs_libcb_error(
122 1.3.12.2 yamt const char* format,
123 1.3.12.2 yamt const char* file,
124 1.3.12.2 yamt int line,
125 1.3.12.2 yamt va_list args)
126 1.3.12.2 yamt {
127 1.3.12.2 yamt #ifdef HFS_DEBUG
128 1.3.12.2 yamt if (file != NULL)
129 1.3.12.2 yamt printf("%s:%i: ", file, line);
130 1.3.12.2 yamt else
131 1.3.12.2 yamt printf("hfs: ");
132 1.3.12.2 yamt #else
133 1.3.12.2 yamt printf("hfs: ");
134 1.3.12.2 yamt #endif
135 1.3.12.2 yamt
136 1.3.12.2 yamt /* XXX Should we really display this if debugging is off? */
137 1.3.12.2 yamt vprintf(format, args);
138 1.3.12.2 yamt printf("\n");
139 1.3.12.2 yamt }
140 1.3.12.2 yamt
141 1.3.12.2 yamt /* XXX change malloc/realloc/free to use pools */
142 1.3.12.2 yamt
143 1.3.12.2 yamt void*
144 1.3.12.2 yamt hfs_libcb_malloc(size_t size, hfs_callback_args* cbargs)
145 1.3.12.2 yamt {
146 1.3.12.2 yamt return malloc(size, /*M_HFSMNT*/ M_TEMP, M_WAITOK);
147 1.3.12.2 yamt }
148 1.3.12.2 yamt
149 1.3.12.2 yamt void*
150 1.3.12.2 yamt hfs_libcb_realloc(void* ptr, size_t size, hfs_callback_args* cbargs)
151 1.3.12.2 yamt {
152 1.3.12.2 yamt return realloc(ptr, size, /*M_HFSMNT*/ M_TEMP, M_WAITOK);
153 1.3.12.2 yamt }
154 1.3.12.2 yamt
155 1.3.12.2 yamt void
156 1.3.12.2 yamt hfs_libcb_free(void* ptr, hfs_callback_args* cbargs)
157 1.3.12.2 yamt {
158 1.3.12.2 yamt free(ptr, /*M_HFSMNT*/ M_TEMP);
159 1.3.12.2 yamt }
160 1.3.12.2 yamt
161 1.3.12.2 yamt /*
162 1.3.12.2 yamt * hfs_libcb_opendev()
163 1.3.12.2 yamt *
164 1.3.12.2 yamt * hfslib uses this callback to open a volume's device node by name. However,
165 1.3.12.2 yamt * by the time this is called here, the device node has already been opened by
166 1.3.12.2 yamt * VFS. So we are passed the vnode to this volume's block device and use that
167 1.3.12.2 yamt * instead of the device's name.
168 1.3.12.2 yamt */
169 1.3.12.2 yamt int
170 1.3.12.2 yamt hfs_libcb_opendev(
171 1.3.12.2 yamt hfs_volume* vol,
172 1.3.12.2 yamt const char* devname,
173 1.3.12.2 yamt hfs_callback_args* cbargs)
174 1.3.12.2 yamt {
175 1.3.12.2 yamt hfs_libcb_data* cbdata = NULL;
176 1.3.12.2 yamt hfs_libcb_argsopen* args;
177 1.3.12.2 yamt struct partinfo dpart;
178 1.3.12.2 yamt int result;
179 1.3.12.2 yamt
180 1.3.12.2 yamt result = 0;
181 1.3.12.2 yamt args = (hfs_libcb_argsopen*)(cbargs->openvol);
182 1.3.12.2 yamt
183 1.3.12.2 yamt if (vol == NULL || devname == NULL) {
184 1.3.12.2 yamt result = EINVAL;
185 1.3.12.2 yamt goto error;
186 1.3.12.2 yamt }
187 1.3.12.2 yamt
188 1.3.12.2 yamt cbdata = malloc(sizeof(hfs_libcb_data), M_HFSMNT, M_WAITOK);
189 1.3.12.2 yamt if (cbdata == NULL) {
190 1.3.12.2 yamt result = ENOMEM;
191 1.3.12.2 yamt goto error;
192 1.3.12.2 yamt }
193 1.3.12.2 yamt vol->cbdata = cbdata;
194 1.3.12.2 yamt
195 1.3.12.2 yamt cbdata->devvp = NULL;
196 1.3.12.2 yamt
197 1.3.12.2 yamt /* Open the device node. */
198 1.3.12.2 yamt if ((result = VOP_OPEN(args->devvp, vol->readonly? FREAD : FREAD|FWRITE,
199 1.3.12.2 yamt FSCRED, args->l)) != 0)
200 1.3.12.2 yamt goto error;
201 1.3.12.2 yamt
202 1.3.12.2 yamt /* Flush out any old buffers remaining from a previous use. */
203 1.3.12.2 yamt vn_lock(args->devvp, LK_EXCLUSIVE | LK_RETRY);
204 1.3.12.2 yamt result = vinvalbuf(args->devvp, V_SAVE, args->cred, args->l, 0, 0);
205 1.3.12.2 yamt VOP_UNLOCK(args->devvp, 0);
206 1.3.12.2 yamt if (result != 0)
207 1.3.12.2 yamt goto error;
208 1.3.12.2 yamt
209 1.3.12.2 yamt cbdata->devvp = args->devvp;
210 1.3.12.2 yamt
211 1.3.12.2 yamt /* Determine the device's block size. Default to DEV_BSIZE if unavailable.*/
212 1.3.12.2 yamt if (VOP_IOCTL(args->devvp, DIOCGPART, &dpart, FREAD, args->cred, args->l)
213 1.3.12.2 yamt != 0)
214 1.3.12.2 yamt cbdata->devblksz = DEV_BSIZE;
215 1.3.12.2 yamt else
216 1.3.12.2 yamt cbdata->devblksz = dpart.disklab->d_secsize;
217 1.3.12.2 yamt
218 1.3.12.2 yamt return 0;
219 1.3.12.2 yamt
220 1.3.12.2 yamt error:
221 1.3.12.2 yamt if (cbdata != NULL) {
222 1.3.12.2 yamt if (cbdata->devvp != NULL) {
223 1.3.12.2 yamt vn_lock(cbdata->devvp, LK_EXCLUSIVE | LK_RETRY);
224 1.3.12.2 yamt (void)VOP_CLOSE(cbdata->devvp, vol->readonly ? FREAD :
225 1.3.12.2 yamt FREAD | FWRITE, NOCRED, args->l);
226 1.3.12.2 yamt VOP_UNLOCK(cbdata->devvp, 0);
227 1.3.12.2 yamt }
228 1.3.12.2 yamt free(cbdata, M_HFSMNT);
229 1.3.12.2 yamt vol->cbdata = NULL;
230 1.3.12.2 yamt }
231 1.3.12.2 yamt
232 1.3.12.2 yamt return result;
233 1.3.12.2 yamt }
234 1.3.12.2 yamt
235 1.3.12.2 yamt void
236 1.3.12.2 yamt hfs_libcb_closedev(hfs_volume* in_vol, hfs_callback_args* cbargs)
237 1.3.12.2 yamt {
238 1.3.12.2 yamt struct vnode *devvp;
239 1.3.12.2 yamt
240 1.3.12.2 yamt if (in_vol == NULL)
241 1.3.12.2 yamt return;
242 1.3.12.2 yamt
243 1.3.12.2 yamt if (in_vol->cbdata != NULL) {
244 1.3.12.2 yamt devvp = ((hfs_libcb_data*)in_vol->cbdata)->devvp;
245 1.3.12.2 yamt if (devvp != NULL) {
246 1.3.12.2 yamt vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
247 1.3.12.2 yamt (void)VOP_CLOSE(devvp, in_vol->readonly ? FREAD : FREAD | FWRITE,
248 1.3.12.2 yamt NOCRED, ((hfs_libcb_argsclose*)cbargs->closevol)->l);
249 1.3.12.2 yamt /* XXX do we need a VOP_UNLOCK() here? */
250 1.3.12.2 yamt }
251 1.3.12.2 yamt
252 1.3.12.2 yamt free(in_vol->cbdata, M_HFSMNT);
253 1.3.12.2 yamt in_vol->cbdata = NULL;
254 1.3.12.2 yamt }
255 1.3.12.2 yamt }
256 1.3.12.2 yamt
257 1.3.12.2 yamt int
258 1.3.12.2 yamt hfs_libcb_read(
259 1.3.12.2 yamt hfs_volume* vol,
260 1.3.12.2 yamt void* outbytes,
261 1.3.12.2 yamt uint64_t length,
262 1.3.12.2 yamt uint64_t offset,
263 1.3.12.2 yamt hfs_callback_args* cbargs)
264 1.3.12.2 yamt {
265 1.3.12.2 yamt hfs_libcb_data *cbdata;
266 1.3.12.2 yamt hfs_libcb_argsread* argsread;
267 1.3.12.2 yamt kauth_cred_t cred;
268 1.3.12.2 yamt uint64_t physoffset; /* physical offset from start of device(?) */
269 1.3.12.2 yamt
270 1.3.12.2 yamt if (vol == NULL || outbytes == NULL)
271 1.3.12.2 yamt return -1;
272 1.3.12.2 yamt
273 1.3.12.2 yamt cbdata = (hfs_libcb_data*)vol->cbdata;
274 1.3.12.2 yamt
275 1.3.12.2 yamt if (cbargs != NULL
276 1.3.12.2 yamt && (argsread = (hfs_libcb_argsread*)cbargs->read) != NULL
277 1.3.12.2 yamt && argsread->cred != NULL)
278 1.3.12.2 yamt cred = argsread->cred;
279 1.3.12.2 yamt else
280 1.3.12.2 yamt cred = NOCRED;
281 1.3.12.2 yamt
282 1.3.12.2 yamt /*
283 1.3.12.2 yamt * Since bread() only reads data in terms of integral blocks, it may have
284 1.3.12.2 yamt * read some data before and/or after our desired offset & length. So when
285 1.3.12.2 yamt * copying that data into the outgoing buffer, start at the actual desired
286 1.3.12.2 yamt * offset and only copy the desired length.
287 1.3.12.2 yamt */
288 1.3.12.2 yamt physoffset = offset + vol->offset;
289 1.3.12.2 yamt
290 1.3.12.2 yamt return hfs_pread(cbdata->devvp, outbytes, cbdata->devblksz, physoffset,
291 1.3.12.2 yamt length, cred);
292 1.3.12.2 yamt }
293 1.3.12.2 yamt
294 1.3.12.2 yamt /*
295 1.3.12.2 yamt * So it turns out that bread() is pretty shoddy. It not only requires the size
296 1.3.12.2 yamt * parameter to be an integral multiple of the device's block size, but also
297 1.3.12.2 yamt * requires the block number to be on a boundary of that same block size -- and
298 1.3.12.2 yamt * yet be given as an integral multiple of DEV_BSIZE! So after much toil and
299 1.3.12.2 yamt * bloodshed, hfs_pread() was written as a convenience (and a model of how sane
300 1.3.12.2 yamt * people take their bread()). Returns 0 on success.
301 1.3.12.2 yamt */
302 1.3.12.2 yamt int
303 1.3.12.2 yamt hfs_pread(struct vnode *vp, void *buf, size_t secsz, uint64_t off,
304 1.3.12.2 yamt uint64_t len, kauth_cred_t cred)
305 1.3.12.2 yamt {
306 1.3.12.2 yamt struct buf *bp;
307 1.3.12.2 yamt uint64_t curoff; /* relative to 'start' variable */
308 1.3.12.2 yamt uint64_t start;
309 1.3.12.2 yamt int error;
310 1.3.12.2 yamt
311 1.3.12.2 yamt if (vp == NULL || buf == NULL)
312 1.3.12.2 yamt return EINVAL;
313 1.3.12.2 yamt
314 1.3.12.2 yamt if (len == 0)
315 1.3.12.2 yamt return 0;
316 1.3.12.2 yamt
317 1.3.12.2 yamt curoff = 0;
318 1.3.12.2 yamt error = 0;
319 1.3.12.2 yamt
320 1.3.12.2 yamt /* align offset to highest preceding sector boundary */
321 1.3.12.2 yamt #define ABSZ(x, bsz) (((x)/(bsz))*(bsz))
322 1.3.12.2 yamt
323 1.3.12.2 yamt /* round size up to integral # of block sizes */
324 1.3.12.2 yamt #define RBSZ(x, bsz) (((x) + (bsz) - 1) & ~((bsz) - 1))
325 1.3.12.2 yamt
326 1.3.12.2 yamt start = ABSZ(off, secsz);
327 1.3.12.2 yamt while (start + curoff < off + len)
328 1.3.12.2 yamt {
329 1.3.12.2 yamt bp = NULL;
330 1.3.12.2 yamt
331 1.3.12.2 yamt /* XXX Does the algorithm always do what's intended here when
332 1.3.12.2 yamt * XXX start != off? Need to test this. */
333 1.3.12.2 yamt
334 1.3.12.2 yamt error = bread(vp, (start + curoff) / DEV_BSIZE,/* no rounding involved*/
335 1.3.12.2 yamt RBSZ(min(len - curoff + (off - start), MAXBSIZE), secsz), cred, &bp);
336 1.3.12.2 yamt
337 1.3.12.2 yamt if (error == 0)
338 1.3.12.2 yamt memcpy((uint8_t*)buf + curoff, (uint8_t*)bp->b_data +
339 1.3.12.2 yamt (off - start), min(len - curoff, MAXBSIZE - (off - start)));
340 1.3.12.2 yamt
341 1.3.12.2 yamt if (bp != NULL)
342 1.3.12.2 yamt brelse(bp);
343 1.3.12.2 yamt if (error != 0)
344 1.3.12.2 yamt return error;
345 1.3.12.2 yamt
346 1.3.12.2 yamt curoff += MAXBSIZE;
347 1.3.12.2 yamt }
348 1.3.12.2 yamt #undef ABSZ
349 1.3.12.2 yamt #undef RBSZ
350 1.3.12.2 yamt
351 1.3.12.2 yamt return 0;
352 1.3.12.2 yamt }
353 1.3.12.2 yamt
354 1.3.12.2 yamt /* XXX Provide a routine to take a catalog record and return its proper BSD file
355 1.3.12.2 yamt * XXX or directory mode value */
356 1.3.12.2 yamt
357 1.3.12.2 yamt
358 1.3.12.2 yamt /* Convert from HFS+ time representation to UNIX time since epoch. */
359 1.3.12.2 yamt void
360 1.3.12.2 yamt hfs_time_to_timespec(uint32_t hfstime, struct timespec *unixtime)
361 1.3.12.2 yamt {
362 1.3.12.2 yamt /*
363 1.3.12.2 yamt * HFS+ time is calculated in seconds since midnight, Jan 1st, 1904.
364 1.3.12.2 yamt * struct timespec counts from midnight, Jan 1st, 1970. Thus, there is
365 1.3.12.2 yamt * precisely a 66 year difference between them, which is equal to
366 1.3.12.2 yamt * 2,082,844,800 seconds. No, I didn't count them by hand.
367 1.3.12.2 yamt */
368 1.3.12.2 yamt
369 1.3.12.2 yamt if (hfstime < 2082844800)
370 1.3.12.2 yamt unixtime->tv_sec = 0; /* dates before 1970 are bs anyway, so use epoch*/
371 1.3.12.2 yamt else
372 1.3.12.2 yamt unixtime->tv_sec = hfstime - 2082844800;
373 1.3.12.2 yamt
374 1.3.12.2 yamt unixtime->tv_nsec = 0; /* we don't have nanosecond resolution */
375 1.3.12.2 yamt }
376 1.3.12.2 yamt
377 1.3.12.2 yamt /*
378 1.3.12.2 yamt * Endian conversion with automatic pointer incrementation.
379 1.3.12.2 yamt */
380 1.3.12.2 yamt
381 1.3.12.2 yamt uint16_t be16tohp(void** inout_ptr)
382 1.3.12.2 yamt {
383 1.3.12.2 yamt uint16_t result;
384 1.3.12.2 yamt uint16_t *ptr;
385 1.3.12.2 yamt
386 1.3.12.2 yamt if(inout_ptr==NULL)
387 1.3.12.2 yamt return 0;
388 1.3.12.2 yamt
389 1.3.12.2 yamt ptr = *inout_ptr;
390 1.3.12.2 yamt
391 1.3.12.2 yamt result = be16toh(*ptr);
392 1.3.12.2 yamt
393 1.3.12.2 yamt ptr++;
394 1.3.12.2 yamt *inout_ptr = ptr;
395 1.3.12.2 yamt
396 1.3.12.2 yamt return result;
397 1.3.12.2 yamt }
398 1.3.12.2 yamt
399 1.3.12.2 yamt uint32_t be32tohp(void** inout_ptr)
400 1.3.12.2 yamt {
401 1.3.12.2 yamt uint32_t result;
402 1.3.12.2 yamt uint32_t *ptr;
403 1.3.12.2 yamt
404 1.3.12.2 yamt if(inout_ptr==NULL)
405 1.3.12.2 yamt return 0;
406 1.3.12.2 yamt
407 1.3.12.2 yamt ptr = *inout_ptr;
408 1.3.12.2 yamt
409 1.3.12.2 yamt result = be32toh(*ptr);
410 1.3.12.2 yamt
411 1.3.12.2 yamt ptr++;
412 1.3.12.2 yamt *inout_ptr = ptr;
413 1.3.12.2 yamt
414 1.3.12.2 yamt return result;
415 1.3.12.2 yamt }
416 1.3.12.2 yamt
417 1.3.12.2 yamt uint64_t be64tohp(void** inout_ptr)
418 1.3.12.2 yamt {
419 1.3.12.2 yamt uint64_t result;
420 1.3.12.2 yamt uint64_t *ptr;
421 1.3.12.2 yamt
422 1.3.12.2 yamt if(inout_ptr==NULL)
423 1.3.12.2 yamt return 0;
424 1.3.12.2 yamt
425 1.3.12.2 yamt ptr = *inout_ptr;
426 1.3.12.2 yamt
427 1.3.12.2 yamt result = be64toh(*ptr);
428 1.3.12.2 yamt
429 1.3.12.2 yamt ptr++;
430 1.3.12.2 yamt *inout_ptr = ptr;
431 1.3.12.2 yamt
432 1.3.12.2 yamt return result;
433 1.3.12.2 yamt }
434 1.3.12.2 yamt
435 1.3.12.2 yamt enum vtype
436 1.3.12.2 yamt hfs_catalog_keyed_record_vtype(const hfs_catalog_keyed_record_t *rec)
437 1.3.12.2 yamt {
438 1.3.12.2 yamt if (rec->type == HFS_REC_FILE) {
439 1.3.12.2 yamt uint32_t mode;
440 1.3.12.2 yamt
441 1.3.12.2 yamt mode = ((const hfs_file_record_t *)rec)->bsd.file_mode;
442 1.3.12.2 yamt if (mode != 0)
443 1.3.12.2 yamt return IFTOVT(mode);
444 1.3.12.2 yamt else
445 1.3.12.2 yamt return VREG;
446 1.3.12.2 yamt }
447 1.3.12.2 yamt else
448 1.3.12.2 yamt return VDIR;
449 1.3.12.2 yamt }
450