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