Home | History | Annotate | Line # | Download | only in hfs
hfs_vnops.c revision 1.31
      1 /*	$NetBSD: hfs_vnops.c,v 1.31 2014/08/10 08:53:22 hannken 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) 1992, 1993
     34  *	The Regents of the University of California.  All rights reserved.
     35  *
     36  * This code is derived from software donated to Berkeley by
     37  * Jan-Simon Pendry.
     38  *
     39  * Redistribution and use in source and binary forms, with or without
     40  * modification, are permitted provided that the following conditions
     41  * are met:
     42  * 1. Redistributions of source code must retain the above copyright
     43  *    notice, this list of conditions and the following disclaimer.
     44  * 2. Redistributions in binary form must reproduce the above copyright
     45  *    notice, this list of conditions and the following disclaimer in the
     46  *    documentation and/or other materials provided with the distribution.
     47  * 3. Neither the name of the University nor the names of its contributors
     48  *    may be used to endorse or promote products derived from this software
     49  *    without specific prior written permission.
     50  *
     51  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     53  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     54  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     55  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     56  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     57  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     58  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     59  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     60  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     61  * SUCH DAMAGE.
     62  */
     63 
     64 /*
     65  * Copyright (c) 1982, 1986, 1989, 1993, 1995
     66  *	The Regents of the University of California.  All rights reserved.
     67  * (c) UNIX System Laboratories, Inc.
     68  * All or some portions of this file are derived from material licensed
     69  * to the University of California by American Telephone and Telegraph
     70  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     71  * the permission of UNIX System Laboratories, Inc.
     72  *
     73  * Redistribution and use in source and binary forms, with or without
     74  * modification, are permitted provided that the following conditions
     75  * are met:
     76  * 1. Redistributions of source code must retain the above copyright
     77  *    notice, this list of conditions and the following disclaimer.
     78  * 2. Redistributions in binary form must reproduce the above copyright
     79  *    notice, this list of conditions and the following disclaimer in the
     80  *    documentation and/or other materials provided with the distribution.
     81  * 3. Neither the name of the University nor the names of its contributors
     82  *    may be used to endorse or promote products derived from this software
     83  *    without specific prior written permission.
     84  *
     85  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     86  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     87  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     88  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     89  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     90  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     91  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     92  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     93  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     94  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     95  * SUCH DAMAGE.
     96  */
     97 
     98 
     99 /*
    100  * Apple HFS+ filesystem
    101  */
    102 
    103 #include <sys/cdefs.h>
    104 __KERNEL_RCSID(0, "$NetBSD: hfs_vnops.c,v 1.31 2014/08/10 08:53:22 hannken Exp $");
    105 
    106 #ifdef _KERNEL_OPT
    107 #include "opt_ipsec.h"
    108 #endif
    109 
    110 #include <sys/param.h>
    111 #include <sys/systm.h>
    112 #include <sys/kernel.h>
    113 #include <sys/vmmeter.h>
    114 #include <sys/time.h>
    115 #include <sys/proc.h>
    116 #include <sys/vnode.h>
    117 #include <sys/malloc.h>
    118 #include <sys/pool.h>
    119 #include <sys/file.h>
    120 #include <sys/stat.h>
    121 #include <sys/mount.h>
    122 #include <sys/namei.h>
    123 #include <sys/buf.h>
    124 #include <sys/dirent.h>
    125 #include <sys/msgbuf.h>
    126 
    127 #include <miscfs/fifofs/fifo.h>
    128 #include <miscfs/specfs/specdev.h>
    129 
    130 #include <fs/hfs/hfs.h>
    131 #include <fs/hfs/unicode.h>
    132 
    133 #include <miscfs/genfs/genfs.h>
    134 
    135 int	hfs_vop_lookup(void *);
    136 int	hfs_vop_open(void *);
    137 int	hfs_vop_close(void *);
    138 int	hfs_vop_access(void *);
    139 int	hfs_vop_getattr(void *);
    140 int	hfs_vop_setattr(void *);
    141 int	hfs_vop_bmap(void *);
    142 int	hfs_vop_read(void *);
    143 int	hfs_vop_readdir(void *);
    144 int	hfs_vop_readlink(void *);
    145 int	hfs_vop_reclaim(void *);
    146 int	hfs_vop_print(void *);
    147 
    148 #ifdef HFS_DEBUG
    149 #define DPRINTF(a) printf a
    150 #else
    151 #define DPRINTF(a)
    152 #endif
    153 
    154 
    155 int (**hfs_vnodeop_p) (void *);
    156 const struct vnodeopv_entry_desc hfs_vnodeop_entries[] = {
    157 	{ &vop_default_desc, vn_default_error },
    158 	{ &vop_lookup_desc, hfs_vop_lookup },		/* lookup */
    159 	{ &vop_create_desc, genfs_eopnotsupp },		/* create */
    160 	{ &vop_whiteout_desc, genfs_eopnotsupp },	/* whiteout */
    161 	{ &vop_mknod_desc, genfs_eopnotsupp },		/* mknod */
    162 	{ &vop_open_desc, hfs_vop_open },		/* open */
    163 	{ &vop_close_desc, hfs_vop_close },		/* close */
    164 	{ &vop_access_desc, hfs_vop_access },		/* access */
    165 	{ &vop_getattr_desc, hfs_vop_getattr },		/* getattr */
    166 	{ &vop_setattr_desc, hfs_vop_setattr },		/* setattr */
    167 	{ &vop_read_desc, hfs_vop_read },		/* read */
    168 	{ &vop_write_desc, genfs_eopnotsupp },		/* write */
    169 	{ &vop_fallocate_desc, genfs_eopnotsupp },	/* fallocate */
    170 	{ &vop_fdiscard_desc, genfs_eopnotsupp },	/* fdiscard */
    171 	{ &vop_ioctl_desc, genfs_eopnotsupp },		/* ioctl */
    172 	{ &vop_fcntl_desc, genfs_fcntl },		/* fcntl */
    173 	{ &vop_poll_desc, genfs_eopnotsupp },		/* poll */
    174 	{ &vop_kqfilter_desc, genfs_kqfilter },		/* kqfilter */
    175 	{ &vop_revoke_desc, genfs_eopnotsupp },		/* revoke */
    176 	{ &vop_mmap_desc, genfs_mmap },			/* mmap */
    177 	{ &vop_fsync_desc, genfs_nullop },		/* fsync */
    178 	{ &vop_seek_desc, genfs_seek },			/* seek */
    179 	{ &vop_remove_desc, genfs_eopnotsupp },		/* remove */
    180 	{ &vop_link_desc, genfs_eopnotsupp },		/* link */
    181 	{ &vop_rename_desc, genfs_eopnotsupp },		/* rename */
    182 	{ &vop_mkdir_desc, genfs_eopnotsupp },		/* mkdir */
    183 	{ &vop_rmdir_desc, genfs_eopnotsupp },		/* rmdir */
    184 	{ &vop_symlink_desc, genfs_eopnotsupp },	/* symlink */
    185 	{ &vop_readdir_desc, hfs_vop_readdir },		/* readdir */
    186 	{ &vop_readlink_desc, hfs_vop_readlink },	/* readlink */
    187 	{ &vop_abortop_desc, genfs_abortop },		/* abortop */
    188 	{ &vop_inactive_desc, genfs_eopnotsupp },	/* inactive */
    189 	{ &vop_reclaim_desc, hfs_vop_reclaim },		/* reclaim */
    190 	{ &vop_lock_desc, genfs_lock },			/* lock */
    191 	{ &vop_unlock_desc, genfs_unlock },		/* unlock */
    192 	{ &vop_bmap_desc, hfs_vop_bmap },		/* bmap */
    193 	{ &vop_strategy_desc, genfs_eopnotsupp },	/* strategy */
    194 	{ &vop_print_desc, hfs_vop_print },		/* print */
    195 	{ &vop_islocked_desc, genfs_islocked },		/* islocked */
    196 	{ &vop_pathconf_desc, genfs_eopnotsupp },	/* pathconf */
    197 	{ &vop_advlock_desc, genfs_eopnotsupp },	/* advlock */
    198 	{ &vop_bwrite_desc, genfs_eopnotsupp },		/* bwrite */
    199 	{ &vop_getpages_desc, genfs_getpages },		/* getpages */
    200 	{ &vop_putpages_desc, genfs_putpages },		/* putpages */
    201 	{ &vop_openextattr_desc, genfs_eopnotsupp },	/* openextattr */
    202 	{ &vop_closeextattr_desc, genfs_eopnotsupp },	/* closeextattr */
    203 	{ &vop_getextattr_desc, genfs_eopnotsupp },	/* getextattr */
    204 	{ &vop_setextattr_desc, genfs_eopnotsupp },	/* setextattr */
    205 	{ &vop_listextattr_desc, genfs_eopnotsupp },	/* listextattr */
    206 	{ &vop_deleteextattr_desc, genfs_eopnotsupp },	/* deleteextattr */
    207 	{ NULL, NULL }
    208 };
    209 const struct vnodeopv_desc hfs_vnodeop_opv_desc =
    210 	{ &hfs_vnodeop_p, hfs_vnodeop_entries };
    211 
    212 int (**hfs_specop_p) (void *);
    213 const struct vnodeopv_entry_desc hfs_specop_entries[] = {
    214 	{ &vop_default_desc, vn_default_error },
    215 	{ &vop_lookup_desc, spec_lookup },		/* lookup */
    216 	{ &vop_create_desc, spec_create },		/* create */
    217 	{ &vop_mknod_desc, spec_mknod },		/* mknod */
    218 	{ &vop_open_desc, spec_open },			/* open */
    219 	{ &vop_close_desc, spec_close },		/* close */
    220 	{ &vop_access_desc, hfs_vop_access },		/* access */
    221 	{ &vop_getattr_desc, hfs_vop_getattr },		/* getattr */
    222 	{ &vop_setattr_desc, hfs_vop_setattr },		/* setattr */
    223 	{ &vop_read_desc, spec_read },			/* read */
    224 	{ &vop_write_desc, spec_write },		/* write */
    225 	{ &vop_fallocate_desc, spec_fallocate },	/* fallocate */
    226 	{ &vop_fdiscard_desc, spec_fdiscard },		/* fdiscard */
    227 	{ &vop_ioctl_desc, spec_ioctl },		/* ioctl */
    228 	{ &vop_fcntl_desc, genfs_fcntl },		/* fcntl */
    229 	{ &vop_poll_desc, spec_poll },			/* poll */
    230 	{ &vop_kqfilter_desc, spec_kqfilter },		/* kqfilter */
    231 	{ &vop_revoke_desc, spec_revoke },		/* revoke */
    232 	{ &vop_mmap_desc, spec_mmap },			/* mmap */
    233 	{ &vop_fsync_desc, spec_fsync },		/* fsync */
    234 	{ &vop_seek_desc, spec_seek },			/* seek */
    235 	{ &vop_remove_desc, spec_remove },		/* remove */
    236 	{ &vop_link_desc, spec_link },			/* link */
    237 	{ &vop_rename_desc, spec_rename },		/* rename */
    238 	{ &vop_mkdir_desc, spec_mkdir },		/* mkdir */
    239 	{ &vop_rmdir_desc, spec_rmdir },		/* rmdir */
    240 	{ &vop_symlink_desc, spec_symlink },		/* symlink */
    241 	{ &vop_readdir_desc, spec_readdir },		/* readdir */
    242 	{ &vop_readlink_desc, spec_readlink },		/* readlink */
    243 	{ &vop_abortop_desc, spec_abortop },		/* abortop */
    244 	{ &vop_inactive_desc, genfs_eopnotsupp },	/* inactive */
    245 	{ &vop_reclaim_desc, hfs_vop_reclaim },		/* reclaim */
    246 	{ &vop_lock_desc, genfs_lock },			/* lock */
    247 	{ &vop_unlock_desc, genfs_unlock },		/* unlock */
    248 	{ &vop_bmap_desc, spec_bmap },			/* bmap */
    249 	{ &vop_strategy_desc, spec_strategy },		/* strategy */
    250 	{ &vop_print_desc, hfs_vop_print },		/* print */
    251 	{ &vop_islocked_desc, genfs_islocked },		/* islocked */
    252 	{ &vop_pathconf_desc, spec_pathconf },		/* pathconf */
    253 	{ &vop_advlock_desc, spec_advlock },		/* advlock */
    254 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    255 	{ &vop_getpages_desc, spec_getpages },		/* getpages */
    256 	{ &vop_putpages_desc, spec_putpages },		/* putpages */
    257 #if 0
    258 	{ &vop_openextattr_desc, ffs_openextattr },	/* openextattr */
    259 	{ &vop_closeextattr_desc, ffs_closeextattr },	/* closeextattr */
    260 	{ &vop_getextattr_desc, ffs_getextattr },	/* getextattr */
    261 	{ &vop_setextattr_desc, ffs_setextattr },	/* setextattr */
    262 	{ &vop_listextattr_desc, ffs_listextattr },	/* listextattr */
    263 	{ &vop_deleteextattr_desc, ffs_deleteextattr },	/* deleteextattr */
    264 #endif
    265 	{ NULL, NULL }
    266 };
    267 const struct vnodeopv_desc hfs_specop_opv_desc =
    268 	{ &hfs_specop_p, hfs_specop_entries };
    269 
    270 int (**hfs_fifoop_p) (void *);
    271 const struct vnodeopv_entry_desc hfs_fifoop_entries[] = {
    272 	{ &vop_default_desc, vn_default_error },
    273 	{ &vop_lookup_desc, vn_fifo_bypass },		/* lookup */
    274 	{ &vop_create_desc, vn_fifo_bypass },		/* create */
    275 	{ &vop_mknod_desc, vn_fifo_bypass },		/* mknod */
    276 	{ &vop_open_desc, vn_fifo_bypass },		/* open */
    277 	{ &vop_close_desc, vn_fifo_bypass },		/* close */
    278 	{ &vop_access_desc, hfs_vop_access },		/* access */
    279 	{ &vop_getattr_desc, hfs_vop_getattr },		/* getattr */
    280 	{ &vop_setattr_desc, hfs_vop_setattr },		/* setattr */
    281 	{ &vop_read_desc, vn_fifo_bypass },		/* read */
    282 	{ &vop_write_desc, vn_fifo_bypass },		/* write */
    283 	{ &vop_fallocate_desc, vn_fifo_bypass },	/* fallocate */
    284 	{ &vop_fdiscard_desc, vn_fifo_bypass },		/* fdiscard */
    285 	{ &vop_ioctl_desc, vn_fifo_bypass },		/* ioctl */
    286 	{ &vop_fcntl_desc, genfs_fcntl },		/* fcntl */
    287 	{ &vop_poll_desc, vn_fifo_bypass },		/* poll */
    288 	{ &vop_kqfilter_desc, vn_fifo_bypass },		/* kqfilter */
    289 	{ &vop_revoke_desc, vn_fifo_bypass },		/* revoke */
    290 	{ &vop_mmap_desc, vn_fifo_bypass },		/* mmap */
    291 	{ &vop_fsync_desc, vn_fifo_bypass },		/* fsync */
    292 	{ &vop_seek_desc, vn_fifo_bypass },		/* seek */
    293 	{ &vop_remove_desc, vn_fifo_bypass },		/* remove */
    294 	{ &vop_link_desc, vn_fifo_bypass },		/* link */
    295 	{ &vop_rename_desc, vn_fifo_bypass },		/* rename */
    296 	{ &vop_mkdir_desc, vn_fifo_bypass },		/* mkdir */
    297 	{ &vop_rmdir_desc, vn_fifo_bypass },		/* rmdir */
    298 	{ &vop_symlink_desc, vn_fifo_bypass },		/* symlink */
    299 	{ &vop_readdir_desc, vn_fifo_bypass },		/* readdir */
    300 	{ &vop_readlink_desc, vn_fifo_bypass },		/* readlink */
    301 	{ &vop_abortop_desc, vn_fifo_bypass },		/* abortop */
    302 	{ &vop_inactive_desc, genfs_eopnotsupp },	/* inactive */
    303 	{ &vop_reclaim_desc, hfs_vop_reclaim },		/* reclaim */
    304 	{ &vop_lock_desc, genfs_lock },			/* lock */
    305 	{ &vop_unlock_desc, genfs_unlock },		/* unlock */
    306 	{ &vop_bmap_desc, vn_fifo_bypass },		/* bmap */
    307 	{ &vop_strategy_desc, vn_fifo_bypass },		/* strategy */
    308 	{ &vop_print_desc, hfs_vop_print },		/* print */
    309 	{ &vop_islocked_desc, genfs_islocked },		/* islocked */
    310 	{ &vop_pathconf_desc, vn_fifo_bypass },		/* pathconf */
    311 	{ &vop_advlock_desc, vn_fifo_bypass },		/* advlock */
    312 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    313 	{ &vop_putpages_desc, vn_fifo_bypass }, 	/* putpages */
    314 #if 0
    315 	{ &vop_openextattr_desc, ffs_openextattr },	/* openextattr */
    316 	{ &vop_closeextattr_desc, ffs_closeextattr },	/* closeextattr */
    317 	{ &vop_getextattr_desc, ffs_getextattr },	/* getextattr */
    318 	{ &vop_setextattr_desc, ffs_setextattr },	/* setextattr */
    319 	{ &vop_listextattr_desc, ffs_listextattr },	/* listextattr */
    320 	{ &vop_deleteextattr_desc, ffs_deleteextattr },	/* deleteextattr */
    321 #endif
    322 	{ NULL, NULL }
    323 };
    324 const struct vnodeopv_desc hfs_fifoop_opv_desc =
    325 	{ &hfs_fifoop_p, hfs_fifoop_entries };
    326 
    327 int
    328 hfs_vop_lookup(void *v)
    329 {
    330 	struct vop_lookup_v2_args /* {
    331 		struct vnode * a_dvp;
    332 		struct vnode ** a_vpp;
    333 		struct componentname * a_cnp;
    334 	} */ *ap = v;
    335 	struct componentname *cnp;
    336 	struct hfsnode *dp;	/* hfsnode for directory being searched */
    337 	kauth_cred_t cred;
    338 	struct vnode **vpp;		/* resultant vnode */
    339 	struct vnode *tdp;		/* returned by VFS_VGET */
    340 	struct vnode *vdp;		/* vnode for directory being searched */
    341 	hfs_catalog_key_t key;	/* hfs+ catalog search key for requested child */
    342 	hfs_catalog_keyed_record_t rec; /* catalog record of requested child */
    343 	unichar_t* unicn;		/* name of component, in Unicode */
    344 	const char *pname;
    345 	int error;
    346 	int flags;
    347 	int result;			/* result of libhfs operations */
    348 
    349 	DPRINTF(("VOP = hfs_vop_lookup()\n"));
    350 
    351 	cnp = ap->a_cnp;
    352 	cred = cnp->cn_cred;
    353 	vdp = ap->a_dvp;
    354 	dp = VTOH(vdp);
    355 	error = 0;
    356 	pname = cnp->cn_nameptr;
    357 	result = 0;
    358 	unicn = NULL;
    359 	vpp = ap->a_vpp;
    360 	*vpp = NULL;
    361 
    362 	flags = cnp->cn_flags;
    363 
    364 
    365 	/*
    366 	 * Check accessiblity of directory.
    367 	 */
    368 	if ((error = VOP_ACCESS(vdp, VEXEC, cred)) != 0)
    369 		return error;
    370 
    371 	if ((flags & ISLASTCN) && (vdp->v_mount->mnt_flag & MNT_RDONLY) &&
    372 	    (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
    373 		return EROFS;
    374 
    375 	/*
    376 	 * We now have a segment name to search for, and a directory to search.
    377 	 *
    378 	 * Before tediously performing a linear scan of the directory,
    379 	 * check the name cache to see if the directory/name pair
    380 	 * we are looking for is known already.
    381 	 */
    382 /* XXX Cache disabled until we can make sure it works. */
    383 #if 0
    384 	if ((error = cache_lookup(vdp, vpp, cnp)) >= 0)
    385 		return error;
    386 #endif
    387 
    388 
    389 #if 0
    390 	if (cnp->cn_namelen == 1 && *pname == '.') {
    391 		*vpp = vdp;
    392 		vref(vdp);
    393 		return 0;
    394 	}
    395 #endif
    396 
    397 	if (flags & ISDOTDOT) {
    398 		DPRINTF(("DOTDOT "));
    399 		error = hfs_vget_internal(vdp->v_mount, dp->h_parent,
    400 		    HFS_RSRCFORK, &tdp);
    401 		if (error != 0)
    402 			goto error;
    403 		*vpp = tdp;
    404 #if 0
    405 	} else if (dp->h_rec.u.cnid == rec.file.u.cnid) {
    406 #endif
    407 	} else if (cnp->cn_namelen == 1 && pname[0] == '.') {
    408 		DPRINTF(("DOT "));
    409 		vref(vdp);	/* we want ourself, ie "." */
    410 		*vpp = vdp;
    411 	} else {
    412 		hfs_callback_args cbargs;
    413 		uint8_t len, ni;
    414 
    415 		hfslib_init_cbargs(&cbargs);
    416 
    417 		/* XXX: when decomposing, string could grow
    418 		   and we have to handle overflow */
    419 		unicn = malloc(cnp->cn_namelen * sizeof(unicn[0]),
    420 		    M_TEMP, M_WAITOK);
    421 		len = utf8_to_utf16(unicn, cnp->cn_namelen,
    422 		    cnp->cn_nameptr, cnp->cn_namelen, 0, NULL);
    423 		for (ni = 0; ni < len; ni++)
    424 			if (unicn[ni] == (unichar_t)':')
    425 				unicn[ni] = (unichar_t)'/';
    426 		/* XXX: check conversion errors? */
    427 		if (hfslib_make_catalog_key(VTOH(vdp)->h_rec.u.cnid, len, unicn,
    428 		    &key) == 0) {
    429 			DPRINTF(("ERROR in hfslib_make_catalog_key\n"));
    430 			error = EINVAL;
    431 			goto error;
    432 		}
    433 
    434 		result = hfslib_find_catalog_record_with_key(&dp->h_hmp->hm_vol,
    435 		    &key, &rec, &cbargs);
    436 		if (result > 0) {
    437 			error = EINVAL;
    438 			goto error;
    439 		}
    440 		if (result < 0) {
    441 			if (cnp->cn_nameiop == CREATE)
    442 				error = EROFS;
    443 			else
    444 				error = ENOENT;
    445 			goto error;
    446 		}
    447 
    448 		if (rec.file.user_info.file_type == HFS_HARD_LINK_FILE_TYPE
    449 		    && rec.file.user_info.file_creator == HFS_HFSLUS_CREATOR) {
    450 			if (hfslib_get_hardlink(&dp->h_hmp->hm_vol,
    451 			    rec.file.bsd.special.inode_num,
    452 			    &rec, &cbargs) != 0) {
    453 				error = EINVAL;
    454 				goto error;
    455 			}
    456 		}
    457 
    458 		if (rec.type == HFS_REC_FILE
    459 		    && strcmp(cnp->cn_nameptr+cnp->cn_namelen, "/rsrc") == 0
    460 		    && rec.file.rsrc_fork.logical_size > 0) {
    461 		    /* advance namei next pointer to end of stirng */
    462 		    cnp->cn_consume = 5;
    463 		    cnp->cn_flags &= ~REQUIREDIR; /* XXX: needed? */
    464 		    error = hfs_vget_internal(vdp->v_mount, rec.file.cnid,
    465 			HFS_RSRCFORK, &tdp);
    466 		}
    467 		else
    468 			error = hfs_vget_internal(vdp->v_mount, rec.file.cnid,
    469 			    HFS_DATAFORK, &tdp);
    470 		if (error != 0)
    471 			goto error;
    472 		*vpp = tdp;
    473 	}
    474 	DPRINTF(("\n"));
    475 	/*
    476 	 * Insert name into cache if appropriate.
    477 	 */
    478 /* XXX Cache disabled until we can make sure it works. */
    479 #if 0
    480 	cache_enter(vdp, *vpp, cnp);
    481 #endif
    482 
    483 	error = 0;
    484 
    485 	/* FALLTHROUGH */
    486 error:
    487 	if (unicn != NULL)
    488 		free(unicn, M_TEMP);
    489 
    490 	return error;
    491 }
    492 
    493 int
    494 hfs_vop_open(void *v)
    495 {
    496 #if 0
    497 	struct vop_open_args /* {
    498 		struct vnode *a_vp;
    499 		int a_mode;
    500 		kauth_cred_t a_cred;
    501 	} */ *ap = v;
    502 	struct hfsnode *hn = VTOH(ap->a_vp);
    503 #endif
    504 	DPRINTF(("VOP = hfs_vop_open()\n"));
    505 
    506 	/*
    507 	 * XXX This is a good place to read and cache the file's extents to
    508 	 * XXX avoid doing it upon every read/write. Must however keep the
    509 	 * XXX cache in sync when the file grows/shrinks. (So would that go
    510 	 * XXX in vop_truncate?)
    511 	 */
    512 
    513 	return 0;
    514 }
    515 
    516 int
    517 hfs_vop_close(void *v)
    518 {
    519 #if 0
    520 	struct vop_close_args /* {
    521 		struct vnode *a_vp;
    522 		int a_fflag;
    523 		kauth_cred_t a_cred;
    524 	} */ *ap = v;
    525 	struct hfsnode *hn = VTOH(ap->a_vp);
    526 #endif
    527 	DPRINTF(("VOP = hfs_vop_close()\n"));
    528 
    529 	/* Release extents cache here. */
    530 
    531 	return 0;
    532 }
    533 
    534 static int
    535 hfs_check_possible(struct vnode *vp, mode_t mode)
    536 {
    537 
    538 	/*
    539 	 * Disallow writes on files, directories, and symlinks
    540 	 * since we have no write support yet.
    541 	 */
    542 
    543 	if (mode & VWRITE) {
    544 		switch (vp->v_type) {
    545 		case VDIR:
    546 		case VLNK:
    547 		case VREG:
    548 			return EROFS;
    549 		default:
    550 			break;
    551 		}
    552 	}
    553 
    554 	return 0;
    555 }
    556 
    557 static int
    558 hfs_check_permitted(vnode_t *vp, struct vattr *va, mode_t mode,
    559     kauth_cred_t cred)
    560 {
    561 
    562 	return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(mode,
    563 	    va->va_type, va->va_mode), vp, NULL,  genfs_can_access(va->va_type,
    564 	    va->va_mode, va->va_uid, va->va_gid, mode, cred));
    565 }
    566 
    567 int
    568 hfs_vop_access(void *v)
    569 {
    570 	struct vop_access_args /* {
    571 		struct vnode *a_vp;
    572 		int a_mode;
    573 		kauth_cred_t a_cred;
    574 	} */ *ap = v;
    575 	struct vattr va;
    576 	int error;
    577 
    578 	DPRINTF(("VOP = hfs_vop_access()\n"));
    579 
    580 	error = hfs_check_possible(ap->a_vp, ap->a_mode);
    581 	if (error)
    582 		return error;
    583 
    584 	if ((error = VOP_GETATTR(ap->a_vp, &va, ap->a_cred)) != 0)
    585 		return error;
    586 
    587 	error = hfs_check_permitted(ap->a_vp, &va, ap->a_mode, ap->a_cred);
    588 
    589 	return error;
    590 }
    591 
    592 int
    593 hfs_vop_getattr(void *v)
    594 {
    595 	struct vop_getattr_args /* {
    596 		struct vnode	*a_vp;
    597 		struct vattr	*a_vap;
    598 		struct ucred	*a_cred;
    599 	} */ *ap = v;
    600 	struct vnode	*vp;
    601 	struct hfsnode	*hp;
    602 	struct vattr	*vap;
    603 	hfs_bsd_data_t *bsd;
    604 	hfs_fork_t     *fork;
    605 
    606 	DPRINTF(("VOP = hfs_vop_getattr()\n"));
    607 
    608 	vp = ap->a_vp;
    609 	hp = VTOH(vp);
    610 	vap = ap->a_vap;
    611 
    612 	vattr_null(vap);
    613 
    614 	/*
    615 	 * XXX Cannot trust permissions/modes/flags stored in an HFS+ catalog
    616 	 * XXX record those values are not set on files created under Mac OS 9.
    617 	 */
    618 	vap->va_type = ap->a_vp->v_type;
    619 	if (hp->h_rec.u.rec_type == HFS_REC_FILE) {
    620 		hfs_file_record_t *f = &hp->h_rec.file;
    621 		if (hp->h_fork == HFS_RSRCFORK)
    622 			fork = &f->rsrc_fork;
    623 		else
    624 			fork = &f->data_fork;
    625 		vap->va_fileid = f->cnid;
    626 		bsd = &f->bsd;
    627 		vap->va_bytes = fork->total_blocks * HFS_BLOCKSIZE(vp);
    628 		vap->va_size = fork->logical_size;
    629 		hfs_time_to_timespec(f->date_created, &vap->va_ctime);
    630 		hfs_time_to_timespec(f->date_content_mod, &vap->va_mtime);
    631 		hfs_time_to_timespec(f->date_accessed, &vap->va_atime);
    632 		vap->va_nlink = 1;
    633 	}
    634 	else if (hp->h_rec.u.rec_type == HFS_REC_FLDR) {
    635 		hfs_folder_record_t *f = &hp->h_rec.folder;
    636 		vap->va_fileid = hp->h_rec.folder.cnid;
    637 		bsd = &f->bsd;
    638 		vap->va_size = 512; /* XXX Temporary */
    639 		vap->va_bytes = 512; /* XXX Temporary */
    640 		hfs_time_to_timespec(f->date_created, &vap->va_ctime);
    641 		hfs_time_to_timespec(f->date_content_mod,&vap->va_mtime);
    642 		hfs_time_to_timespec(f->date_accessed, &vap->va_atime);
    643 		vap->va_nlink = 2; /* XXX */
    644 	}
    645 	else {
    646 		DPRINTF(("hfs+: hfs_vop_getattr(): invalid record type %i",
    647 		    hp->h_rec.u.rec_type));
    648 		return EINVAL;
    649 	}
    650 
    651 	if ((bsd->file_mode & S_IFMT) == 0) {
    652 		/* no bsd permissions recorded, use default values */
    653 		if (hp->h_rec.u.rec_type == HFS_REC_FILE)
    654 			vap->va_mode = (S_IFREG | HFS_DEFAULT_FILE_MODE);
    655 		else
    656 			vap->va_mode = (S_IFDIR | HFS_DEFAULT_DIR_MODE);
    657 		vap->va_uid = HFS_DEFAULT_UID;
    658 		vap->va_gid = HFS_DEFAULT_GID;
    659 	}
    660 	else {
    661 		vap->va_mode = bsd->file_mode;
    662 		vap->va_uid = bsd->owner_id;
    663 		vap->va_gid = bsd->group_id;
    664 		if ((vap->va_mode & S_IFMT) == S_IFCHR
    665 		    || (vap->va_mode & S_IFMT) == S_IFBLK) {
    666 			vap->va_rdev
    667 			    = HFS_CONVERT_RDEV(bsd->special.raw_device);
    668 		}
    669 		else if (bsd->special.link_count != 0) {
    670 		    /* XXX: only if in metadata directory */
    671 		    vap->va_nlink = bsd->special.link_count;
    672 		}
    673 	}
    674 
    675 	vap->va_fsid = hp->h_dev;
    676 	vap->va_blocksize = hp->h_hmp->hm_vol.vh.block_size;
    677 	vap->va_gen = 1;
    678 	vap->va_flags = 0;
    679 
    680 	return 0;
    681 }
    682 
    683 int
    684 hfs_vop_setattr(void *v)
    685 {
    686 	struct vop_setattr_args /* {
    687 		struct vnode	*a_vp;
    688 		struct vattr	*a_vap;
    689 		kauth_cred_t	a_cred;
    690 	} */ *ap = v;
    691 	struct vattr	*vap;
    692 	struct vnode	*vp;
    693 
    694 	vap = ap->a_vap;
    695 	vp = ap->a_vp;
    696 
    697 	/*
    698 	 * Check for unsettable attributes.
    699 	 */
    700 	if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
    701 	    (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
    702 	    (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
    703 	    ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
    704 		return EINVAL;
    705 	}
    706 
    707 	/* XXX: needs revisiting for write support */
    708 	if (vap->va_flags != VNOVAL
    709 	    || vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL
    710 	    || vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL
    711 	    || vap->va_birthtime.tv_sec != VNOVAL) {
    712 		return EROFS;
    713 	}
    714 
    715 	if (vap->va_size != VNOVAL) {
    716 		/*
    717 		 * Disallow write attempts on read-only file systems;
    718 		 * unless the file is a socket, fifo, or a block or
    719 		 * character device resident on the file system.
    720 		 */
    721 		switch (vp->v_type) {
    722 		case VDIR:
    723 			return EISDIR;
    724 		case VCHR:
    725 		case VBLK:
    726 		case VFIFO:
    727 			break;
    728 		case VREG:
    729 			return EROFS;
    730 		default:
    731 			return EOPNOTSUPP;
    732 		}
    733 	}
    734 
    735 	return 0;
    736 }
    737 
    738 int
    739 hfs_vop_bmap(void *v)
    740 {
    741 	struct vop_bmap_args /* {
    742 		struct vnode *a_vp;
    743 		daddr_t  a_bn;
    744 		struct vnode **a_vpp;
    745 		daddr_t *a_bnp;
    746 		int *a_runp;
    747 	} */ *ap = v;
    748 	struct vnode *vp;
    749 	struct hfsnode *hp;
    750 	daddr_t lblkno;
    751 	hfs_callback_args cbargs;
    752 	hfs_libcb_argsread argsread;
    753 	hfs_extent_descriptor_t *extents;
    754 	uint16_t numextents, i;
    755 	int bshift;
    756 
    757 	vp = ap->a_vp;
    758 	hp = VTOH(vp);
    759 	lblkno = ap->a_bn;
    760 	bshift = vp->v_mount->mnt_fs_bshift;
    761 
    762 	/*
    763 	 * Check for underlying vnode requests and ensure that logical
    764 	 * to physical mapping is requested.
    765 	 */
    766 	if (ap->a_vpp != NULL)
    767 		*ap->a_vpp = hp->h_devvp;
    768 	if (ap->a_bnp == NULL)
    769 		return 0;
    770 
    771 	hfslib_init_cbargs(&cbargs);
    772 	argsread.cred = NULL;
    773 	argsread.l = NULL;
    774 	cbargs.read = &argsread;
    775 
    776 	numextents = hfslib_get_file_extents(&hp->h_hmp->hm_vol,
    777 	    hp->h_rec.u.cnid, hp->h_fork, &extents, &cbargs);
    778 
    779 	/* XXX: is this correct for 0-length files? */
    780 	if (numextents == 0)
    781 		return EBADF;
    782 
    783 	for (i = 0; i < numextents; i++) {
    784 		if (lblkno < extents[i].block_count)
    785 			break;
    786 		lblkno -= extents[i].block_count;
    787 	}
    788 
    789 	if (i == numextents) {
    790 		/* XXX: block number past EOF */
    791 		i--;
    792 		lblkno += extents[i].block_count;
    793 	}
    794 
    795 	*ap->a_bnp = ((extents[i].start_block + lblkno) << (bshift-DEV_BSHIFT))
    796 	    + (hp->h_hmp->hm_vol.offset >> DEV_BSHIFT);
    797 
    798 	if (ap->a_runp) {
    799 		int nblk;
    800 
    801 		nblk = extents[i].block_count - lblkno - 1;
    802 		if (nblk <= 0)
    803 			*ap->a_runp = 0;
    804 		else if (nblk > MAXBSIZE >> bshift)
    805 			*ap->a_runp = (MAXBSIZE >> bshift) - 1;
    806 		else
    807 			*ap->a_runp = nblk;
    808 
    809 	}
    810 
    811 	free(extents, M_TEMP);
    812 
    813 	return 0;
    814 }
    815 
    816 int
    817 hfs_vop_read(void *v)
    818 {
    819 	struct vop_read_args /* {
    820 		struct vnode *a_vp;
    821 		struct uio *a_uio;
    822 		int a_ioflag;
    823 		kauth_cred_t a_cred;
    824 	} */ *ap = v;
    825 	struct vnode *vp;
    826 	struct hfsnode *hp;
    827 	struct uio *uio;
    828 	uint64_t fsize; /* logical size of file */
    829 	int advice;
    830         int error;
    831 
    832 	vp = ap->a_vp;
    833 	hp = VTOH(vp);
    834 	uio = ap->a_uio;
    835 	if (hp->h_fork == HFS_RSRCFORK)
    836 		fsize = hp->h_rec.file.rsrc_fork.logical_size;
    837 	else
    838 		fsize = hp->h_rec.file.data_fork.logical_size;
    839 	error = 0;
    840 	advice = IO_ADV_DECODE(ap->a_ioflag);
    841 
    842         if (uio->uio_offset < 0)
    843                 return EINVAL;
    844 
    845         if (uio->uio_resid == 0 || uio->uio_offset >= fsize)
    846                 return 0;
    847 
    848         if (vp->v_type != VREG && vp->v_type != VLNK)
    849 		return EINVAL;
    850 
    851 	error = 0;
    852 	while (uio->uio_resid > 0 && error == 0) {
    853 		vsize_t len;
    854 
    855 		len = MIN(uio->uio_resid, fsize - uio->uio_offset);
    856 		if (len == 0)
    857 			break;
    858 
    859 		error = ubc_uiomove(&vp->v_uobj, uio, len, advice,
    860 		    UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp));
    861 	}
    862 
    863         return error;
    864 }
    865 
    866 int
    867 hfs_vop_readdir(void *v)
    868 {
    869 struct vop_readdir_args /* {
    870 		struct vnode *a_vp;
    871 		struct uio *a_uio;
    872 		kauth_cred_t a_cred;
    873 		int *a_eofflag;
    874 		off_t **a_cookies;
    875 		int a_*ncookies;
    876 	} */ *ap = v;
    877 
    878 	DPRINTF(("VOP = hfs_vop_readdir()\n"));
    879 
    880 	struct dirent curent; /* the dirent entry we are constructing */
    881 	struct hfsnode *hp;
    882 	hfs_catalog_keyed_record_t *children;
    883 	hfs_unistr255_t *childnames;
    884 	hfs_callback_args cbargs;
    885 	hfs_libcb_argsread argsread;
    886 	struct uio *uio;
    887 	off_t bufoff; /* offset in buffer relative to start of dirents */
    888 	uint32_t numchildren;
    889 	uint32_t curchild; /* index of child we are stuffing into dirent */
    890 	size_t namlen, ni;
    891 	int error;
    892 	int i; /* dummy variable */
    893 
    894 	bufoff = 0;
    895 	children = NULL;
    896 	error = 0;
    897 	numchildren = 0;
    898 	hp = VTOH(ap->a_vp);
    899 	uio = ap->a_uio;
    900 
    901 	if (uio->uio_offset < 0)
    902 		return EINVAL;
    903 	if (ap->a_eofflag != NULL)
    904 		*ap->a_eofflag = 0;
    905 
    906 /* XXX Inform that we don't support NFS, for now. */
    907 #if 0
    908 	if(ap->a_eofflag != NULL || ap->a_cookies != NULL ||
    909 	    ap->a_ncookies != NULL)
    910 		return EOPNOTSUPP;
    911 #endif
    912 	DPRINTF(("READDIR uio: offset=%td, resid=%zu\n",
    913 	    uio->uio_offset, uio->uio_resid));
    914 	hfslib_init_cbargs(&cbargs);
    915 	argsread.cred = ap->a_cred;
    916 	argsread.l = NULL;
    917 	cbargs.read = &argsread;
    918 
    919 	/* XXX Should we cache this? */
    920 	if (hfslib_get_directory_contents(&hp->h_hmp->hm_vol, hp->h_rec.u.cnid,
    921 	    &children, &childnames, &numchildren, &cbargs) != 0) {
    922 		DPRINTF(("ENOENT\n"));
    923 		error = ENOENT;
    924 		goto error;
    925 	}
    926 
    927 	DPRINTF(("numchildren = %u\n", numchildren));
    928 	for (curchild = 0; curchild < numchildren && uio->uio_resid > 0;
    929 	    curchild++) {
    930 		namlen = utf16_to_utf8(curent.d_name, NAME_MAX,
    931 		    childnames[curchild].unicode, childnames[curchild].length,
    932 		    0, NULL);
    933 		/* XXX: check conversion errors? */
    934 		if (namlen > NAME_MAX) {
    935 			/* XXX: how to handle name too long? */
    936 			continue;
    937 		}
    938 		for (ni = 0; ni < namlen; ni++)
    939 			if (curent.d_name[ni] == '/')
    940 				curent.d_name[ni] = ':';
    941 		curent.d_namlen = namlen;
    942 		curent.d_reclen = _DIRENT_SIZE(&curent);
    943 
    944 		/* Skip to desired dirent. */
    945 		bufoff += curent.d_reclen;
    946 		if (bufoff - curent.d_reclen < uio->uio_offset)
    947 			continue;
    948 
    949 		/* Make sure we don't return partial entries. */
    950 		if (uio->uio_resid < curent.d_reclen) {
    951 			DPRINTF(("PARTIAL ENTRY\n"));
    952 			if (ap->a_eofflag != NULL)
    953 				*ap->a_eofflag = 1;
    954 			break;
    955 		}
    956 
    957 		curent.d_fileno = children[curchild].file.cnid;
    958 		switch (hfs_catalog_keyed_record_vtype(children+curchild)) {
    959 		case VREG:
    960 			curent.d_type = DT_REG;
    961 			break;
    962 		case VDIR:
    963 			curent.d_type = DT_DIR;
    964 			break;
    965 		case VBLK:
    966 			curent.d_type = DT_BLK;
    967 			break;
    968 		case VCHR:
    969 			curent.d_type = DT_CHR;
    970 			break;
    971 		case VLNK:
    972 			curent.d_type = DT_LNK;
    973 			break;
    974 		case VSOCK:
    975 			curent.d_type = DT_SOCK;
    976 			break;
    977 		case VFIFO:
    978 			curent.d_type = DT_FIFO;
    979 			break;
    980 		default:
    981 			curent.d_type = DT_UNKNOWN;
    982 			break;
    983 		}
    984 		DPRINTF(("curchildname = %s\t\t", curchildname));
    985 		/* pad curent.d_name to aligned byte boundary */
    986                 for (i = curent.d_namlen;
    987                      i < curent.d_reclen - _DIRENT_NAMEOFF(&curent); i++)
    988                         curent.d_name[i] = 0;
    989 
    990 		DPRINTF(("curent.d_name = %s\n", curent.d_name));
    991 
    992 		if ((error = uiomove(&curent, curent.d_reclen, uio)) != 0)
    993 			goto error;
    994 	}
    995 
    996 
    997 	/* FALLTHROUGH */
    998 
    999 error:
   1000 	if (numchildren > 0) {
   1001 		if (children != NULL)
   1002 			free(children, M_TEMP);
   1003 		if (childnames != NULL)
   1004 			free(childnames, M_TEMP);
   1005 	}
   1006 
   1007 	if (error) {
   1008 		DPRINTF(("ERROR = %i\n", error));
   1009 	}
   1010 
   1011 	return error;
   1012 }
   1013 
   1014 int
   1015 hfs_vop_readlink(void *v) {
   1016 	struct vop_readlink_args /* {
   1017 		struct vnode *a_vp;
   1018         	struct uio *a_uio;
   1019         	kauth_cred_t a_cred;
   1020 	} */ *ap = v;
   1021 
   1022 	return VOP_READ(ap->a_vp, ap->a_uio, 0, ap->a_cred);
   1023 }
   1024 
   1025 int
   1026 hfs_vop_reclaim(void *v)
   1027 {
   1028 	struct vop_reclaim_args /* {
   1029 		struct vnode *a_vp;
   1030 	} */ *ap = v;
   1031 	struct vnode *vp;
   1032 	struct hfsnode *hp;
   1033 
   1034 	DPRINTF(("VOP = hfs_vop_reclaim()\n"));
   1035 
   1036 	vp = ap->a_vp;
   1037 	hp = VTOH(vp);
   1038 
   1039 	KASSERT(hp->h_key.hnk_cnid == hp->h_rec.u.cnid);
   1040 	vcache_remove(vp->v_mount, &hp->h_key, sizeof(hp->h_key));
   1041 
   1042 	/* Decrement the reference count to the volume's device. */
   1043 	if (hp->h_devvp) {
   1044 		vrele(hp->h_devvp);
   1045 		hp->h_devvp = 0;
   1046 	}
   1047 
   1048 	genfs_node_destroy(vp);
   1049 	pool_put(&hfs_node_pool, hp);
   1050 	vp->v_data = NULL;
   1051 
   1052 	return 0;
   1053 }
   1054 
   1055 int
   1056 hfs_vop_print(void *v)
   1057 {
   1058 	struct vop_print_args /* {
   1059 		struct vnode	*a_vp;
   1060 	} */ *ap = v;
   1061 	struct vnode	*vp;
   1062 	struct hfsnode	*hp;
   1063 
   1064 	DPRINTF(("VOP = hfs_vop_print()\n"));
   1065 
   1066 	vp = ap->a_vp;
   1067 	hp = VTOH(vp);
   1068 
   1069 	printf("dummy = %X\n", (unsigned)hp->dummy);
   1070 	printf("\n");
   1071 
   1072 	return 0;
   1073 }
   1074