Home | History | Annotate | Line # | Download | only in hfs
hfs_vfsops.c revision 1.33.2.2
      1 /*	$NetBSD: hfs_vfsops.c,v 1.33.2.2 2017/03/20 06:57:46 pgoyette 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.33.2.2 2017/03/20 06:57:46 pgoyette Exp $");
    103 
    104 #ifdef _KERNEL_OPT
    105 #include "opt_compat_netbsd.h"
    106 #endif
    107 
    108 #include <sys/param.h>
    109 #include <sys/systm.h>
    110 #include <sys/namei.h>
    111 #include <sys/proc.h>
    112 #include <sys/kernel.h>
    113 #include <sys/vnode.h>
    114 #include <sys/socket.h>
    115 #include <sys/mount.h>
    116 #include <sys/buf.h>
    117 #include <sys/device.h>
    118 #include <sys/mbuf.h>
    119 #include <sys/file.h>
    120 #include <sys/disklabel.h>
    121 #include <sys/ioctl.h>
    122 #include <sys/errno.h>
    123 #include <sys/malloc.h>
    124 #include <sys/pool.h>
    125 #include <sys/lock.h>
    126 #include <sys/sysctl.h>
    127 #include <sys/conf.h>
    128 #include <sys/kauth.h>
    129 #include <sys/stat.h>
    130 #include <sys/module.h>
    131 
    132 #include <miscfs/genfs/genfs.h>
    133 #include <miscfs/specfs/specdev.h>
    134 
    135 #include <fs/hfs/hfs.h>
    136 #include <fs/hfs/libhfs.h>
    137 
    138 MODULE(MODULE_CLASS_VFS, hfs, NULL);
    139 
    140 MALLOC_JUSTDEFINE(M_HFSMNT, "hfs mount", "hfs mount structures");
    141 
    142 struct pool hfs_node_pool;
    143 
    144 const struct vnodeopv_desc * const hfs_vnodeopv_descs[] = {
    145 	&hfs_vnodeop_opv_desc,
    146 	&hfs_specop_opv_desc,
    147 	&hfs_fifoop_opv_desc,
    148 	NULL,
    149 };
    150 
    151 struct vfsops hfs_vfsops = {
    152 	.vfs_name = MOUNT_HFS,
    153 	.vfs_min_mount_data = sizeof (struct hfs_args),
    154 	.vfs_mount = hfs_mount,
    155 	.vfs_start = hfs_start,
    156 	.vfs_unmount = hfs_unmount,
    157 	.vfs_root = hfs_root,
    158 	.vfs_quotactl = (void *)eopnotsupp,
    159 	.vfs_statvfs = hfs_statvfs,
    160 	.vfs_sync = hfs_sync,
    161 	.vfs_vget = hfs_vget,
    162 	.vfs_loadvnode = hfs_loadvnode,
    163 	.vfs_fhtovp = hfs_fhtovp,
    164 	.vfs_vptofh = hfs_vptofh,
    165 	.vfs_init = hfs_init,
    166 	.vfs_reinit = hfs_reinit,
    167 	.vfs_done = hfs_done,
    168 	.vfs_extattrctl = vfs_stdextattrctl,
    169 	.vfs_suspendctl = genfs_suspendctl,
    170 	.vfs_renamelock_enter = genfs_renamelock_enter,
    171 	.vfs_renamelock_exit = genfs_renamelock_exit,
    172 	.vfs_fsync = (void *)eopnotsupp,
    173 	.vfs_opv_descs = hfs_vnodeopv_descs
    174 };
    175 
    176 static const struct genfs_ops hfs_genfsops = {
    177 	.gop_size = genfs_size,
    178 };
    179 
    180 static int
    181 hfs_modcmd(modcmd_t cmd, void *arg)
    182 {
    183 	switch (cmd) {
    184 	case MODULE_CMD_INIT:
    185 		return vfs_attach(&hfs_vfsops);
    186 	case MODULE_CMD_FINI:
    187 		return vfs_detach(&hfs_vfsops);
    188 	default:
    189 		return ENOTTY;
    190 	}
    191 }
    192 
    193 int
    194 hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
    195 {
    196 	struct lwp *l = curlwp;
    197 	struct hfs_args *args = data;
    198 	struct vnode *devvp;
    199 	struct hfsmount *hmp;
    200 	int error = 0;
    201 	int update;
    202 	mode_t accessmode;
    203 	const struct bdevsw *bdev;
    204 
    205 	if (args == NULL)
    206 		return EINVAL;
    207 	if (*data_len < sizeof *args)
    208 		return EINVAL;
    209 
    210 #ifdef HFS_DEBUG
    211 	printf("vfsop = hfs_mount()\n");
    212 #endif /* HFS_DEBUG */
    213 
    214 	if (mp->mnt_flag & MNT_GETARGS) {
    215 		hmp = VFSTOHFS(mp);
    216 		if (hmp == NULL)
    217 			return EIO;
    218 		args->fspec = NULL;
    219 		*data_len = sizeof *args;
    220 		return 0;
    221 	}
    222 
    223 /* FIXME: For development ONLY - disallow remounting for now */
    224 #if 0
    225 	update = mp->mnt_flag & MNT_UPDATE;
    226 #else
    227 	update = 0;
    228 #endif
    229 
    230 	/* Check arguments */
    231 	bdev = NULL;
    232 	if (args->fspec != NULL) {
    233 		/*
    234 		 * Look up the name and verify that it's sane.
    235 		 */
    236 		error = namei_simple_user(args->fspec,
    237 					NSM_FOLLOW_NOEMULROOT, &devvp);
    238 		if (error != 0)
    239 			return error;
    240 
    241 		if (!update) {
    242 			/*
    243 			 * Be sure this is a valid block device
    244 			 */
    245 			if (devvp->v_type != VBLK)
    246 				error = ENOTBLK;
    247 			else if ((bdev = bdevsw_lookup_acquire(devvp->v_rdev))
    248 					== 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 	 * If mount by non-root, then verify that user has necessary
    273 	 * permissions on the device.
    274 	 *
    275 	 * Permission to update a mount is checked higher, so here we presume
    276 	 * updating the mount is okay (for example, as far as securelevel goes)
    277 	 * which leaves us with the normal check.
    278 	 */
    279 	if (error == 0) {
    280 		accessmode = VREAD;
    281 		if (update ?
    282 			(mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
    283 			(mp->mnt_flag & MNT_RDONLY) == 0)
    284 			accessmode |= VWRITE;
    285 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    286 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
    287 		    KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp,
    288 		    KAUTH_ARG(accessmode));
    289 		VOP_UNLOCK(devvp);
    290 	}
    291 
    292 	if (error != 0)
    293 		goto error;
    294 
    295 	if (update) {
    296 		printf("HFS: live remounting not yet supported!\n");
    297 		error = EINVAL;
    298 		goto error;
    299 	}
    300 
    301 	if ((error = hfs_mountfs(devvp, mp, l, args->fspec)) != 0)
    302 		goto error;
    303 
    304 	error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
    305 		mp->mnt_op->vfs_name, mp, l);
    306 
    307 #ifdef HFS_DEBUG
    308 	if(!update) {
    309 		char* volname;
    310 
    311 		hmp = VFSTOHFS(mp);
    312 		volname = malloc(hmp->hm_vol.name.length + 1, M_TEMP, M_WAITOK);
    313 		if (volname == NULL)
    314 			printf("could not allocate volname; ignored\n");
    315 		else {
    316 			if (hfs_unicode_to_ascii(hmp->hm_vol.name.unicode,
    317 				hmp->hm_vol.name.length, volname) == NULL)
    318 				printf("could not convert volume name to ascii; ignored\n");
    319 			else
    320 				printf("mounted volume \"%s\"\n", volname);
    321 			free(volname, M_TEMP);
    322 		}
    323 	}
    324 #endif /* HFS_DEBUG */
    325 
    326 	if (bdev != NULL)
    327 		bdevsw_release(bdev);
    328 	return error;
    329 
    330 error:
    331 	if (bdev != NULL)
    332 		bdevsw_release(bdev);
    333 	vrele(devvp);
    334 	return error;
    335 }
    336 
    337 int
    338 hfs_start(struct mount *mp, int flags)
    339 {
    340 #ifdef HFS_DEBUG
    341 	printf("vfsop = hfs_start()\n");
    342 #endif /* HFS_DEBUG */
    343 
    344 	return 0;
    345 }
    346 
    347 int
    348 hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l,
    349     const char *devpath)
    350 {
    351 	hfs_callback_args cbargs;
    352 	hfs_libcb_argsopen argsopen;
    353 	hfs_libcb_argsread argsread;
    354 	struct hfsmount *hmp;
    355 	kauth_cred_t cred;
    356 	int error;
    357 
    358 	cred = l ? l->l_cred : NOCRED;
    359 	error = 0;
    360 	hmp = NULL;
    361 
    362 	/* Create mounted volume structure. */
    363 	hmp = malloc(sizeof(struct hfsmount), M_HFSMNT, M_WAITOK|M_ZERO);
    364 	if (hmp == NULL) {
    365 		error = ENOMEM;
    366 		goto error;
    367 	}
    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 	return error;
    411 }
    412 
    413 int
    414 hfs_unmount(struct mount *mp, int mntflags)
    415 {
    416 	hfs_callback_args cbargs;
    417 	hfs_libcb_argsread argsclose;
    418 	struct hfsmount* hmp;
    419 	int error;
    420 	int flags;
    421 
    422 #ifdef HFS_DEBUG
    423 	printf("vfsop = hfs_unmount()\n");
    424 #endif /* HFS_DEBUG */
    425 
    426 	hmp = VFSTOHFS(mp);
    427 
    428 	flags = 0;
    429 	if (mntflags & MNT_FORCE)
    430 		flags |= FORCECLOSE;
    431 
    432 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    433 		return error;
    434 
    435 	hfslib_init_cbargs(&cbargs);
    436 	argsclose.l = curlwp;
    437 	cbargs.closevol = (void*)&argsclose;
    438 	hfslib_close_volume(&hmp->hm_vol, &cbargs);
    439 
    440 	vrele(hmp->hm_devvp);
    441 
    442 	free(hmp, M_HFSMNT);
    443 	mp->mnt_data = NULL;
    444 	mp->mnt_flag &= ~MNT_LOCAL;
    445 
    446 	return error;
    447 }
    448 
    449 int
    450 hfs_root(struct mount *mp, struct vnode **vpp)
    451 {
    452 	struct vnode *nvp;
    453 	int error;
    454 
    455 #ifdef HFS_DEBUG
    456 	printf("vfsop = hfs_root()\n");
    457 #endif /* HFS_DEBUG */
    458 
    459 	if ((error = VFS_VGET(mp, HFS_CNID_ROOT_FOLDER, &nvp)) != 0)
    460 		return error;
    461 	*vpp = nvp;
    462 
    463 	return 0;
    464 }
    465 
    466 int
    467 hfs_statvfs(struct mount *mp, struct statvfs *sbp)
    468 {
    469 	hfs_volume_header_t *vh;
    470 
    471 #ifdef HFS_DEBUG
    472 	printf("vfsop = hfs_statvfs()\n");
    473 #endif /* HFS_DEBUG */
    474 
    475 	vh = &VFSTOHFS(mp)->hm_vol.vh;
    476 
    477 	sbp->f_bsize = vh->block_size;
    478 	sbp->f_frsize = sbp->f_bsize;
    479 	sbp->f_iosize = 4096;/* mac os x uses a 4 kb io size, so do the same */
    480 	sbp->f_blocks = vh->total_blocks;
    481 	sbp->f_bfree = vh->free_blocks; /* total free blocks */
    482 	sbp->f_bavail = vh->free_blocks; /* blocks free for non superuser */
    483 	sbp->f_bresvd = 0;
    484 	sbp->f_files =  vh->file_count; /* total files */
    485 	sbp->f_ffree = (1<<31) - vh->file_count; /* free file nodes */
    486 	copy_statvfs_info(sbp, mp);
    487 
    488 	return 0;
    489 }
    490 
    491 int
    492 hfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
    493 {
    494 #ifdef HFS_DEBUG
    495 	printf("vfsop = hfs_sync()\n");
    496 #endif /* HFS_DEBUG */
    497 
    498 	return 0;
    499 }
    500 
    501 /*
    502  * an ino_t corresponds directly to a CNID in our particular case,
    503  * since both are conveniently 32-bit numbers
    504  */
    505 int
    506 hfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
    507 {
    508 	int error;
    509 
    510 	error = hfs_vget_internal(mp, ino, HFS_DATAFORK, vpp);
    511 	if (error)
    512 		return error;
    513 	error = vn_lock(*vpp, LK_EXCLUSIVE);
    514 	if (error) {
    515 		vrele(*vpp);
    516 		*vpp = NULL;
    517 		return error;
    518 	}
    519 	return 0;
    520 }
    521 
    522 /*
    523  * internal version with extra arguments to allow accessing resource fork
    524  */
    525 int
    526 hfs_vget_internal(struct mount *mp, ino_t ino, uint8_t fork,
    527     struct vnode **vpp)
    528 {
    529 	struct hfsnode_key key;
    530 
    531 	memset(&key, 0, sizeof(key));
    532 	key.hnk_cnid = (hfs_cnid_t)ino;
    533 	key.hnk_fork = (fork != HFS_RSRCFORK ? HFS_DATAFORK : HFS_RSRCFORK);
    534 
    535 	return vcache_get(mp, &key, sizeof(key), vpp);
    536 }
    537 
    538 int
    539 hfs_loadvnode(struct mount *mp, struct vnode *vp,
    540     const void *key, size_t key_len, const void **new_key)
    541 {
    542 	struct hfsmount *hmp;
    543 	struct hfsnode *hnode;
    544 	struct hfsnode_key hfskey;
    545 	hfs_callback_args cbargs;
    546 	hfs_catalog_keyed_record_t rec;
    547 	hfs_catalog_key_t cat_key; /* the search key used to find this file on disk */
    548 	dev_t dev;
    549 
    550 #ifdef HFS_DEBUG
    551 	printf("vfsop = hfs_loadvnode()\n");
    552 #endif /* HFS_DEBUG */
    553 
    554 	KASSERT(key_len == sizeof(hfskey));
    555 	memcpy(&hfskey, key, key_len);
    556 
    557 	hmp = VFSTOHFS(mp);
    558 	dev = hmp->hm_dev;
    559 
    560 	hnode = pool_get(&hfs_node_pool, PR_WAITOK);
    561 	memset(hnode, 0, sizeof(*hnode));
    562 	hnode->h_vnode = vp;
    563 	hnode->h_hmp = hmp;
    564 	hnode->dummy = 0x1337BABE;
    565 	hnode->h_dev = dev;
    566 	hnode->h_rec.u.cnid = hfskey.hnk_cnid;
    567 	hnode->h_fork = hfskey.hnk_fork;
    568 	hnode->h_key = hfskey;
    569 
    570 	/*
    571 	 * Read catalog record from disk.
    572 	 */
    573 	hfslib_init_cbargs(&cbargs);
    574 
    575 	if (hfslib_find_catalog_record_with_cnid(&hmp->hm_vol, hfskey.hnk_cnid,
    576 		&rec, &cat_key, &cbargs) != 0) {
    577 		pool_put(&hfs_node_pool, hnode);
    578 		return EBADF;
    579 	}
    580 
    581 	memcpy(&hnode->h_rec, &rec, sizeof(hnode->h_rec));
    582 	hnode->h_parent = cat_key.parent_cnid;
    583 
    584 	/* XXX Eventually need to add an "ignore permissions" mount option */
    585 
    586 	/*
    587 	 * Now convert some of the catalog record's fields into values that make
    588 	 * sense on this system.
    589 	 */
    590 	/* DATE AND TIME */
    591 
    592 	vp->v_tag = VT_HFS;
    593 	vp->v_op = hfs_vnodeop_p;
    594 	vp->v_vflag |= VV_LOCKSWORK;
    595 	vp->v_data = hnode;
    596 	genfs_node_init(vp, &hfs_genfsops);
    597 
    598 	/*
    599 	 * Initialize the vnode from the hfsnode, check for aliases.
    600 	 */
    601 	hfs_vinit(mp, hfs_specop_p, hfs_fifoop_p, &vp);
    602 
    603 	hnode->h_devvp = hmp->hm_devvp;
    604 	vref(hnode->h_devvp);  /* Increment the ref count to the volume's device. */
    605 
    606 	/* Make sure UVM has allocated enough memory. (?) */
    607 	if (hnode->h_rec.u.rec_type == HFS_REC_FILE) {
    608 		if (hnode->h_fork == HFS_DATAFORK)
    609 			uvm_vnp_setsize(vp,
    610 			    hnode->h_rec.file.data_fork.logical_size);
    611 		else
    612 			uvm_vnp_setsize(vp,
    613 			    hnode->h_rec.file.rsrc_fork.logical_size);
    614 	}
    615 	else
    616 		uvm_vnp_setsize(vp, 0); /* no directly reading directories */
    617 
    618 	*new_key = &hnode->h_key;
    619 	return 0;
    620 }
    621 
    622 int
    623 hfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
    624 {
    625 
    626 #ifdef HFS_DEBUG
    627 	printf("vfsop = hfs_fhtovp()\n");
    628 #endif /* HFS_DEBUG */
    629 
    630 	return EOPNOTSUPP;
    631 }
    632 
    633 int
    634 hfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
    635 {
    636 #ifdef HFS_DEBUG
    637 	printf("vfsop = hfs_vptofh()\n");
    638 #endif /* HFS_DEBUG */
    639 
    640 	return EOPNOTSUPP;
    641 }
    642 
    643 void
    644 hfs_init(void)
    645 {
    646 	hfs_callbacks	callbacks;
    647 
    648 #ifdef HFS_DEBUG
    649 	printf("vfsop = hfs_init()\n");
    650 #endif /* HFS_DEBUG */
    651 
    652 	malloc_type_attach(M_HFSMNT);
    653 	pool_init(&hfs_node_pool, sizeof(struct hfsnode), 0, 0, 0, "hfsndpl",
    654 	    &pool_allocator_nointr, IPL_NONE);
    655 
    656 	callbacks.error = hfs_libcb_error;
    657 	callbacks.allocmem = hfs_libcb_malloc;
    658 	callbacks.reallocmem = hfs_libcb_realloc;
    659 	callbacks.freemem = hfs_libcb_free;
    660 	callbacks.openvol = hfs_libcb_opendev;
    661 	callbacks.closevol = hfs_libcb_closedev;
    662 	callbacks.read = hfs_libcb_read;
    663 
    664 	hfslib_init(&callbacks);
    665 }
    666 
    667 void
    668 hfs_reinit(void)
    669 {
    670 #ifdef HFS_DEBUG
    671 	printf("vfsop = hfs_reinit()\n");
    672 #endif /* HFS_DEBUG */
    673 
    674 	return;
    675 }
    676 
    677 void
    678 hfs_done(void)
    679 {
    680 #ifdef HFS_DEBUG
    681 	printf("vfsop = hfs_done()\n");
    682 #endif /* HFS_DEBUG */
    683 
    684 	malloc_type_detach(M_HFSMNT);
    685 	pool_destroy(&hfs_node_pool);
    686 	hfslib_done();
    687 }
    688 
    689 int
    690 hfs_mountroot(void)
    691 {
    692 #ifdef HFS_DEBUG
    693 	printf("vfsop = hfs_mountroot()\n");
    694 #endif /* HFS_DEBUG */
    695 
    696 	return EOPNOTSUPP;
    697 }
    698