2007-07-17 15:19:31 +04:00
|
|
|
/* $NetBSD: hfs_vfsops.c,v 1.7 2007/07/17 11:19:32 pooka Exp $ */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Yevgeny Binder and Dieter Baron.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1991, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* (c) UNIX System Laboratories, Inc.
|
|
|
|
* All or some portions of this file are derived from material licensed
|
|
|
|
* to the University of California by American Telephone and Telegraph
|
|
|
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
|
|
|
* the permission of UNIX System Laboratories, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1989, 1991, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Apple HFS+ filesystem
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2007-07-17 15:19:31 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: hfs_vfsops.c,v 1.7 2007/07/17 11:19:32 pooka Exp $");
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
#ifdef _KERNEL_OPT
|
|
|
|
#include "opt_compat_netbsd.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/pool.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kauth.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#include <fs/hfs/hfs.h>
|
|
|
|
#include <fs/hfs/libhfs.h>
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-06-30 13:37:53 +04:00
|
|
|
MALLOC_JUSTDEFINE(M_HFSMNT, "hfs mount", "hfs mount structures");
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
extern struct lock hfs_hashlock;
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
const struct vnodeopv_desc * const hfs_vnodeopv_descs[] = {
|
|
|
|
&hfs_vnodeop_opv_desc,
|
|
|
|
&hfs_specop_opv_desc,
|
|
|
|
&hfs_fifoop_opv_desc,
|
2007-03-06 03:10:34 +03:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
struct vfsops hfs_vfsops = {
|
|
|
|
MOUNT_HFS,
|
2007-07-12 23:35:32 +04:00
|
|
|
sizeof (struct hfs_args),
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_mount,
|
|
|
|
hfs_start,
|
|
|
|
hfs_unmount,
|
|
|
|
hfs_root,
|
|
|
|
hfs_quotactl,
|
|
|
|
hfs_statvfs,
|
|
|
|
hfs_sync,
|
|
|
|
hfs_vget,
|
|
|
|
hfs_fhtovp,
|
|
|
|
hfs_vptofh,
|
|
|
|
hfs_init,
|
|
|
|
hfs_reinit,
|
|
|
|
hfs_done,
|
2007-03-06 03:10:34 +03:00
|
|
|
NULL, /* vfs_mountroot */
|
|
|
|
NULL, /* vfs_snapshot */
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_extattrctl,
|
2007-03-06 03:10:34 +03:00
|
|
|
NULL, /* vfs_suspendctl */
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_vnodeopv_descs,
|
2007-03-06 03:10:34 +03:00
|
|
|
0,
|
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
2007-03-06 14:28:44 +03:00
|
|
|
VFS_ATTACH(hfs_vfsops); /* XXX Is this needed? */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
static const struct genfs_ops hfs_genfsops = {
|
2007-03-06 03:10:34 +03:00
|
|
|
.gop_size = genfs_size,
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2007-07-12 23:35:32 +04:00
|
|
|
hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len,
|
2007-03-06 03:10:34 +03:00
|
|
|
struct nameidata *ndp, struct lwp *l)
|
|
|
|
{
|
2007-07-12 23:35:32 +04:00
|
|
|
struct hfs_args *args = data;
|
2007-03-06 03:10:34 +03:00
|
|
|
struct vnode *devvp;
|
2007-03-06 14:28:44 +03:00
|
|
|
struct hfsmount *hmp;
|
2007-03-06 03:10:34 +03:00
|
|
|
int error;
|
|
|
|
int update;
|
|
|
|
mode_t accessmode;
|
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
if (*data_len < sizeof *args)
|
|
|
|
return EINVAL;
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_mount()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
2007-03-06 14:28:44 +03:00
|
|
|
hmp = VFSTOHFS(mp);
|
2007-03-06 03:10:34 +03:00
|
|
|
if (hmp == NULL)
|
|
|
|
return EIO;
|
2007-07-12 23:35:32 +04:00
|
|
|
args->fspec = NULL;
|
|
|
|
*data_len = sizeof *args;
|
|
|
|
return 0;
|
2007-03-06 03:10:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* FIXME: For development ONLY - disallow remounting for now */
|
|
|
|
#if 0
|
|
|
|
update = mp->mnt_flag & MNT_UPDATE;
|
|
|
|
#else
|
|
|
|
update = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check arguments */
|
2007-07-12 23:35:32 +04:00
|
|
|
if (args->fspec != NULL) {
|
2007-03-06 03:10:34 +03:00
|
|
|
/*
|
|
|
|
* Look up the name and verify that it's sane.
|
|
|
|
*/
|
2007-07-12 23:35:32 +04:00
|
|
|
NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args->fspec, l);
|
2007-03-06 03:10:34 +03:00
|
|
|
if ((error = namei(ndp)) != 0)
|
|
|
|
return error;
|
|
|
|
devvp = ndp->ni_vp;
|
|
|
|
|
|
|
|
if (!update) {
|
|
|
|
/*
|
|
|
|
* Be sure this is a valid block device
|
|
|
|
*/
|
|
|
|
if (devvp->v_type != VBLK)
|
|
|
|
error = ENOTBLK;
|
|
|
|
else if (bdevsw_lookup(devvp->v_rdev) == NULL)
|
|
|
|
error = ENXIO;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Be sure we're still naming the same device
|
|
|
|
* used for our initial mount
|
|
|
|
*/
|
2007-03-06 14:28:44 +03:00
|
|
|
hmp = VFSTOHFS(mp);
|
2007-03-06 03:10:34 +03:00
|
|
|
if (devvp != hmp->hm_devvp)
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (update) {
|
|
|
|
/* Use the extant mount */
|
2007-03-06 14:28:44 +03:00
|
|
|
hmp = VFSTOHFS(mp);
|
2007-03-06 03:10:34 +03:00
|
|
|
devvp = hmp->hm_devvp;
|
|
|
|
vref(devvp);
|
|
|
|
} else {
|
|
|
|
/* New mounts must have a filename for the device */
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If mount by non-root, then verify that user has necessary
|
|
|
|
* permissions on the device.
|
|
|
|
*/
|
|
|
|
if (error == 0 && kauth_authorize_generic(l->l_cred,
|
|
|
|
KAUTH_GENERIC_ISSUSER, NULL) != 0) {
|
|
|
|
accessmode = VREAD;
|
|
|
|
if (update ?
|
|
|
|
(mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
|
|
|
|
(mp->mnt_flag & MNT_RDONLY) == 0)
|
|
|
|
accessmode |= VWRITE;
|
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
error = VOP_ACCESS(devvp, accessmode, l->l_cred, l);
|
|
|
|
VOP_UNLOCK(devvp, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (update) {
|
2007-03-06 14:28:44 +03:00
|
|
|
printf("HFS: live remounting not yet supported!\n");
|
2007-03-06 03:10:34 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disallow multiple mounts of the same device.
|
|
|
|
* Disallow mounting of a device that is currently in use
|
|
|
|
* (except for root, which might share swap device for miniroot).
|
|
|
|
* Flush out any old buffers remaining from a previous use.
|
|
|
|
*/
|
|
|
|
if ((error = vfs_mountedon(devvp)) != 0)
|
|
|
|
goto error;
|
|
|
|
if (vcount(devvp) > 1 && devvp != rootvp) {
|
|
|
|
error = EBUSY;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
if ((error = hfs_mountfs(devvp, mp, l, args->fspec)) != 0)
|
2007-03-06 03:10:34 +03:00
|
|
|
goto error;
|
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
|
2007-07-17 15:19:31 +04:00
|
|
|
mp->mnt_op->vfs_name, mp, l);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
2007-03-06 03:10:34 +03:00
|
|
|
if(!update) {
|
|
|
|
char* volname;
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hmp = VFSTOHFS(mp);
|
2007-03-06 03:10:34 +03:00
|
|
|
volname = malloc(hmp->hm_vol.name.length + 1, M_TEMP, M_WAITOK);
|
|
|
|
if (volname == NULL)
|
|
|
|
printf("could not allocate volname; ignored\n");
|
|
|
|
else {
|
2007-03-06 14:28:44 +03:00
|
|
|
if (hfs_unicode_to_ascii(hmp->hm_vol.name.unicode,
|
2007-03-06 03:10:34 +03:00
|
|
|
hmp->hm_vol.name.length, volname) == NULL)
|
|
|
|
printf("could not convert volume name to ascii; ignored\n");
|
|
|
|
else
|
|
|
|
printf("mounted volume \"%s\"\n", volname);
|
|
|
|
free(volname, M_TEMP);
|
|
|
|
}
|
|
|
|
}
|
2007-03-06 14:28:44 +03:00
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
error:
|
|
|
|
vrele(devvp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_start(struct mount *mp, int flags, struct lwp *l)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_start()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l,
|
2007-03-22 16:21:28 +03:00
|
|
|
const char *devpath)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_callback_args cbargs;
|
|
|
|
hfs_libcb_argsopen argsopen;
|
|
|
|
hfs_libcb_argsread argsread;
|
|
|
|
struct hfsmount *hmp;
|
2007-03-06 03:10:34 +03:00
|
|
|
kauth_cred_t cred;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
cred = l ? l->l_cred : NOCRED;
|
|
|
|
error = 0;
|
|
|
|
hmp = NULL;
|
|
|
|
|
|
|
|
/* Create mounted volume structure. */
|
2007-03-06 14:28:44 +03:00
|
|
|
hmp = (struct hfsmount*)malloc(sizeof(struct hfsmount),
|
|
|
|
M_HFSMNT, M_WAITOK);
|
2007-03-06 03:10:34 +03:00
|
|
|
if (hmp == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
2007-03-06 14:28:44 +03:00
|
|
|
memset(hmp, 0, sizeof(struct hfsmount));
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
mp->mnt_data = hmp;
|
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
|
|
|
vfs_getnewfsid(mp);
|
|
|
|
|
|
|
|
hmp->hm_mountp = mp;
|
|
|
|
hmp->hm_dev = devvp->v_rdev;
|
|
|
|
hmp->hm_devvp = devvp;
|
|
|
|
|
|
|
|
/*
|
2007-03-06 14:28:44 +03:00
|
|
|
* Use libhfs to open the volume and read the volume header and other
|
2007-03-06 03:10:34 +03:00
|
|
|
* useful information.
|
|
|
|
*/
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hfslib_init_cbargs(&cbargs);
|
2007-03-06 03:10:34 +03:00
|
|
|
argsopen.cred = argsread.cred = cred;
|
|
|
|
argsopen.l = argsread.l = l;
|
|
|
|
argsopen.devvp = devvp;
|
|
|
|
cbargs.read = (void*)&argsread;
|
|
|
|
cbargs.openvol = (void*)&argsopen;
|
|
|
|
|
2007-03-22 16:21:28 +03:00
|
|
|
if ((error = hfslib_open_volume(devpath, mp->mnt_flag & MNT_RDONLY,
|
2007-03-06 03:10:34 +03:00
|
|
|
&hmp->hm_vol, &cbargs)) != 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Make sure this is not a journaled volume whose journal is dirty. */
|
2007-03-06 14:28:44 +03:00
|
|
|
if (!hfslib_is_journal_clean(&hmp->hm_vol)) {
|
2007-03-06 03:10:34 +03:00
|
|
|
printf("volume journal is dirty; not mounting\n");
|
|
|
|
error = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp->mnt_fs_bshift = 0;
|
|
|
|
while ((1 << mp->mnt_fs_bshift) < hmp->hm_vol.vh.block_size)
|
|
|
|
mp->mnt_fs_bshift++;
|
|
|
|
mp->mnt_dev_bshift = DEV_BSHIFT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (hmp != NULL)
|
2007-03-06 14:28:44 +03:00
|
|
|
free(hmp, M_HFSMNT);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_unmount(struct mount *mp, int mntflags, struct lwp *l)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_callback_args cbargs;
|
|
|
|
hfs_libcb_argsread argsclose;
|
|
|
|
struct hfsmount* hmp;
|
2007-03-06 03:10:34 +03:00
|
|
|
int error;
|
|
|
|
int flags;
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_unmount()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hmp = VFSTOHFS(mp);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
if (mntflags & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
|
|
|
|
if ((error = vflush(mp, NULLVP, flags)) != 0)
|
|
|
|
return error;
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hfslib_init_cbargs(&cbargs);
|
2007-03-06 03:10:34 +03:00
|
|
|
argsclose.l = l;
|
|
|
|
cbargs.closevol = (void*)&argsclose;
|
2007-03-06 14:28:44 +03:00
|
|
|
hfslib_close_volume(&hmp->hm_vol, &cbargs);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
vput(hmp->hm_devvp);
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
free(hmp, M_HFSMNT);
|
2007-03-06 03:10:34 +03:00
|
|
|
mp->mnt_data = NULL;
|
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_root(struct mount *mp, struct vnode **vpp)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
|
|
|
struct vnode *nvp;
|
|
|
|
int error;
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_root()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
if ((error = VFS_VGET(mp, HFS_CNID_ROOT_FOLDER, &nvp)) != 0)
|
2007-03-06 03:10:34 +03:00
|
|
|
return error;
|
|
|
|
*vpp = nvp;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg,
|
2007-03-06 03:10:34 +03:00
|
|
|
struct lwp *l)
|
|
|
|
{
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_quotactl()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_volume_header_t *vh;
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_statvfs()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
vh = &VFSTOHFS(mp)->hm_vol.vh;
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
sbp->f_bsize = vh->block_size;
|
|
|
|
sbp->f_frsize = sbp->f_bsize;
|
|
|
|
sbp->f_iosize = 4096;/* mac os x uses a 4 kb io size, so do the same */
|
|
|
|
sbp->f_blocks = vh->total_blocks;
|
|
|
|
sbp->f_bfree = vh->free_blocks; /* total free blocks */
|
|
|
|
sbp->f_bavail = vh->free_blocks; /* blocks free for non superuser */
|
|
|
|
sbp->f_bresvd = 0;
|
|
|
|
sbp->f_files = vh->file_count; /* total files */
|
|
|
|
sbp->f_ffree = (1<<31) - vh->file_count; /* free file nodes */
|
|
|
|
copy_statvfs_info(sbp, mp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred, struct lwp *l)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_sync()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* an ino_t corresponds directly to a CNID in our particular case,
|
|
|
|
* since both are conveniently 32-bit numbers
|
|
|
|
*/
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
2007-03-06 14:28:44 +03:00
|
|
|
return hfs_vget_internal(mp, ino, HFS_DATAFORK, vpp);
|
2007-03-06 03:10:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* internal version with extra arguments to allow accessing resource fork
|
|
|
|
*/
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_vget_internal(struct mount *mp, ino_t ino, uint8_t fork,
|
2007-03-06 03:10:34 +03:00
|
|
|
struct vnode **vpp)
|
|
|
|
{
|
2007-03-06 14:28:44 +03:00
|
|
|
struct hfsmount *hmp;
|
|
|
|
struct hfsnode *hnode;
|
2007-03-06 03:10:34 +03:00
|
|
|
struct vnode *vp;
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_callback_args cbargs;
|
|
|
|
hfs_cnid_t cnid;
|
|
|
|
hfs_catalog_keyed_record_t rec;
|
|
|
|
hfs_catalog_key_t key; /* the search key used to find this file on disk */
|
2007-03-06 03:10:34 +03:00
|
|
|
dev_t dev;
|
|
|
|
int error;
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_vget()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
hnode = NULL;
|
|
|
|
vp = NULL;
|
2007-03-06 14:28:44 +03:00
|
|
|
hmp = VFSTOHFS(mp);
|
2007-03-06 03:10:34 +03:00
|
|
|
dev = hmp->hm_dev;
|
2007-03-06 14:28:44 +03:00
|
|
|
cnid = (hfs_cnid_t)ino;
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
if (fork != HFS_RSRCFORK)
|
|
|
|
fork = HFS_DATAFORK;
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
/* Check if this vnode has already been allocated. If so, just return it. */
|
2007-03-06 14:28:44 +03:00
|
|
|
if ((*vpp = hfs_nhashget(dev, cnid, fork, LK_EXCLUSIVE)) != NULL)
|
2007-03-06 03:10:34 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Allocate a new vnode/inode. */
|
2007-03-06 14:28:44 +03:00
|
|
|
if ((error = getnewvnode(VT_HFS, mp, hfs_vnodeop_p, &vp)) != 0)
|
2007-03-06 03:10:34 +03:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If someone beat us to it while sleeping in getnewvnode(),
|
|
|
|
* push back the freshly allocated vnode we don't need, and return.
|
|
|
|
*/
|
|
|
|
|
|
|
|
do {
|
2007-03-06 14:28:44 +03:00
|
|
|
if ((*vpp = hfs_nhashget(dev, cnid, fork, LK_EXCLUSIVE))
|
2007-03-06 03:10:34 +03:00
|
|
|
!= NULL) {
|
|
|
|
ungetnewvnode(vp);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-06 14:28:44 +03:00
|
|
|
} while (lockmgr(&hfs_hashlock, LK_EXCLUSIVE|LK_SLEEPFAIL, 0));
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
vp->v_flag |= VLOCKSWORK;
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
MALLOC(hnode, struct hfsnode *, sizeof(struct hfsnode), M_TEMP,
|
2007-03-06 03:10:34 +03:00
|
|
|
M_WAITOK + M_ZERO);
|
|
|
|
vp->v_data = hnode;
|
|
|
|
|
|
|
|
hnode->h_vnode = vp;
|
|
|
|
hnode->h_hmp = hmp;
|
|
|
|
hnode->dummy = 0x1337BABE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to put this vnode into the hash chain and lock it so that other
|
|
|
|
* requests for this inode will block if they arrive while we are sleeping
|
|
|
|
* waiting for old data structures to be purged or for the contents of the
|
|
|
|
* disk portion of this inode to be read. The hash chain requires the node's
|
|
|
|
* device and cnid to be known. Since this information was passed in the
|
2007-03-06 14:28:44 +03:00
|
|
|
* arguments, fill in the appropriate hfsnode fields without reading having
|
2007-03-06 03:10:34 +03:00
|
|
|
* to read the disk.
|
|
|
|
*/
|
|
|
|
hnode->h_dev = dev;
|
|
|
|
hnode->h_rec.cnid = cnid;
|
|
|
|
hnode->h_fork = fork;
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_nhashinsert(hnode);
|
|
|
|
lockmgr(&hfs_hashlock, LK_RELEASE, 0);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read catalog record from disk.
|
|
|
|
*/
|
2007-03-06 14:28:44 +03:00
|
|
|
hfslib_init_cbargs(&cbargs);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
if (hfslib_find_catalog_record_with_cnid(&hmp->hm_vol, cnid,
|
2007-03-06 03:10:34 +03:00
|
|
|
&rec, &key, &cbargs) != 0) {
|
|
|
|
vput(vp);
|
|
|
|
error = EBADF;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&hnode->h_rec, &rec, sizeof(hnode->h_rec));
|
|
|
|
hnode->h_parent = key.parent_cnid;
|
|
|
|
|
|
|
|
/* XXX Eventually need to add an "ignore permissions" mount option */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now convert some of the catalog record's fields into values that make
|
|
|
|
* sense on this system.
|
|
|
|
*/
|
|
|
|
/* DATE AND TIME */
|
|
|
|
|
|
|
|
/*
|
2007-03-06 14:28:44 +03:00
|
|
|
* Initialize the vnode from the hfsnode, check for aliases.
|
2007-03-06 03:10:34 +03:00
|
|
|
* Note that the underlying vnode may have changed.
|
|
|
|
*/
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_vinit(mp, hfs_specop_p, hfs_fifoop_p, &vp);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
genfs_node_init(vp, &hfs_genfsops);
|
2007-03-06 03:10:34 +03:00
|
|
|
hnode->h_devvp = hmp->hm_devvp;
|
|
|
|
VREF(hnode->h_devvp); /* Increment the ref count to the volume's device. */
|
|
|
|
|
|
|
|
/* Make sure UVM has allocated enough memory. (?) */
|
2007-03-06 14:28:44 +03:00
|
|
|
if (hnode->h_rec.rec_type == HFS_REC_FILE) {
|
|
|
|
if (hnode->h_fork == HFS_DATAFORK)
|
2007-03-06 03:10:34 +03:00
|
|
|
uvm_vnp_setsize(vp,
|
|
|
|
hnode->h_rec.file.data_fork.logical_size);
|
|
|
|
else
|
|
|
|
uvm_vnp_setsize(vp,
|
|
|
|
hnode->h_rec.file.rsrc_fork.logical_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
uvm_vnp_setsize(vp, 0); /* no directly reading directories */
|
|
|
|
|
|
|
|
*vpp = vp;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
*vpp = NULL;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_fhtovp()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_vptofh()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_init(void)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_callbacks callbacks;
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_init()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
malloc_type_attach(M_HFSMNT);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
callbacks.error = hfs_libcb_error;
|
|
|
|
callbacks.allocmem = hfs_libcb_malloc;
|
|
|
|
callbacks.reallocmem = hfs_libcb_realloc;
|
|
|
|
callbacks.freemem = hfs_libcb_free;
|
|
|
|
callbacks.openvol = hfs_libcb_opendev;
|
|
|
|
callbacks.closevol = hfs_libcb_closedev;
|
|
|
|
callbacks.read = hfs_libcb_read;
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_nhashinit();
|
|
|
|
hfslib_init(&callbacks);
|
2007-03-06 03:10:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_reinit(void)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_reinit()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_done(void)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_done()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
malloc_type_detach(M_HFSMNT);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hfslib_done();
|
|
|
|
hfs_nhashdone();
|
2007-03-06 03:10:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_mountroot(void)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_mountroot()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
int hfs_extattrctl(struct mount *mp, int cmd, struct vnode *vp,
|
2007-03-06 03:10:34 +03:00
|
|
|
int attrnamespace, const char *attrname, struct lwp *l)
|
|
|
|
{
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
|
|
|
printf("vfsop = hfs_checkexp()\n");
|
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|