Home | History | Annotate | Line # | Download | only in udf
udf_vfsops.c revision 1.52.2.1
      1  1.52.2.1       snj /* $NetBSD: udf_vfsops.c,v 1.52.2.1 2008/12/18 01:10:52 snj Exp $ */
      2       1.1   reinoud 
      3       1.1   reinoud /*
      4      1.38   reinoud  * Copyright (c) 2006, 2008 Reinoud Zandijk
      5       1.1   reinoud  * All rights reserved.
      6       1.1   reinoud  *
      7       1.1   reinoud  * Redistribution and use in source and binary forms, with or without
      8       1.1   reinoud  * modification, are permitted provided that the following conditions
      9       1.1   reinoud  * are met:
     10       1.1   reinoud  * 1. Redistributions of source code must retain the above copyright
     11       1.1   reinoud  *    notice, this list of conditions and the following disclaimer.
     12       1.1   reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   reinoud  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   reinoud  *    documentation and/or other materials provided with the distribution.
     15       1.1   reinoud  *
     16       1.1   reinoud  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.1   reinoud  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18       1.1   reinoud  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19       1.1   reinoud  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20       1.1   reinoud  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21       1.1   reinoud  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22       1.1   reinoud  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23       1.1   reinoud  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24       1.1   reinoud  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25       1.1   reinoud  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26       1.1   reinoud  *
     27       1.1   reinoud  */
     28       1.1   reinoud 
     29       1.1   reinoud #include <sys/cdefs.h>
     30       1.1   reinoud #ifndef lint
     31  1.52.2.1       snj __KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.52.2.1 2008/12/18 01:10:52 snj Exp $");
     32       1.1   reinoud #endif /* not lint */
     33       1.1   reinoud 
     34       1.1   reinoud 
     35       1.1   reinoud #if defined(_KERNEL_OPT)
     36       1.1   reinoud #include "opt_quota.h"
     37       1.1   reinoud #include "opt_compat_netbsd.h"
     38       1.1   reinoud #endif
     39       1.1   reinoud 
     40       1.1   reinoud #include <sys/param.h>
     41       1.1   reinoud #include <sys/systm.h>
     42       1.1   reinoud #include <sys/sysctl.h>
     43       1.1   reinoud #include <sys/namei.h>
     44       1.1   reinoud #include <sys/proc.h>
     45       1.1   reinoud #include <sys/kernel.h>
     46       1.1   reinoud #include <sys/vnode.h>
     47      1.35  dholland #include <miscfs/genfs/genfs.h>
     48       1.1   reinoud #include <miscfs/specfs/specdev.h>
     49       1.1   reinoud #include <sys/mount.h>
     50       1.1   reinoud #include <sys/buf.h>
     51       1.1   reinoud #include <sys/file.h>
     52       1.1   reinoud #include <sys/device.h>
     53       1.1   reinoud #include <sys/disklabel.h>
     54       1.1   reinoud #include <sys/ioctl.h>
     55       1.1   reinoud #include <sys/malloc.h>
     56       1.1   reinoud #include <sys/dirent.h>
     57       1.1   reinoud #include <sys/stat.h>
     58       1.1   reinoud #include <sys/conf.h>
     59       1.5  christos #include <sys/kauth.h>
     60      1.37    rumble #include <sys/module.h>
     61       1.1   reinoud 
     62       1.1   reinoud #include <fs/udf/ecma167-udf.h>
     63       1.1   reinoud #include <fs/udf/udf_mount.h>
     64      1.51   reinoud #include <sys/dirhash.h>
     65       1.1   reinoud 
     66       1.1   reinoud #include "udf.h"
     67       1.1   reinoud #include "udf_subr.h"
     68       1.1   reinoud #include "udf_bswap.h"
     69       1.1   reinoud 
     70      1.37    rumble MODULE(MODULE_CLASS_VFS, udf, NULL);
     71       1.1   reinoud 
     72      1.38   reinoud #define VTOI(vnode) ((struct udf_node *) vnode->v_data)
     73      1.38   reinoud 
     74       1.1   reinoud /* verbose levels of the udf filingsystem */
     75       1.1   reinoud int udf_verbose = UDF_DEBUGGING;
     76       1.1   reinoud 
     77       1.1   reinoud /* malloc regions */
     78      1.25     pooka MALLOC_JUSTDEFINE(M_UDFMNT,   "UDF mount",	"UDF mount structures");
     79      1.25     pooka MALLOC_JUSTDEFINE(M_UDFVOLD,  "UDF volspace",	"UDF volume space descriptors");
     80      1.25     pooka MALLOC_JUSTDEFINE(M_UDFTEMP,  "UDF temp",	"UDF scrap space");
     81       1.1   reinoud struct pool udf_node_pool;
     82       1.1   reinoud 
     83       1.1   reinoud /* supported functions predefined */
     84      1.29     pooka VFS_PROTOS(udf);
     85       1.1   reinoud 
     86      1.39    rumble static struct sysctllog *udf_sysctl_log;
     87       1.1   reinoud 
     88       1.1   reinoud /* internal functions */
     89       1.1   reinoud static int udf_mountfs(struct vnode *, struct mount *, struct lwp *, struct udf_args *);
     90       1.1   reinoud 
     91       1.1   reinoud 
     92       1.1   reinoud /* --------------------------------------------------------------------- */
     93       1.1   reinoud 
     94       1.1   reinoud /* predefine vnode-op list descriptor */
     95       1.1   reinoud extern const struct vnodeopv_desc udf_vnodeop_opv_desc;
     96       1.1   reinoud 
     97       1.1   reinoud const struct vnodeopv_desc * const udf_vnodeopv_descs[] = {
     98       1.1   reinoud 	&udf_vnodeop_opv_desc,
     99       1.1   reinoud 	NULL,
    100       1.1   reinoud };
    101       1.1   reinoud 
    102       1.1   reinoud 
    103       1.1   reinoud /* vfsops descriptor linked in as anchor point for the filingsystem */
    104       1.1   reinoud struct vfsops udf_vfsops = {
    105       1.1   reinoud 	MOUNT_UDF,			/* vfs_name */
    106      1.26       dsl 	sizeof (struct udf_args),
    107       1.1   reinoud 	udf_mount,
    108       1.1   reinoud 	udf_start,
    109       1.1   reinoud 	udf_unmount,
    110       1.1   reinoud 	udf_root,
    111      1.31     pooka 	(void *)eopnotsupp,		/* vfs_quotactl */
    112       1.1   reinoud 	udf_statvfs,
    113       1.1   reinoud 	udf_sync,
    114       1.1   reinoud 	udf_vget,
    115       1.1   reinoud 	udf_fhtovp,
    116       1.1   reinoud 	udf_vptofh,
    117       1.1   reinoud 	udf_init,
    118       1.1   reinoud 	udf_reinit,
    119       1.1   reinoud 	udf_done,
    120       1.1   reinoud 	udf_mountroot,
    121       1.1   reinoud 	udf_snapshot,
    122       1.1   reinoud 	vfs_stdextattrctl,
    123      1.28     pooka 	(void *)eopnotsupp,		/* vfs_suspendctl */
    124      1.35  dholland 	genfs_renamelock_enter,
    125      1.35  dholland 	genfs_renamelock_exit,
    126      1.36        ad 	(void *)eopnotsupp,
    127       1.1   reinoud 	udf_vnodeopv_descs,
    128      1.12  christos 	0, /* int vfs_refcount   */
    129      1.12  christos 	{ NULL, NULL, }, /* LIST_ENTRY(vfsops) */
    130       1.1   reinoud };
    131       1.1   reinoud 
    132       1.1   reinoud /* --------------------------------------------------------------------- */
    133       1.1   reinoud 
    134       1.1   reinoud /* file system starts here */
    135       1.1   reinoud void
    136       1.1   reinoud udf_init(void)
    137       1.1   reinoud {
    138       1.1   reinoud 	size_t size;
    139       1.1   reinoud 
    140      1.43   reinoud 	/* setup memory types */
    141       1.1   reinoud 	malloc_type_attach(M_UDFMNT);
    142       1.1   reinoud 	malloc_type_attach(M_UDFVOLD);
    143       1.1   reinoud 	malloc_type_attach(M_UDFTEMP);
    144       1.1   reinoud 
    145      1.40   reinoud 	/* init node pools */
    146       1.1   reinoud 	size = sizeof(struct udf_node);
    147      1.40   reinoud 	pool_init(&udf_node_pool, size, 0, 0, 0,
    148      1.40   reinoud 		"udf_node_pool", NULL, IPL_NONE);
    149       1.1   reinoud }
    150       1.1   reinoud 
    151       1.1   reinoud 
    152       1.1   reinoud void
    153       1.1   reinoud udf_reinit(void)
    154       1.1   reinoud {
    155      1.40   reinoud 	/* nothing to do */
    156       1.1   reinoud }
    157       1.1   reinoud 
    158       1.1   reinoud 
    159       1.1   reinoud void
    160       1.1   reinoud udf_done(void)
    161       1.1   reinoud {
    162      1.40   reinoud 	/* remove pools */
    163       1.1   reinoud 	pool_destroy(&udf_node_pool);
    164       1.1   reinoud 
    165       1.1   reinoud 	malloc_type_detach(M_UDFMNT);
    166       1.1   reinoud 	malloc_type_detach(M_UDFVOLD);
    167       1.1   reinoud 	malloc_type_detach(M_UDFTEMP);
    168       1.1   reinoud }
    169       1.1   reinoud 
    170      1.39    rumble /*
    171      1.39    rumble  * If running a DEBUG kernel, provide an easy way to set the debug flags when
    172      1.39    rumble  * running into a problem.
    173      1.39    rumble  */
    174      1.43   reinoud #define UDF_VERBOSE_SYSCTLOPT        1
    175      1.38   reinoud 
    176      1.38   reinoud static int
    177      1.38   reinoud udf_modcmd(modcmd_t cmd, void *arg)
    178      1.38   reinoud {
    179      1.43   reinoud 	const struct sysctlnode *node;
    180      1.39    rumble 	int error;
    181      1.38   reinoud 
    182      1.38   reinoud 	switch (cmd) {
    183      1.38   reinoud 	case MODULE_CMD_INIT:
    184      1.39    rumble 		error = vfs_attach(&udf_vfsops);
    185      1.39    rumble 		if (error != 0)
    186      1.39    rumble 			break;
    187      1.39    rumble 		/*
    188      1.39    rumble 		 * XXX the "24" below could be dynamic, thereby eliminating one
    189      1.39    rumble 		 * more instance of the "number to vfs" mapping problem, but
    190      1.39    rumble 		 * "24" is the order as taken from sys/mount.h
    191      1.39    rumble 		 */
    192      1.39    rumble 		sysctl_createv(&udf_sysctl_log, 0, NULL, NULL,
    193      1.39    rumble 			       CTLFLAG_PERMANENT,
    194      1.39    rumble 			       CTLTYPE_NODE, "vfs", NULL,
    195      1.39    rumble 			       NULL, 0, NULL, 0,
    196      1.39    rumble 			       CTL_VFS, CTL_EOL);
    197      1.43   reinoud 		sysctl_createv(&udf_sysctl_log, 0, NULL, &node,
    198      1.39    rumble 			       CTLFLAG_PERMANENT,
    199      1.39    rumble 			       CTLTYPE_NODE, "udf",
    200      1.39    rumble 			       SYSCTL_DESCR("OSTA Universal File System"),
    201      1.39    rumble 			       NULL, 0, NULL, 0,
    202      1.39    rumble 			       CTL_VFS, 24, CTL_EOL);
    203      1.39    rumble #ifdef DEBUG
    204      1.43   reinoud 		sysctl_createv(&udf_sysctl_log, 0, NULL, &node,
    205      1.39    rumble 			       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    206      1.39    rumble 			       CTLTYPE_INT, "verbose",
    207      1.39    rumble 			       SYSCTL_DESCR("Bitmask for filesystem debugging"),
    208      1.39    rumble 			       NULL, 0, &udf_verbose, 0,
    209      1.39    rumble 			       CTL_VFS, 24, UDF_VERBOSE_SYSCTLOPT, CTL_EOL);
    210      1.39    rumble #endif
    211      1.39    rumble 		break;
    212      1.38   reinoud 	case MODULE_CMD_FINI:
    213      1.39    rumble 		error = vfs_detach(&udf_vfsops);
    214      1.39    rumble 		if (error != 0)
    215      1.39    rumble 			break;
    216      1.39    rumble 		sysctl_teardown(&udf_sysctl_log);
    217      1.39    rumble 		break;
    218      1.38   reinoud 	default:
    219      1.39    rumble 		error = ENOTTY;
    220      1.39    rumble 		break;
    221      1.38   reinoud 	}
    222      1.39    rumble 
    223      1.39    rumble 	return (error);
    224      1.38   reinoud }
    225      1.38   reinoud 
    226       1.1   reinoud /* --------------------------------------------------------------------- */
    227       1.1   reinoud 
    228       1.1   reinoud int
    229       1.1   reinoud udf_mountroot(void)
    230       1.1   reinoud {
    231       1.1   reinoud 	return EOPNOTSUPP;
    232       1.1   reinoud }
    233       1.1   reinoud 
    234       1.1   reinoud /* --------------------------------------------------------------------- */
    235       1.1   reinoud 
    236       1.1   reinoud #define MPFREE(a, lst) \
    237       1.1   reinoud 	if ((a)) free((a), lst);
    238       1.1   reinoud static void
    239       1.1   reinoud free_udf_mountinfo(struct mount *mp)
    240       1.1   reinoud {
    241       1.1   reinoud 	struct udf_mount *ump;
    242       1.1   reinoud 	int i;
    243       1.1   reinoud 
    244      1.15   reinoud 	if (!mp)
    245      1.15   reinoud 		return;
    246      1.15   reinoud 
    247       1.1   reinoud 	ump = VFSTOUDF(mp);
    248       1.1   reinoud 	if (ump) {
    249      1.10   reinoud 		/* clear our data */
    250       1.1   reinoud 		for (i = 0; i < UDF_ANCHORS; i++)
    251       1.1   reinoud 			MPFREE(ump->anchors[i], M_UDFVOLD);
    252       1.1   reinoud 		MPFREE(ump->primary_vol,      M_UDFVOLD);
    253       1.1   reinoud 		MPFREE(ump->logical_vol,      M_UDFVOLD);
    254       1.1   reinoud 		MPFREE(ump->unallocated,      M_UDFVOLD);
    255       1.1   reinoud 		MPFREE(ump->implementation,   M_UDFVOLD);
    256       1.1   reinoud 		MPFREE(ump->logvol_integrity, M_UDFVOLD);
    257      1.38   reinoud 		for (i = 0; i < UDF_PARTITIONS; i++) {
    258      1.45   reinoud 			MPFREE(ump->partitions[i],        M_UDFVOLD);
    259      1.38   reinoud 			MPFREE(ump->part_unalloc_dscr[i], M_UDFVOLD);
    260      1.45   reinoud 			MPFREE(ump->part_freed_dscr[i],   M_UDFVOLD);
    261      1.38   reinoud 		}
    262      1.45   reinoud 		MPFREE(ump->metadata_unalloc_dscr, M_UDFVOLD);
    263      1.45   reinoud 
    264      1.45   reinoud 		MPFREE(ump->fileset_desc,   M_UDFVOLD);
    265      1.45   reinoud 		MPFREE(ump->sparing_table,  M_UDFVOLD);
    266      1.38   reinoud 
    267      1.38   reinoud 		MPFREE(ump->la_node_ad_cpy, M_UDFMNT);
    268      1.45   reinoud 		MPFREE(ump->la_pmapping,    M_TEMP);
    269      1.45   reinoud 		MPFREE(ump->la_lmapping,    M_TEMP);
    270       1.1   reinoud 
    271      1.30        ad 		mutex_destroy(&ump->ihash_lock);
    272      1.30        ad 		mutex_destroy(&ump->get_node_lock);
    273      1.49   reinoud 		mutex_destroy(&ump->logvol_mutex);
    274      1.49   reinoud 		mutex_destroy(&ump->allocate_mutex);
    275      1.49   reinoud 		cv_destroy(&ump->dirtynodes_cv);
    276      1.38   reinoud 
    277      1.38   reinoud 		MPFREE(ump->vat_table, M_UDFVOLD);
    278      1.38   reinoud 
    279       1.1   reinoud 		free(ump, M_UDFMNT);
    280       1.6  christos 	}
    281       1.1   reinoud }
    282       1.1   reinoud #undef MPFREE
    283       1.1   reinoud 
    284       1.1   reinoud /* --------------------------------------------------------------------- */
    285       1.1   reinoud 
    286      1.38   reinoud /* if the system nodes exist, release them */
    287      1.38   reinoud static void
    288      1.38   reinoud udf_release_system_nodes(struct mount *mp)
    289      1.38   reinoud {
    290      1.38   reinoud 	struct udf_mount *ump = VFSTOUDF(mp);
    291      1.38   reinoud 	int error;
    292      1.38   reinoud 
    293      1.38   reinoud 	/* if we haven't even got an ump, dont bother */
    294      1.38   reinoud 	if (!ump)
    295      1.38   reinoud 		return;
    296      1.38   reinoud 
    297      1.38   reinoud 	/* VAT partition support */
    298      1.38   reinoud 	if (ump->vat_node)
    299      1.38   reinoud 		vrele(ump->vat_node->vnode);
    300      1.38   reinoud 
    301      1.38   reinoud 	/* Metadata partition support */
    302      1.38   reinoud 	if (ump->metadata_node)
    303      1.38   reinoud 		vrele(ump->metadata_node->vnode);
    304      1.38   reinoud 	if (ump->metadatamirror_node)
    305      1.38   reinoud 		vrele(ump->metadatamirror_node->vnode);
    306      1.38   reinoud 	if (ump->metadatabitmap_node)
    307      1.38   reinoud 		vrele(ump->metadatabitmap_node->vnode);
    308      1.38   reinoud 
    309      1.38   reinoud 	/* This flush should NOT write anything nor allow any node to remain */
    310      1.38   reinoud 	if ((error = vflush(ump->vfs_mountp, NULLVP, 0)) != 0)
    311      1.38   reinoud 		panic("Failure to flush UDF system vnodes\n");
    312      1.38   reinoud }
    313      1.38   reinoud 
    314      1.38   reinoud 
    315       1.1   reinoud int
    316       1.1   reinoud udf_mount(struct mount *mp, const char *path,
    317      1.31     pooka 	  void *data, size_t *data_len)
    318       1.1   reinoud {
    319      1.31     pooka 	struct lwp *l = curlwp;
    320      1.29     pooka 	struct nameidata nd;
    321      1.26       dsl 	struct udf_args *args = data;
    322       1.1   reinoud 	struct udf_mount *ump;
    323       1.1   reinoud 	struct vnode *devvp;
    324       1.1   reinoud 	int openflags, accessmode, error;
    325       1.1   reinoud 
    326       1.1   reinoud 	DPRINTF(CALL, ("udf_mount called\n"));
    327       1.1   reinoud 
    328      1.26       dsl 	if (*data_len < sizeof *args)
    329      1.26       dsl 		return EINVAL;
    330      1.26       dsl 
    331       1.1   reinoud 	if (mp->mnt_flag & MNT_GETARGS) {
    332       1.1   reinoud 		/* request for the mount arguments */
    333       1.1   reinoud 		ump = VFSTOUDF(mp);
    334       1.1   reinoud 		if (ump == NULL)
    335       1.1   reinoud 			return EINVAL;
    336      1.26       dsl 		*args = ump->mount_args;
    337      1.26       dsl 		*data_len = sizeof *args;
    338      1.26       dsl 		return 0;
    339       1.6  christos 	}
    340       1.1   reinoud 
    341       1.1   reinoud 	/* handle request for updating mount parameters */
    342       1.1   reinoud 	/* TODO can't update my mountpoint yet */
    343       1.1   reinoud 	if (mp->mnt_flag & MNT_UPDATE) {
    344       1.1   reinoud 		return EOPNOTSUPP;
    345       1.6  christos 	}
    346       1.1   reinoud 
    347      1.15   reinoud 	/* OK, so we are asked to mount the device */
    348       1.1   reinoud 
    349       1.1   reinoud 	/* check/translate struct version */
    350       1.1   reinoud 	/* TODO sanity checking other mount arguments */
    351      1.26       dsl 	if (args->version != 1) {
    352       1.1   reinoud 		printf("mount_udf: unrecognized argument structure version\n");
    353       1.1   reinoud 		return EINVAL;
    354       1.6  christos 	}
    355       1.1   reinoud 
    356       1.1   reinoud 	/* lookup name to get its vnode */
    357      1.32     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, args->fspec);
    358      1.29     pooka 	error = namei(&nd);
    359       1.1   reinoud 	if (error)
    360       1.1   reinoud 		return error;
    361      1.29     pooka 	devvp = nd.ni_vp;
    362       1.1   reinoud 
    363       1.1   reinoud #ifdef DEBUG
    364       1.1   reinoud 	if (udf_verbose & UDF_DEBUG_VOLUMES)
    365       1.1   reinoud 		vprint("UDF mount, trying to mount \n", devvp);
    366       1.1   reinoud #endif
    367       1.1   reinoud 
    368       1.1   reinoud 	/* check if its a block device specified */
    369       1.1   reinoud 	if (devvp->v_type != VBLK) {
    370       1.1   reinoud 		vrele(devvp);
    371       1.1   reinoud 		return ENOTBLK;
    372       1.1   reinoud 	}
    373       1.1   reinoud 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    374       1.1   reinoud 		vrele(devvp);
    375       1.1   reinoud 		return ENXIO;
    376       1.1   reinoud 	}
    377       1.1   reinoud 
    378       1.1   reinoud 	/*
    379       1.1   reinoud 	 * If mount by non-root, then verify that user has necessary
    380       1.1   reinoud 	 * permissions on the device.
    381       1.1   reinoud 	 */
    382      1.20      elad 	if (kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER, NULL)) {
    383       1.1   reinoud 		accessmode = VREAD;
    384       1.1   reinoud 		if ((mp->mnt_flag & MNT_RDONLY) == 0)
    385       1.1   reinoud 			accessmode |= VWRITE;
    386      1.13   reinoud 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    387      1.31     pooka 		error = VOP_ACCESS(devvp, accessmode, l->l_cred);
    388      1.13   reinoud 		VOP_UNLOCK(devvp, 0);
    389       1.1   reinoud 		if (error) {
    390      1.13   reinoud 			vrele(devvp);
    391      1.13   reinoud 			return error;
    392       1.1   reinoud 		}
    393       1.1   reinoud 	}
    394       1.1   reinoud 
    395       1.1   reinoud 	/*
    396       1.1   reinoud 	 * Open device and try to mount it!
    397       1.1   reinoud 	 */
    398       1.1   reinoud 	if (mp->mnt_flag & MNT_RDONLY) {
    399       1.1   reinoud 		openflags = FREAD;
    400       1.1   reinoud 	} else {
    401       1.1   reinoud 		openflags = FREAD | FWRITE;
    402       1.6  christos 	}
    403      1.31     pooka 	error = VOP_OPEN(devvp, openflags, FSCRED);
    404       1.1   reinoud 	if (error == 0) {
    405       1.1   reinoud 		/* opened ok, try mounting */
    406      1.26       dsl 		error = udf_mountfs(devvp, mp, l, args);
    407       1.1   reinoud 		if (error) {
    408      1.38   reinoud 			udf_release_system_nodes(mp);
    409      1.38   reinoud 			/* cleanup */
    410      1.38   reinoud 			udf_discstrat_finish(VFSTOUDF(mp));
    411       1.1   reinoud 			free_udf_mountinfo(mp);
    412      1.13   reinoud 			vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    413      1.31     pooka 			(void) VOP_CLOSE(devvp, openflags, NOCRED);
    414      1.13   reinoud 			VOP_UNLOCK(devvp, 0);
    415       1.6  christos 		}
    416       1.6  christos 	}
    417       1.1   reinoud 	if (error) {
    418       1.1   reinoud 		/* devvp is still locked */
    419      1.13   reinoud 		vrele(devvp);
    420       1.1   reinoud 		return error;
    421       1.6  christos 	}
    422       1.1   reinoud 
    423       1.1   reinoud 	/* register our mountpoint being on this device */
    424       1.1   reinoud 	devvp->v_specmountpoint = mp;
    425       1.1   reinoud 
    426       1.1   reinoud 	/* successfully mounted */
    427       1.1   reinoud 	DPRINTF(VOLUMES, ("udf_mount() successfull\n"));
    428       1.1   reinoud 
    429      1.38   reinoud 	error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
    430      1.27     pooka 			mp->mnt_op->vfs_name, mp, l);
    431      1.38   reinoud 	if (error)
    432      1.38   reinoud 		return error;
    433      1.38   reinoud 
    434      1.38   reinoud 	/* If we're not opened read-only, open its logical volume */
    435      1.38   reinoud 	if ((mp->mnt_flag & MNT_RDONLY) == 0) {
    436      1.38   reinoud 		if ((error = udf_open_logvol(VFSTOUDF(mp))) != 0) {
    437      1.38   reinoud 			printf( "mount_udf: can't open logical volume for "
    438      1.41   reinoud 				"writing, downgrading access to read-only\n");
    439      1.38   reinoud 			mp->mnt_flag |= MNT_RDONLY;
    440      1.38   reinoud 			/* FIXME we can't return error now on open failure */
    441      1.38   reinoud 			return 0;
    442      1.38   reinoud 		}
    443      1.38   reinoud 	}
    444      1.38   reinoud 
    445      1.38   reinoud 	return 0;
    446       1.1   reinoud }
    447       1.1   reinoud 
    448       1.1   reinoud /* --------------------------------------------------------------------- */
    449       1.1   reinoud 
    450       1.1   reinoud #ifdef DEBUG
    451       1.1   reinoud static void
    452       1.1   reinoud udf_unmount_sanity_check(struct mount *mp)
    453       1.1   reinoud {
    454       1.1   reinoud 	struct vnode *vp;
    455       1.1   reinoud 
    456       1.1   reinoud 	printf("On unmount, i found the following nodes:\n");
    457      1.17   reinoud 	TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
    458       1.1   reinoud 		vprint("", vp);
    459       1.1   reinoud 		if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) {
    460       1.1   reinoud 			printf("  is locked\n");
    461       1.6  christos 		}
    462       1.1   reinoud 		if (vp->v_usecount > 1)
    463       1.1   reinoud 			printf("  more than one usecount %d\n", vp->v_usecount);
    464       1.6  christos 	}
    465       1.1   reinoud }
    466       1.1   reinoud #endif
    467       1.1   reinoud 
    468       1.1   reinoud 
    469       1.1   reinoud int
    470      1.31     pooka udf_unmount(struct mount *mp, int mntflags)
    471       1.1   reinoud {
    472       1.1   reinoud 	struct udf_mount *ump;
    473       1.1   reinoud 	int error, flags, closeflags;
    474       1.1   reinoud 
    475       1.1   reinoud 	DPRINTF(CALL, ("udf_umount called\n"));
    476       1.1   reinoud 
    477       1.1   reinoud 	ump = VFSTOUDF(mp);
    478       1.1   reinoud 	if (!ump)
    479       1.1   reinoud 		panic("UDF unmount: empty ump\n");
    480       1.1   reinoud 
    481      1.19   reinoud 	flags = (mntflags & MNT_FORCE) ? FORCECLOSE : 0;
    482       1.1   reinoud 	/* TODO remove these paranoid functions */
    483       1.1   reinoud #ifdef DEBUG
    484       1.1   reinoud 	if (udf_verbose & UDF_DEBUG_LOCKING)
    485       1.1   reinoud 		udf_unmount_sanity_check(mp);
    486       1.1   reinoud #endif
    487       1.1   reinoud 
    488      1.19   reinoud 	/*
    489      1.30        ad 	 * By specifying SKIPSYSTEM we can skip vnodes marked with VV_SYSTEM.
    490      1.19   reinoud 	 * This hardly documented feature allows us to exempt certain files
    491      1.19   reinoud 	 * from being flushed.
    492      1.19   reinoud 	 */
    493      1.30        ad 	if ((error = vflush(mp, NULLVP, flags | SKIPSYSTEM)) != 0)
    494       1.1   reinoud 		return error;
    495       1.1   reinoud 
    496      1.38   reinoud 	/* update nodes and wait for completion of writeout of system nodes */
    497      1.38   reinoud 	udf_sync(mp, FSYNC_WAIT, NOCRED);
    498      1.38   reinoud 
    499       1.1   reinoud #ifdef DEBUG
    500       1.1   reinoud 	if (udf_verbose & UDF_DEBUG_LOCKING)
    501       1.1   reinoud 		udf_unmount_sanity_check(mp);
    502       1.1   reinoud #endif
    503       1.1   reinoud 
    504      1.38   reinoud 	/* flush again, to check if we are still busy for something else */
    505      1.38   reinoud 	if ((error = vflush(ump->vfs_mountp, NULLVP, flags | SKIPSYSTEM)) != 0)
    506      1.38   reinoud 		return error;
    507      1.38   reinoud 
    508      1.38   reinoud 	DPRINTF(VOLUMES, ("flush OK on unmount\n"));
    509       1.1   reinoud 
    510      1.38   reinoud 	/* close logical volume and close session if requested */
    511      1.38   reinoud 	if ((error = udf_close_logvol(ump, mntflags)) != 0)
    512      1.38   reinoud 		return error;
    513      1.38   reinoud 
    514      1.38   reinoud #ifdef DEBUG
    515      1.38   reinoud 	DPRINTF(VOLUMES, ("FINAL sanity check\n"));
    516      1.38   reinoud 	if (udf_verbose & UDF_DEBUG_LOCKING)
    517      1.38   reinoud 		udf_unmount_sanity_check(mp);
    518      1.38   reinoud #endif
    519      1.38   reinoud 
    520      1.38   reinoud 	/* NOTE release system nodes should NOT write anything */
    521      1.38   reinoud 	udf_release_system_nodes(mp);
    522      1.38   reinoud 
    523      1.38   reinoud 	/* finalise disc strategy */
    524      1.38   reinoud 	udf_discstrat_finish(ump);
    525      1.38   reinoud 
    526      1.38   reinoud 	/* synchronise device caches */
    527      1.38   reinoud 	(void) udf_synchronise_caches(ump);
    528       1.1   reinoud 
    529       1.1   reinoud 	/* close device */
    530       1.1   reinoud 	DPRINTF(VOLUMES, ("closing device\n"));
    531       1.1   reinoud 	if (mp->mnt_flag & MNT_RDONLY) {
    532       1.1   reinoud 		closeflags = FREAD;
    533       1.1   reinoud 	} else {
    534       1.1   reinoud 		closeflags = FREAD | FWRITE;
    535       1.6  christos 	}
    536       1.1   reinoud 
    537       1.1   reinoud 	/* devvp is still locked by us */
    538       1.1   reinoud 	vn_lock(ump->devvp, LK_EXCLUSIVE | LK_RETRY);
    539      1.31     pooka 	error = VOP_CLOSE(ump->devvp, closeflags, NOCRED);
    540       1.1   reinoud 	if (error)
    541       1.1   reinoud 		printf("Error during closure of device! error %d, "
    542       1.1   reinoud 		       "device might stay locked\n", error);
    543       1.1   reinoud 	DPRINTF(VOLUMES, ("device close ok\n"));
    544       1.1   reinoud 
    545       1.1   reinoud 	/* clear our mount reference and release device node */
    546       1.1   reinoud 	ump->devvp->v_specmountpoint = NULL;
    547       1.1   reinoud 	vput(ump->devvp);
    548       1.1   reinoud 
    549      1.38   reinoud 	/* free our ump */
    550      1.15   reinoud 	free_udf_mountinfo(mp);
    551      1.15   reinoud 
    552      1.38   reinoud 	/* free ump struct references */
    553       1.1   reinoud 	mp->mnt_data = NULL;
    554       1.1   reinoud 	mp->mnt_flag &= ~MNT_LOCAL;
    555       1.1   reinoud 
    556       1.1   reinoud 	DPRINTF(VOLUMES, ("Fin unmount\n"));
    557       1.1   reinoud 	return error;
    558       1.1   reinoud }
    559       1.1   reinoud 
    560       1.1   reinoud /* --------------------------------------------------------------------- */
    561       1.1   reinoud 
    562       1.1   reinoud /*
    563       1.1   reinoud  * Helper function of udf_mount() that actually mounts the disc.
    564       1.1   reinoud  */
    565       1.1   reinoud 
    566       1.1   reinoud static int
    567       1.1   reinoud udf_mountfs(struct vnode *devvp, struct mount *mp,
    568       1.1   reinoud 	    struct lwp *l, struct udf_args *args)
    569       1.1   reinoud {
    570       1.1   reinoud 	struct udf_mount     *ump;
    571       1.1   reinoud 	uint32_t sector_size, lb_size, bshift;
    572      1.38   reinoud 	uint32_t logvol_integrity;
    573       1.1   reinoud 	int    num_anchors, error, lst;
    574       1.1   reinoud 
    575       1.1   reinoud 	/* flush out any old buffers remaining from a previous use. */
    576       1.9   reinoud 	if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)))
    577       1.1   reinoud 		return error;
    578       1.1   reinoud 
    579      1.38   reinoud 	/* setup basic mount information */
    580      1.38   reinoud 	mp->mnt_data = NULL;
    581      1.38   reinoud 	mp->mnt_stat.f_fsidx.__fsid_val[0] = (uint32_t) devvp->v_rdev;
    582      1.38   reinoud 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_UDF);
    583      1.38   reinoud 	mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
    584      1.38   reinoud 	mp->mnt_stat.f_namemax = UDF_MAX_NAMELEN;
    585      1.38   reinoud 	mp->mnt_flag |= MNT_LOCAL;
    586      1.38   reinoud 
    587      1.24   msaitoh 	/* allocate udf part of mount structure; malloc always succeeds */
    588      1.30        ad 	ump = malloc(sizeof(struct udf_mount), M_UDFMNT, M_WAITOK | M_ZERO);
    589       1.1   reinoud 
    590       1.1   reinoud 	/* init locks */
    591      1.38   reinoud 	mutex_init(&ump->logvol_mutex, MUTEX_DEFAULT, IPL_NONE);
    592      1.30        ad 	mutex_init(&ump->ihash_lock, MUTEX_DEFAULT, IPL_NONE);
    593      1.30        ad 	mutex_init(&ump->get_node_lock, MUTEX_DEFAULT, IPL_NONE);
    594      1.38   reinoud 	mutex_init(&ump->allocate_mutex, MUTEX_DEFAULT, IPL_NONE);
    595      1.38   reinoud 	cv_init(&ump->dirtynodes_cv, "udfsync2");
    596       1.1   reinoud 
    597      1.38   reinoud 	/* init `ino_t' to udf_node hash table and other lists */
    598       1.1   reinoud 	for (lst = 0; lst < UDF_INODE_HASHSIZE; lst++) {
    599       1.1   reinoud 		LIST_INIT(&ump->udf_nodes[lst]);
    600       1.6  christos 	}
    601       1.1   reinoud 
    602       1.1   reinoud 	/* set up linkage */
    603       1.1   reinoud 	mp->mnt_data    = ump;
    604       1.1   reinoud 	ump->vfs_mountp = mp;
    605       1.1   reinoud 
    606       1.1   reinoud 	/* set up arguments and device */
    607       1.1   reinoud 	ump->mount_args = *args;
    608       1.1   reinoud 	ump->devvp      = devvp;
    609       1.9   reinoud 	if ((error = udf_update_discinfo(ump))) {
    610       1.1   reinoud 		printf("UDF mount: error inspecting fs node\n");
    611       1.1   reinoud 		return error;
    612       1.6  christos 	}
    613       1.1   reinoud 
    614       1.1   reinoud 	/* inspect sector size */
    615       1.1   reinoud 	sector_size = ump->discinfo.sector_size;
    616       1.1   reinoud 	bshift = 1;
    617       1.1   reinoud 	while ((1 << bshift) < sector_size)
    618       1.1   reinoud 		bshift++;
    619       1.1   reinoud 	if ((1 << bshift) != sector_size) {
    620       1.1   reinoud 		printf("UDF mount: "
    621       1.1   reinoud 		       "hit NetBSD implementation fence on sector size\n");
    622       1.1   reinoud 		return EIO;
    623       1.6  christos 	}
    624       1.1   reinoud 
    625      1.42   reinoud 	/* temporary check to overcome sectorsize >= 8192 bytes panic */
    626      1.42   reinoud 	if (sector_size >= 8192) {
    627      1.42   reinoud 		printf("UDF mount: "
    628      1.42   reinoud 			"hit implementation limit, sectorsize to big\n");
    629      1.42   reinoud 		return EIO;
    630      1.42   reinoud 	}
    631      1.42   reinoud 
    632      1.38   reinoud 	/*
    633      1.38   reinoud 	 * Inspect if we're asked to mount read-write on a non recordable or
    634      1.38   reinoud 	 * closed sequential disc.
    635      1.38   reinoud 	 */
    636      1.38   reinoud 	if ((mp->mnt_flag & MNT_RDONLY) == 0) {
    637      1.38   reinoud 		if ((ump->discinfo.mmc_cur & MMC_CAP_RECORDABLE) == 0) {
    638      1.38   reinoud 			printf("UDF mount: disc is not recordable\n");
    639      1.38   reinoud 			return EROFS;
    640      1.38   reinoud 		}
    641      1.52   reinoud 		if (ump->discinfo.mmc_cur & MMC_CAP_SEQUENTIAL) {
    642      1.52   reinoud 			if (ump->discinfo.disc_state == MMC_STATE_FULL) {
    643      1.52   reinoud 				printf("UDF mount: disc is not appendable\n");
    644      1.52   reinoud 				return EROFS;
    645      1.52   reinoud 			}
    646      1.52   reinoud 
    647      1.52   reinoud 			/*
    648      1.52   reinoud 			 * TODO if the last session is closed check if there
    649      1.52   reinoud 			 * is enough space to open/close new session
    650      1.52   reinoud 			 */
    651      1.52   reinoud 		}
    652      1.38   reinoud 	}
    653      1.38   reinoud 
    654      1.38   reinoud 	/* initialise bootstrap disc strategy */
    655      1.38   reinoud 	ump->strategy = &udf_strat_bootstrap;
    656      1.38   reinoud 	udf_discstrat_init(ump);
    657      1.38   reinoud 
    658       1.1   reinoud 	/* read all anchors to get volume descriptor sequence */
    659      1.38   reinoud 	num_anchors = udf_read_anchors(ump);
    660       1.1   reinoud 	if (num_anchors == 0)
    661      1.38   reinoud 		return EINVAL;
    662       1.1   reinoud 
    663       1.1   reinoud 	DPRINTF(VOLUMES, ("Read %d anchors on this disc, session %d\n",
    664       1.1   reinoud 	    num_anchors, args->sessionnr));
    665       1.1   reinoud 
    666       1.1   reinoud 	/* read in volume descriptor sequence */
    667       1.9   reinoud 	if ((error = udf_read_vds_space(ump))) {
    668       1.1   reinoud 		printf("UDF mount: error reading volume space\n");
    669       1.9   reinoud 		return error;
    670       1.9   reinoud 	}
    671       1.1   reinoud 
    672      1.38   reinoud 	/* close down (direct) disc strategy */
    673      1.38   reinoud 	udf_discstrat_finish(ump);
    674      1.38   reinoud 
    675       1.1   reinoud 	/* check consistency and completeness */
    676      1.38   reinoud 	if ((error = udf_process_vds(ump))) {
    677      1.19   reinoud 		printf( "UDF mount: disc not properly formatted"
    678      1.19   reinoud 			"(bad VDS)\n");
    679       1.9   reinoud 		return error;
    680       1.6  christos 	}
    681       1.1   reinoud 
    682      1.38   reinoud 	/* switch to new disc strategy */
    683      1.38   reinoud 	KASSERT(ump->strategy != &udf_strat_bootstrap);
    684      1.38   reinoud 	udf_discstrat_init(ump);
    685      1.38   reinoud 
    686      1.38   reinoud 	/* initialise late allocation administration space */
    687      1.38   reinoud 	ump->la_lmapping = malloc(sizeof(uint64_t) * UDF_MAX_MAPPINGS,
    688      1.38   reinoud 			M_TEMP, M_WAITOK);
    689      1.38   reinoud 	ump->la_pmapping = malloc(sizeof(uint64_t) * UDF_MAX_MAPPINGS,
    690      1.38   reinoud 			M_TEMP, M_WAITOK);
    691      1.38   reinoud 
    692      1.38   reinoud 	/* setup node cleanup extents copy space */
    693       1.1   reinoud 	lb_size = udf_rw32(ump->logical_vol->lb_size);
    694      1.38   reinoud 	ump->la_node_ad_cpy = malloc(lb_size * UDF_MAX_ALLOC_EXTENTS,
    695      1.38   reinoud 		M_UDFMNT, M_WAITOK);
    696      1.38   reinoud 	memset(ump->la_node_ad_cpy, 0, lb_size * UDF_MAX_ALLOC_EXTENTS);
    697      1.38   reinoud 
    698      1.38   reinoud 	/* setup rest of mount information */
    699      1.38   reinoud 	mp->mnt_data = ump;
    700      1.38   reinoud 
    701      1.38   reinoud 	/* bshift is allways equal to disc sector size */
    702      1.38   reinoud 	mp->mnt_dev_bshift = bshift;
    703      1.38   reinoud 	mp->mnt_fs_bshift  = bshift;
    704       1.1   reinoud 
    705      1.38   reinoud 	/* note that the mp info needs to be initialised for reading! */
    706       1.1   reinoud 	/* read vds support tables like VAT, sparable etc. */
    707      1.38   reinoud 	if ((error = udf_read_vds_tables(ump))) {
    708      1.19   reinoud 		printf( "UDF mount: error in format or damaged disc "
    709      1.19   reinoud 			"(VDS tables failing)\n");
    710       1.9   reinoud 		return error;
    711       1.6  christos 	}
    712       1.9   reinoud 
    713      1.38   reinoud 	/* check if volume integrity is closed otherwise its dirty */
    714      1.38   reinoud 	logvol_integrity = udf_rw32(ump->logvol_integrity->integrity_type);
    715      1.38   reinoud 	if (logvol_integrity != UDF_INTEGRITY_CLOSED) {
    716      1.38   reinoud 		printf("UDF mount: file system is not clean; ");
    717      1.38   reinoud 		printf("please fsck(8)\n");
    718      1.38   reinoud 		return EPERM;
    719      1.38   reinoud 	}
    720      1.38   reinoud 
    721      1.38   reinoud 	/* read root directory */
    722      1.38   reinoud 	if ((error = udf_read_rootdirs(ump))) {
    723      1.19   reinoud 		printf( "UDF mount: "
    724      1.19   reinoud 			"disc not properly formatted or damaged disc "
    725      1.19   reinoud 			"(rootdirs failing)\n");
    726       1.1   reinoud 		return error;
    727       1.9   reinoud 	}
    728       1.1   reinoud 
    729       1.1   reinoud 	/* do we have to set this? */
    730       1.1   reinoud 	devvp->v_specmountpoint = mp;
    731       1.1   reinoud 
    732       1.1   reinoud 	/* success! */
    733       1.1   reinoud 	return 0;
    734       1.1   reinoud }
    735       1.1   reinoud 
    736       1.1   reinoud /* --------------------------------------------------------------------- */
    737       1.1   reinoud 
    738       1.1   reinoud int
    739      1.31     pooka udf_start(struct mount *mp, int flags)
    740       1.1   reinoud {
    741       1.1   reinoud 	/* do we have to do something here? */
    742       1.1   reinoud 	return 0;
    743       1.1   reinoud }
    744       1.1   reinoud 
    745       1.1   reinoud /* --------------------------------------------------------------------- */
    746       1.1   reinoud 
    747       1.1   reinoud int
    748       1.1   reinoud udf_root(struct mount *mp, struct vnode **vpp)
    749       1.1   reinoud {
    750       1.1   reinoud 	struct vnode *vp;
    751       1.1   reinoud 	struct long_ad *dir_loc;
    752       1.1   reinoud 	struct udf_mount *ump = VFSTOUDF(mp);
    753       1.1   reinoud 	struct udf_node *root_dir;
    754       1.1   reinoud 	int error;
    755       1.1   reinoud 
    756       1.1   reinoud 	DPRINTF(CALL, ("udf_root called\n"));
    757       1.1   reinoud 
    758       1.1   reinoud 	dir_loc = &ump->fileset_desc->rootdir_icb;
    759       1.1   reinoud 	error = udf_get_node(ump, dir_loc, &root_dir);
    760       1.1   reinoud 
    761       1.1   reinoud 	if (!root_dir)
    762       1.1   reinoud 		error = ENOENT;
    763       1.1   reinoud 	if (error)
    764       1.1   reinoud 		return error;
    765       1.1   reinoud 
    766       1.1   reinoud 	vp = root_dir->vnode;
    767  1.52.2.1       snj 	KASSERT(vp->v_vflag & VV_ROOT);
    768       1.1   reinoud 
    769       1.1   reinoud 	*vpp = vp;
    770       1.1   reinoud 	return 0;
    771       1.1   reinoud }
    772       1.1   reinoud 
    773       1.1   reinoud /* --------------------------------------------------------------------- */
    774       1.1   reinoud 
    775       1.1   reinoud int
    776      1.31     pooka udf_statvfs(struct mount *mp, struct statvfs *sbp)
    777       1.1   reinoud {
    778       1.1   reinoud 	struct udf_mount *ump = VFSTOUDF(mp);
    779       1.1   reinoud 	struct logvol_int_desc *lvid;
    780       1.1   reinoud 	struct udf_logvol_info *impl;
    781       1.1   reinoud 	uint64_t freeblks, sizeblks;
    782       1.1   reinoud 	uint32_t *pos1, *pos2;
    783       1.1   reinoud 	int part, num_part;
    784       1.1   reinoud 
    785       1.1   reinoud 	DPRINTF(CALL, ("udf_statvfs called\n"));
    786       1.1   reinoud 	sbp->f_flag   = mp->mnt_flag;
    787       1.1   reinoud 	sbp->f_bsize  = ump->discinfo.sector_size;
    788       1.1   reinoud 	sbp->f_frsize = ump->discinfo.sector_size;
    789       1.1   reinoud 	sbp->f_iosize = ump->discinfo.sector_size;
    790       1.1   reinoud 
    791      1.38   reinoud 	mutex_enter(&ump->allocate_mutex);
    792       1.1   reinoud 	lvid = ump->logvol_integrity;
    793      1.38   reinoud 	freeblks = sizeblks = 0;
    794       1.1   reinoud 
    795      1.38   reinoud 	/* Sequentials report free space directly (CD/DVD/BD-R) */
    796      1.38   reinoud 	KASSERT(lvid);
    797      1.38   reinoud 	num_part = udf_rw32(lvid->num_part);
    798      1.38   reinoud 	impl = (struct udf_logvol_info *) (lvid->tables + 2*num_part);
    799      1.38   reinoud 
    800      1.38   reinoud 	if (ump->discinfo.mmc_cur & MMC_CAP_SEQUENTIAL) {
    801      1.38   reinoud 		/* XXX assumption at most two tracks open */
    802      1.38   reinoud 		freeblks = ump->data_track.free_blocks;
    803      1.38   reinoud 		if (ump->data_track.tracknr != ump->metadata_track.tracknr)
    804      1.38   reinoud 			freeblks += ump->metadata_track.free_blocks;
    805      1.38   reinoud 		sizeblks = ump->discinfo.last_possible_lba;
    806      1.38   reinoud 	} else {
    807      1.38   reinoud 		/* free and used space for mountpoint based on logvol integrity */
    808       1.1   reinoud 		for (part=0; part < num_part; part++) {
    809       1.1   reinoud 			pos1 = &lvid->tables[0] + part;
    810       1.1   reinoud 			pos2 = &lvid->tables[0] + num_part + part;
    811       1.1   reinoud 			if (udf_rw32(*pos1) != (uint32_t) -1) {
    812       1.1   reinoud 				freeblks += udf_rw32(*pos1);
    813       1.1   reinoud 				sizeblks += udf_rw32(*pos2);
    814       1.6  christos 			}
    815       1.6  christos 		}
    816      1.38   reinoud 	}
    817      1.38   reinoud 	freeblks -= ump->uncomitted_lb;
    818      1.38   reinoud 
    819      1.38   reinoud 	sbp->f_blocks = sizeblks;
    820      1.38   reinoud 	sbp->f_bfree  = freeblks;
    821      1.38   reinoud 	sbp->f_files  = 0;
    822      1.38   reinoud 	if (impl) {
    823       1.1   reinoud 		sbp->f_files  = udf_rw32(impl->num_files);
    824       1.1   reinoud 		sbp->f_files += udf_rw32(impl->num_directories);
    825      1.38   reinoud 	}
    826      1.38   reinoud 
    827      1.38   reinoud 	/* XXX read only for now XXX */
    828      1.38   reinoud 	sbp->f_bavail = 0;
    829      1.38   reinoud 	sbp->f_bresvd = 0;
    830      1.38   reinoud 
    831      1.38   reinoud 	/* tricky, next only aplies to ffs i think, so set to zero */
    832      1.38   reinoud 	sbp->f_ffree  = 0;
    833      1.38   reinoud 	sbp->f_favail = 0;
    834      1.38   reinoud 	sbp->f_fresvd = 0;
    835       1.1   reinoud 
    836      1.38   reinoud 	mutex_exit(&ump->allocate_mutex);
    837       1.1   reinoud 
    838       1.1   reinoud 	copy_statvfs_info(sbp, mp);
    839       1.1   reinoud 	return 0;
    840       1.1   reinoud }
    841       1.1   reinoud 
    842       1.1   reinoud /* --------------------------------------------------------------------- */
    843       1.1   reinoud 
    844      1.38   reinoud /*
    845      1.38   reinoud  * TODO what about writing out free space maps, lvid etc? only on `waitfor'
    846      1.38   reinoud  * i.e. explicit syncing by the user?
    847      1.38   reinoud  */
    848      1.38   reinoud 
    849      1.47   reinoud static int
    850      1.47   reinoud udf_sync_writeout_system_files(struct udf_mount *ump, int clearflags)
    851      1.47   reinoud {
    852      1.47   reinoud 	int error;
    853      1.47   reinoud 
    854      1.47   reinoud 	/* XXX lock for VAT en bitmaps? */
    855      1.47   reinoud 	/* metadata nodes are written synchronous */
    856      1.47   reinoud 	DPRINTF(CALL, ("udf_sync: syncing metadata\n"));
    857      1.47   reinoud 	if (ump->lvclose & UDF_WRITE_VAT)
    858      1.47   reinoud 		udf_writeout_vat(ump);
    859      1.47   reinoud 
    860      1.47   reinoud 	error = 0;
    861      1.47   reinoud 	if (ump->lvclose & UDF_WRITE_PART_BITMAPS) {
    862      1.47   reinoud 		/* writeout metadata spacetable if existing */
    863      1.47   reinoud 		error = udf_write_metadata_partition_spacetable(ump, MNT_WAIT);
    864      1.47   reinoud 		if (error)
    865      1.47   reinoud 			printf( "udf_writeout_system_files : "
    866      1.47   reinoud 				" writeout of metadata space bitmap failed\n");
    867      1.47   reinoud 
    868      1.47   reinoud 		/* writeout partition spacetables */
    869      1.47   reinoud 		error = udf_write_physical_partition_spacetables(ump, MNT_WAIT);
    870      1.47   reinoud 		if (error)
    871      1.47   reinoud 			printf( "udf_writeout_system_files : "
    872      1.47   reinoud 				"writeout of space tables failed\n");
    873      1.47   reinoud 		if (!error && clearflags)
    874      1.47   reinoud 			ump->lvclose &= ~UDF_WRITE_PART_BITMAPS;
    875      1.47   reinoud 	}
    876      1.47   reinoud 
    877      1.47   reinoud 	return error;
    878      1.47   reinoud }
    879      1.47   reinoud 
    880      1.47   reinoud 
    881       1.1   reinoud int
    882      1.38   reinoud udf_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
    883       1.1   reinoud {
    884      1.38   reinoud 	struct udf_mount *ump = VFSTOUDF(mp);
    885      1.38   reinoud 
    886       1.1   reinoud 	DPRINTF(CALL, ("udf_sync called\n"));
    887      1.38   reinoud 	/* if called when mounted readonly, just ignore */
    888      1.38   reinoud 	if (mp->mnt_flag & MNT_RDONLY)
    889      1.38   reinoud 		return 0;
    890      1.38   reinoud 
    891      1.38   reinoud 	if (ump->syncing && !waitfor) {
    892      1.38   reinoud 		printf("UDF: skipping autosync\n");
    893      1.38   reinoud 		return 0;
    894      1.38   reinoud 	}
    895      1.38   reinoud 
    896      1.38   reinoud 	/* get sync lock */
    897      1.38   reinoud 	ump->syncing = 1;
    898      1.38   reinoud 
    899      1.46   reinoud 	/* pre-sync */
    900      1.38   reinoud 	udf_do_sync(ump, cred, waitfor);
    901      1.38   reinoud 
    902      1.47   reinoud 	if (waitfor == MNT_WAIT)
    903      1.47   reinoud 		udf_sync_writeout_system_files(ump, true);
    904      1.38   reinoud 
    905      1.38   reinoud 	DPRINTF(CALL, ("end of udf_sync()\n"));
    906      1.38   reinoud 	ump->syncing = 0;
    907      1.38   reinoud 
    908       1.1   reinoud 	return 0;
    909       1.1   reinoud }
    910       1.1   reinoud 
    911       1.1   reinoud /* --------------------------------------------------------------------- */
    912       1.1   reinoud 
    913       1.1   reinoud /*
    914       1.1   reinoud  * Get vnode for the file system type specific file id ino for the fs. Its
    915       1.1   reinoud  * used for reference to files by unique ID and for NFSv3.
    916       1.1   reinoud  * (optional) TODO lookup why some sources state NFSv3
    917       1.1   reinoud  */
    918       1.1   reinoud int
    919      1.18  christos udf_vget(struct mount *mp, ino_t ino,
    920      1.18  christos     struct vnode **vpp)
    921       1.1   reinoud {
    922       1.1   reinoud 	DPRINTF(NOTIMPL, ("udf_vget called\n"));
    923       1.1   reinoud 	return EOPNOTSUPP;
    924       1.1   reinoud }
    925       1.1   reinoud 
    926       1.1   reinoud /* --------------------------------------------------------------------- */
    927       1.1   reinoud 
    928       1.1   reinoud /*
    929       1.1   reinoud  * Lookup vnode for file handle specified
    930       1.1   reinoud  */
    931       1.1   reinoud int
    932      1.18  christos udf_fhtovp(struct mount *mp, struct fid *fhp,
    933      1.18  christos     struct vnode **vpp)
    934       1.1   reinoud {
    935       1.1   reinoud 	DPRINTF(NOTIMPL, ("udf_fhtovp called\n"));
    936       1.1   reinoud 	return EOPNOTSUPP;
    937       1.1   reinoud }
    938       1.1   reinoud 
    939       1.1   reinoud /* --------------------------------------------------------------------- */
    940       1.1   reinoud 
    941       1.1   reinoud /*
    942       1.1   reinoud  * Create an unique file handle. Its structure is opaque and won't be used by
    943       1.1   reinoud  * other subsystems. It should uniquely identify the file in the filingsystem
    944       1.1   reinoud  * and enough information to know if a file has been removed and/or resources
    945       1.1   reinoud  * have been recycled.
    946       1.1   reinoud  */
    947       1.1   reinoud int
    948      1.18  christos udf_vptofh(struct vnode *vp, struct fid *fid,
    949      1.18  christos     size_t *fh_size)
    950       1.1   reinoud {
    951       1.1   reinoud 	DPRINTF(NOTIMPL, ("udf_vptofh called\n"));
    952       1.1   reinoud 	return EOPNOTSUPP;
    953       1.1   reinoud }
    954       1.1   reinoud 
    955       1.1   reinoud /* --------------------------------------------------------------------- */
    956       1.1   reinoud 
    957       1.1   reinoud /*
    958       1.1   reinoud  * Create a filingsystem snapshot at the specified timestamp. Could be
    959       1.1   reinoud  * implemented by explicitly creating a new session or with spare room in the
    960       1.1   reinoud  * integrity descriptor space
    961       1.1   reinoud  */
    962       1.1   reinoud int
    963      1.18  christos udf_snapshot(struct mount *mp, struct vnode *vp,
    964      1.18  christos     struct timespec *tm)
    965       1.1   reinoud {
    966       1.1   reinoud 	DPRINTF(NOTIMPL, ("udf_snapshot called\n"));
    967       1.1   reinoud 	return EOPNOTSUPP;
    968       1.1   reinoud }
    969      1.14   reinoud 
    970      1.14   reinoud /* --------------------------------------------------------------------- */
    971