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