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