2014-08-10 12:53:22 +04:00
|
|
|
/* $NetBSD: hfs_vfsops.c,v 1.32 2014/08/10 08:53:22 hannken 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>
|
2014-08-10 12:53:22 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: hfs_vfsops.c,v 1.32 2014/08/10 08:53:22 hannken 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>
|
2008-05-10 06:26:09 +04:00
|
|
|
#include <sys/module.h>
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2008-01-28 17:31:15 +03:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
2007-03-06 03:10:34 +03:00
|
|
|
#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
|
|
|
|
2008-05-10 06:26:09 +04:00
|
|
|
MODULE(MODULE_CLASS_VFS, hfs, NULL);
|
|
|
|
|
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
|
|
|
|
2014-08-10 12:53:22 +04:00
|
|
|
struct pool hfs_node_pool;
|
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 = {
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_name = MOUNT_HFS,
|
|
|
|
.vfs_min_mount_data = sizeof (struct hfs_args),
|
|
|
|
.vfs_mount = hfs_mount,
|
|
|
|
.vfs_start = hfs_start,
|
|
|
|
.vfs_unmount = hfs_unmount,
|
|
|
|
.vfs_root = hfs_root,
|
|
|
|
.vfs_quotactl = (void *)eopnotsupp,
|
|
|
|
.vfs_statvfs = hfs_statvfs,
|
|
|
|
.vfs_sync = hfs_sync,
|
|
|
|
.vfs_vget = hfs_vget,
|
2014-08-10 12:53:22 +04:00
|
|
|
.vfs_loadvnode = hfs_loadvnode,
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_fhtovp = hfs_fhtovp,
|
|
|
|
.vfs_vptofh = hfs_vptofh,
|
|
|
|
.vfs_init = hfs_init,
|
|
|
|
.vfs_reinit = hfs_reinit,
|
|
|
|
.vfs_done = hfs_done,
|
|
|
|
.vfs_extattrctl = vfs_stdextattrctl,
|
|
|
|
.vfs_suspendctl = (void *)eopnotsupp,
|
|
|
|
.vfs_renamelock_enter = genfs_renamelock_enter,
|
|
|
|
.vfs_renamelock_exit = genfs_renamelock_exit,
|
|
|
|
.vfs_fsync = (void *)eopnotsupp,
|
|
|
|
.vfs_opv_descs = hfs_vnodeopv_descs
|
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,
|
|
|
|
};
|
|
|
|
|
2008-05-10 06:26:09 +04:00
|
|
|
static int
|
|
|
|
hfs_modcmd(modcmd_t cmd, void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MODULE_CMD_INIT:
|
|
|
|
return vfs_attach(&hfs_vfsops);
|
|
|
|
case MODULE_CMD_FINI:
|
|
|
|
return vfs_detach(&hfs_vfsops);
|
|
|
|
default:
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-06 03:10:34 +03:00
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
hfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
2007-11-26 22:01:26 +03:00
|
|
|
struct lwp *l = curlwp;
|
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;
|
2012-06-14 02:56:50 +04:00
|
|
|
int error = 0;
|
2007-03-06 03:10:34 +03:00
|
|
|
int update;
|
|
|
|
mode_t accessmode;
|
|
|
|
|
2014-04-16 22:55:17 +04:00
|
|
|
if (args == NULL)
|
|
|
|
return EINVAL;
|
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.
|
|
|
|
*/
|
Convert 67 namei call sites to use namei_simple, in these functions:
check_console, veriexecclose, veriexec_delete, veriexec_file_add,
emul_find_root, coff_load_shlib (sh3 version), coff_load_shlib,
compat_20_sys_statfs, compat_20_netbsd32_statfs,
ELFNAME2(netbsd32,probe_noteless), darwin_sys_statfs,
ibcs2_sys_statfs, ibcs2_sys_statvfs, linux_sys_uselib,
osf1_sys_statfs, sunos_sys_statfs, sunos32_sys_statfs,
ultrix_sys_statfs, do_sys_mount, fss_create_files (3 of 4),
adosfs_mount, cd9660_mount, coda_ioctl, coda_mount, ext2fs_mount,
ffs_mount, filecore_mount, hfs_mount, lfs_mount, msdosfs_mount,
ntfs_mount, sysvbfs_mount, udf_mount, union_mount, sys_chflags,
sys_lchflags, sys_chmod, sys_lchmod, sys_chown, sys_lchown,
sys___posix_chown, sys___posix_lchown, sys_link, do_sys_pstatvfs,
sys_quotactl, sys_revoke, sys_truncate, do_sys_utimes, sys_extattrctl,
sys_extattr_set_file, sys_extattr_set_link, sys_extattr_get_file,
sys_extattr_get_link, sys_extattr_delete_file,
sys_extattr_delete_link, sys_extattr_list_file, sys_extattr_list_link,
sys_setxattr, sys_lsetxattr, sys_getxattr, sys_lgetxattr,
sys_listxattr, sys_llistxattr, sys_removexattr, sys_lremovexattr
All have been scrutinized (several times, in fact) and compile-tested,
but not all have been explicitly tested in action.
XXX: While I haven't (intentionally) changed the use or nonuse of
XXX: TRYEMULROOT in any of these places, I'm not convinced all the
XXX: uses are correct; an audit might be desirable.
2009-06-29 09:08:15 +04:00
|
|
|
error = namei_simple_user(args->fspec,
|
|
|
|
NSM_FOLLOW_NOEMULROOT, &devvp);
|
|
|
|
if (error != 0)
|
2007-03-06 03:10:34 +03:00
|
|
|
return error;
|
|
|
|
|
|
|
|
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.
|
2009-04-25 22:53:43 +04:00
|
|
|
*
|
|
|
|
* Permission to update a mount is checked higher, so here we presume
|
|
|
|
* updating the mount is okay (for example, as far as securelevel goes)
|
|
|
|
* which leaves us with the normal check.
|
2007-03-06 03:10:34 +03:00
|
|
|
*/
|
2009-11-27 19:11:35 +03:00
|
|
|
if (error == 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);
|
2012-03-13 22:40:26 +04:00
|
|
|
error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
|
|
|
|
KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp,
|
|
|
|
KAUTH_ARG(accessmode));
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(devvp);
|
2009-11-27 19:11:35 +03:00
|
|
|
}
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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-11-26 22:01:26 +03:00
|
|
|
hfs_start(struct mount *mp, int flags)
|
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-11-26 22:01:26 +03:00
|
|
|
hfs_unmount(struct mount *mp, int mntflags)
|
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-11-26 22:01:26 +03:00
|
|
|
argsclose.l = curlwp;
|
2007-03-06 03:10:34 +03:00
|
|
|
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
|
|
|
|
2009-12-03 17:29:04 +03:00
|
|
|
vrele(hmp->hm_devvp);
|
2007-03-06 03:10:34 +03:00
|
|
|
|
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-11-26 22:01:26 +03:00
|
|
|
hfs_statvfs(struct mount *mp, struct statvfs *sbp)
|
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-11-26 22:01:26 +03:00
|
|
|
hfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
|
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
|
|
|
{
|
2014-08-10 12:53:22 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = hfs_vget_internal(mp, ino, HFS_DATAFORK, vpp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = vn_lock(*vpp, LK_EXCLUSIVE);
|
|
|
|
if (error) {
|
|
|
|
vrele(*vpp);
|
|
|
|
*vpp = NULL;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return 0;
|
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)
|
2014-08-10 12:53:22 +04:00
|
|
|
{
|
|
|
|
struct hfsnode_key key;
|
|
|
|
|
|
|
|
memset(&key, 0, sizeof(key));
|
|
|
|
key.hnk_cnid = (hfs_cnid_t)ino;
|
|
|
|
key.hnk_fork = (fork != HFS_RSRCFORK ? HFS_DATAFORK : HFS_RSRCFORK);
|
|
|
|
|
|
|
|
return vcache_get(mp, &key, sizeof(key), vpp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
hfs_loadvnode(struct mount *mp, struct vnode *vp,
|
|
|
|
const void *key, size_t key_len, const void **new_key)
|
2007-03-06 03:10:34 +03:00
|
|
|
{
|
2007-03-06 14:28:44 +03:00
|
|
|
struct hfsmount *hmp;
|
|
|
|
struct hfsnode *hnode;
|
2014-08-10 12:53:22 +04:00
|
|
|
struct hfsnode_key hfskey;
|
2007-03-06 14:28:44 +03:00
|
|
|
hfs_callback_args cbargs;
|
|
|
|
hfs_catalog_keyed_record_t rec;
|
2014-08-10 12:53:22 +04:00
|
|
|
hfs_catalog_key_t cat_key; /* the search key used to find this file on disk */
|
2007-03-06 03:10:34 +03:00
|
|
|
dev_t dev;
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
#ifdef HFS_DEBUG
|
2014-08-10 12:53:22 +04:00
|
|
|
printf("vfsop = hfs_loadvnode()\n");
|
2007-03-06 14:28:44 +03:00
|
|
|
#endif /* HFS_DEBUG */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
2014-08-10 12:53:22 +04:00
|
|
|
KASSERT(key_len == sizeof(hfskey));
|
|
|
|
memcpy(&hfskey, key, key_len);
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hmp = VFSTOHFS(mp);
|
2007-03-06 03:10:34 +03:00
|
|
|
dev = hmp->hm_dev;
|
|
|
|
|
2014-08-10 12:53:22 +04:00
|
|
|
hnode = pool_get(&hfs_node_pool, PR_WAITOK);
|
|
|
|
memset(hnode, 0, sizeof(*hnode));
|
2007-03-06 03:10:34 +03:00
|
|
|
hnode->h_vnode = vp;
|
|
|
|
hnode->h_hmp = hmp;
|
|
|
|
hnode->dummy = 0x1337BABE;
|
|
|
|
hnode->h_dev = dev;
|
2014-08-10 12:53:22 +04:00
|
|
|
hnode->h_rec.u.cnid = hfskey.hnk_cnid;
|
|
|
|
hnode->h_fork = hfskey.hnk_fork;
|
|
|
|
hnode->h_key = hfskey;
|
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
|
|
|
|
2014-08-10 12:53:22 +04:00
|
|
|
if (hfslib_find_catalog_record_with_cnid(&hmp->hm_vol, hfskey.hnk_cnid,
|
|
|
|
&rec, &cat_key, &cbargs) != 0) {
|
|
|
|
pool_put(&hfs_node_pool, hnode);
|
|
|
|
return EBADF;
|
2007-03-06 03:10:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&hnode->h_rec, &rec, sizeof(hnode->h_rec));
|
2014-08-10 12:53:22 +04:00
|
|
|
hnode->h_parent = cat_key.parent_cnid;
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
|
2014-08-10 12:53:22 +04:00
|
|
|
vp->v_tag = VT_HFS;
|
|
|
|
vp->v_op = hfs_vnodeop_p;
|
|
|
|
vp->v_vflag |= VV_LOCKSWORK;
|
|
|
|
vp->v_data = hnode;
|
|
|
|
genfs_node_init(vp, &hfs_genfsops);
|
|
|
|
|
2007-03-06 03:10:34 +03:00
|
|
|
/*
|
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
|
|
|
*/
|
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
|
|
|
|
|
|
|
hnode->h_devvp = hmp->hm_devvp;
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(hnode->h_devvp); /* Increment the ref count to the volume's device. */
|
2007-03-06 03:10:34 +03:00
|
|
|
|
|
|
|
/* Make sure UVM has allocated enough memory. (?) */
|
2008-09-04 02:57:46 +04:00
|
|
|
if (hnode->h_rec.u.rec_type == HFS_REC_FILE) {
|
2007-03-06 14:28:44 +03:00
|
|
|
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 */
|
|
|
|
|
2014-08-10 12:53:22 +04:00
|
|
|
*new_key = &hnode->h_key;
|
2007-03-06 03:10:34 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-08-10 12:53:22 +04:00
|
|
|
pool_init(&hfs_node_pool, sizeof(struct hfsnode), 0, 0, 0, "hfsndpl",
|
|
|
|
&pool_allocator_nointr, IPL_NONE);
|
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
|
|
|
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
|
|
|
|
2014-08-10 12:53:22 +04:00
|
|
|
pool_destroy(&hfs_node_pool);
|
|
|
|
|
2007-03-06 14:28:44 +03:00
|
|
|
hfslib_done();
|
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;
|
|
|
|
}
|