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