2017-04-01 22:35:56 +03:00
|
|
|
/* $NetBSD: udf_vfsops.c,v 1.75 2017/04/01 19:35:56 riastradh Exp $ */
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/*
|
2008-05-14 20:49:47 +04:00
|
|
|
* Copyright (c) 2006, 2008 Reinoud Zandijk
|
2006-02-02 18:19:15 +03:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2017-04-01 22:35:56 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.75 2017/04/01 19:35:56 riastradh Exp $");
|
2006-02-02 18:19:15 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_KERNEL_OPT)
|
|
|
|
#include "opt_compat_netbsd.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/vnode.h>
|
2008-01-28 17:31:15 +03:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
2006-02-02 18:19:15 +03:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/dirent.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/conf.h>
|
2006-05-15 04:05:16 +04:00
|
|
|
#include <sys/kauth.h>
|
2008-05-10 06:26:09 +04:00
|
|
|
#include <sys/module.h>
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
#include <fs/udf/ecma167-udf.h>
|
|
|
|
#include <fs/udf/udf_mount.h>
|
2008-09-27 17:05:34 +04:00
|
|
|
#include <sys/dirhash.h>
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
#include "udf.h"
|
|
|
|
#include "udf_subr.h"
|
|
|
|
#include "udf_bswap.h"
|
|
|
|
|
2008-05-10 06:26:09 +04:00
|
|
|
MODULE(MODULE_CLASS_VFS, udf, NULL);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
#define VTOI(vnode) ((struct udf_node *) vnode->v_data)
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
/* verbose levels of the udf filingsystem */
|
|
|
|
int udf_verbose = UDF_DEBUGGING;
|
|
|
|
|
|
|
|
/* malloc regions */
|
2007-06-30 13:37:53 +04:00
|
|
|
MALLOC_JUSTDEFINE(M_UDFMNT, "UDF mount", "UDF mount structures");
|
|
|
|
MALLOC_JUSTDEFINE(M_UDFVOLD, "UDF volspace", "UDF volume space descriptors");
|
|
|
|
MALLOC_JUSTDEFINE(M_UDFTEMP, "UDF temp", "UDF scrap space");
|
2006-02-02 18:19:15 +03:00
|
|
|
struct pool udf_node_pool;
|
|
|
|
|
2008-06-28 05:34:05 +04:00
|
|
|
static struct sysctllog *udf_sysctl_log;
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* internal functions */
|
|
|
|
static int udf_mountfs(struct vnode *, struct mount *, struct lwp *, struct udf_args *);
|
|
|
|
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* predefine vnode-op list descriptor */
|
|
|
|
extern const struct vnodeopv_desc udf_vnodeop_opv_desc;
|
|
|
|
|
|
|
|
const struct vnodeopv_desc * const udf_vnodeopv_descs[] = {
|
|
|
|
&udf_vnodeop_opv_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* vfsops descriptor linked in as anchor point for the filingsystem */
|
|
|
|
struct vfsops udf_vfsops = {
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_name = MOUNT_UDF,
|
|
|
|
.vfs_min_mount_data = sizeof (struct udf_args),
|
|
|
|
.vfs_mount = udf_mount,
|
|
|
|
.vfs_start = udf_start,
|
|
|
|
.vfs_unmount = udf_unmount,
|
|
|
|
.vfs_root = udf_root,
|
|
|
|
.vfs_quotactl = (void *)eopnotsupp,
|
|
|
|
.vfs_statvfs = udf_statvfs,
|
|
|
|
.vfs_sync = udf_sync,
|
|
|
|
.vfs_vget = udf_vget,
|
2015-04-06 11:39:23 +03:00
|
|
|
.vfs_loadvnode = udf_loadvnode,
|
|
|
|
.vfs_newvnode = udf_newvnode,
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_fhtovp = udf_fhtovp,
|
|
|
|
.vfs_vptofh = udf_vptofh,
|
|
|
|
.vfs_init = udf_init,
|
|
|
|
.vfs_reinit = udf_reinit,
|
|
|
|
.vfs_done = udf_done,
|
|
|
|
.vfs_mountroot = udf_mountroot,
|
|
|
|
.vfs_snapshot = udf_snapshot,
|
|
|
|
.vfs_extattrctl = vfs_stdextattrctl,
|
2017-02-17 11:31:23 +03:00
|
|
|
.vfs_suspendctl = genfs_suspendctl,
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_renamelock_enter = genfs_renamelock_enter,
|
|
|
|
.vfs_renamelock_exit = genfs_renamelock_exit,
|
|
|
|
.vfs_fsync = (void *)eopnotsupp,
|
|
|
|
.vfs_opv_descs = udf_vnodeopv_descs
|
2006-02-02 18:19:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* file system starts here */
|
|
|
|
void
|
|
|
|
udf_init(void)
|
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
|
2008-07-22 23:06:55 +04:00
|
|
|
/* setup memory types */
|
2006-02-02 18:19:15 +03:00
|
|
|
malloc_type_attach(M_UDFMNT);
|
|
|
|
malloc_type_attach(M_UDFVOLD);
|
|
|
|
malloc_type_attach(M_UDFTEMP);
|
|
|
|
|
2008-07-17 23:10:22 +04:00
|
|
|
/* init node pools */
|
2006-02-02 18:19:15 +03:00
|
|
|
size = sizeof(struct udf_node);
|
2008-07-17 23:10:22 +04:00
|
|
|
pool_init(&udf_node_pool, size, 0, 0, 0,
|
|
|
|
"udf_node_pool", NULL, IPL_NONE);
|
2006-02-02 18:19:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
udf_reinit(void)
|
|
|
|
{
|
2008-07-17 23:10:22 +04:00
|
|
|
/* nothing to do */
|
2006-02-02 18:19:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
udf_done(void)
|
|
|
|
{
|
2008-07-17 23:10:22 +04:00
|
|
|
/* remove pools */
|
2006-02-02 18:19:15 +03:00
|
|
|
pool_destroy(&udf_node_pool);
|
|
|
|
|
|
|
|
malloc_type_detach(M_UDFMNT);
|
|
|
|
malloc_type_detach(M_UDFVOLD);
|
|
|
|
malloc_type_detach(M_UDFTEMP);
|
|
|
|
}
|
|
|
|
|
2008-06-28 05:34:05 +04:00
|
|
|
/*
|
|
|
|
* If running a DEBUG kernel, provide an easy way to set the debug flags when
|
|
|
|
* running into a problem.
|
|
|
|
*/
|
2008-07-22 23:06:55 +04:00
|
|
|
#define UDF_VERBOSE_SYSCTLOPT 1
|
2008-05-14 20:49:47 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
udf_modcmd(modcmd_t cmd, void *arg)
|
|
|
|
{
|
2008-07-22 23:06:55 +04:00
|
|
|
const struct sysctlnode *node;
|
2008-06-28 05:34:05 +04:00
|
|
|
int error;
|
2008-05-14 20:49:47 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MODULE_CMD_INIT:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_attach(&udf_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* XXX the "24" below could be dynamic, thereby eliminating one
|
|
|
|
* more instance of the "number to vfs" mapping problem, but
|
|
|
|
* "24" is the order as taken from sys/mount.h
|
|
|
|
*/
|
2008-07-22 23:06:55 +04:00
|
|
|
sysctl_createv(&udf_sysctl_log, 0, NULL, &node,
|
2008-06-28 05:34:05 +04:00
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "udf",
|
|
|
|
SYSCTL_DESCR("OSTA Universal File System"),
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, 24, CTL_EOL);
|
|
|
|
#ifdef DEBUG
|
2008-07-22 23:06:55 +04:00
|
|
|
sysctl_createv(&udf_sysctl_log, 0, NULL, &node,
|
2008-06-28 05:34:05 +04:00
|
|
|
CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
|
|
|
|
CTLTYPE_INT, "verbose",
|
|
|
|
SYSCTL_DESCR("Bitmask for filesystem debugging"),
|
|
|
|
NULL, 0, &udf_verbose, 0,
|
|
|
|
CTL_VFS, 24, UDF_VERBOSE_SYSCTLOPT, CTL_EOL);
|
|
|
|
#endif
|
|
|
|
break;
|
2008-05-14 20:49:47 +04:00
|
|
|
case MODULE_CMD_FINI:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_detach(&udf_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
sysctl_teardown(&udf_sysctl_log);
|
|
|
|
break;
|
2008-05-14 20:49:47 +04:00
|
|
|
default:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
2008-05-14 20:49:47 +04:00
|
|
|
}
|
2008-06-28 05:34:05 +04:00
|
|
|
|
|
|
|
return (error);
|
2008-05-14 20:49:47 +04:00
|
|
|
}
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
udf_mountroot(void)
|
|
|
|
{
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#define MPFREE(a, lst) \
|
|
|
|
if ((a)) free((a), lst);
|
|
|
|
static void
|
|
|
|
free_udf_mountinfo(struct mount *mp)
|
|
|
|
{
|
|
|
|
struct udf_mount *ump;
|
|
|
|
int i;
|
|
|
|
|
2006-10-03 19:54:03 +04:00
|
|
|
if (!mp)
|
|
|
|
return;
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
ump = VFSTOUDF(mp);
|
|
|
|
if (ump) {
|
2006-08-22 02:23:09 +04:00
|
|
|
/* clear our data */
|
2006-02-02 18:19:15 +03:00
|
|
|
for (i = 0; i < UDF_ANCHORS; i++)
|
|
|
|
MPFREE(ump->anchors[i], M_UDFVOLD);
|
|
|
|
MPFREE(ump->primary_vol, M_UDFVOLD);
|
|
|
|
MPFREE(ump->logical_vol, M_UDFVOLD);
|
|
|
|
MPFREE(ump->unallocated, M_UDFVOLD);
|
|
|
|
MPFREE(ump->implementation, M_UDFVOLD);
|
|
|
|
MPFREE(ump->logvol_integrity, M_UDFVOLD);
|
2008-05-14 20:49:47 +04:00
|
|
|
for (i = 0; i < UDF_PARTITIONS; i++) {
|
2008-07-27 15:21:21 +04:00
|
|
|
MPFREE(ump->partitions[i], M_UDFVOLD);
|
2008-05-14 20:49:47 +04:00
|
|
|
MPFREE(ump->part_unalloc_dscr[i], M_UDFVOLD);
|
2008-07-27 15:21:21 +04:00
|
|
|
MPFREE(ump->part_freed_dscr[i], M_UDFVOLD);
|
2008-05-14 20:49:47 +04:00
|
|
|
}
|
2008-07-27 15:21:21 +04:00
|
|
|
MPFREE(ump->metadata_unalloc_dscr, M_UDFVOLD);
|
|
|
|
|
|
|
|
MPFREE(ump->fileset_desc, M_UDFVOLD);
|
|
|
|
MPFREE(ump->sparing_table, M_UDFVOLD);
|
2008-05-14 20:49:47 +04:00
|
|
|
|
|
|
|
MPFREE(ump->la_node_ad_cpy, M_UDFMNT);
|
2008-07-27 15:21:21 +04:00
|
|
|
MPFREE(ump->la_pmapping, M_TEMP);
|
|
|
|
MPFREE(ump->la_lmapping, M_TEMP);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2008-08-29 17:55:45 +04:00
|
|
|
mutex_destroy(&ump->logvol_mutex);
|
2008-05-14 20:49:47 +04:00
|
|
|
mutex_destroy(&ump->allocate_mutex);
|
2015-08-24 11:31:56 +03:00
|
|
|
mutex_destroy(&ump->sync_lock);
|
2008-08-29 17:55:45 +04:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
MPFREE(ump->vat_table, M_UDFVOLD);
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
free(ump, M_UDFMNT);
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
}
|
|
|
|
#undef MPFREE
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* if the system nodes exist, release them */
|
|
|
|
static void
|
|
|
|
udf_release_system_nodes(struct mount *mp)
|
|
|
|
{
|
|
|
|
struct udf_mount *ump = VFSTOUDF(mp);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* if we haven't even got an ump, dont bother */
|
|
|
|
if (!ump)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* VAT partition support */
|
|
|
|
if (ump->vat_node)
|
|
|
|
vrele(ump->vat_node->vnode);
|
|
|
|
|
|
|
|
/* Metadata partition support */
|
|
|
|
if (ump->metadata_node)
|
|
|
|
vrele(ump->metadata_node->vnode);
|
|
|
|
if (ump->metadatamirror_node)
|
|
|
|
vrele(ump->metadatamirror_node->vnode);
|
|
|
|
if (ump->metadatabitmap_node)
|
|
|
|
vrele(ump->metadatabitmap_node->vnode);
|
|
|
|
|
|
|
|
/* This flush should NOT write anything nor allow any node to remain */
|
|
|
|
if ((error = vflush(ump->vfs_mountp, NULLVP, 0)) != 0)
|
|
|
|
panic("Failure to flush UDF system vnodes\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
int
|
|
|
|
udf_mount(struct mount *mp, const char *path,
|
2007-11-26 22:01:26 +03:00
|
|
|
void *data, size_t *data_len)
|
2006-02-02 18:19:15 +03:00
|
|
|
{
|
2007-11-26 22:01:26 +03:00
|
|
|
struct lwp *l = curlwp;
|
2007-07-12 23:35:32 +04:00
|
|
|
struct udf_args *args = data;
|
2006-02-02 18:19:15 +03:00
|
|
|
struct udf_mount *ump;
|
|
|
|
struct vnode *devvp;
|
|
|
|
int openflags, accessmode, error;
|
|
|
|
|
|
|
|
DPRINTF(CALL, ("udf_mount called\n"));
|
|
|
|
|
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;
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
|
|
|
/* request for the mount arguments */
|
|
|
|
ump = VFSTOUDF(mp);
|
|
|
|
if (ump == NULL)
|
|
|
|
return EINVAL;
|
2007-07-12 23:35:32 +04:00
|
|
|
*args = ump->mount_args;
|
|
|
|
*data_len = sizeof *args;
|
|
|
|
return 0;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* handle request for updating mount parameters */
|
|
|
|
/* TODO can't update my mountpoint yet */
|
|
|
|
if (mp->mnt_flag & MNT_UPDATE) {
|
|
|
|
return EOPNOTSUPP;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2006-10-03 19:54:03 +04:00
|
|
|
/* OK, so we are asked to mount the device */
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* check/translate struct version */
|
|
|
|
/* TODO sanity checking other mount arguments */
|
2007-07-12 23:35:32 +04:00
|
|
|
if (args->version != 1) {
|
2006-02-02 18:19:15 +03:00
|
|
|
printf("mount_udf: unrecognized argument structure version\n");
|
|
|
|
return EINVAL;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* lookup name to get its vnode */
|
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);
|
2006-02-02 18:19:15 +03:00
|
|
|
if (error)
|
|
|
|
return error;
|
2006-09-05 21:03:04 +04:00
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (udf_verbose & UDF_DEBUG_VOLUMES)
|
|
|
|
vprint("UDF mount, trying to mount \n", devvp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check if its a block device specified */
|
|
|
|
if (devvp->v_type != VBLK) {
|
|
|
|
vrele(devvp);
|
|
|
|
return ENOTBLK;
|
|
|
|
}
|
|
|
|
if (bdevsw_lookup(devvp->v_rdev) == NULL) {
|
|
|
|
vrele(devvp);
|
2016-07-07 09:55:38 +03:00
|
|
|
return ENXIO;
|
2006-02-02 18:19:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If mount by non-root, then verify that user has necessary
|
|
|
|
* permissions on the device.
|
|
|
|
*/
|
2009-04-25 22:53:44 +04:00
|
|
|
accessmode = VREAD;
|
|
|
|
if ((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-04-25 22:53:44 +04:00
|
|
|
if (error) {
|
|
|
|
vrele(devvp);
|
|
|
|
return error;
|
2006-02-02 18:19:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open device and try to mount it!
|
|
|
|
*/
|
|
|
|
if (mp->mnt_flag & MNT_RDONLY) {
|
|
|
|
openflags = FREAD;
|
|
|
|
} else {
|
|
|
|
openflags = FREAD | FWRITE;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2011-11-14 22:35:12 +04:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_OPEN(devvp, openflags, FSCRED);
|
2011-11-14 22:35:12 +04:00
|
|
|
VOP_UNLOCK(devvp);
|
2006-02-02 18:19:15 +03:00
|
|
|
if (error == 0) {
|
|
|
|
/* opened ok, try mounting */
|
2007-07-12 23:35:32 +04:00
|
|
|
error = udf_mountfs(devvp, mp, l, args);
|
2006-02-02 18:19:15 +03:00
|
|
|
if (error) {
|
2008-05-14 20:49:47 +04:00
|
|
|
udf_release_system_nodes(mp);
|
|
|
|
/* cleanup */
|
|
|
|
udf_discstrat_finish(VFSTOUDF(mp));
|
2006-02-02 18:19:15 +03:00
|
|
|
free_udf_mountinfo(mp);
|
2006-09-05 21:03:04 +04:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
2007-11-26 22:01:26 +03:00
|
|
|
(void) VOP_CLOSE(devvp, openflags, NOCRED);
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(devvp);
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
if (error) {
|
|
|
|
/* devvp is still locked */
|
2006-09-05 21:03:04 +04:00
|
|
|
vrele(devvp);
|
2006-02-02 18:19:15 +03:00
|
|
|
return error;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* register our mountpoint being on this device */
|
2013-09-30 22:57:59 +04:00
|
|
|
spec_node_setmountedfs(devvp, mp);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* successfully mounted */
|
|
|
|
DPRINTF(VOLUMES, ("udf_mount() successfull\n"));
|
|
|
|
|
2008-05-14 20:49:47 +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);
|
2008-05-14 20:49:47 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* If we're not opened read-only, open its logical volume */
|
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0) {
|
|
|
|
if ((error = udf_open_logvol(VFSTOUDF(mp))) != 0) {
|
|
|
|
printf( "mount_udf: can't open logical volume for "
|
2008-07-18 16:45:08 +04:00
|
|
|
"writing, downgrading access to read-only\n");
|
2008-05-14 20:49:47 +04:00
|
|
|
mp->mnt_flag |= MNT_RDONLY;
|
|
|
|
/* FIXME we can't return error now on open failure */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-02-02 18:19:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2015-08-24 11:30:52 +03:00
|
|
|
static bool
|
|
|
|
udf_sanity_selector(void *cl, struct vnode *vp)
|
|
|
|
{
|
|
|
|
|
2017-04-01 22:35:56 +03:00
|
|
|
KASSERT(mutex_owned(vp->v_interlock));
|
|
|
|
|
2015-08-24 11:30:52 +03:00
|
|
|
vprint("", vp);
|
|
|
|
if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) {
|
|
|
|
printf(" is locked\n");
|
|
|
|
}
|
|
|
|
if (vp->v_usecount > 1)
|
|
|
|
printf(" more than one usecount %d\n", vp->v_usecount);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
static void
|
|
|
|
udf_unmount_sanity_check(struct mount *mp)
|
|
|
|
{
|
2015-08-24 11:30:52 +03:00
|
|
|
struct vnode_iterator *marker;
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
printf("On unmount, i found the following nodes:\n");
|
2015-08-24 11:30:52 +03:00
|
|
|
vfs_vnode_iterator_init(mp, &marker);
|
|
|
|
vfs_vnode_iterator_next(marker, udf_sanity_selector, NULL);
|
|
|
|
vfs_vnode_iterator_destroy(marker);
|
2006-02-02 18:19:15 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
udf_unmount(struct mount *mp, int mntflags)
|
2006-02-02 18:19:15 +03:00
|
|
|
{
|
|
|
|
struct udf_mount *ump;
|
|
|
|
int error, flags, closeflags;
|
|
|
|
|
|
|
|
DPRINTF(CALL, ("udf_umount called\n"));
|
|
|
|
|
|
|
|
ump = VFSTOUDF(mp);
|
|
|
|
if (!ump)
|
|
|
|
panic("UDF unmount: empty ump\n");
|
|
|
|
|
2007-01-04 05:02:40 +03:00
|
|
|
flags = (mntflags & MNT_FORCE) ? FORCECLOSE : 0;
|
2006-02-02 18:19:15 +03:00
|
|
|
/* TODO remove these paranoid functions */
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (udf_verbose & UDF_DEBUG_LOCKING)
|
|
|
|
udf_unmount_sanity_check(mp);
|
|
|
|
#endif
|
|
|
|
|
2007-01-04 05:02:40 +03:00
|
|
|
/*
|
2007-10-11 00:42:20 +04:00
|
|
|
* By specifying SKIPSYSTEM we can skip vnodes marked with VV_SYSTEM.
|
2007-01-04 05:02:40 +03:00
|
|
|
* This hardly documented feature allows us to exempt certain files
|
|
|
|
* from being flushed.
|
|
|
|
*/
|
2007-10-11 00:42:20 +04:00
|
|
|
if ((error = vflush(mp, NULLVP, flags | SKIPSYSTEM)) != 0)
|
2006-02-02 18:19:15 +03:00
|
|
|
return error;
|
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* update nodes and wait for completion of writeout of system nodes */
|
|
|
|
udf_sync(mp, FSYNC_WAIT, NOCRED);
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (udf_verbose & UDF_DEBUG_LOCKING)
|
|
|
|
udf_unmount_sanity_check(mp);
|
|
|
|
#endif
|
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* flush again, to check if we are still busy for something else */
|
|
|
|
if ((error = vflush(ump->vfs_mountp, NULLVP, flags | SKIPSYSTEM)) != 0)
|
|
|
|
return error;
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
DPRINTF(VOLUMES, ("flush OK on unmount\n"));
|
|
|
|
|
|
|
|
/* close logical volume and close session if requested */
|
|
|
|
if ((error = udf_close_logvol(ump, mntflags)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
DPRINTF(VOLUMES, ("FINAL sanity check\n"));
|
|
|
|
if (udf_verbose & UDF_DEBUG_LOCKING)
|
|
|
|
udf_unmount_sanity_check(mp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* NOTE release system nodes should NOT write anything */
|
|
|
|
udf_release_system_nodes(mp);
|
|
|
|
|
|
|
|
/* finalise disc strategy */
|
|
|
|
udf_discstrat_finish(ump);
|
|
|
|
|
|
|
|
/* synchronise device caches */
|
|
|
|
(void) udf_synchronise_caches(ump);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* close device */
|
|
|
|
DPRINTF(VOLUMES, ("closing device\n"));
|
|
|
|
if (mp->mnt_flag & MNT_RDONLY) {
|
|
|
|
closeflags = FREAD;
|
|
|
|
} else {
|
|
|
|
closeflags = FREAD | FWRITE;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* devvp is still locked by us */
|
|
|
|
vn_lock(ump->devvp, LK_EXCLUSIVE | LK_RETRY);
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_CLOSE(ump->devvp, closeflags, NOCRED);
|
2006-02-02 18:19:15 +03:00
|
|
|
if (error)
|
|
|
|
printf("Error during closure of device! error %d, "
|
|
|
|
"device might stay locked\n", error);
|
|
|
|
DPRINTF(VOLUMES, ("device close ok\n"));
|
|
|
|
|
|
|
|
/* clear our mount reference and release device node */
|
2013-09-30 22:57:59 +04:00
|
|
|
spec_node_setmountedfs(ump->devvp, NULL);
|
2006-02-02 18:19:15 +03:00
|
|
|
vput(ump->devvp);
|
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* free our ump */
|
2006-02-02 18:19:15 +03:00
|
|
|
free_udf_mountinfo(mp);
|
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* free ump struct references */
|
2006-10-03 19:54:03 +04:00
|
|
|
mp->mnt_data = NULL;
|
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
DPRINTF(VOLUMES, ("Fin unmount\n"));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function of udf_mount() that actually mounts the disc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
udf_mountfs(struct vnode *devvp, struct mount *mp,
|
|
|
|
struct lwp *l, struct udf_args *args)
|
|
|
|
{
|
|
|
|
struct udf_mount *ump;
|
|
|
|
uint32_t sector_size, lb_size, bshift;
|
2008-05-14 20:49:47 +04:00
|
|
|
uint32_t logvol_integrity;
|
2009-07-07 14:23:36 +04:00
|
|
|
int num_anchors, error;
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* flush out any old buffers remaining from a previous use. */
|
2006-08-10 16:39:56 +04:00
|
|
|
if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)))
|
2006-02-02 18:19:15 +03:00
|
|
|
return error;
|
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* setup basic mount information */
|
|
|
|
mp->mnt_data = NULL;
|
|
|
|
mp->mnt_stat.f_fsidx.__fsid_val[0] = (uint32_t) devvp->v_rdev;
|
|
|
|
mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_UDF);
|
|
|
|
mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
|
2011-09-27 05:13:16 +04:00
|
|
|
mp->mnt_stat.f_namemax = UDF_MAXNAMLEN;
|
2008-05-14 20:49:47 +04:00
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
2009-07-07 14:23:36 +04:00
|
|
|
// mp->mnt_iflag |= IMNT_MPSAFE;
|
2008-05-14 20:49:47 +04:00
|
|
|
|
2007-04-30 00:23:34 +04:00
|
|
|
/* allocate udf part of mount structure; malloc always succeeds */
|
2007-10-11 00:42:20 +04:00
|
|
|
ump = malloc(sizeof(struct udf_mount), M_UDFMNT, M_WAITOK | M_ZERO);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* init locks */
|
2008-05-14 20:49:47 +04:00
|
|
|
mutex_init(&ump->logvol_mutex, MUTEX_DEFAULT, IPL_NONE);
|
|
|
|
mutex_init(&ump->allocate_mutex, MUTEX_DEFAULT, IPL_NONE);
|
2015-08-24 11:31:56 +03:00
|
|
|
mutex_init(&ump->sync_lock, MUTEX_DEFAULT, IPL_NONE);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2009-07-07 14:23:36 +04:00
|
|
|
/* init rbtree for nodes, ordered by their icb address (long_ad) */
|
|
|
|
udf_init_nodes_tree(ump);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* set up linkage */
|
|
|
|
mp->mnt_data = ump;
|
|
|
|
ump->vfs_mountp = mp;
|
|
|
|
|
|
|
|
/* set up arguments and device */
|
|
|
|
ump->mount_args = *args;
|
|
|
|
ump->devvp = devvp;
|
2006-08-10 16:39:56 +04:00
|
|
|
if ((error = udf_update_discinfo(ump))) {
|
2006-02-02 18:19:15 +03:00
|
|
|
printf("UDF mount: error inspecting fs node\n");
|
|
|
|
return error;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* inspect sector size */
|
|
|
|
sector_size = ump->discinfo.sector_size;
|
|
|
|
bshift = 1;
|
|
|
|
while ((1 << bshift) < sector_size)
|
|
|
|
bshift++;
|
|
|
|
if ((1 << bshift) != sector_size) {
|
|
|
|
printf("UDF mount: "
|
|
|
|
"hit NetBSD implementation fence on sector size\n");
|
|
|
|
return EIO;
|
2008-07-19 20:36:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* temporary check to overcome sectorsize >= 8192 bytes panic */
|
|
|
|
if (sector_size >= 8192) {
|
|
|
|
printf("UDF mount: "
|
|
|
|
"hit implementation limit, sectorsize to big\n");
|
|
|
|
return EIO;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/*
|
|
|
|
* Inspect if we're asked to mount read-write on a non recordable or
|
|
|
|
* closed sequential disc.
|
|
|
|
*/
|
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0) {
|
|
|
|
if ((ump->discinfo.mmc_cur & MMC_CAP_RECORDABLE) == 0) {
|
|
|
|
printf("UDF mount: disc is not recordable\n");
|
|
|
|
return EROFS;
|
|
|
|
}
|
2008-10-29 21:09:47 +03:00
|
|
|
if (ump->discinfo.mmc_cur & MMC_CAP_SEQUENTIAL) {
|
|
|
|
if (ump->discinfo.disc_state == MMC_STATE_FULL) {
|
|
|
|
printf("UDF mount: disc is not appendable\n");
|
|
|
|
return EROFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO if the last session is closed check if there
|
|
|
|
* is enough space to open/close new session
|
|
|
|
*/
|
|
|
|
}
|
2009-02-08 22:04:41 +03:00
|
|
|
/* double check if we're not mounting a pervious session RW */
|
|
|
|
if (args->sessionnr != 0) {
|
|
|
|
printf("UDF mount: updating a previous session "
|
|
|
|
"not yet allowed\n");
|
|
|
|
return EROFS;
|
|
|
|
}
|
2008-05-14 20:49:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialise bootstrap disc strategy */
|
|
|
|
ump->strategy = &udf_strat_bootstrap;
|
|
|
|
udf_discstrat_init(ump);
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
/* read all anchors to get volume descriptor sequence */
|
2008-05-14 20:49:47 +04:00
|
|
|
num_anchors = udf_read_anchors(ump);
|
2006-02-02 18:19:15 +03:00
|
|
|
if (num_anchors == 0)
|
2008-05-14 20:49:47 +04:00
|
|
|
return EINVAL;
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
DPRINTF(VOLUMES, ("Read %d anchors on this disc, session %d\n",
|
|
|
|
num_anchors, args->sessionnr));
|
|
|
|
|
|
|
|
/* read in volume descriptor sequence */
|
2006-08-10 16:39:56 +04:00
|
|
|
if ((error = udf_read_vds_space(ump))) {
|
2006-02-02 18:19:15 +03:00
|
|
|
printf("UDF mount: error reading volume space\n");
|
2006-08-10 16:39:56 +04:00
|
|
|
return error;
|
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2009-02-08 22:04:41 +03:00
|
|
|
/* close down bootstrap disc strategy */
|
2008-05-14 20:49:47 +04:00
|
|
|
udf_discstrat_finish(ump);
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
/* check consistency and completeness */
|
2008-05-14 20:49:47 +04:00
|
|
|
if ((error = udf_process_vds(ump))) {
|
2007-01-04 05:02:40 +03:00
|
|
|
printf( "UDF mount: disc not properly formatted"
|
|
|
|
"(bad VDS)\n");
|
2006-08-10 16:39:56 +04:00
|
|
|
return error;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* switch to new disc strategy */
|
|
|
|
KASSERT(ump->strategy != &udf_strat_bootstrap);
|
|
|
|
udf_discstrat_init(ump);
|
|
|
|
|
|
|
|
/* initialise late allocation administration space */
|
|
|
|
ump->la_lmapping = malloc(sizeof(uint64_t) * UDF_MAX_MAPPINGS,
|
|
|
|
M_TEMP, M_WAITOK);
|
|
|
|
ump->la_pmapping = malloc(sizeof(uint64_t) * UDF_MAX_MAPPINGS,
|
|
|
|
M_TEMP, M_WAITOK);
|
|
|
|
|
|
|
|
/* setup node cleanup extents copy space */
|
2006-02-02 18:19:15 +03:00
|
|
|
lb_size = udf_rw32(ump->logical_vol->lb_size);
|
2008-05-14 20:49:47 +04:00
|
|
|
ump->la_node_ad_cpy = malloc(lb_size * UDF_MAX_ALLOC_EXTENTS,
|
|
|
|
M_UDFMNT, M_WAITOK);
|
|
|
|
memset(ump->la_node_ad_cpy, 0, lb_size * UDF_MAX_ALLOC_EXTENTS);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* setup rest of mount information */
|
|
|
|
mp->mnt_data = ump;
|
|
|
|
|
|
|
|
/* bshift is allways equal to disc sector size */
|
|
|
|
mp->mnt_dev_bshift = bshift;
|
|
|
|
mp->mnt_fs_bshift = bshift;
|
|
|
|
|
|
|
|
/* note that the mp info needs to be initialised for reading! */
|
2006-02-02 18:19:15 +03:00
|
|
|
/* read vds support tables like VAT, sparable etc. */
|
2008-05-14 20:49:47 +04:00
|
|
|
if ((error = udf_read_vds_tables(ump))) {
|
2007-01-04 05:02:40 +03:00
|
|
|
printf( "UDF mount: error in format or damaged disc "
|
|
|
|
"(VDS tables failing)\n");
|
2006-08-10 16:39:56 +04:00
|
|
|
return error;
|
2006-06-12 04:20:21 +04:00
|
|
|
}
|
2006-08-10 16:39:56 +04:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* check if volume integrity is closed otherwise its dirty */
|
|
|
|
logvol_integrity = udf_rw32(ump->logvol_integrity->integrity_type);
|
|
|
|
if (logvol_integrity != UDF_INTEGRITY_CLOSED) {
|
|
|
|
printf("UDF mount: file system is not clean; ");
|
|
|
|
printf("please fsck(8)\n");
|
|
|
|
return EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read root directory */
|
|
|
|
if ((error = udf_read_rootdirs(ump))) {
|
2007-01-04 05:02:40 +03:00
|
|
|
printf( "UDF mount: "
|
|
|
|
"disc not properly formatted or damaged disc "
|
|
|
|
"(rootdirs failing)\n");
|
2006-02-02 18:19:15 +03:00
|
|
|
return error;
|
2006-08-10 16:39:56 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
/* success! */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
udf_start(struct mount *mp, int flags)
|
2006-02-02 18:19:15 +03:00
|
|
|
{
|
|
|
|
/* do we have to do something here? */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
udf_root(struct mount *mp, struct vnode **vpp)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct long_ad *dir_loc;
|
|
|
|
struct udf_mount *ump = VFSTOUDF(mp);
|
|
|
|
struct udf_node *root_dir;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
DPRINTF(CALL, ("udf_root called\n"));
|
|
|
|
|
|
|
|
dir_loc = &ump->fileset_desc->rootdir_icb;
|
|
|
|
error = udf_get_node(ump, dir_loc, &root_dir);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2016-01-29 13:42:30 +03:00
|
|
|
if (!root_dir)
|
|
|
|
error = ENOENT;
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
vp = root_dir->vnode;
|
2008-12-16 19:27:05 +03:00
|
|
|
KASSERT(vp->v_vflag & VV_ROOT);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
*vpp = vp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
udf_statvfs(struct mount *mp, struct statvfs *sbp)
|
2006-02-02 18:19:15 +03:00
|
|
|
{
|
|
|
|
struct udf_mount *ump = VFSTOUDF(mp);
|
|
|
|
struct logvol_int_desc *lvid;
|
|
|
|
struct udf_logvol_info *impl;
|
|
|
|
uint64_t freeblks, sizeblks;
|
2009-06-24 21:09:13 +04:00
|
|
|
int num_part;
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
DPRINTF(CALL, ("udf_statvfs called\n"));
|
|
|
|
sbp->f_flag = mp->mnt_flag;
|
|
|
|
sbp->f_bsize = ump->discinfo.sector_size;
|
|
|
|
sbp->f_frsize = ump->discinfo.sector_size;
|
|
|
|
sbp->f_iosize = ump->discinfo.sector_size;
|
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
mutex_enter(&ump->allocate_mutex);
|
|
|
|
|
2009-06-24 21:09:13 +04:00
|
|
|
udf_calc_freespace(ump, &sizeblks, &freeblks);
|
2008-05-14 20:49:47 +04:00
|
|
|
|
|
|
|
sbp->f_blocks = sizeblks;
|
|
|
|
sbp->f_bfree = freeblks;
|
|
|
|
sbp->f_files = 0;
|
2009-06-24 21:09:13 +04:00
|
|
|
|
|
|
|
lvid = ump->logvol_integrity;
|
|
|
|
num_part = udf_rw32(lvid->num_part);
|
|
|
|
impl = (struct udf_logvol_info *) (lvid->tables + 2*num_part);
|
2008-05-14 20:49:47 +04:00
|
|
|
if (impl) {
|
2006-02-02 18:19:15 +03:00
|
|
|
sbp->f_files = udf_rw32(impl->num_files);
|
|
|
|
sbp->f_files += udf_rw32(impl->num_directories);
|
2008-05-14 20:49:47 +04:00
|
|
|
}
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* XXX read only for now XXX */
|
|
|
|
sbp->f_bavail = 0;
|
|
|
|
sbp->f_bresvd = 0;
|
2006-02-02 18:19:15 +03:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/* tricky, next only aplies to ffs i think, so set to zero */
|
|
|
|
sbp->f_ffree = 0;
|
|
|
|
sbp->f_favail = 0;
|
|
|
|
sbp->f_fresvd = 0;
|
|
|
|
|
|
|
|
mutex_exit(&ump->allocate_mutex);
|
2006-02-02 18:19:15 +03:00
|
|
|
|
|
|
|
copy_statvfs_info(sbp, mp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
/*
|
|
|
|
* TODO what about writing out free space maps, lvid etc? only on `waitfor'
|
|
|
|
* i.e. explicit syncing by the user?
|
|
|
|
*/
|
|
|
|
|
2008-08-06 17:41:12 +04:00
|
|
|
static int
|
|
|
|
udf_sync_writeout_system_files(struct udf_mount *ump, int clearflags)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* XXX lock for VAT en bitmaps? */
|
|
|
|
/* metadata nodes are written synchronous */
|
|
|
|
DPRINTF(CALL, ("udf_sync: syncing metadata\n"));
|
|
|
|
if (ump->lvclose & UDF_WRITE_VAT)
|
|
|
|
udf_writeout_vat(ump);
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
if (ump->lvclose & UDF_WRITE_PART_BITMAPS) {
|
|
|
|
/* writeout metadata spacetable if existing */
|
|
|
|
error = udf_write_metadata_partition_spacetable(ump, MNT_WAIT);
|
|
|
|
if (error)
|
|
|
|
printf( "udf_writeout_system_files : "
|
|
|
|
" writeout of metadata space bitmap failed\n");
|
|
|
|
|
|
|
|
/* writeout partition spacetables */
|
|
|
|
error = udf_write_physical_partition_spacetables(ump, MNT_WAIT);
|
|
|
|
if (error)
|
|
|
|
printf( "udf_writeout_system_files : "
|
|
|
|
"writeout of space tables failed\n");
|
|
|
|
if (!error && clearflags)
|
|
|
|
ump->lvclose &= ~UDF_WRITE_PART_BITMAPS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
int
|
2008-05-14 20:49:47 +04:00
|
|
|
udf_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
|
2006-02-02 18:19:15 +03:00
|
|
|
{
|
2008-05-14 20:49:47 +04:00
|
|
|
struct udf_mount *ump = VFSTOUDF(mp);
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
DPRINTF(CALL, ("udf_sync called\n"));
|
2008-05-14 20:49:47 +04:00
|
|
|
/* if called when mounted readonly, just ignore */
|
|
|
|
if (mp->mnt_flag & MNT_RDONLY)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ump->syncing && !waitfor) {
|
|
|
|
printf("UDF: skipping autosync\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get sync lock */
|
|
|
|
ump->syncing = 1;
|
|
|
|
|
2008-07-28 23:41:13 +04:00
|
|
|
/* pre-sync */
|
2008-05-14 20:49:47 +04:00
|
|
|
udf_do_sync(ump, cred, waitfor);
|
|
|
|
|
2008-08-06 17:41:12 +04:00
|
|
|
if (waitfor == MNT_WAIT)
|
|
|
|
udf_sync_writeout_system_files(ump, true);
|
2008-07-28 23:41:13 +04:00
|
|
|
|
2008-05-14 20:49:47 +04:00
|
|
|
DPRINTF(CALL, ("end of udf_sync()\n"));
|
|
|
|
ump->syncing = 0;
|
|
|
|
|
2006-02-02 18:19:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get vnode for the file system type specific file id ino for the fs. Its
|
|
|
|
* used for reference to files by unique ID and for NFSv3.
|
|
|
|
* (optional) TODO lookup why some sources state NFSv3
|
|
|
|
*/
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
udf_vget(struct mount *mp, ino_t ino,
|
|
|
|
struct vnode **vpp)
|
2006-02-02 18:19:15 +03:00
|
|
|
{
|
|
|
|
DPRINTF(NOTIMPL, ("udf_vget called\n"));
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup vnode for file handle specified
|
|
|
|
*/
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
udf_fhtovp(struct mount *mp, struct fid *fhp,
|
|
|
|
struct vnode **vpp)
|
2006-02-02 18:19:15 +03:00
|
|
|
{
|
|
|
|
DPRINTF(NOTIMPL, ("udf_fhtovp called\n"));
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create an unique file handle. Its structure is opaque and won't be used by
|
|
|
|
* other subsystems. It should uniquely identify the file in the filingsystem
|
|
|
|
* and enough information to know if a file has been removed and/or resources
|
|
|
|
* have been recycled.
|
|
|
|
*/
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
udf_vptofh(struct vnode *vp, struct fid *fid,
|
|
|
|
size_t *fh_size)
|
2006-02-02 18:19:15 +03:00
|
|
|
{
|
|
|
|
DPRINTF(NOTIMPL, ("udf_vptofh called\n"));
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a filingsystem snapshot at the specified timestamp. Could be
|
|
|
|
* implemented by explicitly creating a new session or with spare room in the
|
|
|
|
* integrity descriptor space
|
|
|
|
*/
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
udf_snapshot(struct mount *mp, struct vnode *vp,
|
|
|
|
struct timespec *tm)
|
2006-02-02 18:19:15 +03:00
|
|
|
{
|
|
|
|
DPRINTF(NOTIMPL, ("udf_snapshot called\n"));
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
2006-09-29 05:36:28 +04:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|