xref: /netbsd-src/sys/fs/hfs/hfs_vfsops.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: hfs_vfsops.c,v 1.29 2012/06/13 22:56:50 joerg Exp $	*/
2 
3 /*-
4  * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Yevgeny Binder and Dieter Baron.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1991, 1993, 1994
34  *	The Regents of the University of California.  All rights reserved.
35  * (c) UNIX System Laboratories, Inc.
36  * All or some portions of this file are derived from material licensed
37  * to the University of California by American Telephone and Telegraph
38  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
39  * the permission of UNIX System Laboratories, Inc.
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  * 1. Redistributions of source code must retain the above copyright
45  *    notice, this list of conditions and the following disclaimer.
46  * 2. Redistributions in binary form must reproduce the above copyright
47  *    notice, this list of conditions and the following disclaimer in the
48  *    documentation and/or other materials provided with the distribution.
49  * 3. Neither the name of the University nor the names of its contributors
50  *    may be used to endorse or promote products derived from this software
51  *    without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63  * SUCH DAMAGE.
64  */
65 
66  /*
67  * Copyright (c) 1989, 1991, 1993, 1994
68  *	The Regents of the University of California.  All rights reserved.
69  *
70  * Redistribution and use in source and binary forms, with or without
71  * modification, are permitted provided that the following conditions
72  * are met:
73  * 1. Redistributions of source code must retain the above copyright
74  *    notice, this list of conditions and the following disclaimer.
75  * 2. Redistributions in binary form must reproduce the above copyright
76  *    notice, this list of conditions and the following disclaimer in the
77  *    documentation and/or other materials provided with the distribution.
78  * 3. Neither the name of the University nor the names of its contributors
79  *    may be used to endorse or promote products derived from this software
80  *    without specific prior written permission.
81  *
82  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
83  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
86  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92  * SUCH DAMAGE.
93  */
94 
95 
96 
97 /*
98  * Apple HFS+ filesystem
99  */
100 
101 #include <sys/cdefs.h>
102 __KERNEL_RCSID(0, "$NetBSD: hfs_vfsops.c,v 1.29 2012/06/13 22:56:50 joerg Exp $");
103 
104 #ifdef _KERNEL_OPT
105 #include "opt_compat_netbsd.h"
106 #endif
107 
108 #include <sys/param.h>
109 #include <sys/systm.h>
110 #include <sys/namei.h>
111 #include <sys/proc.h>
112 #include <sys/kernel.h>
113 #include <sys/vnode.h>
114 #include <sys/socket.h>
115 #include <sys/mount.h>
116 #include <sys/buf.h>
117 #include <sys/device.h>
118 #include <sys/mbuf.h>
119 #include <sys/file.h>
120 #include <sys/disklabel.h>
121 #include <sys/ioctl.h>
122 #include <sys/errno.h>
123 #include <sys/malloc.h>
124 #include <sys/pool.h>
125 #include <sys/lock.h>
126 #include <sys/sysctl.h>
127 #include <sys/conf.h>
128 #include <sys/kauth.h>
129 #include <sys/stat.h>
130 #include <sys/module.h>
131 
132 #include <miscfs/genfs/genfs.h>
133 #include <miscfs/specfs/specdev.h>
134 
135 #include <fs/hfs/hfs.h>
136 #include <fs/hfs/libhfs.h>
137 
138 MODULE(MODULE_CLASS_VFS, hfs, NULL);
139 
140 MALLOC_JUSTDEFINE(M_HFSMNT, "hfs mount", "hfs mount structures");
141 
142 extern kmutex_t hfs_hashlock;
143 
144 const struct vnodeopv_desc * const hfs_vnodeopv_descs[] = {
145 	&hfs_vnodeop_opv_desc,
146 	&hfs_specop_opv_desc,
147 	&hfs_fifoop_opv_desc,
148 	NULL,
149 };
150 
151 struct vfsops hfs_vfsops = {
152 	MOUNT_HFS,
153 	sizeof (struct hfs_args),
154 	hfs_mount,
155 	hfs_start,
156 	hfs_unmount,
157 	hfs_root,
158 	(void *)eopnotsupp,		/* vfs_quotactl */
159 	hfs_statvfs,
160 	hfs_sync,
161 	hfs_vget,
162 	hfs_fhtovp,
163 	hfs_vptofh,
164 	hfs_init,
165 	hfs_reinit,
166 	hfs_done,
167 	NULL,				/* vfs_mountroot */
168 	NULL,				/* vfs_snapshot */
169 	vfs_stdextattrctl,
170 	(void *)eopnotsupp,		/* vfs_suspendctl */
171 	genfs_renamelock_enter,
172 	genfs_renamelock_exit,
173 	(void *)eopnotsupp,
174 	hfs_vnodeopv_descs,
175 	0,
176 	{ NULL, NULL },
177 };
178 
179 static const struct genfs_ops hfs_genfsops = {
180         .gop_size = genfs_size,
181 };
182 
183 static int
184 hfs_modcmd(modcmd_t cmd, void *arg)
185 {
186 
187 	switch (cmd) {
188 	case MODULE_CMD_INIT:
189 		return vfs_attach(&hfs_vfsops);
190 	case MODULE_CMD_FINI:
191 		return vfs_detach(&hfs_vfsops);
192 	default:
193 		return ENOTTY;
194 	}
195 }
196 
197 int
198 hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
199 {
200 	struct lwp *l = curlwp;
201 	struct hfs_args *args = data;
202 	struct vnode *devvp;
203 	struct hfsmount *hmp;
204 	int error = 0;
205 	int update;
206 	mode_t accessmode;
207 
208 	if (*data_len < sizeof *args)
209 		return EINVAL;
210 
211 #ifdef HFS_DEBUG
212 	printf("vfsop = hfs_mount()\n");
213 #endif /* HFS_DEBUG */
214 
215 	if (mp->mnt_flag & MNT_GETARGS) {
216 		hmp = VFSTOHFS(mp);
217 		if (hmp == NULL)
218 			return EIO;
219 		args->fspec = NULL;
220 		*data_len = sizeof *args;
221 		return 0;
222 	}
223 
224 	if (data == NULL)
225 		return EINVAL;
226 
227 /* FIXME: For development ONLY - disallow remounting for now */
228 #if 0
229 	update = mp->mnt_flag & MNT_UPDATE;
230 #else
231 	update = 0;
232 #endif
233 
234 	/* Check arguments */
235 	if (args->fspec != NULL) {
236 		/*
237 		 * Look up the name and verify that it's sane.
238 		 */
239 		error = namei_simple_user(args->fspec,
240 					NSM_FOLLOW_NOEMULROOT, &devvp);
241 		if (error != 0)
242 			return error;
243 
244 		if (!update) {
245 			/*
246 			 * Be sure this is a valid block device
247 			 */
248 			if (devvp->v_type != VBLK)
249 				error = ENOTBLK;
250 			else if (bdevsw_lookup(devvp->v_rdev) == NULL)
251 				error = ENXIO;
252 		} else {
253 			/*
254 			 * Be sure we're still naming the same device
255 			 * used for our initial mount
256 			 */
257 			hmp = VFSTOHFS(mp);
258 			if (devvp != hmp->hm_devvp)
259 				error = EINVAL;
260 		}
261 	} else {
262 		if (update) {
263 			/* Use the extant mount */
264 			hmp = VFSTOHFS(mp);
265 			devvp = hmp->hm_devvp;
266 			vref(devvp);
267 		} else {
268 			/* New mounts must have a filename for the device */
269 			return EINVAL;
270 		}
271 	}
272 
273 
274 	/*
275 	 * If mount by non-root, then verify that user has necessary
276 	 * permissions on the device.
277 	 *
278 	 * Permission to update a mount is checked higher, so here we presume
279 	 * updating the mount is okay (for example, as far as securelevel goes)
280 	 * which leaves us with the normal check.
281 	 */
282 	if (error == 0) {
283 		accessmode = VREAD;
284 		if (update ?
285 			(mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
286 			(mp->mnt_flag & MNT_RDONLY) == 0)
287 			accessmode |= VWRITE;
288 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
289 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
290 		    KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp,
291 		    KAUTH_ARG(accessmode));
292 		VOP_UNLOCK(devvp);
293 	}
294 
295 	if (error != 0)
296 		goto error;
297 
298 	if (update) {
299 		printf("HFS: live remounting not yet supported!\n");
300 		error = EINVAL;
301 		goto error;
302 	}
303 
304 	if ((error = hfs_mountfs(devvp, mp, l, args->fspec)) != 0)
305 		goto error;
306 
307 	error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
308 		mp->mnt_op->vfs_name, mp, l);
309 
310 #ifdef HFS_DEBUG
311 	if(!update) {
312 		char* volname;
313 
314 		hmp = VFSTOHFS(mp);
315 		volname = malloc(hmp->hm_vol.name.length + 1, M_TEMP, M_WAITOK);
316 		if (volname == NULL)
317 			printf("could not allocate volname; ignored\n");
318 		else {
319 			if (hfs_unicode_to_ascii(hmp->hm_vol.name.unicode,
320 				hmp->hm_vol.name.length, volname) == NULL)
321 				printf("could not convert volume name to ascii; ignored\n");
322 			else
323 				printf("mounted volume \"%s\"\n", volname);
324 			free(volname, M_TEMP);
325 		}
326 	}
327 #endif /* HFS_DEBUG */
328 
329 	return error;
330 
331 error:
332 	vrele(devvp);
333 	return error;
334 }
335 
336 int
337 hfs_start(struct mount *mp, int flags)
338 {
339 
340 #ifdef HFS_DEBUG
341 	printf("vfsop = hfs_start()\n");
342 #endif /* HFS_DEBUG */
343 
344 	return 0;
345 }
346 
347 int
348 hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l,
349     const char *devpath)
350 {
351 	hfs_callback_args cbargs;
352 	hfs_libcb_argsopen argsopen;
353 	hfs_libcb_argsread argsread;
354 	struct hfsmount *hmp;
355 	kauth_cred_t cred;
356 	int error;
357 
358 	cred = l ? l->l_cred : NOCRED;
359 	error = 0;
360 	hmp = NULL;
361 
362 	/* Create mounted volume structure. */
363 	hmp = (struct hfsmount*)malloc(sizeof(struct hfsmount),
364             M_HFSMNT, M_WAITOK);
365 	if (hmp == NULL) {
366 		error = ENOMEM;
367 		goto error;
368 	}
369 	memset(hmp, 0, sizeof(struct hfsmount));
370 
371 	mp->mnt_data = hmp;
372 	mp->mnt_flag |= MNT_LOCAL;
373 	vfs_getnewfsid(mp);
374 
375 	hmp->hm_mountp = mp;
376 	hmp->hm_dev = devvp->v_rdev;
377 	hmp->hm_devvp = devvp;
378 
379 	/*
380 	 * Use libhfs to open the volume and read the volume header and other
381 	 * useful information.
382 	 */
383 
384 	hfslib_init_cbargs(&cbargs);
385 	argsopen.cred = argsread.cred = cred;
386 	argsopen.l = argsread.l = l;
387 	argsopen.devvp = devvp;
388 	cbargs.read = (void*)&argsread;
389 	cbargs.openvol = (void*)&argsopen;
390 
391 	if ((error = hfslib_open_volume(devpath, mp->mnt_flag & MNT_RDONLY,
392 		&hmp->hm_vol, &cbargs)) != 0)
393 		goto error;
394 
395 	/* Make sure this is not a journaled volume whose journal is dirty. */
396 	if (!hfslib_is_journal_clean(&hmp->hm_vol)) {
397 		printf("volume journal is dirty; not mounting\n");
398 		error = EIO;
399 		goto error;
400 	}
401 
402 	mp->mnt_fs_bshift = 0;
403         while ((1 << mp->mnt_fs_bshift) < hmp->hm_vol.vh.block_size)
404 		mp->mnt_fs_bshift++;
405 	mp->mnt_dev_bshift = DEV_BSHIFT;
406 
407 	return 0;
408 
409 error:
410 	if (hmp != NULL)
411 		free(hmp, M_HFSMNT);
412 
413 	return error;
414 }
415 
416 int
417 hfs_unmount(struct mount *mp, int mntflags)
418 {
419 	hfs_callback_args cbargs;
420 	hfs_libcb_argsread argsclose;
421 	struct hfsmount* hmp;
422 	int error;
423 	int flags;
424 
425 #ifdef HFS_DEBUG
426 	printf("vfsop = hfs_unmount()\n");
427 #endif /* HFS_DEBUG */
428 
429 	hmp = VFSTOHFS(mp);
430 
431 	flags = 0;
432 	if (mntflags & MNT_FORCE)
433 		flags |= FORCECLOSE;
434 
435 	if ((error = vflush(mp, NULLVP, flags)) != 0)
436 		return error;
437 
438 	hfslib_init_cbargs(&cbargs);
439 	argsclose.l = curlwp;
440 	cbargs.closevol = (void*)&argsclose;
441 	hfslib_close_volume(&hmp->hm_vol, &cbargs);
442 
443 	vrele(hmp->hm_devvp);
444 
445 	free(hmp, M_HFSMNT);
446 	mp->mnt_data = NULL;
447 	mp->mnt_flag &= ~MNT_LOCAL;
448 
449 	return error;
450 }
451 
452 int
453 hfs_root(struct mount *mp, struct vnode **vpp)
454 {
455 	struct vnode *nvp;
456 	int error;
457 
458 #ifdef HFS_DEBUG
459 	printf("vfsop = hfs_root()\n");
460 #endif /* HFS_DEBUG */
461 
462 	if ((error = VFS_VGET(mp, HFS_CNID_ROOT_FOLDER, &nvp)) != 0)
463 		return error;
464 	*vpp = nvp;
465 
466 	return 0;
467 }
468 
469 int
470 hfs_statvfs(struct mount *mp, struct statvfs *sbp)
471 {
472 	hfs_volume_header_t *vh;
473 
474 #ifdef HFS_DEBUG
475 	printf("vfsop = hfs_statvfs()\n");
476 #endif /* HFS_DEBUG */
477 
478 	vh = &VFSTOHFS(mp)->hm_vol.vh;
479 
480 	sbp->f_bsize = vh->block_size;
481 	sbp->f_frsize = sbp->f_bsize;
482 	sbp->f_iosize = 4096;/* mac os x uses a 4 kb io size, so do the same */
483 	sbp->f_blocks = vh->total_blocks;
484 	sbp->f_bfree = vh->free_blocks; /* total free blocks */
485 	sbp->f_bavail = vh->free_blocks; /* blocks free for non superuser */
486 	sbp->f_bresvd = 0;
487 	sbp->f_files =  vh->file_count; /* total files */
488 	sbp->f_ffree = (1<<31) - vh->file_count; /* free file nodes */
489 	copy_statvfs_info(sbp, mp);
490 
491 	return 0;
492 }
493 
494 int
495 hfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
496 {
497 
498 #ifdef HFS_DEBUG
499 	printf("vfsop = hfs_sync()\n");
500 #endif /* HFS_DEBUG */
501 
502 	return 0;
503 }
504 
505 /*
506  * an ino_t corresponds directly to a CNID in our particular case,
507  * since both are conveniently 32-bit numbers
508  */
509 int
510 hfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
511 {
512     return hfs_vget_internal(mp, ino, HFS_DATAFORK, vpp);
513 }
514 
515 /*
516  * internal version with extra arguments to allow accessing resource fork
517  */
518 int
519 hfs_vget_internal(struct mount *mp, ino_t ino, uint8_t fork,
520     struct vnode **vpp)
521 {
522 	struct hfsmount *hmp;
523 	struct hfsnode *hnode;
524 	struct vnode *vp;
525 	hfs_callback_args cbargs;
526 	hfs_cnid_t cnid;
527 	hfs_catalog_keyed_record_t rec;
528 	hfs_catalog_key_t key; /* the search key used to find this file on disk */
529 	dev_t dev;
530 	int error;
531 
532 #ifdef HFS_DEBUG
533 	printf("vfsop = hfs_vget()\n");
534 #endif /* HFS_DEBUG */
535 
536 	hnode = NULL;
537 	vp = NULL;
538 	hmp = VFSTOHFS(mp);
539 	dev = hmp->hm_dev;
540 	cnid = (hfs_cnid_t)ino;
541 
542 	if (fork != HFS_RSRCFORK)
543 	    fork = HFS_DATAFORK;
544 
545  retry:
546 	/* Check if this vnode has already been allocated. If so, just return it. */
547 	if ((*vpp = hfs_nhashget(dev, cnid, fork, LK_EXCLUSIVE)) != NULL)
548 		return 0;
549 
550 	/* Allocate a new vnode/inode. */
551 	error = getnewvnode(VT_HFS, mp, hfs_vnodeop_p, NULL, &vp);
552 	if (error) {
553 		goto error;
554 	}
555 	hnode = malloc(sizeof(struct hfsnode), M_TEMP,
556 		M_WAITOK | M_ZERO);
557 
558 	/*
559 	 * If someone beat us to it while sleeping in getnewvnode(),
560 	 * push back the freshly allocated vnode we don't need, and return.
561 	 */
562 	mutex_enter(&hfs_hashlock);
563 	if (hfs_nhashget(dev, cnid, fork, 0) != NULL) {
564 		mutex_exit(&hfs_hashlock);
565 		ungetnewvnode(vp);
566 		free(hnode, M_TEMP);
567 		goto retry;
568 	}
569 
570 	vp->v_vflag |= VV_LOCKSWORK;
571 	vp->v_data = hnode;
572 	genfs_node_init(vp, &hfs_genfsops);
573 
574 	hnode->h_vnode = vp;
575 	hnode->h_hmp = hmp;
576 	hnode->dummy = 0x1337BABE;
577 
578 	/*
579 	 * We need to put this vnode into the hash chain and lock it so that other
580 	 * requests for this inode will block if they arrive while we are sleeping
581 	 * waiting for old data structures to be purged or for the contents of the
582 	 * disk portion of this inode to be read. The hash chain requires the node's
583 	 * device and cnid to be known. Since this information was passed in the
584 	 * arguments, fill in the appropriate hfsnode fields without reading having
585 	 * to read the disk.
586 	 */
587 	hnode->h_dev = dev;
588 	hnode->h_rec.u.cnid = cnid;
589 	hnode->h_fork = fork;
590 
591 	hfs_nhashinsert(hnode);
592 	mutex_exit(&hfs_hashlock);
593 
594 
595 	/*
596 	 * Read catalog record from disk.
597 	 */
598 	hfslib_init_cbargs(&cbargs);
599 
600 	if (hfslib_find_catalog_record_with_cnid(&hmp->hm_vol, cnid,
601 		&rec, &key, &cbargs) != 0) {
602 		vput(vp);
603 		error = EBADF;
604 		goto error;
605 	}
606 
607 	memcpy(&hnode->h_rec, &rec, sizeof(hnode->h_rec));
608 	hnode->h_parent = key.parent_cnid;
609 
610 	/* XXX Eventually need to add an "ignore permissions" mount option */
611 
612 	/*
613 	 * Now convert some of the catalog record's fields into values that make
614 	 * sense on this system.
615 	 */
616 	/* DATE AND TIME */
617 
618 	/*
619 	 * Initialize the vnode from the hfsnode, check for aliases.
620 	 * Note that the underlying vnode may change.
621 	 */
622 	hfs_vinit(mp, hfs_specop_p, hfs_fifoop_p, &vp);
623 
624 	hnode->h_devvp = hmp->hm_devvp;
625 	vref(hnode->h_devvp);  /* Increment the ref count to the volume's device. */
626 
627 	/* Make sure UVM has allocated enough memory. (?) */
628 	if (hnode->h_rec.u.rec_type == HFS_REC_FILE) {
629 		if (hnode->h_fork == HFS_DATAFORK)
630 			uvm_vnp_setsize(vp,
631 			    hnode->h_rec.file.data_fork.logical_size);
632 		else
633 			uvm_vnp_setsize(vp,
634 			    hnode->h_rec.file.rsrc_fork.logical_size);
635 	}
636 	else
637 		uvm_vnp_setsize(vp, 0); /* no directly reading directories */
638 
639 	*vpp = vp;
640 
641 	return 0;
642 
643 error:
644 	*vpp = NULL;
645 	return error;
646 }
647 
648 int
649 hfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
650 {
651 
652 #ifdef HFS_DEBUG
653 	printf("vfsop = hfs_fhtovp()\n");
654 #endif /* HFS_DEBUG */
655 
656 	return EOPNOTSUPP;
657 }
658 
659 int
660 hfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
661 {
662 
663 #ifdef HFS_DEBUG
664 	printf("vfsop = hfs_vptofh()\n");
665 #endif /* HFS_DEBUG */
666 
667 	return EOPNOTSUPP;
668 }
669 
670 void
671 hfs_init(void)
672 {
673 	hfs_callbacks	callbacks;
674 
675 #ifdef HFS_DEBUG
676 	printf("vfsop = hfs_init()\n");
677 #endif /* HFS_DEBUG */
678 
679 	malloc_type_attach(M_HFSMNT);
680 
681 	callbacks.error = hfs_libcb_error;
682 	callbacks.allocmem = hfs_libcb_malloc;
683 	callbacks.reallocmem = hfs_libcb_realloc;
684 	callbacks.freemem = hfs_libcb_free;
685 	callbacks.openvol = hfs_libcb_opendev;
686 	callbacks.closevol = hfs_libcb_closedev;
687 	callbacks.read = hfs_libcb_read;
688 
689 	hfs_nhashinit();
690 	hfslib_init(&callbacks);
691 }
692 
693 void
694 hfs_reinit(void)
695 {
696 
697 #ifdef HFS_DEBUG
698 	printf("vfsop = hfs_reinit()\n");
699 #endif /* HFS_DEBUG */
700 
701 	return;
702 }
703 
704 void
705 hfs_done(void)
706 {
707 
708 #ifdef HFS_DEBUG
709 	printf("vfsop = hfs_done()\n");
710 #endif /* HFS_DEBUG */
711 
712 	malloc_type_detach(M_HFSMNT);
713 
714 	hfslib_done();
715 	hfs_nhashdone();
716 }
717 
718 int
719 hfs_mountroot(void)
720 {
721 
722 #ifdef HFS_DEBUG
723 	printf("vfsop = hfs_mountroot()\n");
724 #endif /* HFS_DEBUG */
725 
726 	return EOPNOTSUPP;
727 }
728