xref: /netbsd-src/sys/fs/hfs/hfs_vfsops.c (revision 03dcb730d46d34d85c9f496c1f5a3a6a43f2b7b3)
1 /*	$NetBSD: hfs_vfsops.c,v 1.34 2017/02/17 08:31:24 hannken 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.34 2017/02/17 08:31:24 hannken 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 struct pool hfs_node_pool;
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 	.vfs_name = MOUNT_HFS,
153 	.vfs_min_mount_data = sizeof (struct hfs_args),
154 	.vfs_mount = hfs_mount,
155 	.vfs_start = hfs_start,
156 	.vfs_unmount = hfs_unmount,
157 	.vfs_root = hfs_root,
158 	.vfs_quotactl = (void *)eopnotsupp,
159 	.vfs_statvfs = hfs_statvfs,
160 	.vfs_sync = hfs_sync,
161 	.vfs_vget = hfs_vget,
162 	.vfs_loadvnode = hfs_loadvnode,
163 	.vfs_fhtovp = hfs_fhtovp,
164 	.vfs_vptofh = hfs_vptofh,
165 	.vfs_init = hfs_init,
166 	.vfs_reinit = hfs_reinit,
167 	.vfs_done = hfs_done,
168 	.vfs_extattrctl = vfs_stdextattrctl,
169 	.vfs_suspendctl = genfs_suspendctl,
170 	.vfs_renamelock_enter = genfs_renamelock_enter,
171 	.vfs_renamelock_exit = genfs_renamelock_exit,
172 	.vfs_fsync = (void *)eopnotsupp,
173 	.vfs_opv_descs = hfs_vnodeopv_descs
174 };
175 
176 static const struct genfs_ops hfs_genfsops = {
177 	.gop_size = genfs_size,
178 };
179 
180 static int
181 hfs_modcmd(modcmd_t cmd, void *arg)
182 {
183 	switch (cmd) {
184 	case MODULE_CMD_INIT:
185 		return vfs_attach(&hfs_vfsops);
186 	case MODULE_CMD_FINI:
187 		return vfs_detach(&hfs_vfsops);
188 	default:
189 		return ENOTTY;
190 	}
191 }
192 
193 int
194 hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
195 {
196 	struct lwp *l = curlwp;
197 	struct hfs_args *args = data;
198 	struct vnode *devvp;
199 	struct hfsmount *hmp;
200 	int error = 0;
201 	int update;
202 	mode_t accessmode;
203 
204 	if (args == NULL)
205 		return EINVAL;
206 	if (*data_len < sizeof *args)
207 		return EINVAL;
208 
209 #ifdef HFS_DEBUG
210 	printf("vfsop = hfs_mount()\n");
211 #endif /* HFS_DEBUG */
212 
213 	if (mp->mnt_flag & MNT_GETARGS) {
214 		hmp = VFSTOHFS(mp);
215 		if (hmp == NULL)
216 			return EIO;
217 		args->fspec = NULL;
218 		*data_len = sizeof *args;
219 		return 0;
220 	}
221 
222 /* FIXME: For development ONLY - disallow remounting for now */
223 #if 0
224 	update = mp->mnt_flag & MNT_UPDATE;
225 #else
226 	update = 0;
227 #endif
228 
229 	/* Check arguments */
230 	if (args->fspec != NULL) {
231 		/*
232 		 * Look up the name and verify that it's sane.
233 		 */
234 		error = namei_simple_user(args->fspec,
235 					NSM_FOLLOW_NOEMULROOT, &devvp);
236 		if (error != 0)
237 			return error;
238 
239 		if (!update) {
240 			/*
241 			 * Be sure this is a valid block device
242 			 */
243 			if (devvp->v_type != VBLK)
244 				error = ENOTBLK;
245 			else if (bdevsw_lookup(devvp->v_rdev) == NULL)
246 				error = ENXIO;
247 		} else {
248 			/*
249 			 * Be sure we're still naming the same device
250 			 * used for our initial mount
251 			 */
252 			hmp = VFSTOHFS(mp);
253 			if (devvp != hmp->hm_devvp)
254 				error = EINVAL;
255 		}
256 	} else {
257 		if (update) {
258 			/* Use the extant mount */
259 			hmp = VFSTOHFS(mp);
260 			devvp = hmp->hm_devvp;
261 			vref(devvp);
262 		} else {
263 			/* New mounts must have a filename for the device */
264 			return EINVAL;
265 		}
266 	}
267 
268 	/*
269 	 * If mount by non-root, then verify that user has necessary
270 	 * permissions on the device.
271 	 *
272 	 * Permission to update a mount is checked higher, so here we presume
273 	 * updating the mount is okay (for example, as far as securelevel goes)
274 	 * which leaves us with the normal check.
275 	 */
276 	if (error == 0) {
277 		accessmode = VREAD;
278 		if (update ?
279 			(mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
280 			(mp->mnt_flag & MNT_RDONLY) == 0)
281 			accessmode |= VWRITE;
282 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
283 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
284 		    KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp,
285 		    KAUTH_ARG(accessmode));
286 		VOP_UNLOCK(devvp);
287 	}
288 
289 	if (error != 0)
290 		goto error;
291 
292 	if (update) {
293 		printf("HFS: live remounting not yet supported!\n");
294 		error = EINVAL;
295 		goto error;
296 	}
297 
298 	if ((error = hfs_mountfs(devvp, mp, l, args->fspec)) != 0)
299 		goto error;
300 
301 	error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
302 		mp->mnt_op->vfs_name, mp, l);
303 
304 #ifdef HFS_DEBUG
305 	if(!update) {
306 		char* volname;
307 
308 		hmp = VFSTOHFS(mp);
309 		volname = malloc(hmp->hm_vol.name.length + 1, M_TEMP, M_WAITOK);
310 		if (volname == NULL)
311 			printf("could not allocate volname; ignored\n");
312 		else {
313 			if (hfs_unicode_to_ascii(hmp->hm_vol.name.unicode,
314 				hmp->hm_vol.name.length, volname) == NULL)
315 				printf("could not convert volume name to ascii; ignored\n");
316 			else
317 				printf("mounted volume \"%s\"\n", volname);
318 			free(volname, M_TEMP);
319 		}
320 	}
321 #endif /* HFS_DEBUG */
322 
323 	return error;
324 
325 error:
326 	vrele(devvp);
327 	return error;
328 }
329 
330 int
331 hfs_start(struct mount *mp, int flags)
332 {
333 #ifdef HFS_DEBUG
334 	printf("vfsop = hfs_start()\n");
335 #endif /* HFS_DEBUG */
336 
337 	return 0;
338 }
339 
340 int
341 hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l,
342     const char *devpath)
343 {
344 	hfs_callback_args cbargs;
345 	hfs_libcb_argsopen argsopen;
346 	hfs_libcb_argsread argsread;
347 	struct hfsmount *hmp;
348 	kauth_cred_t cred;
349 	int error;
350 
351 	cred = l ? l->l_cred : NOCRED;
352 	error = 0;
353 	hmp = NULL;
354 
355 	/* Create mounted volume structure. */
356 	hmp = malloc(sizeof(struct hfsmount), M_HFSMNT, M_WAITOK|M_ZERO);
357 	if (hmp == NULL) {
358 		error = ENOMEM;
359 		goto error;
360 	}
361 
362 	mp->mnt_data = hmp;
363 	mp->mnt_flag |= MNT_LOCAL;
364 	vfs_getnewfsid(mp);
365 
366 	hmp->hm_mountp = mp;
367 	hmp->hm_dev = devvp->v_rdev;
368 	hmp->hm_devvp = devvp;
369 
370 	/*
371 	 * Use libhfs to open the volume and read the volume header and other
372 	 * useful information.
373 	 */
374 
375 	hfslib_init_cbargs(&cbargs);
376 	argsopen.cred = argsread.cred = cred;
377 	argsopen.l = argsread.l = l;
378 	argsopen.devvp = devvp;
379 	cbargs.read = (void*)&argsread;
380 	cbargs.openvol = (void*)&argsopen;
381 
382 	if ((error = hfslib_open_volume(devpath, mp->mnt_flag & MNT_RDONLY,
383 		&hmp->hm_vol, &cbargs)) != 0)
384 		goto error;
385 
386 	/* Make sure this is not a journaled volume whose journal is dirty. */
387 	if (!hfslib_is_journal_clean(&hmp->hm_vol)) {
388 		printf("volume journal is dirty; not mounting\n");
389 		error = EIO;
390 		goto error;
391 	}
392 
393 	mp->mnt_fs_bshift = 0;
394 	while ((1 << mp->mnt_fs_bshift) < hmp->hm_vol.vh.block_size)
395 		mp->mnt_fs_bshift++;
396 	mp->mnt_dev_bshift = DEV_BSHIFT;
397 
398 	return 0;
399 
400 error:
401 	if (hmp != NULL)
402 		free(hmp, M_HFSMNT);
403 	return error;
404 }
405 
406 int
407 hfs_unmount(struct mount *mp, int mntflags)
408 {
409 	hfs_callback_args cbargs;
410 	hfs_libcb_argsread argsclose;
411 	struct hfsmount* hmp;
412 	int error;
413 	int flags;
414 
415 #ifdef HFS_DEBUG
416 	printf("vfsop = hfs_unmount()\n");
417 #endif /* HFS_DEBUG */
418 
419 	hmp = VFSTOHFS(mp);
420 
421 	flags = 0;
422 	if (mntflags & MNT_FORCE)
423 		flags |= FORCECLOSE;
424 
425 	if ((error = vflush(mp, NULLVP, flags)) != 0)
426 		return error;
427 
428 	hfslib_init_cbargs(&cbargs);
429 	argsclose.l = curlwp;
430 	cbargs.closevol = (void*)&argsclose;
431 	hfslib_close_volume(&hmp->hm_vol, &cbargs);
432 
433 	vrele(hmp->hm_devvp);
434 
435 	free(hmp, M_HFSMNT);
436 	mp->mnt_data = NULL;
437 	mp->mnt_flag &= ~MNT_LOCAL;
438 
439 	return error;
440 }
441 
442 int
443 hfs_root(struct mount *mp, struct vnode **vpp)
444 {
445 	struct vnode *nvp;
446 	int error;
447 
448 #ifdef HFS_DEBUG
449 	printf("vfsop = hfs_root()\n");
450 #endif /* HFS_DEBUG */
451 
452 	if ((error = VFS_VGET(mp, HFS_CNID_ROOT_FOLDER, &nvp)) != 0)
453 		return error;
454 	*vpp = nvp;
455 
456 	return 0;
457 }
458 
459 int
460 hfs_statvfs(struct mount *mp, struct statvfs *sbp)
461 {
462 	hfs_volume_header_t *vh;
463 
464 #ifdef HFS_DEBUG
465 	printf("vfsop = hfs_statvfs()\n");
466 #endif /* HFS_DEBUG */
467 
468 	vh = &VFSTOHFS(mp)->hm_vol.vh;
469 
470 	sbp->f_bsize = vh->block_size;
471 	sbp->f_frsize = sbp->f_bsize;
472 	sbp->f_iosize = 4096;/* mac os x uses a 4 kb io size, so do the same */
473 	sbp->f_blocks = vh->total_blocks;
474 	sbp->f_bfree = vh->free_blocks; /* total free blocks */
475 	sbp->f_bavail = vh->free_blocks; /* blocks free for non superuser */
476 	sbp->f_bresvd = 0;
477 	sbp->f_files =  vh->file_count; /* total files */
478 	sbp->f_ffree = (1<<31) - vh->file_count; /* free file nodes */
479 	copy_statvfs_info(sbp, mp);
480 
481 	return 0;
482 }
483 
484 int
485 hfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
486 {
487 #ifdef HFS_DEBUG
488 	printf("vfsop = hfs_sync()\n");
489 #endif /* HFS_DEBUG */
490 
491 	return 0;
492 }
493 
494 /*
495  * an ino_t corresponds directly to a CNID in our particular case,
496  * since both are conveniently 32-bit numbers
497  */
498 int
499 hfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
500 {
501 	int error;
502 
503 	error = hfs_vget_internal(mp, ino, HFS_DATAFORK, vpp);
504 	if (error)
505 		return error;
506 	error = vn_lock(*vpp, LK_EXCLUSIVE);
507 	if (error) {
508 		vrele(*vpp);
509 		*vpp = NULL;
510 		return error;
511 	}
512 	return 0;
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 hfsnode_key key;
523 
524 	memset(&key, 0, sizeof(key));
525 	key.hnk_cnid = (hfs_cnid_t)ino;
526 	key.hnk_fork = (fork != HFS_RSRCFORK ? HFS_DATAFORK : HFS_RSRCFORK);
527 
528 	return vcache_get(mp, &key, sizeof(key), vpp);
529 }
530 
531 int
532 hfs_loadvnode(struct mount *mp, struct vnode *vp,
533     const void *key, size_t key_len, const void **new_key)
534 {
535 	struct hfsmount *hmp;
536 	struct hfsnode *hnode;
537 	struct hfsnode_key hfskey;
538 	hfs_callback_args cbargs;
539 	hfs_catalog_keyed_record_t rec;
540 	hfs_catalog_key_t cat_key; /* the search key used to find this file on disk */
541 	dev_t dev;
542 
543 #ifdef HFS_DEBUG
544 	printf("vfsop = hfs_loadvnode()\n");
545 #endif /* HFS_DEBUG */
546 
547 	KASSERT(key_len == sizeof(hfskey));
548 	memcpy(&hfskey, key, key_len);
549 
550 	hmp = VFSTOHFS(mp);
551 	dev = hmp->hm_dev;
552 
553 	hnode = pool_get(&hfs_node_pool, PR_WAITOK);
554 	memset(hnode, 0, sizeof(*hnode));
555 	hnode->h_vnode = vp;
556 	hnode->h_hmp = hmp;
557 	hnode->dummy = 0x1337BABE;
558 	hnode->h_dev = dev;
559 	hnode->h_rec.u.cnid = hfskey.hnk_cnid;
560 	hnode->h_fork = hfskey.hnk_fork;
561 	hnode->h_key = hfskey;
562 
563 	/*
564 	 * Read catalog record from disk.
565 	 */
566 	hfslib_init_cbargs(&cbargs);
567 
568 	if (hfslib_find_catalog_record_with_cnid(&hmp->hm_vol, hfskey.hnk_cnid,
569 		&rec, &cat_key, &cbargs) != 0) {
570 		pool_put(&hfs_node_pool, hnode);
571 		return EBADF;
572 	}
573 
574 	memcpy(&hnode->h_rec, &rec, sizeof(hnode->h_rec));
575 	hnode->h_parent = cat_key.parent_cnid;
576 
577 	/* XXX Eventually need to add an "ignore permissions" mount option */
578 
579 	/*
580 	 * Now convert some of the catalog record's fields into values that make
581 	 * sense on this system.
582 	 */
583 	/* DATE AND TIME */
584 
585 	vp->v_tag = VT_HFS;
586 	vp->v_op = hfs_vnodeop_p;
587 	vp->v_vflag |= VV_LOCKSWORK;
588 	vp->v_data = hnode;
589 	genfs_node_init(vp, &hfs_genfsops);
590 
591 	/*
592 	 * Initialize the vnode from the hfsnode, check for aliases.
593 	 */
594 	hfs_vinit(mp, hfs_specop_p, hfs_fifoop_p, &vp);
595 
596 	hnode->h_devvp = hmp->hm_devvp;
597 	vref(hnode->h_devvp);  /* Increment the ref count to the volume's device. */
598 
599 	/* Make sure UVM has allocated enough memory. (?) */
600 	if (hnode->h_rec.u.rec_type == HFS_REC_FILE) {
601 		if (hnode->h_fork == HFS_DATAFORK)
602 			uvm_vnp_setsize(vp,
603 			    hnode->h_rec.file.data_fork.logical_size);
604 		else
605 			uvm_vnp_setsize(vp,
606 			    hnode->h_rec.file.rsrc_fork.logical_size);
607 	}
608 	else
609 		uvm_vnp_setsize(vp, 0); /* no directly reading directories */
610 
611 	*new_key = &hnode->h_key;
612 	return 0;
613 }
614 
615 int
616 hfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
617 {
618 
619 #ifdef HFS_DEBUG
620 	printf("vfsop = hfs_fhtovp()\n");
621 #endif /* HFS_DEBUG */
622 
623 	return EOPNOTSUPP;
624 }
625 
626 int
627 hfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
628 {
629 #ifdef HFS_DEBUG
630 	printf("vfsop = hfs_vptofh()\n");
631 #endif /* HFS_DEBUG */
632 
633 	return EOPNOTSUPP;
634 }
635 
636 void
637 hfs_init(void)
638 {
639 	hfs_callbacks	callbacks;
640 
641 #ifdef HFS_DEBUG
642 	printf("vfsop = hfs_init()\n");
643 #endif /* HFS_DEBUG */
644 
645 	malloc_type_attach(M_HFSMNT);
646 	pool_init(&hfs_node_pool, sizeof(struct hfsnode), 0, 0, 0, "hfsndpl",
647 	    &pool_allocator_nointr, IPL_NONE);
648 
649 	callbacks.error = hfs_libcb_error;
650 	callbacks.allocmem = hfs_libcb_malloc;
651 	callbacks.reallocmem = hfs_libcb_realloc;
652 	callbacks.freemem = hfs_libcb_free;
653 	callbacks.openvol = hfs_libcb_opendev;
654 	callbacks.closevol = hfs_libcb_closedev;
655 	callbacks.read = hfs_libcb_read;
656 
657 	hfslib_init(&callbacks);
658 }
659 
660 void
661 hfs_reinit(void)
662 {
663 #ifdef HFS_DEBUG
664 	printf("vfsop = hfs_reinit()\n");
665 #endif /* HFS_DEBUG */
666 
667 	return;
668 }
669 
670 void
671 hfs_done(void)
672 {
673 #ifdef HFS_DEBUG
674 	printf("vfsop = hfs_done()\n");
675 #endif /* HFS_DEBUG */
676 
677 	malloc_type_detach(M_HFSMNT);
678 	pool_destroy(&hfs_node_pool);
679 	hfslib_done();
680 }
681 
682 int
683 hfs_mountroot(void)
684 {
685 #ifdef HFS_DEBUG
686 	printf("vfsop = hfs_mountroot()\n");
687 #endif /* HFS_DEBUG */
688 
689 	return EOPNOTSUPP;
690 }
691