Home | History | Annotate | Line # | Download | only in hfs
hfs_vfsops.c revision 1.1
      1 /*	$NetBSD: hfs_vfsops.c,v 1.1 2007/03/06 00:22:04 dillo 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.1 2007/03/06 00:22:04 dillo 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/hfsp/hfsp.h>
    134 #include <fs/hfsp/libhfsp.h>
    135 
    136 MALLOC_DEFINE(M_HFSPMNT, "hfsp mount", "hfsp mount structures");
    137 
    138 extern struct lock hfsp_hashlock;
    139 
    140 const struct vnodeopv_desc * const hfsp_vnodeopv_descs[] = {
    141 	&hfsp_vnodeop_opv_desc,
    142 	&hfsp_specop_opv_desc,
    143 	&hfsp_fifoop_opv_desc,
    144 	NULL,
    145 };
    146 
    147 struct vfsops hfsp_vfsops = {
    148 	MOUNT_HFSP,
    149 	hfsp_mount,
    150 	hfsp_start,
    151 	hfsp_unmount,
    152 	hfsp_root,
    153 	hfsp_quotactl,
    154 	hfsp_statvfs,
    155 	hfsp_sync,
    156 	hfsp_vget,
    157 	hfsp_fhtovp,
    158 	hfsp_vptofh,
    159 	hfsp_init,
    160 	hfsp_reinit,
    161 	hfsp_done,
    162 	NULL,				/* vfs_mountroot */
    163 	NULL,				/* vfs_snapshot */
    164 	hfsp_extattrctl,
    165 	NULL,				/* vfs_suspendctl */
    166 	hfsp_vnodeopv_descs,
    167 	0,
    168 	{ NULL, NULL },
    169 };
    170 VFS_ATTACH(hfsp_vfsops); /* XXX Is this needed? */
    171 
    172 static const struct genfs_ops hfsp_genfsops = {
    173         .gop_size = genfs_size,
    174 };
    175 
    176 int
    177 hfsp_mount(struct mount *mp, const char *path, void *data,
    178     struct nameidata *ndp, struct lwp *l)
    179 {
    180 	struct hfsp_args args;
    181 	struct vnode *devvp;
    182 	struct hfspmount *hmp;
    183 	int error;
    184 	int update;
    185 	mode_t accessmode;
    186 
    187 #ifdef HFSP_DEBUG
    188 	printf("vfsop = hfsp_mount()\n");
    189 #endif /* HFSP_DEBUG */
    190 
    191 	if (mp->mnt_flag & MNT_GETARGS) {
    192 		hmp = VFSTOHFSP(mp);
    193 		if (hmp == NULL)
    194 			return EIO;
    195 		args.fspec = NULL;
    196 		return copyout(&args, data, sizeof(args));
    197 	}
    198 
    199 	if (data == NULL)
    200 		return EINVAL;
    201 
    202 	if ((error = copyin(data, &args, sizeof (struct hfsp_args))) != 0)
    203 		return error;
    204 
    205 /* FIXME: For development ONLY - disallow remounting for now */
    206 #if 0
    207 	update = mp->mnt_flag & MNT_UPDATE;
    208 #else
    209 	update = 0;
    210 #endif
    211 
    212 	/* Check arguments */
    213 	if (args.fspec != NULL) {
    214 		/*
    215 		 * Look up the name and verify that it's sane.
    216 		 */
    217 		NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, l);
    218 		if ((error = namei(ndp)) != 0)
    219 			return error;
    220 		devvp = ndp->ni_vp;
    221 
    222 		if (!update) {
    223 			/*
    224 			 * Be sure this is a valid block device
    225 			 */
    226 			if (devvp->v_type != VBLK)
    227 				error = ENOTBLK;
    228 			else if (bdevsw_lookup(devvp->v_rdev) == NULL)
    229 				error = ENXIO;
    230 		} else {
    231 			/*
    232 			 * Be sure we're still naming the same device
    233 			 * used for our initial mount
    234 			 */
    235 			hmp = VFSTOHFSP(mp);
    236 			if (devvp != hmp->hm_devvp)
    237 				error = EINVAL;
    238 		}
    239 	} else {
    240 		if (update) {
    241 			/* Use the extant mount */
    242 			hmp = VFSTOHFSP(mp);
    243 			devvp = hmp->hm_devvp;
    244 			vref(devvp);
    245 		} else {
    246 			/* New mounts must have a filename for the device */
    247 			return EINVAL;
    248 		}
    249 	}
    250 
    251 
    252 	/*
    253 	 * If mount by non-root, then verify that user has necessary
    254 	 * permissions on the device.
    255 	 */
    256 	if (error == 0 && kauth_authorize_generic(l->l_cred,
    257             KAUTH_GENERIC_ISSUSER, NULL) != 0) {
    258 		accessmode = VREAD;
    259 		if (update ?
    260 			(mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
    261 			(mp->mnt_flag & MNT_RDONLY) == 0)
    262 			accessmode |= VWRITE;
    263 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    264 		error = VOP_ACCESS(devvp, accessmode, l->l_cred, l);
    265 		VOP_UNLOCK(devvp, 0);
    266 	}
    267 
    268 	if (error != 0)
    269 		goto error;
    270 
    271 	if (update) {
    272 		printf("HFSP: live remounting not yet supported!\n");
    273 		error = EINVAL;
    274 		goto error;
    275 	}
    276 
    277 	/*
    278 	 * Disallow multiple mounts of the same device.
    279 	 * Disallow mounting of a device that is currently in use
    280 	 * (except for root, which might share swap device for miniroot).
    281 	 * Flush out any old buffers remaining from a previous use.
    282 	 */
    283 	if ((error = vfs_mountedon(devvp)) != 0)
    284 		goto error;
    285 	if (vcount(devvp) > 1 && devvp != rootvp) {
    286 		error = EBUSY;
    287 		goto error;
    288 	}
    289 
    290 	if ((error = hfsp_mountfs(devvp, mp, l, args.fspec, args.offset)) != 0)
    291 		goto error;
    292 
    293 	error = set_statvfs_info(path, UIO_USERSPACE, args.fspec, UIO_SYSSPACE,
    294 		mp, l);
    295 
    296 #ifdef HFSP_DEBUG
    297 	if(!update) {
    298 		char* volname;
    299 
    300 		hmp = VFSTOHFSP(mp);
    301 		volname = malloc(hmp->hm_vol.name.length + 1, M_TEMP, M_WAITOK);
    302 		if (volname == NULL)
    303 			printf("could not allocate volname; ignored\n");
    304 		else {
    305 			if (hfsp_unicode_to_ascii(hmp->hm_vol.name.unicode,
    306 				hmp->hm_vol.name.length, volname) == NULL)
    307 				printf("could not convert volume name to ascii; ignored\n");
    308 			else
    309 				printf("mounted volume \"%s\"\n", volname);
    310 			free(volname, M_TEMP);
    311 		}
    312 	}
    313 #endif /* HFSP_DEBUG */
    314 
    315 	return error;
    316 
    317 error:
    318 	vrele(devvp);
    319 	return error;
    320 }
    321 
    322 int
    323 hfsp_start(struct mount *mp, int flags, struct lwp *l)
    324 {
    325 
    326 #ifdef HFSP_DEBUG
    327 	printf("vfsop = hfsp_start()\n");
    328 #endif /* HFSP_DEBUG */
    329 
    330 	return 0;
    331 }
    332 
    333 int
    334 hfsp_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l,
    335     const char *devpath, uint64_t offset)
    336 {
    337 	hfsp_callback_args cbargs;
    338 	hfsp_libcb_argsopen argsopen;
    339 	hfsp_libcb_argsread argsread;
    340 	struct hfspmount *hmp;
    341 	kauth_cred_t cred;
    342 	int error;
    343 
    344 	cred = l ? l->l_cred : NOCRED;
    345 	error = 0;
    346 	hmp = NULL;
    347 
    348 	/* Create mounted volume structure. */
    349 	hmp = (struct hfspmount*)malloc(sizeof(struct hfspmount),
    350             M_HFSPMNT, M_WAITOK);
    351 	if (hmp == NULL) {
    352 		error = ENOMEM;
    353 		goto error;
    354 	}
    355 	memset(hmp, 0, sizeof(struct hfspmount));
    356 
    357 	mp->mnt_data = hmp;
    358 	mp->mnt_flag |= MNT_LOCAL;
    359 	vfs_getnewfsid(mp);
    360 
    361 	hmp->hm_mountp = mp;
    362 	hmp->hm_dev = devvp->v_rdev;
    363 	hmp->hm_devvp = devvp;
    364 
    365 	/*
    366 	 * Use libhfsp to open the volume and read the volume header and other
    367 	 * useful information.
    368 	 */
    369 
    370 	hfsplib_init_cbargs(&cbargs);
    371 	argsopen.cred = argsread.cred = cred;
    372 	argsopen.l = argsread.l = l;
    373 	argsopen.devvp = devvp;
    374 	cbargs.read = (void*)&argsread;
    375 	cbargs.openvol = (void*)&argsopen;
    376 
    377 	if ((error = hfsplib_open_volume(devpath, offset, mp->mnt_flag & MNT_RDONLY,
    378 		&hmp->hm_vol, &cbargs)) != 0)
    379 		goto error;
    380 
    381 	/* Make sure this is not a journaled volume whose journal is dirty. */
    382 	if (!hfsplib_is_journal_clean(&hmp->hm_vol)) {
    383 		printf("volume journal is dirty; not mounting\n");
    384 		error = EIO;
    385 		goto error;
    386 	}
    387 
    388 	hmp->offset = offset >> DEV_BSHIFT;
    389 	mp->mnt_fs_bshift = 0;
    390         while ((1 << mp->mnt_fs_bshift) < hmp->hm_vol.vh.block_size)
    391 		mp->mnt_fs_bshift++;
    392 	mp->mnt_dev_bshift = DEV_BSHIFT;
    393 
    394 	return 0;
    395 
    396 error:
    397 	if (hmp != NULL)
    398 		free(hmp, M_HFSPMNT);
    399 
    400 	return error;
    401 }
    402 
    403 int
    404 hfsp_unmount(struct mount *mp, int mntflags, struct lwp *l)
    405 {
    406 	hfsp_callback_args cbargs;
    407 	hfsp_libcb_argsread argsclose;
    408 	struct hfspmount* hmp;
    409 	int error;
    410 	int flags;
    411 
    412 #ifdef HFSP_DEBUG
    413 	printf("vfsop = hfsp_unmount()\n");
    414 #endif /* HFSP_DEBUG */
    415 
    416 	hmp = VFSTOHFSP(mp);
    417 
    418 	flags = 0;
    419 	if (mntflags & MNT_FORCE)
    420 		flags |= FORCECLOSE;
    421 
    422 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    423 		return error;
    424 
    425 	hfsplib_init_cbargs(&cbargs);
    426 	argsclose.l = l;
    427 	cbargs.closevol = (void*)&argsclose;
    428 	hfsplib_close_volume(&hmp->hm_vol, &cbargs);
    429 
    430 	vput(hmp->hm_devvp);
    431 
    432 	free(hmp, M_HFSPMNT);
    433 	mp->mnt_data = NULL;
    434 	mp->mnt_flag &= ~MNT_LOCAL;
    435 
    436 	return error;
    437 }
    438 
    439 int
    440 hfsp_root(struct mount *mp, struct vnode **vpp)
    441 {
    442 	struct vnode *nvp;
    443 	int error;
    444 
    445 #ifdef HFSP_DEBUG
    446 	printf("vfsop = hfsp_root()\n");
    447 #endif /* HFSP_DEBUG */
    448 
    449 	if ((error = VFS_VGET(mp, HFSP_CNID_ROOT_FOLDER, &nvp)) != 0)
    450 		return error;
    451 	*vpp = nvp;
    452 
    453 	return 0;
    454 }
    455 
    456 int
    457 hfsp_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg,
    458     struct lwp *l)
    459 {
    460 
    461 #ifdef HFSP_DEBUG
    462 	printf("vfsop = hfsp_quotactl()\n");
    463 #endif /* HFSP_DEBUG */
    464 
    465 	return EOPNOTSUPP;
    466 }
    467 
    468 int
    469 hfsp_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
    470 {
    471 	hfsp_volume_header_t *vh;
    472 
    473 #ifdef HFSP_DEBUG
    474 	printf("vfsop = hfsp_statvfs()\n");
    475 #endif /* HFSP_DEBUG */
    476 
    477 	vh = &VFSTOHFSP(mp)->hm_vol.vh;
    478 
    479 	sbp->f_bsize = vh->block_size;
    480 	sbp->f_frsize = sbp->f_bsize;
    481 	sbp->f_iosize = 4096;/* mac os x uses a 4 kb io size, so do the same */
    482 	sbp->f_blocks = vh->total_blocks;
    483 	sbp->f_bfree = vh->free_blocks; /* total free blocks */
    484 	sbp->f_bavail = vh->free_blocks; /* blocks free for non superuser */
    485 	sbp->f_bresvd = 0;
    486 	sbp->f_files =  vh->file_count; /* total files */
    487 	sbp->f_ffree = (1<<31) - vh->file_count; /* free file nodes */
    488 	copy_statvfs_info(sbp, mp);
    489 
    490 	return 0;
    491 }
    492 
    493 int
    494 hfsp_sync(struct mount *mp, int waitfor, kauth_cred_t cred, struct lwp *l)
    495 {
    496 
    497 #ifdef HFSP_DEBUG
    498 	printf("vfsop = hfsp_sync()\n");
    499 #endif /* HFSP_DEBUG */
    500 
    501 	return 0;
    502 }
    503 
    504 /*
    505  * an ino_t corresponds directly to a CNID in our particular case,
    506  * since both are conveniently 32-bit numbers
    507  */
    508 int
    509 hfsp_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
    510 {
    511     return hfsp_vget_internal(mp, ino, HFSP_DATAFORK, vpp);
    512 }
    513 
    514 /*
    515  * internal version with extra arguments to allow accessing resource fork
    516  */
    517 int
    518 hfsp_vget_internal(struct mount *mp, ino_t ino, uint8_t fork,
    519     struct vnode **vpp)
    520 {
    521 	struct hfspmount *hmp;
    522 	struct hfspnode *hnode;
    523 	struct vnode *vp;
    524 	hfsp_callback_args cbargs;
    525 	hfsp_cnid_t cnid;
    526 	hfsp_catalog_keyed_record_t rec;
    527 	hfsp_catalog_key_t key; /* the search key used to find this file on disk */
    528 	dev_t dev;
    529 	int error;
    530 
    531 #ifdef HFSP_DEBUG
    532 	printf("vfsop = hfsp_vget()\n");
    533 #endif /* HFSP_DEBUG */
    534 
    535 	hnode = NULL;
    536 	vp = NULL;
    537 	hmp = VFSTOHFSP(mp);
    538 	dev = hmp->hm_dev;
    539 	cnid = (hfsp_cnid_t)ino;
    540 
    541 	if (fork != HFSP_RSRCFORK)
    542 	    fork = HFSP_DATAFORK;
    543 
    544 	/* Check if this vnode has already been allocated. If so, just return it. */
    545 	if ((*vpp = hfsp_nhashget(dev, cnid, fork, LK_EXCLUSIVE)) != NULL)
    546 		return 0;
    547 
    548 	/* Allocate a new vnode/inode. */
    549 	if ((error = getnewvnode(VT_HFSP, mp, hfsp_vnodeop_p, &vp)) != 0)
    550 		goto error;
    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 
    557 	do {
    558 		if ((*vpp = hfsp_nhashget(dev, cnid, fork, LK_EXCLUSIVE))
    559 		    != NULL) {
    560 			ungetnewvnode(vp);
    561 			return 0;
    562 		}
    563 	} while (lockmgr(&hfsp_hashlock, LK_EXCLUSIVE|LK_SLEEPFAIL, 0));
    564 
    565 	vp->v_flag |= VLOCKSWORK;
    566 
    567 	MALLOC(hnode, struct hfspnode *, sizeof(struct hfspnode), M_TEMP,
    568 		M_WAITOK + M_ZERO);
    569 	vp->v_data = hnode;
    570 
    571 	hnode->h_vnode = vp;
    572 	hnode->h_hmp = hmp;
    573 	hnode->dummy = 0x1337BABE;
    574 
    575 	/*
    576 	 * We need to put this vnode into the hash chain and lock it so that other
    577 	 * requests for this inode will block if they arrive while we are sleeping
    578 	 * waiting for old data structures to be purged or for the contents of the
    579 	 * disk portion of this inode to be read. The hash chain requires the node's
    580 	 * device and cnid to be known. Since this information was passed in the
    581 	 * arguments, fill in the appropriate hfspnode fields without reading having
    582 	 * to read the disk.
    583 	 */
    584 	hnode->h_dev = dev;
    585 	hnode->h_rec.cnid = cnid;
    586 	hnode->h_fork = fork;
    587 
    588 	hfsp_nhashinsert(hnode);
    589 	lockmgr(&hfsp_hashlock, LK_RELEASE, 0);
    590 
    591 
    592 	/*
    593 	 * Read catalog record from disk.
    594 	 */
    595 	hfsplib_init_cbargs(&cbargs);
    596 
    597 	if (hfsplib_find_catalog_record_with_cnid(&hmp->hm_vol, cnid,
    598 		&rec, &key, &cbargs) != 0) {
    599 		vput(vp);
    600 		error = EBADF;
    601 		goto error;
    602 	}
    603 
    604 	memcpy(&hnode->h_rec, &rec, sizeof(hnode->h_rec));
    605 	hnode->h_parent = key.parent_cnid;
    606 
    607 	/* XXX Eventually need to add an "ignore permissions" mount option */
    608 
    609 	/*
    610 	 * Now convert some of the catalog record's fields into values that make
    611 	 * sense on this system.
    612 	 */
    613 	/* DATE AND TIME */
    614 
    615 	/*
    616 	 * Initialize the vnode from the hfspnode, check for aliases.
    617 	 * Note that the underlying vnode may have changed.
    618 	 */
    619 
    620 	hfsp_vinit(mp, hfsp_specop_p, hfsp_fifoop_p, &vp);
    621 
    622 	genfs_node_init(vp, &hfsp_genfsops);
    623 	hnode->h_devvp = hmp->hm_devvp;
    624 	VREF(hnode->h_devvp);  /* Increment the ref count to the volume's device. */
    625 
    626 	/* Make sure UVM has allocated enough memory. (?) */
    627 	if (hnode->h_rec.rec_type == HFSP_REC_FILE) {
    628 		if (hnode->h_fork == HFSP_DATAFORK)
    629 			uvm_vnp_setsize(vp,
    630 			    hnode->h_rec.file.data_fork.logical_size);
    631 		else
    632 			uvm_vnp_setsize(vp,
    633 			    hnode->h_rec.file.rsrc_fork.logical_size);
    634 	}
    635 	else
    636 		uvm_vnp_setsize(vp, 0); /* no directly reading directories */
    637 
    638 	*vpp = vp;
    639 
    640 	return 0;
    641 
    642 error:
    643 	*vpp = NULL;
    644 	return error;
    645 }
    646 
    647 int
    648 hfsp_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
    649 {
    650 
    651 #ifdef HFSP_DEBUG
    652 	printf("vfsop = hfsp_fhtovp()\n");
    653 #endif /* HFSP_DEBUG */
    654 
    655 	return EOPNOTSUPP;
    656 }
    657 
    658 int
    659 hfsp_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
    660 {
    661 
    662 #ifdef HFSP_DEBUG
    663 	printf("vfsop = hfsp_vptofh()\n");
    664 #endif /* HFSP_DEBUG */
    665 
    666 	return EOPNOTSUPP;
    667 }
    668 
    669 void
    670 hfsp_init(void)
    671 {
    672 	hfsp_callbacks	callbacks;
    673 
    674 #ifdef HFSP_DEBUG
    675 	printf("vfsop = hfsp_init()\n");
    676 #endif /* HFSP_DEBUG */
    677 
    678 #ifdef _LKM
    679 	malloc_type_attach(M_HFSPMNT);
    680 #endif
    681 
    682 	callbacks.error = hfsp_libcb_error;
    683 	callbacks.allocmem = hfsp_libcb_malloc;
    684 	callbacks.reallocmem = hfsp_libcb_realloc;
    685 	callbacks.freemem = hfsp_libcb_free;
    686 	callbacks.openvol = hfsp_libcb_opendev;
    687 	callbacks.closevol = hfsp_libcb_closedev;
    688 	callbacks.read = hfsp_libcb_read;
    689 
    690 	hfsp_nhashinit();
    691 	hfsplib_init(&callbacks);
    692 }
    693 
    694 void
    695 hfsp_reinit(void)
    696 {
    697 
    698 #ifdef HFSP_DEBUG
    699 	printf("vfsop = hfsp_reinit()\n");
    700 #endif /* HFSP_DEBUG */
    701 
    702 	return;
    703 }
    704 
    705 void
    706 hfsp_done(void)
    707 {
    708 
    709 #ifdef HFSP_DEBUG
    710 	printf("vfsop = hfsp_done()\n");
    711 #endif /* HFSP_DEBUG */
    712 
    713 #ifdef _LKM
    714 	malloc_type_detach(M_HFSPMNT);
    715 #endif
    716 
    717 	hfsplib_done();
    718 	hfsp_nhashdone();
    719 }
    720 
    721 int
    722 hfsp_mountroot(void)
    723 {
    724 
    725 #ifdef HFSP_DEBUG
    726 	printf("vfsop = hfsp_mountroot()\n");
    727 #endif /* HFSP_DEBUG */
    728 
    729 	return EOPNOTSUPP;
    730 }
    731 
    732 int hfsp_extattrctl(struct mount *mp, int cmd, struct vnode *vp,
    733     int attrnamespace, const char *attrname, struct lwp *l)
    734 {
    735 
    736 #ifdef HFSP_DEBUG
    737 	printf("vfsop = hfsp_checkexp()\n");
    738 #endif /* HFSP_DEBUG */
    739 
    740 	return EOPNOTSUPP;
    741 }
    742