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