xref: /netbsd-src/sys/fs/hfs/hfs_vfsops.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: hfs_vfsops.c,v 1.20 2008/12/17 20:51:35 cegger 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.20 2008/12/17 20:51:35 cegger 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 nameidata nd;
202 	struct hfs_args *args = data;
203 	struct vnode *devvp;
204 	struct hfsmount *hmp;
205 	int error;
206 	int update;
207 	mode_t accessmode;
208 
209 	if (*data_len < sizeof *args)
210 		return EINVAL;
211 
212 #ifdef HFS_DEBUG
213 	printf("vfsop = hfs_mount()\n");
214 #endif /* HFS_DEBUG */
215 
216 	if (mp->mnt_flag & MNT_GETARGS) {
217 		hmp = VFSTOHFS(mp);
218 		if (hmp == NULL)
219 			return EIO;
220 		args->fspec = NULL;
221 		*data_len = sizeof *args;
222 		return 0;
223 	}
224 
225 	if (data == NULL)
226 		return EINVAL;
227 
228 /* FIXME: For development ONLY - disallow remounting for now */
229 #if 0
230 	update = mp->mnt_flag & MNT_UPDATE;
231 #else
232 	update = 0;
233 #endif
234 
235 	/* Check arguments */
236 	if (args->fspec != NULL) {
237 		/*
238 		 * Look up the name and verify that it's sane.
239 		 */
240 		NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, args->fspec);
241 		if ((error = namei(&nd)) != 0)
242 			return error;
243 		devvp = nd.ni_vp;
244 
245 		if (!update) {
246 			/*
247 			 * Be sure this is a valid block device
248 			 */
249 			if (devvp->v_type != VBLK)
250 				error = ENOTBLK;
251 			else if (bdevsw_lookup(devvp->v_rdev) == NULL)
252 				error = ENXIO;
253 		} else {
254 			/*
255 			 * Be sure we're still naming the same device
256 			 * used for our initial mount
257 			 */
258 			hmp = VFSTOHFS(mp);
259 			if (devvp != hmp->hm_devvp)
260 				error = EINVAL;
261 		}
262 	} else {
263 		if (update) {
264 			/* Use the extant mount */
265 			hmp = VFSTOHFS(mp);
266 			devvp = hmp->hm_devvp;
267 			vref(devvp);
268 		} else {
269 			/* New mounts must have a filename for the device */
270 			return EINVAL;
271 		}
272 	}
273 
274 
275 	/*
276 	 * If mount by non-root, then verify that user has necessary
277 	 * permissions on the device.
278 	 */
279 	if (error == 0 && kauth_authorize_generic(l->l_cred,
280             KAUTH_GENERIC_ISSUSER, NULL) != 0) {
281 		accessmode = VREAD;
282 		if (update ?
283 			(mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
284 			(mp->mnt_flag & MNT_RDONLY) == 0)
285 			accessmode |= VWRITE;
286 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
287 		error = VOP_ACCESS(devvp, accessmode, l->l_cred);
288 		VOP_UNLOCK(devvp, 0);
289 	}
290 
291 	if (error != 0)
292 		goto error;
293 
294 	if (update) {
295 		printf("HFS: live remounting not yet supported!\n");
296 		error = EINVAL;
297 		goto error;
298 	}
299 
300 	if ((error = hfs_mountfs(devvp, mp, l, args->fspec)) != 0)
301 		goto error;
302 
303 	error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
304 		mp->mnt_op->vfs_name, mp, l);
305 
306 #ifdef HFS_DEBUG
307 	if(!update) {
308 		char* volname;
309 
310 		hmp = VFSTOHFS(mp);
311 		volname = malloc(hmp->hm_vol.name.length + 1, M_TEMP, M_WAITOK);
312 		if (volname == NULL)
313 			printf("could not allocate volname; ignored\n");
314 		else {
315 			if (hfs_unicode_to_ascii(hmp->hm_vol.name.unicode,
316 				hmp->hm_vol.name.length, volname) == NULL)
317 				printf("could not convert volume name to ascii; ignored\n");
318 			else
319 				printf("mounted volume \"%s\"\n", volname);
320 			free(volname, M_TEMP);
321 		}
322 	}
323 #endif /* HFS_DEBUG */
324 
325 	return error;
326 
327 error:
328 	vrele(devvp);
329 	return error;
330 }
331 
332 int
333 hfs_start(struct mount *mp, int flags)
334 {
335 
336 #ifdef HFS_DEBUG
337 	printf("vfsop = hfs_start()\n");
338 #endif /* HFS_DEBUG */
339 
340 	return 0;
341 }
342 
343 int
344 hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l,
345     const char *devpath)
346 {
347 	hfs_callback_args cbargs;
348 	hfs_libcb_argsopen argsopen;
349 	hfs_libcb_argsread argsread;
350 	struct hfsmount *hmp;
351 	kauth_cred_t cred;
352 	int error;
353 
354 	cred = l ? l->l_cred : NOCRED;
355 	error = 0;
356 	hmp = NULL;
357 
358 	/* Create mounted volume structure. */
359 	hmp = (struct hfsmount*)malloc(sizeof(struct hfsmount),
360             M_HFSMNT, M_WAITOK);
361 	if (hmp == NULL) {
362 		error = ENOMEM;
363 		goto error;
364 	}
365 	memset(hmp, 0, sizeof(struct hfsmount));
366 
367 	mp->mnt_data = hmp;
368 	mp->mnt_flag |= MNT_LOCAL;
369 	vfs_getnewfsid(mp);
370 
371 	hmp->hm_mountp = mp;
372 	hmp->hm_dev = devvp->v_rdev;
373 	hmp->hm_devvp = devvp;
374 
375 	/*
376 	 * Use libhfs to open the volume and read the volume header and other
377 	 * useful information.
378 	 */
379 
380 	hfslib_init_cbargs(&cbargs);
381 	argsopen.cred = argsread.cred = cred;
382 	argsopen.l = argsread.l = l;
383 	argsopen.devvp = devvp;
384 	cbargs.read = (void*)&argsread;
385 	cbargs.openvol = (void*)&argsopen;
386 
387 	if ((error = hfslib_open_volume(devpath, mp->mnt_flag & MNT_RDONLY,
388 		&hmp->hm_vol, &cbargs)) != 0)
389 		goto error;
390 
391 	/* Make sure this is not a journaled volume whose journal is dirty. */
392 	if (!hfslib_is_journal_clean(&hmp->hm_vol)) {
393 		printf("volume journal is dirty; not mounting\n");
394 		error = EIO;
395 		goto error;
396 	}
397 
398 	mp->mnt_fs_bshift = 0;
399         while ((1 << mp->mnt_fs_bshift) < hmp->hm_vol.vh.block_size)
400 		mp->mnt_fs_bshift++;
401 	mp->mnt_dev_bshift = DEV_BSHIFT;
402 
403 	return 0;
404 
405 error:
406 	if (hmp != NULL)
407 		free(hmp, M_HFSMNT);
408 
409 	return error;
410 }
411 
412 int
413 hfs_unmount(struct mount *mp, int mntflags)
414 {
415 	hfs_callback_args cbargs;
416 	hfs_libcb_argsread argsclose;
417 	struct hfsmount* hmp;
418 	int error;
419 	int flags;
420 
421 #ifdef HFS_DEBUG
422 	printf("vfsop = hfs_unmount()\n");
423 #endif /* HFS_DEBUG */
424 
425 	hmp = VFSTOHFS(mp);
426 
427 	flags = 0;
428 	if (mntflags & MNT_FORCE)
429 		flags |= FORCECLOSE;
430 
431 	if ((error = vflush(mp, NULLVP, flags)) != 0)
432 		return error;
433 
434 	hfslib_init_cbargs(&cbargs);
435 	argsclose.l = curlwp;
436 	cbargs.closevol = (void*)&argsclose;
437 	hfslib_close_volume(&hmp->hm_vol, &cbargs);
438 
439 	vput(hmp->hm_devvp);
440 
441 	free(hmp, M_HFSMNT);
442 	mp->mnt_data = NULL;
443 	mp->mnt_flag &= ~MNT_LOCAL;
444 
445 	return error;
446 }
447 
448 int
449 hfs_root(struct mount *mp, struct vnode **vpp)
450 {
451 	struct vnode *nvp;
452 	int error;
453 
454 #ifdef HFS_DEBUG
455 	printf("vfsop = hfs_root()\n");
456 #endif /* HFS_DEBUG */
457 
458 	if ((error = VFS_VGET(mp, HFS_CNID_ROOT_FOLDER, &nvp)) != 0)
459 		return error;
460 	*vpp = nvp;
461 
462 	return 0;
463 }
464 
465 int
466 hfs_statvfs(struct mount *mp, struct statvfs *sbp)
467 {
468 	hfs_volume_header_t *vh;
469 
470 #ifdef HFS_DEBUG
471 	printf("vfsop = hfs_statvfs()\n");
472 #endif /* HFS_DEBUG */
473 
474 	vh = &VFSTOHFS(mp)->hm_vol.vh;
475 
476 	sbp->f_bsize = vh->block_size;
477 	sbp->f_frsize = sbp->f_bsize;
478 	sbp->f_iosize = 4096;/* mac os x uses a 4 kb io size, so do the same */
479 	sbp->f_blocks = vh->total_blocks;
480 	sbp->f_bfree = vh->free_blocks; /* total free blocks */
481 	sbp->f_bavail = vh->free_blocks; /* blocks free for non superuser */
482 	sbp->f_bresvd = 0;
483 	sbp->f_files =  vh->file_count; /* total files */
484 	sbp->f_ffree = (1<<31) - vh->file_count; /* free file nodes */
485 	copy_statvfs_info(sbp, mp);
486 
487 	return 0;
488 }
489 
490 int
491 hfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
492 {
493 
494 #ifdef HFS_DEBUG
495 	printf("vfsop = hfs_sync()\n");
496 #endif /* HFS_DEBUG */
497 
498 	return 0;
499 }
500 
501 /*
502  * an ino_t corresponds directly to a CNID in our particular case,
503  * since both are conveniently 32-bit numbers
504  */
505 int
506 hfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
507 {
508     return hfs_vget_internal(mp, ino, HFS_DATAFORK, vpp);
509 }
510 
511 /*
512  * internal version with extra arguments to allow accessing resource fork
513  */
514 int
515 hfs_vget_internal(struct mount *mp, ino_t ino, uint8_t fork,
516     struct vnode **vpp)
517 {
518 	struct hfsmount *hmp;
519 	struct hfsnode *hnode;
520 	struct vnode *vp;
521 	hfs_callback_args cbargs;
522 	hfs_cnid_t cnid;
523 	hfs_catalog_keyed_record_t rec;
524 	hfs_catalog_key_t key; /* the search key used to find this file on disk */
525 	dev_t dev;
526 	int error;
527 
528 #ifdef HFS_DEBUG
529 	printf("vfsop = hfs_vget()\n");
530 #endif /* HFS_DEBUG */
531 
532 	hnode = NULL;
533 	vp = NULL;
534 	hmp = VFSTOHFS(mp);
535 	dev = hmp->hm_dev;
536 	cnid = (hfs_cnid_t)ino;
537 
538 	if (fork != HFS_RSRCFORK)
539 	    fork = HFS_DATAFORK;
540 
541  retry:
542 	/* Check if this vnode has already been allocated. If so, just return it. */
543 	if ((*vpp = hfs_nhashget(dev, cnid, fork, LK_EXCLUSIVE)) != NULL)
544 		return 0;
545 
546 	/* Allocate a new vnode/inode. */
547 	if ((error = getnewvnode(VT_HFS, mp, hfs_vnodeop_p, &vp)) != 0)
548 		goto error;
549 	hnode = malloc(sizeof(struct hfsnode), M_TEMP,
550 		M_WAITOK | M_ZERO);
551 
552 	/*
553 	 * If someone beat us to it while sleeping in getnewvnode(),
554 	 * push back the freshly allocated vnode we don't need, and return.
555 	 */
556 	mutex_enter(&hfs_hashlock);
557 	if (hfs_nhashget(dev, cnid, fork, 0) != NULL) {
558 		mutex_exit(&hfs_hashlock);
559 		ungetnewvnode(vp);
560 		free(hnode, M_TEMP);
561 		goto retry;
562 	}
563 
564 	vp->v_vflag |= VV_LOCKSWORK;
565 	vp->v_data = hnode;
566 	genfs_node_init(vp, &hfs_genfsops);
567 
568 	hnode->h_vnode = vp;
569 	hnode->h_hmp = hmp;
570 	hnode->dummy = 0x1337BABE;
571 
572 	/*
573 	 * We need to put this vnode into the hash chain and lock it so that other
574 	 * requests for this inode will block if they arrive while we are sleeping
575 	 * waiting for old data structures to be purged or for the contents of the
576 	 * disk portion of this inode to be read. The hash chain requires the node's
577 	 * device and cnid to be known. Since this information was passed in the
578 	 * arguments, fill in the appropriate hfsnode fields without reading having
579 	 * to read the disk.
580 	 */
581 	hnode->h_dev = dev;
582 	hnode->h_rec.u.cnid = cnid;
583 	hnode->h_fork = fork;
584 
585 	hfs_nhashinsert(hnode);
586 	mutex_exit(&hfs_hashlock);
587 
588 
589 	/*
590 	 * Read catalog record from disk.
591 	 */
592 	hfslib_init_cbargs(&cbargs);
593 
594 	if (hfslib_find_catalog_record_with_cnid(&hmp->hm_vol, cnid,
595 		&rec, &key, &cbargs) != 0) {
596 		vput(vp);
597 		error = EBADF;
598 		goto error;
599 	}
600 
601 	memcpy(&hnode->h_rec, &rec, sizeof(hnode->h_rec));
602 	hnode->h_parent = key.parent_cnid;
603 
604 	/* XXX Eventually need to add an "ignore permissions" mount option */
605 
606 	/*
607 	 * Now convert some of the catalog record's fields into values that make
608 	 * sense on this system.
609 	 */
610 	/* DATE AND TIME */
611 
612 	/*
613 	 * Initialize the vnode from the hfsnode, check for aliases.
614 	 * Note that the underlying vnode may change.
615 	 */
616 	hfs_vinit(mp, hfs_specop_p, hfs_fifoop_p, &vp);
617 
618 	hnode->h_devvp = hmp->hm_devvp;
619 	VREF(hnode->h_devvp);  /* Increment the ref count to the volume's device. */
620 
621 	/* Make sure UVM has allocated enough memory. (?) */
622 	if (hnode->h_rec.u.rec_type == HFS_REC_FILE) {
623 		if (hnode->h_fork == HFS_DATAFORK)
624 			uvm_vnp_setsize(vp,
625 			    hnode->h_rec.file.data_fork.logical_size);
626 		else
627 			uvm_vnp_setsize(vp,
628 			    hnode->h_rec.file.rsrc_fork.logical_size);
629 	}
630 	else
631 		uvm_vnp_setsize(vp, 0); /* no directly reading directories */
632 
633 	*vpp = vp;
634 
635 	return 0;
636 
637 error:
638 	*vpp = NULL;
639 	return error;
640 }
641 
642 int
643 hfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
644 {
645 
646 #ifdef HFS_DEBUG
647 	printf("vfsop = hfs_fhtovp()\n");
648 #endif /* HFS_DEBUG */
649 
650 	return EOPNOTSUPP;
651 }
652 
653 int
654 hfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
655 {
656 
657 #ifdef HFS_DEBUG
658 	printf("vfsop = hfs_vptofh()\n");
659 #endif /* HFS_DEBUG */
660 
661 	return EOPNOTSUPP;
662 }
663 
664 void
665 hfs_init(void)
666 {
667 	hfs_callbacks	callbacks;
668 
669 #ifdef HFS_DEBUG
670 	printf("vfsop = hfs_init()\n");
671 #endif /* HFS_DEBUG */
672 
673 	malloc_type_attach(M_HFSMNT);
674 
675 	callbacks.error = hfs_libcb_error;
676 	callbacks.allocmem = hfs_libcb_malloc;
677 	callbacks.reallocmem = hfs_libcb_realloc;
678 	callbacks.freemem = hfs_libcb_free;
679 	callbacks.openvol = hfs_libcb_opendev;
680 	callbacks.closevol = hfs_libcb_closedev;
681 	callbacks.read = hfs_libcb_read;
682 
683 	hfs_nhashinit();
684 	hfslib_init(&callbacks);
685 }
686 
687 void
688 hfs_reinit(void)
689 {
690 
691 #ifdef HFS_DEBUG
692 	printf("vfsop = hfs_reinit()\n");
693 #endif /* HFS_DEBUG */
694 
695 	return;
696 }
697 
698 void
699 hfs_done(void)
700 {
701 
702 #ifdef HFS_DEBUG
703 	printf("vfsop = hfs_done()\n");
704 #endif /* HFS_DEBUG */
705 
706 	malloc_type_detach(M_HFSMNT);
707 
708 	hfslib_done();
709 	hfs_nhashdone();
710 }
711 
712 int
713 hfs_mountroot(void)
714 {
715 
716 #ifdef HFS_DEBUG
717 	printf("vfsop = hfs_mountroot()\n");
718 #endif /* HFS_DEBUG */
719 
720 	return EOPNOTSUPP;
721 }
722