Home | History | Annotate | Line # | Download | only in hfs
hfs_vfsops.c revision 1.7
      1 /*	$NetBSD: hfs_vfsops.c,v 1.7 2007/07/17 11:19:32 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.7 2007/07/17 11:19:32 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 
    131 #include <miscfs/specfs/specdev.h>
    132 
    133 #include <fs/hfs/hfs.h>
    134 #include <fs/hfs/libhfs.h>
    135 
    136 MALLOC_JUSTDEFINE(M_HFSMNT, "hfs mount", "hfs mount structures");
    137 
    138 extern struct lock hfs_hashlock;
    139 
    140 const struct vnodeopv_desc * const hfs_vnodeopv_descs[] = {
    141 	&hfs_vnodeop_opv_desc,
    142 	&hfs_specop_opv_desc,
    143 	&hfs_fifoop_opv_desc,
    144 	NULL,
    145 };
    146 
    147 struct vfsops hfs_vfsops = {
    148 	MOUNT_HFS,
    149 	sizeof (struct hfs_args),
    150 	hfs_mount,
    151 	hfs_start,
    152 	hfs_unmount,
    153 	hfs_root,
    154 	hfs_quotactl,
    155 	hfs_statvfs,
    156 	hfs_sync,
    157 	hfs_vget,
    158 	hfs_fhtovp,
    159 	hfs_vptofh,
    160 	hfs_init,
    161 	hfs_reinit,
    162 	hfs_done,
    163 	NULL,				/* vfs_mountroot */
    164 	NULL,				/* vfs_snapshot */
    165 	hfs_extattrctl,
    166 	NULL,				/* vfs_suspendctl */
    167 	hfs_vnodeopv_descs,
    168 	0,
    169 	{ NULL, NULL },
    170 };
    171 VFS_ATTACH(hfs_vfsops); /* XXX Is this needed? */
    172 
    173 static const struct genfs_ops hfs_genfsops = {
    174         .gop_size = genfs_size,
    175 };
    176 
    177 int
    178 hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len,
    179     struct nameidata *ndp, struct lwp *l)
    180 {
    181 	struct hfs_args *args = data;
    182 	struct vnode *devvp;
    183 	struct hfsmount *hmp;
    184 	int error;
    185 	int update;
    186 	mode_t accessmode;
    187 
    188 	if (*data_len < sizeof *args)
    189 		return EINVAL;
    190 
    191 #ifdef HFS_DEBUG
    192 	printf("vfsop = hfs_mount()\n");
    193 #endif /* HFS_DEBUG */
    194 
    195 	if (mp->mnt_flag & MNT_GETARGS) {
    196 		hmp = VFSTOHFS(mp);
    197 		if (hmp == NULL)
    198 			return EIO;
    199 		args->fspec = NULL;
    200 		*data_len = sizeof *args;
    201 		return 0;
    202 	}
    203 
    204 	if (data == NULL)
    205 		return EINVAL;
    206 
    207 /* FIXME: For development ONLY - disallow remounting for now */
    208 #if 0
    209 	update = mp->mnt_flag & MNT_UPDATE;
    210 #else
    211 	update = 0;
    212 #endif
    213 
    214 	/* Check arguments */
    215 	if (args->fspec != NULL) {
    216 		/*
    217 		 * Look up the name and verify that it's sane.
    218 		 */
    219 		NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args->fspec, l);
    220 		if ((error = namei(ndp)) != 0)
    221 			return error;
    222 		devvp = ndp->ni_vp;
    223 
    224 		if (!update) {
    225 			/*
    226 			 * Be sure this is a valid block device
    227 			 */
    228 			if (devvp->v_type != VBLK)
    229 				error = ENOTBLK;
    230 			else if (bdevsw_lookup(devvp->v_rdev) == NULL)
    231 				error = ENXIO;
    232 		} else {
    233 			/*
    234 			 * Be sure we're still naming the same device
    235 			 * used for our initial mount
    236 			 */
    237 			hmp = VFSTOHFS(mp);
    238 			if (devvp != hmp->hm_devvp)
    239 				error = EINVAL;
    240 		}
    241 	} else {
    242 		if (update) {
    243 			/* Use the extant mount */
    244 			hmp = VFSTOHFS(mp);
    245 			devvp = hmp->hm_devvp;
    246 			vref(devvp);
    247 		} else {
    248 			/* New mounts must have a filename for the device */
    249 			return EINVAL;
    250 		}
    251 	}
    252 
    253 
    254 	/*
    255 	 * If mount by non-root, then verify that user has necessary
    256 	 * permissions on the device.
    257 	 */
    258 	if (error == 0 && kauth_authorize_generic(l->l_cred,
    259             KAUTH_GENERIC_ISSUSER, NULL) != 0) {
    260 		accessmode = VREAD;
    261 		if (update ?
    262 			(mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
    263 			(mp->mnt_flag & MNT_RDONLY) == 0)
    264 			accessmode |= VWRITE;
    265 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    266 		error = VOP_ACCESS(devvp, accessmode, l->l_cred, l);
    267 		VOP_UNLOCK(devvp, 0);
    268 	}
    269 
    270 	if (error != 0)
    271 		goto error;
    272 
    273 	if (update) {
    274 		printf("HFS: live remounting not yet supported!\n");
    275 		error = EINVAL;
    276 		goto error;
    277 	}
    278 
    279 	/*
    280 	 * Disallow multiple mounts of the same device.
    281 	 * Disallow mounting of a device that is currently in use
    282 	 * (except for root, which might share swap device for miniroot).
    283 	 * Flush out any old buffers remaining from a previous use.
    284 	 */
    285 	if ((error = vfs_mountedon(devvp)) != 0)
    286 		goto error;
    287 	if (vcount(devvp) > 1 && devvp != rootvp) {
    288 		error = EBUSY;
    289 		goto error;
    290 	}
    291 
    292 	if ((error = hfs_mountfs(devvp, mp, l, args->fspec)) != 0)
    293 		goto error;
    294 
    295 	error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
    296 		mp->mnt_op->vfs_name, mp, l);
    297 
    298 #ifdef HFS_DEBUG
    299 	if(!update) {
    300 		char* volname;
    301 
    302 		hmp = VFSTOHFS(mp);
    303 		volname = malloc(hmp->hm_vol.name.length + 1, M_TEMP, M_WAITOK);
    304 		if (volname == NULL)
    305 			printf("could not allocate volname; ignored\n");
    306 		else {
    307 			if (hfs_unicode_to_ascii(hmp->hm_vol.name.unicode,
    308 				hmp->hm_vol.name.length, volname) == NULL)
    309 				printf("could not convert volume name to ascii; ignored\n");
    310 			else
    311 				printf("mounted volume \"%s\"\n", volname);
    312 			free(volname, M_TEMP);
    313 		}
    314 	}
    315 #endif /* HFS_DEBUG */
    316 
    317 	return error;
    318 
    319 error:
    320 	vrele(devvp);
    321 	return error;
    322 }
    323 
    324 int
    325 hfs_start(struct mount *mp, int flags, struct lwp *l)
    326 {
    327 
    328 #ifdef HFS_DEBUG
    329 	printf("vfsop = hfs_start()\n");
    330 #endif /* HFS_DEBUG */
    331 
    332 	return 0;
    333 }
    334 
    335 int
    336 hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l,
    337     const char *devpath)
    338 {
    339 	hfs_callback_args cbargs;
    340 	hfs_libcb_argsopen argsopen;
    341 	hfs_libcb_argsread argsread;
    342 	struct hfsmount *hmp;
    343 	kauth_cred_t cred;
    344 	int error;
    345 
    346 	cred = l ? l->l_cred : NOCRED;
    347 	error = 0;
    348 	hmp = NULL;
    349 
    350 	/* Create mounted volume structure. */
    351 	hmp = (struct hfsmount*)malloc(sizeof(struct hfsmount),
    352             M_HFSMNT, M_WAITOK);
    353 	if (hmp == NULL) {
    354 		error = ENOMEM;
    355 		goto error;
    356 	}
    357 	memset(hmp, 0, sizeof(struct hfsmount));
    358 
    359 	mp->mnt_data = hmp;
    360 	mp->mnt_flag |= MNT_LOCAL;
    361 	vfs_getnewfsid(mp);
    362 
    363 	hmp->hm_mountp = mp;
    364 	hmp->hm_dev = devvp->v_rdev;
    365 	hmp->hm_devvp = devvp;
    366 
    367 	/*
    368 	 * Use libhfs to open the volume and read the volume header and other
    369 	 * useful information.
    370 	 */
    371 
    372 	hfslib_init_cbargs(&cbargs);
    373 	argsopen.cred = argsread.cred = cred;
    374 	argsopen.l = argsread.l = l;
    375 	argsopen.devvp = devvp;
    376 	cbargs.read = (void*)&argsread;
    377 	cbargs.openvol = (void*)&argsopen;
    378 
    379 	if ((error = hfslib_open_volume(devpath, mp->mnt_flag & MNT_RDONLY,
    380 		&hmp->hm_vol, &cbargs)) != 0)
    381 		goto error;
    382 
    383 	/* Make sure this is not a journaled volume whose journal is dirty. */
    384 	if (!hfslib_is_journal_clean(&hmp->hm_vol)) {
    385 		printf("volume journal is dirty; not mounting\n");
    386 		error = EIO;
    387 		goto error;
    388 	}
    389 
    390 	mp->mnt_fs_bshift = 0;
    391         while ((1 << mp->mnt_fs_bshift) < hmp->hm_vol.vh.block_size)
    392 		mp->mnt_fs_bshift++;
    393 	mp->mnt_dev_bshift = DEV_BSHIFT;
    394 
    395 	return 0;
    396 
    397 error:
    398 	if (hmp != NULL)
    399 		free(hmp, M_HFSMNT);
    400 
    401 	return error;
    402 }
    403 
    404 int
    405 hfs_unmount(struct mount *mp, int mntflags, struct lwp *l)
    406 {
    407 	hfs_callback_args cbargs;
    408 	hfs_libcb_argsread argsclose;
    409 	struct hfsmount* hmp;
    410 	int error;
    411 	int flags;
    412 
    413 #ifdef HFS_DEBUG
    414 	printf("vfsop = hfs_unmount()\n");
    415 #endif /* HFS_DEBUG */
    416 
    417 	hmp = VFSTOHFS(mp);
    418 
    419 	flags = 0;
    420 	if (mntflags & MNT_FORCE)
    421 		flags |= FORCECLOSE;
    422 
    423 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    424 		return error;
    425 
    426 	hfslib_init_cbargs(&cbargs);
    427 	argsclose.l = l;
    428 	cbargs.closevol = (void*)&argsclose;
    429 	hfslib_close_volume(&hmp->hm_vol, &cbargs);
    430 
    431 	vput(hmp->hm_devvp);
    432 
    433 	free(hmp, M_HFSMNT);
    434 	mp->mnt_data = NULL;
    435 	mp->mnt_flag &= ~MNT_LOCAL;
    436 
    437 	return error;
    438 }
    439 
    440 int
    441 hfs_root(struct mount *mp, struct vnode **vpp)
    442 {
    443 	struct vnode *nvp;
    444 	int error;
    445 
    446 #ifdef HFS_DEBUG
    447 	printf("vfsop = hfs_root()\n");
    448 #endif /* HFS_DEBUG */
    449 
    450 	if ((error = VFS_VGET(mp, HFS_CNID_ROOT_FOLDER, &nvp)) != 0)
    451 		return error;
    452 	*vpp = nvp;
    453 
    454 	return 0;
    455 }
    456 
    457 int
    458 hfs_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg,
    459     struct lwp *l)
    460 {
    461 
    462 #ifdef HFS_DEBUG
    463 	printf("vfsop = hfs_quotactl()\n");
    464 #endif /* HFS_DEBUG */
    465 
    466 	return EOPNOTSUPP;
    467 }
    468 
    469 int
    470 hfs_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
    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, struct lwp *l)
    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 	/* Check if this vnode has already been allocated. If so, just return it. */
    546 	if ((*vpp = hfs_nhashget(dev, cnid, fork, LK_EXCLUSIVE)) != NULL)
    547 		return 0;
    548 
    549 	/* Allocate a new vnode/inode. */
    550 	if ((error = getnewvnode(VT_HFS, mp, hfs_vnodeop_p, &vp)) != 0)
    551 		goto error;
    552 
    553 	/*
    554 	 * If someone beat us to it while sleeping in getnewvnode(),
    555 	 * push back the freshly allocated vnode we don't need, and return.
    556 	 */
    557 
    558 	do {
    559 		if ((*vpp = hfs_nhashget(dev, cnid, fork, LK_EXCLUSIVE))
    560 		    != NULL) {
    561 			ungetnewvnode(vp);
    562 			return 0;
    563 		}
    564 	} while (lockmgr(&hfs_hashlock, LK_EXCLUSIVE|LK_SLEEPFAIL, 0));
    565 
    566 	vp->v_flag |= VLOCKSWORK;
    567 
    568 	MALLOC(hnode, struct hfsnode *, sizeof(struct hfsnode), M_TEMP,
    569 		M_WAITOK + M_ZERO);
    570 	vp->v_data = hnode;
    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.cnid = cnid;
    587 	hnode->h_fork = fork;
    588 
    589 	hfs_nhashinsert(hnode);
    590 	lockmgr(&hfs_hashlock, LK_RELEASE, 0);
    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 have changed.
    619 	 */
    620 
    621 	hfs_vinit(mp, hfs_specop_p, hfs_fifoop_p, &vp);
    622 
    623 	genfs_node_init(vp, &hfs_genfsops);
    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.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 
    729 int hfs_extattrctl(struct mount *mp, int cmd, struct vnode *vp,
    730     int attrnamespace, const char *attrname, struct lwp *l)
    731 {
    732 
    733 #ifdef HFS_DEBUG
    734 	printf("vfsop = hfs_checkexp()\n");
    735 #endif /* HFS_DEBUG */
    736 
    737 	return EOPNOTSUPP;
    738 }
    739