Home | History | Annotate | Line # | Download | only in hfs
hfs_vfsops.c revision 1.23
      1 /*	$NetBSD: hfs_vfsops.c,v 1.23 2009/11/27 16:11:35 pooka 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.23 2009/11/27 16:11:35 pooka 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;
    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 = genfs_can_mount(devvp, accessmode, l->l_cred);
    290 		VOP_UNLOCK(devvp, 0);
    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 	vput(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 	if ((error = getnewvnode(VT_HFS, mp, hfs_vnodeop_p, &vp)) != 0)
    550 		goto error;
    551 	hnode = malloc(sizeof(struct hfsnode), M_TEMP,
    552 		M_WAITOK | M_ZERO);
    553 
    554 	/*
    555 	 * If someone beat us to it while sleeping in getnewvnode(),
    556 	 * push back the freshly allocated vnode we don't need, and return.
    557 	 */
    558 	mutex_enter(&hfs_hashlock);
    559 	if (hfs_nhashget(dev, cnid, fork, 0) != NULL) {
    560 		mutex_exit(&hfs_hashlock);
    561 		ungetnewvnode(vp);
    562 		free(hnode, M_TEMP);
    563 		goto retry;
    564 	}
    565 
    566 	vp->v_vflag |= VV_LOCKSWORK;
    567 	vp->v_data = hnode;
    568 	genfs_node_init(vp, &hfs_genfsops);
    569 
    570 	hnode->h_vnode = vp;
    571 	hnode->h_hmp = hmp;
    572 	hnode->dummy = 0x1337BABE;
    573 
    574 	/*
    575 	 * We need to put this vnode into the hash chain and lock it so that other
    576 	 * requests for this inode will block if they arrive while we are sleeping
    577 	 * waiting for old data structures to be purged or for the contents of the
    578 	 * disk portion of this inode to be read. The hash chain requires the node's
    579 	 * device and cnid to be known. Since this information was passed in the
    580 	 * arguments, fill in the appropriate hfsnode fields without reading having
    581 	 * to read the disk.
    582 	 */
    583 	hnode->h_dev = dev;
    584 	hnode->h_rec.u.cnid = cnid;
    585 	hnode->h_fork = fork;
    586 
    587 	hfs_nhashinsert(hnode);
    588 	mutex_exit(&hfs_hashlock);
    589 
    590 
    591 	/*
    592 	 * Read catalog record from disk.
    593 	 */
    594 	hfslib_init_cbargs(&cbargs);
    595 
    596 	if (hfslib_find_catalog_record_with_cnid(&hmp->hm_vol, cnid,
    597 		&rec, &key, &cbargs) != 0) {
    598 		vput(vp);
    599 		error = EBADF;
    600 		goto error;
    601 	}
    602 
    603 	memcpy(&hnode->h_rec, &rec, sizeof(hnode->h_rec));
    604 	hnode->h_parent = key.parent_cnid;
    605 
    606 	/* XXX Eventually need to add an "ignore permissions" mount option */
    607 
    608 	/*
    609 	 * Now convert some of the catalog record's fields into values that make
    610 	 * sense on this system.
    611 	 */
    612 	/* DATE AND TIME */
    613 
    614 	/*
    615 	 * Initialize the vnode from the hfsnode, check for aliases.
    616 	 * Note that the underlying vnode may change.
    617 	 */
    618 	hfs_vinit(mp, hfs_specop_p, hfs_fifoop_p, &vp);
    619 
    620 	hnode->h_devvp = hmp->hm_devvp;
    621 	VREF(hnode->h_devvp);  /* Increment the ref count to the volume's device. */
    622 
    623 	/* Make sure UVM has allocated enough memory. (?) */
    624 	if (hnode->h_rec.u.rec_type == HFS_REC_FILE) {
    625 		if (hnode->h_fork == HFS_DATAFORK)
    626 			uvm_vnp_setsize(vp,
    627 			    hnode->h_rec.file.data_fork.logical_size);
    628 		else
    629 			uvm_vnp_setsize(vp,
    630 			    hnode->h_rec.file.rsrc_fork.logical_size);
    631 	}
    632 	else
    633 		uvm_vnp_setsize(vp, 0); /* no directly reading directories */
    634 
    635 	*vpp = vp;
    636 
    637 	return 0;
    638 
    639 error:
    640 	*vpp = NULL;
    641 	return error;
    642 }
    643 
    644 int
    645 hfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
    646 {
    647 
    648 #ifdef HFS_DEBUG
    649 	printf("vfsop = hfs_fhtovp()\n");
    650 #endif /* HFS_DEBUG */
    651 
    652 	return EOPNOTSUPP;
    653 }
    654 
    655 int
    656 hfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
    657 {
    658 
    659 #ifdef HFS_DEBUG
    660 	printf("vfsop = hfs_vptofh()\n");
    661 #endif /* HFS_DEBUG */
    662 
    663 	return EOPNOTSUPP;
    664 }
    665 
    666 void
    667 hfs_init(void)
    668 {
    669 	hfs_callbacks	callbacks;
    670 
    671 #ifdef HFS_DEBUG
    672 	printf("vfsop = hfs_init()\n");
    673 #endif /* HFS_DEBUG */
    674 
    675 	malloc_type_attach(M_HFSMNT);
    676 
    677 	callbacks.error = hfs_libcb_error;
    678 	callbacks.allocmem = hfs_libcb_malloc;
    679 	callbacks.reallocmem = hfs_libcb_realloc;
    680 	callbacks.freemem = hfs_libcb_free;
    681 	callbacks.openvol = hfs_libcb_opendev;
    682 	callbacks.closevol = hfs_libcb_closedev;
    683 	callbacks.read = hfs_libcb_read;
    684 
    685 	hfs_nhashinit();
    686 	hfslib_init(&callbacks);
    687 }
    688 
    689 void
    690 hfs_reinit(void)
    691 {
    692 
    693 #ifdef HFS_DEBUG
    694 	printf("vfsop = hfs_reinit()\n");
    695 #endif /* HFS_DEBUG */
    696 
    697 	return;
    698 }
    699 
    700 void
    701 hfs_done(void)
    702 {
    703 
    704 #ifdef HFS_DEBUG
    705 	printf("vfsop = hfs_done()\n");
    706 #endif /* HFS_DEBUG */
    707 
    708 	malloc_type_detach(M_HFSMNT);
    709 
    710 	hfslib_done();
    711 	hfs_nhashdone();
    712 }
    713 
    714 int
    715 hfs_mountroot(void)
    716 {
    717 
    718 #ifdef HFS_DEBUG
    719 	printf("vfsop = hfs_mountroot()\n");
    720 #endif /* HFS_DEBUG */
    721 
    722 	return EOPNOTSUPP;
    723 }
    724