Home | History | Annotate | Line # | Download | only in udf
udf_vfsops.c revision 1.2.6.2
      1  1.2.6.2     yamt /* $NetBSD: udf_vfsops.c,v 1.2.6.2 2006/06/26 12:52:56 yamt Exp $ */
      2      1.1  reinoud 
      3      1.1  reinoud /*
      4      1.1  reinoud  * Copyright (c) 2006 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  * 3. All advertising materials mentioning features or use of this software
     16      1.1  reinoud  *    must display the following acknowledgement:
     17      1.1  reinoud  *          This product includes software developed for the
     18      1.1  reinoud  *          NetBSD Project.  See http://www.NetBSD.org/ for
     19      1.1  reinoud  *          information about NetBSD.
     20      1.1  reinoud  * 4. The name of the author may not be used to endorse or promote products
     21      1.1  reinoud  *    derived from this software without specific prior written permission.
     22      1.1  reinoud  *
     23      1.1  reinoud  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24      1.1  reinoud  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25      1.1  reinoud  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26      1.1  reinoud  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27      1.1  reinoud  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28      1.1  reinoud  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29      1.1  reinoud  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30      1.1  reinoud  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31      1.1  reinoud  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32      1.1  reinoud  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33      1.1  reinoud  *
     34      1.1  reinoud  */
     35      1.1  reinoud 
     36      1.1  reinoud 
     37      1.1  reinoud #include <sys/cdefs.h>
     38      1.1  reinoud #ifndef lint
     39  1.2.6.2     yamt __RCSID("$NetBSD: udf_vfsops.c,v 1.2.6.2 2006/06/26 12:52:56 yamt Exp $");
     40      1.1  reinoud #endif /* not lint */
     41      1.1  reinoud 
     42      1.1  reinoud 
     43      1.1  reinoud #if defined(_KERNEL_OPT)
     44      1.1  reinoud #include "opt_quota.h"
     45      1.1  reinoud #include "opt_compat_netbsd.h"
     46      1.1  reinoud #endif
     47      1.1  reinoud 
     48      1.1  reinoud #include <sys/param.h>
     49      1.1  reinoud #include <sys/systm.h>
     50      1.1  reinoud #include <sys/sysctl.h>
     51      1.1  reinoud #include <sys/namei.h>
     52      1.1  reinoud #include <sys/proc.h>
     53      1.1  reinoud #include <sys/kernel.h>
     54      1.1  reinoud #include <sys/vnode.h>
     55      1.1  reinoud #include <miscfs/specfs/specdev.h>
     56      1.1  reinoud #include <sys/mount.h>
     57      1.1  reinoud #include <sys/buf.h>
     58      1.1  reinoud #include <sys/file.h>
     59      1.1  reinoud #include <sys/device.h>
     60      1.1  reinoud #include <sys/disklabel.h>
     61      1.1  reinoud #include <sys/ioctl.h>
     62      1.1  reinoud #include <sys/malloc.h>
     63      1.1  reinoud #include <sys/dirent.h>
     64      1.1  reinoud #include <sys/stat.h>
     65      1.1  reinoud #include <sys/conf.h>
     66  1.2.6.1     yamt #include <sys/kauth.h>
     67      1.1  reinoud 
     68      1.1  reinoud #include <fs/udf/ecma167-udf.h>
     69      1.1  reinoud #include <fs/udf/udf_mount.h>
     70      1.1  reinoud 
     71      1.1  reinoud #include "udf.h"
     72      1.1  reinoud #include "udf_subr.h"
     73      1.1  reinoud #include "udf_bswap.h"
     74      1.1  reinoud 
     75      1.1  reinoud 
     76      1.1  reinoud /* verbose levels of the udf filingsystem */
     77      1.1  reinoud int udf_verbose = UDF_DEBUGGING;
     78      1.1  reinoud 
     79      1.1  reinoud /* malloc regions */
     80      1.1  reinoud MALLOC_DEFINE(M_UDFMNT,   "UDF mount",		"UDF mount structures");
     81      1.1  reinoud MALLOC_DEFINE(M_UDFVOLD,  "UDF volspace",	"UDF volume space descriptors");
     82      1.1  reinoud MALLOC_DEFINE(M_UDFTEMP,  "UDF temp",		"UDF scrap space");
     83      1.1  reinoud struct pool udf_node_pool;
     84      1.1  reinoud 
     85      1.1  reinoud /* supported functions predefined */
     86      1.1  reinoud int udf_mountroot(void);
     87      1.1  reinoud int udf_mount(struct mount *, const char *, void *, struct nameidata *, struct lwp *);
     88      1.1  reinoud int udf_start(struct mount *, int, struct lwp *);
     89      1.1  reinoud int udf_unmount(struct mount *, int, struct lwp *);
     90      1.1  reinoud int udf_root(struct mount *, struct vnode **);
     91      1.1  reinoud int udf_quotactl(struct mount *, int, uid_t, void *, struct lwp *);
     92      1.1  reinoud int udf_statvfs(struct mount *, struct statvfs *, struct lwp *);
     93  1.2.6.1     yamt int udf_sync(struct mount *, int, kauth_cred_t, struct lwp *);
     94      1.1  reinoud int udf_vget(struct mount *, ino_t, struct vnode **);
     95      1.1  reinoud int udf_fhtovp(struct mount *, struct fid *, struct vnode **);
     96  1.2.6.1     yamt int udf_checkexp(struct mount *, struct mbuf *, int *, kauth_cred_t *);
     97      1.1  reinoud int udf_vptofh(struct vnode *, struct fid *);
     98      1.1  reinoud int udf_snapshot(struct mount *, struct vnode *, struct timespec *);
     99      1.1  reinoud 
    100      1.1  reinoud void udf_init(void);
    101      1.1  reinoud void udf_reinit(void);
    102      1.1  reinoud void udf_done(void);
    103      1.1  reinoud 
    104      1.1  reinoud 
    105      1.1  reinoud /* internal functions */
    106      1.1  reinoud static int udf_mountfs(struct vnode *, struct mount *, struct lwp *, struct udf_args *);
    107      1.1  reinoud #if 0
    108      1.1  reinoud static int update_mp(struct mount *, struct udf_args *);
    109      1.1  reinoud #endif
    110      1.1  reinoud 
    111      1.1  reinoud 
    112      1.1  reinoud /* handies */
    113      1.1  reinoud #define	VFSTOUDF(mp)	((struct udf_mount *)mp->mnt_data)
    114      1.1  reinoud 
    115      1.1  reinoud 
    116      1.1  reinoud /* --------------------------------------------------------------------- */
    117      1.1  reinoud 
    118      1.1  reinoud /* predefine vnode-op list descriptor */
    119      1.1  reinoud extern const struct vnodeopv_desc udf_vnodeop_opv_desc;
    120      1.1  reinoud 
    121      1.1  reinoud const struct vnodeopv_desc * const udf_vnodeopv_descs[] = {
    122      1.1  reinoud 	&udf_vnodeop_opv_desc,
    123      1.1  reinoud 	NULL,
    124      1.1  reinoud };
    125      1.1  reinoud 
    126      1.1  reinoud 
    127      1.1  reinoud /* vfsops descriptor linked in as anchor point for the filingsystem */
    128      1.1  reinoud struct vfsops udf_vfsops = {
    129      1.1  reinoud 	MOUNT_UDF,			/* vfs_name */
    130      1.1  reinoud 	udf_mount,
    131      1.1  reinoud 	udf_start,
    132      1.1  reinoud 	udf_unmount,
    133      1.1  reinoud 	udf_root,
    134      1.1  reinoud 	udf_quotactl,
    135      1.1  reinoud 	udf_statvfs,
    136      1.1  reinoud 	udf_sync,
    137      1.1  reinoud 	udf_vget,
    138      1.1  reinoud 	udf_fhtovp,
    139      1.1  reinoud 	udf_vptofh,
    140      1.1  reinoud 	udf_init,
    141      1.1  reinoud 	udf_reinit,
    142      1.1  reinoud 	udf_done,
    143      1.1  reinoud 	udf_mountroot,
    144      1.1  reinoud 	udf_snapshot,
    145      1.1  reinoud 	vfs_stdextattrctl,
    146      1.1  reinoud 	udf_vnodeopv_descs,
    147      1.1  reinoud 	/* int vfs_refcount   */
    148      1.1  reinoud 	/* LIST_ENTRY(vfsops) */
    149      1.1  reinoud };
    150      1.1  reinoud VFS_ATTACH(udf_vfsops);
    151      1.1  reinoud 
    152      1.1  reinoud 
    153      1.1  reinoud /* --------------------------------------------------------------------- */
    154      1.1  reinoud 
    155      1.1  reinoud /* file system starts here */
    156      1.1  reinoud void
    157      1.1  reinoud udf_init(void)
    158      1.1  reinoud {
    159      1.1  reinoud 	size_t size;
    160      1.1  reinoud 
    161      1.1  reinoud #ifdef _LKM
    162      1.1  reinoud 	malloc_type_attach(M_UDFMNT);
    163      1.1  reinoud 	malloc_type_attach(M_UDFVOLD);
    164      1.1  reinoud 	malloc_type_attach(M_UDFTEMP);
    165      1.1  reinoud #endif
    166      1.1  reinoud 
    167      1.1  reinoud 	/* init hashtables and pools */
    168      1.1  reinoud 	size = sizeof(struct udf_node);
    169      1.1  reinoud 	pool_init(&udf_node_pool, size, 0, 0, 0, "udf_node_pool", NULL);
    170      1.1  reinoud }
    171      1.1  reinoud 
    172      1.1  reinoud /* --------------------------------------------------------------------- */
    173      1.1  reinoud 
    174      1.1  reinoud void
    175      1.1  reinoud udf_reinit(void)
    176      1.1  reinoud {
    177      1.1  reinoud 	/* recreate hashtables */
    178      1.1  reinoud 	/* reinit pool? */
    179      1.1  reinoud }
    180      1.1  reinoud 
    181      1.1  reinoud /* --------------------------------------------------------------------- */
    182      1.1  reinoud 
    183      1.1  reinoud void
    184      1.1  reinoud udf_done(void)
    185      1.1  reinoud {
    186      1.1  reinoud 	/* remove hashtables and pools */
    187      1.1  reinoud 	pool_destroy(&udf_node_pool);
    188      1.1  reinoud 
    189      1.1  reinoud #ifdef _LKM
    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 #endif
    194      1.1  reinoud }
    195      1.1  reinoud 
    196      1.1  reinoud /* --------------------------------------------------------------------- */
    197      1.1  reinoud 
    198      1.1  reinoud int
    199      1.1  reinoud udf_mountroot(void)
    200      1.1  reinoud {
    201      1.1  reinoud 	return EOPNOTSUPP;
    202      1.1  reinoud }
    203      1.1  reinoud 
    204      1.1  reinoud /* --------------------------------------------------------------------- */
    205      1.1  reinoud 
    206      1.1  reinoud #define MPFREE(a, lst) \
    207      1.1  reinoud 	if ((a)) free((a), lst);
    208      1.1  reinoud static void
    209      1.1  reinoud free_udf_mountinfo(struct mount *mp)
    210      1.1  reinoud {
    211      1.1  reinoud 	struct udf_mount *ump;
    212      1.1  reinoud 	int i;
    213      1.1  reinoud 
    214      1.1  reinoud 	ump = VFSTOUDF(mp);
    215      1.1  reinoud 	if (ump) {
    216      1.1  reinoud 		mp->mnt_data = NULL;
    217      1.1  reinoud 		for (i = 0; i < UDF_ANCHORS; i++)
    218      1.1  reinoud 			MPFREE(ump->anchors[i], M_UDFVOLD);
    219      1.1  reinoud 		MPFREE(ump->primary_vol,      M_UDFVOLD);
    220      1.1  reinoud 		MPFREE(ump->logical_vol,      M_UDFVOLD);
    221      1.1  reinoud 		MPFREE(ump->unallocated,      M_UDFVOLD);
    222      1.1  reinoud 		MPFREE(ump->implementation,   M_UDFVOLD);
    223      1.1  reinoud 		MPFREE(ump->logvol_integrity, M_UDFVOLD);
    224      1.1  reinoud 		for (i = 0; i < UDF_PARTITIONS; i++)
    225      1.1  reinoud 			MPFREE(ump->partitions[i], M_UDFVOLD);
    226      1.1  reinoud 		MPFREE(ump->fileset_desc,     M_UDFVOLD);
    227      1.1  reinoud 		MPFREE(ump->vat_table,        M_UDFVOLD);
    228      1.1  reinoud 		MPFREE(ump->sparing_table,    M_UDFVOLD);
    229      1.1  reinoud 
    230      1.1  reinoud 		/*
    231      1.1  reinoud 		 * Note that the node related (e)fe descriptors pool is
    232  1.2.6.1     yamt 		 * destroyed already if it was used.
    233      1.1  reinoud 		 */
    234      1.1  reinoud 
    235      1.1  reinoud 		free(ump, M_UDFMNT);
    236  1.2.6.2     yamt 	}
    237      1.1  reinoud }
    238      1.1  reinoud #undef MPFREE
    239      1.1  reinoud 
    240      1.1  reinoud /* --------------------------------------------------------------------- */
    241      1.1  reinoud 
    242      1.1  reinoud int
    243      1.1  reinoud udf_mount(struct mount *mp, const char *path,
    244      1.1  reinoud 	  void *data, struct nameidata *ndp, struct lwp *l)
    245      1.1  reinoud {
    246      1.1  reinoud 	struct udf_args args;
    247      1.1  reinoud 	struct udf_mount *ump;
    248      1.1  reinoud 	struct vnode *devvp;
    249      1.1  reinoud 	struct proc *p;
    250      1.1  reinoud 	int openflags, accessmode, error;
    251      1.1  reinoud 
    252      1.1  reinoud 	DPRINTF(CALL, ("udf_mount called\n"));
    253      1.1  reinoud 
    254      1.1  reinoud 	p = l->l_proc;
    255      1.1  reinoud 	if (mp->mnt_flag & MNT_GETARGS) {
    256      1.1  reinoud 		/* request for the mount arguments */
    257      1.1  reinoud 		ump = VFSTOUDF(mp);
    258      1.1  reinoud 		if (ump == NULL)
    259      1.1  reinoud 			return EINVAL;
    260      1.1  reinoud 		return copyout(&ump->mount_args, data, sizeof(args));
    261  1.2.6.2     yamt 	}
    262      1.1  reinoud 
    263      1.1  reinoud 	/* handle request for updating mount parameters */
    264      1.1  reinoud 	/* TODO can't update my mountpoint yet */
    265      1.1  reinoud 	if (mp->mnt_flag & MNT_UPDATE) {
    266      1.1  reinoud 		return EOPNOTSUPP;
    267  1.2.6.2     yamt 	}
    268      1.1  reinoud 
    269      1.1  reinoud 	/* OK, so we are asked to mount the device/file! */
    270      1.1  reinoud 	error = copyin(data, &args, sizeof(struct udf_args));
    271      1.1  reinoud 	if (error)
    272      1.1  reinoud 		return error;
    273      1.1  reinoud 
    274      1.1  reinoud 	/* check/translate struct version */
    275      1.1  reinoud 	/* TODO sanity checking other mount arguments */
    276      1.1  reinoud 	if (args.version != 1) {
    277      1.1  reinoud 		printf("mount_udf: unrecognized argument structure version\n");
    278      1.1  reinoud 		return EINVAL;
    279  1.2.6.2     yamt 	}
    280      1.1  reinoud 
    281      1.1  reinoud 	/* lookup name to get its vnode */
    282      1.1  reinoud 	NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, args.fspec, l);
    283      1.1  reinoud 	error = namei(ndp);
    284      1.1  reinoud 	if (error)
    285      1.1  reinoud 		return error;
    286      1.1  reinoud 
    287      1.1  reinoud 	/* devvp is *locked* now */
    288      1.1  reinoud 	devvp = ndp->ni_vp;
    289      1.1  reinoud #ifdef DEBUG
    290      1.1  reinoud 	if (udf_verbose & UDF_DEBUG_VOLUMES)
    291      1.1  reinoud 		vprint("UDF mount, trying to mount \n", devvp);
    292      1.1  reinoud #endif
    293      1.1  reinoud 
    294      1.1  reinoud 	/* check if its a block device specified */
    295      1.1  reinoud 	if (devvp->v_type != VBLK) {
    296      1.1  reinoud 		vrele(devvp);
    297      1.1  reinoud 		return ENOTBLK;
    298      1.1  reinoud 	}
    299      1.1  reinoud 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    300      1.1  reinoud 		vrele(devvp);
    301      1.1  reinoud 		return ENXIO;
    302      1.1  reinoud 	}
    303      1.1  reinoud 
    304      1.1  reinoud 	/* force read-only for now */
    305      1.1  reinoud 	mp->mnt_flag |= MNT_RDONLY;
    306      1.1  reinoud 
    307      1.1  reinoud 	/*
    308      1.1  reinoud 	 * If mount by non-root, then verify that user has necessary
    309      1.1  reinoud 	 * permissions on the device.
    310      1.1  reinoud 	 */
    311  1.2.6.1     yamt 	if (kauth_cred_geteuid(p->p_cred) != 0) {
    312      1.1  reinoud 		accessmode = VREAD;
    313      1.1  reinoud 		if ((mp->mnt_flag & MNT_RDONLY) == 0)
    314      1.1  reinoud 			accessmode |= VWRITE;
    315  1.2.6.1     yamt 		error = VOP_ACCESS(devvp, accessmode, p->p_cred, l);
    316      1.1  reinoud 		if (error) {
    317      1.1  reinoud 			vput(devvp);
    318      1.1  reinoud 			return (error);
    319      1.1  reinoud 		}
    320      1.1  reinoud 	}
    321      1.1  reinoud 
    322      1.1  reinoud 	/*
    323      1.1  reinoud 	 * Disallow multiple mounts of the same device.  Disallow mounting of
    324      1.1  reinoud 	 * a device that is currently in use (except for root, which might
    325      1.1  reinoud 	 * share swap device for miniroot).
    326      1.1  reinoud 	 */
    327      1.1  reinoud 	error = vfs_mountedon(devvp);
    328      1.1  reinoud 	if (error) {
    329      1.1  reinoud 		vput(devvp);
    330      1.1  reinoud 		return error;
    331  1.2.6.2     yamt 	}
    332      1.1  reinoud 	if ((vcount(devvp) > 1) && (devvp != rootvp)) {
    333      1.1  reinoud 		vput(devvp);
    334      1.1  reinoud 		return EBUSY;
    335      1.1  reinoud 	}
    336      1.1  reinoud 
    337      1.1  reinoud 	/*
    338      1.1  reinoud 	 * Open device and try to mount it!
    339      1.1  reinoud 	 */
    340      1.1  reinoud 	if (mp->mnt_flag & MNT_RDONLY) {
    341      1.1  reinoud 		openflags = FREAD;
    342      1.1  reinoud 	} else {
    343      1.1  reinoud 		openflags = FREAD | FWRITE;
    344  1.2.6.2     yamt 	}
    345      1.1  reinoud 	error = VOP_OPEN(devvp, openflags, FSCRED, l);
    346      1.1  reinoud 	if (error == 0) {
    347      1.1  reinoud 		/* opened ok, try mounting */
    348      1.1  reinoud 		error = udf_mountfs(devvp, mp, l, &args);
    349      1.1  reinoud 		if (error) {
    350      1.1  reinoud 			free_udf_mountinfo(mp);
    351      1.1  reinoud 			/* devvp is still locked */
    352      1.1  reinoud 			(void) VOP_CLOSE(devvp, openflags, NOCRED, l);
    353  1.2.6.2     yamt 		}
    354  1.2.6.2     yamt 	}
    355      1.1  reinoud 	if (error) {
    356      1.1  reinoud 		/* devvp is still locked */
    357      1.1  reinoud 		vput(devvp);
    358      1.1  reinoud 		return error;
    359  1.2.6.2     yamt 	}
    360      1.1  reinoud 
    361      1.1  reinoud 	/* register our mountpoint being on this device */
    362      1.1  reinoud 	devvp->v_specmountpoint = mp;
    363      1.1  reinoud 
    364      1.1  reinoud 	/* successfully mounted */
    365      1.1  reinoud 	DPRINTF(VOLUMES, ("udf_mount() successfull\n"));
    366      1.1  reinoud 
    367      1.1  reinoud 	/* unlock it but dont deref it */
    368      1.1  reinoud 	VOP_UNLOCK(devvp, 0);
    369      1.1  reinoud 
    370      1.1  reinoud 	return set_statvfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE, mp, l);
    371      1.1  reinoud }
    372      1.1  reinoud 
    373      1.1  reinoud /* --------------------------------------------------------------------- */
    374      1.1  reinoud 
    375      1.1  reinoud #ifdef DEBUG
    376      1.1  reinoud static void
    377      1.1  reinoud udf_unmount_sanity_check(struct mount *mp)
    378      1.1  reinoud {
    379      1.1  reinoud 	struct vnode *vp;
    380      1.1  reinoud 
    381      1.1  reinoud 	printf("On unmount, i found the following nodes:\n");
    382      1.1  reinoud 	LIST_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
    383      1.1  reinoud 		vprint("", vp);
    384      1.1  reinoud 		if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) {
    385      1.1  reinoud 			printf("  is locked\n");
    386  1.2.6.2     yamt 		}
    387      1.1  reinoud 		if (vp->v_usecount > 1)
    388      1.1  reinoud 			printf("  more than one usecount %d\n", vp->v_usecount);
    389  1.2.6.2     yamt 	}
    390      1.1  reinoud }
    391      1.1  reinoud #endif
    392      1.1  reinoud 
    393      1.1  reinoud 
    394      1.1  reinoud int
    395      1.1  reinoud udf_unmount(struct mount *mp, int mntflags, struct lwp *l)
    396      1.1  reinoud {
    397      1.1  reinoud 	struct udf_mount *ump;
    398      1.1  reinoud 	int error, flags, closeflags;
    399      1.1  reinoud 
    400      1.1  reinoud 	DPRINTF(CALL, ("udf_umount called\n"));
    401      1.1  reinoud 
    402      1.1  reinoud 	/*
    403      1.1  reinoud 	 * By specifying SKIPSYSTEM we can skip vnodes marked with VSYSTEM.
    404      1.1  reinoud 	 * This hardly documented feature allows us to exempt certain files
    405      1.1  reinoud 	 * from being flushed.
    406      1.1  reinoud 	 */
    407      1.1  reinoud 	flags = SKIPSYSTEM;	/* allow for system vnodes to stay alive */
    408      1.1  reinoud 	if (mntflags & MNT_FORCE)
    409      1.1  reinoud 		flags |= FORCECLOSE;
    410      1.1  reinoud 
    411      1.1  reinoud 	ump = VFSTOUDF(mp);
    412      1.1  reinoud 	if (!ump)
    413      1.1  reinoud 		panic("UDF unmount: empty ump\n");
    414      1.1  reinoud 
    415      1.1  reinoud 	/* TODO remove these paranoid functions */
    416      1.1  reinoud #ifdef DEBUG
    417      1.1  reinoud 	if (udf_verbose & UDF_DEBUG_LOCKING)
    418      1.1  reinoud 		udf_unmount_sanity_check(mp);
    419      1.1  reinoud #endif
    420      1.1  reinoud 
    421      1.1  reinoud 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    422      1.1  reinoud 		return error;
    423      1.1  reinoud 
    424      1.1  reinoud #ifdef DEBUG
    425      1.1  reinoud 	if (udf_verbose & UDF_DEBUG_LOCKING)
    426      1.1  reinoud 		udf_unmount_sanity_check(mp);
    427      1.1  reinoud #endif
    428      1.1  reinoud 
    429      1.1  reinoud 	DPRINTF(VOLUMES, ("flush OK\n"));
    430      1.1  reinoud 
    431      1.1  reinoud 	/*
    432      1.1  reinoud 	 * TODO close logical volume and close session if requested.
    433      1.1  reinoud 	 *
    434      1.1  reinoud 	 * XXX no system nodes defined yet.  Code to reclaim them is calling
    435      1.1  reinoud 	 * VOP_RECLAIM on the nodes themselves.
    436      1.1  reinoud 	 */
    437      1.1  reinoud 
    438      1.1  reinoud 	/* dispose of our descriptor pool */
    439      1.1  reinoud 	pool_destroy(&ump->desc_pool);
    440      1.1  reinoud 
    441      1.1  reinoud 	/* close device */
    442      1.1  reinoud 	DPRINTF(VOLUMES, ("closing device\n"));
    443      1.1  reinoud 	if (mp->mnt_flag & MNT_RDONLY) {
    444      1.1  reinoud 		closeflags = FREAD;
    445      1.1  reinoud 	} else {
    446      1.1  reinoud 		closeflags = FREAD | FWRITE;
    447  1.2.6.2     yamt 	}
    448      1.1  reinoud 
    449      1.1  reinoud 	/* devvp is still locked by us */
    450      1.1  reinoud 	vn_lock(ump->devvp, LK_EXCLUSIVE | LK_RETRY);
    451      1.1  reinoud 	error = VOP_CLOSE(ump->devvp, closeflags, NOCRED, l);
    452      1.1  reinoud 	if (error)
    453      1.1  reinoud 		printf("Error during closure of device! error %d, "
    454      1.1  reinoud 		       "device might stay locked\n", error);
    455      1.1  reinoud 	DPRINTF(VOLUMES, ("device close ok\n"));
    456      1.1  reinoud 
    457      1.1  reinoud 	/* clear our mount reference and release device node */
    458      1.1  reinoud 	ump->devvp->v_specmountpoint = NULL;
    459      1.1  reinoud 	vput(ump->devvp);
    460      1.1  reinoud 
    461      1.1  reinoud 	/* free ump struct */
    462      1.1  reinoud 	mp->mnt_data = NULL;
    463      1.1  reinoud 	mp->mnt_flag &= ~MNT_LOCAL;
    464      1.1  reinoud 
    465      1.1  reinoud 	/* free up umt structure */
    466      1.1  reinoud 	free_udf_mountinfo(mp);
    467      1.1  reinoud 
    468      1.1  reinoud 	DPRINTF(VOLUMES, ("Fin unmount\n"));
    469      1.1  reinoud 	return error;
    470      1.1  reinoud }
    471      1.1  reinoud 
    472      1.1  reinoud /* --------------------------------------------------------------------- */
    473      1.1  reinoud 
    474      1.1  reinoud /*
    475      1.1  reinoud  * Helper function of udf_mount() that actually mounts the disc.
    476      1.1  reinoud  */
    477      1.1  reinoud 
    478      1.1  reinoud static int
    479      1.1  reinoud udf_mountfs(struct vnode *devvp, struct mount *mp,
    480      1.1  reinoud 	    struct lwp *l, struct udf_args *args)
    481      1.1  reinoud {
    482      1.1  reinoud 	struct udf_mount     *ump;
    483      1.1  reinoud 	uint32_t sector_size, lb_size, bshift;
    484      1.1  reinoud 	int    num_anchors, error, lst;
    485      1.1  reinoud 
    486      1.1  reinoud 	/* flush out any old buffers remaining from a previous use. */
    487  1.2.6.1     yamt 	error = vinvalbuf(devvp, V_SAVE, l->l_proc->p_cred, l, 0, 0);
    488      1.1  reinoud 	if (error)
    489      1.1  reinoud 		return error;
    490      1.1  reinoud 
    491      1.1  reinoud 	/* allocate udf part of mount structure; malloc allways succeeds */
    492      1.1  reinoud 	ump = malloc(sizeof(struct udf_mount), M_UDFMNT, M_WAITOK);
    493      1.1  reinoud 	memset(ump, 0, sizeof(struct udf_mount));
    494      1.1  reinoud 
    495      1.1  reinoud 	/* init locks */
    496      1.1  reinoud 	simple_lock_init(&ump->ihash_slock);
    497      1.1  reinoud 	lockinit(&ump->get_node_lock, PINOD, "udf_getnode", 0, 0);
    498      1.1  reinoud 
    499      1.1  reinoud 	/* init `ino_t' to udf_node hash table */
    500      1.1  reinoud 	for (lst = 0; lst < UDF_INODE_HASHSIZE; lst++) {
    501      1.1  reinoud 		LIST_INIT(&ump->udf_nodes[lst]);
    502  1.2.6.2     yamt 	}
    503      1.1  reinoud 
    504      1.1  reinoud 	/* set up linkage */
    505      1.1  reinoud 	mp->mnt_data    = ump;
    506      1.1  reinoud 	ump->vfs_mountp = mp;
    507      1.1  reinoud 
    508      1.1  reinoud 	/* set up arguments and device */
    509      1.1  reinoud 	ump->mount_args = *args;
    510      1.1  reinoud 	ump->devvp      = devvp;
    511      1.1  reinoud 	error = udf_update_discinfo(ump);
    512      1.1  reinoud 
    513      1.1  reinoud 	if (error) {
    514      1.1  reinoud 		printf("UDF mount: error inspecting fs node\n");
    515      1.1  reinoud 		return error;
    516  1.2.6.2     yamt 	}
    517      1.1  reinoud 
    518      1.1  reinoud 	/* inspect sector size */
    519      1.1  reinoud 	sector_size = ump->discinfo.sector_size;
    520      1.1  reinoud 	bshift = 1;
    521      1.1  reinoud 	while ((1 << bshift) < sector_size)
    522      1.1  reinoud 		bshift++;
    523      1.1  reinoud 	if ((1 << bshift) != sector_size) {
    524      1.1  reinoud 		printf("UDF mount: "
    525      1.1  reinoud 		       "hit NetBSD implementation fence on sector size\n");
    526      1.1  reinoud 		return EIO;
    527  1.2.6.2     yamt 	}
    528      1.1  reinoud 
    529      1.1  reinoud 	/* read all anchors to get volume descriptor sequence */
    530      1.1  reinoud 	num_anchors = udf_read_anchors(ump, args);
    531      1.1  reinoud 	if (num_anchors == 0)
    532      1.1  reinoud 		return ENOENT;
    533      1.1  reinoud 
    534      1.1  reinoud 	DPRINTF(VOLUMES, ("Read %d anchors on this disc, session %d\n",
    535      1.1  reinoud 	    num_anchors, args->sessionnr));
    536      1.1  reinoud 
    537      1.1  reinoud 	/* read in volume descriptor sequence */
    538      1.1  reinoud 	error = udf_read_vds_space(ump);
    539      1.1  reinoud 	if (error)
    540      1.1  reinoud 		printf("UDF mount: error reading volume space\n");
    541      1.1  reinoud 
    542      1.1  reinoud 	/* check consistency and completeness */
    543      1.1  reinoud 	if (!error) {
    544      1.1  reinoud 		error = udf_process_vds(ump, args);
    545      1.1  reinoud 		if (error)
    546      1.1  reinoud 			printf("UDF mount: disc not properly formatted\n");
    547  1.2.6.2     yamt 	}
    548      1.1  reinoud 
    549      1.1  reinoud 	/*
    550      1.1  reinoud 	 * Initialise pool for descriptors associated with nodes. This is done
    551      1.1  reinoud 	 * in lb_size units though currently lb_size is dictated to be
    552      1.1  reinoud 	 * sector_size.
    553      1.1  reinoud 	 */
    554      1.1  reinoud 	lb_size = udf_rw32(ump->logical_vol->lb_size);
    555      1.1  reinoud 	pool_init(&ump->desc_pool, lb_size, 0, 0, 0, "udf_desc_pool", NULL);
    556      1.1  reinoud 
    557      1.1  reinoud 	/* read vds support tables like VAT, sparable etc. */
    558      1.1  reinoud 	if (!error) {
    559      1.1  reinoud 		error = udf_read_vds_tables(ump, args);
    560      1.1  reinoud 		if (error)
    561      1.1  reinoud 			printf("UDF mount: error in format or damaged disc\n");
    562  1.2.6.2     yamt 	}
    563      1.1  reinoud 	if (!error) {
    564      1.1  reinoud 		error = udf_read_rootdirs(ump, args);
    565      1.1  reinoud 		if (error)
    566      1.1  reinoud 			printf("UDF mount: "
    567      1.1  reinoud 			       "disc not properly formatted or damaged disc\n");
    568  1.2.6.2     yamt 	}
    569      1.1  reinoud 	if (error)
    570      1.1  reinoud 		return error;
    571      1.1  reinoud 
    572      1.1  reinoud 	/* setup rest of mount information */
    573      1.1  reinoud 	mp->mnt_data = ump;
    574      1.1  reinoud 	mp->mnt_stat.f_fsidx.__fsid_val[0] = (uint32_t) devvp->v_rdev;
    575      1.1  reinoud 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_UDF);
    576      1.1  reinoud 	mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
    577      1.1  reinoud 	mp->mnt_stat.f_namemax = UDF_MAX_NAMELEN;
    578      1.1  reinoud 	mp->mnt_flag |= MNT_LOCAL;
    579      1.1  reinoud 
    580      1.1  reinoud 	/* bshift is allways equal to disc sector size */
    581      1.1  reinoud 	mp->mnt_dev_bshift = bshift;
    582      1.1  reinoud 	mp->mnt_fs_bshift  = bshift;
    583      1.1  reinoud 
    584      1.1  reinoud 	/* do we have to set this? */
    585      1.1  reinoud 	devvp->v_specmountpoint = mp;
    586      1.1  reinoud 
    587      1.1  reinoud 	/* success! */
    588      1.1  reinoud 	return 0;
    589      1.1  reinoud }
    590      1.1  reinoud 
    591      1.1  reinoud /* --------------------------------------------------------------------- */
    592      1.1  reinoud 
    593      1.1  reinoud int
    594      1.1  reinoud udf_start(struct mount *mp, int flags, struct lwp *l)
    595      1.1  reinoud {
    596      1.1  reinoud 	/* do we have to do something here? */
    597      1.1  reinoud 	return 0;
    598      1.1  reinoud }
    599      1.1  reinoud 
    600      1.1  reinoud /* --------------------------------------------------------------------- */
    601      1.1  reinoud 
    602      1.1  reinoud int
    603      1.1  reinoud udf_root(struct mount *mp, struct vnode **vpp)
    604      1.1  reinoud {
    605      1.1  reinoud 	struct vnode *vp;
    606      1.1  reinoud 	struct long_ad *dir_loc;
    607      1.1  reinoud 	struct udf_mount *ump = VFSTOUDF(mp);
    608      1.1  reinoud 	struct udf_node *root_dir;
    609      1.1  reinoud 	int error;
    610      1.1  reinoud 
    611      1.1  reinoud 	DPRINTF(CALL, ("udf_root called\n"));
    612      1.1  reinoud 
    613      1.1  reinoud 	dir_loc = &ump->fileset_desc->rootdir_icb;
    614      1.1  reinoud 	error = udf_get_node(ump, dir_loc, &root_dir);
    615      1.1  reinoud 
    616      1.1  reinoud 	if (!root_dir)
    617      1.1  reinoud 		error = ENOENT;
    618      1.1  reinoud 	if (error)
    619      1.1  reinoud 		return error;
    620      1.1  reinoud 
    621      1.1  reinoud 	vp = root_dir->vnode;
    622      1.1  reinoud 	simple_lock(&vp->v_interlock);
    623      1.1  reinoud 		root_dir->vnode->v_flag |= VROOT;
    624      1.1  reinoud 	simple_unlock(&vp->v_interlock);
    625      1.1  reinoud 
    626      1.1  reinoud 	*vpp = vp;
    627      1.1  reinoud 	return 0;
    628      1.1  reinoud }
    629      1.1  reinoud 
    630      1.1  reinoud /* --------------------------------------------------------------------- */
    631      1.1  reinoud 
    632      1.1  reinoud int
    633      1.1  reinoud udf_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg, struct lwp *l)
    634      1.1  reinoud {
    635      1.1  reinoud 	DPRINTF(NOTIMPL, ("udf_quotactl called\n"));
    636      1.1  reinoud 	return EOPNOTSUPP;
    637      1.1  reinoud }
    638      1.1  reinoud 
    639      1.1  reinoud /* --------------------------------------------------------------------- */
    640      1.1  reinoud 
    641      1.1  reinoud int
    642      1.1  reinoud udf_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
    643      1.1  reinoud {
    644      1.1  reinoud 	struct udf_mount *ump = VFSTOUDF(mp);
    645      1.1  reinoud 	struct logvol_int_desc *lvid;
    646      1.1  reinoud 	struct udf_logvol_info *impl;
    647      1.1  reinoud 	uint64_t freeblks, sizeblks;
    648      1.1  reinoud 	uint32_t *pos1, *pos2;
    649      1.1  reinoud 	int part, num_part;
    650      1.1  reinoud 
    651      1.1  reinoud 	DPRINTF(CALL, ("udf_statvfs called\n"));
    652      1.1  reinoud 	sbp->f_flag   = mp->mnt_flag;
    653      1.1  reinoud 	sbp->f_bsize  = ump->discinfo.sector_size;
    654      1.1  reinoud 	sbp->f_frsize = ump->discinfo.sector_size;
    655      1.1  reinoud 	sbp->f_iosize = ump->discinfo.sector_size;
    656      1.1  reinoud 
    657      1.1  reinoud 	/* TODO integrity locking */
    658      1.1  reinoud 	/* free and used space for mountpoint based on logvol integrity */
    659      1.1  reinoud 	lvid = ump->logvol_integrity;
    660      1.1  reinoud 	if (lvid) {
    661      1.1  reinoud 		num_part = udf_rw32(lvid->num_part);
    662      1.1  reinoud 		impl = (struct udf_logvol_info *) (lvid->tables + 2*num_part);
    663      1.1  reinoud 
    664      1.1  reinoud 		freeblks = sizeblks = 0;
    665      1.1  reinoud 		for (part=0; part < num_part; part++) {
    666      1.1  reinoud 			pos1 = &lvid->tables[0] + part;
    667      1.1  reinoud 			pos2 = &lvid->tables[0] + num_part + part;
    668      1.1  reinoud 			if (udf_rw32(*pos1) != (uint32_t) -1) {
    669      1.1  reinoud 				freeblks += udf_rw32(*pos1);
    670      1.1  reinoud 				sizeblks += udf_rw32(*pos2);
    671  1.2.6.2     yamt 			}
    672  1.2.6.2     yamt 		}
    673      1.1  reinoud 		sbp->f_blocks = sizeblks;
    674      1.1  reinoud 		sbp->f_bfree  = freeblks;
    675      1.1  reinoud 		sbp->f_files  = udf_rw32(impl->num_files);
    676      1.1  reinoud 		sbp->f_files += udf_rw32(impl->num_directories);
    677      1.1  reinoud 
    678      1.1  reinoud 		/* XXX read only for now XXX */
    679      1.1  reinoud 		sbp->f_bavail = 0;
    680      1.1  reinoud 		sbp->f_bresvd = 0;
    681      1.1  reinoud 
    682      1.1  reinoud 		/* tricky, next only aplies to ffs i think, so set to zero */
    683      1.1  reinoud 		sbp->f_ffree  = 0;
    684      1.1  reinoud 		sbp->f_favail = 0;
    685      1.1  reinoud 		sbp->f_fresvd = 0;
    686  1.2.6.2     yamt 	}
    687      1.1  reinoud 
    688      1.1  reinoud 	copy_statvfs_info(sbp, mp);
    689      1.1  reinoud 	return 0;
    690      1.1  reinoud }
    691      1.1  reinoud 
    692      1.1  reinoud /* --------------------------------------------------------------------- */
    693      1.1  reinoud 
    694      1.1  reinoud int
    695  1.2.6.1     yamt udf_sync(struct mount *mp, int waitfor, kauth_cred_t cred, struct lwp *p)
    696      1.1  reinoud {
    697      1.1  reinoud 	DPRINTF(CALL, ("udf_sync called\n"));
    698      1.1  reinoud 	/* nothing to be done as upto now read-only */
    699      1.1  reinoud 	return 0;
    700      1.1  reinoud }
    701      1.1  reinoud 
    702      1.1  reinoud /* --------------------------------------------------------------------- */
    703      1.1  reinoud 
    704      1.1  reinoud /*
    705      1.1  reinoud  * Get vnode for the file system type specific file id ino for the fs. Its
    706      1.1  reinoud  * used for reference to files by unique ID and for NFSv3.
    707      1.1  reinoud  * (optional) TODO lookup why some sources state NFSv3
    708      1.1  reinoud  */
    709      1.1  reinoud int
    710      1.1  reinoud udf_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
    711      1.1  reinoud {
    712      1.1  reinoud 	DPRINTF(NOTIMPL, ("udf_vget called\n"));
    713      1.1  reinoud 	return EOPNOTSUPP;
    714      1.1  reinoud }
    715      1.1  reinoud 
    716      1.1  reinoud /* --------------------------------------------------------------------- */
    717      1.1  reinoud 
    718      1.1  reinoud /*
    719      1.1  reinoud  * Lookup vnode for file handle specified
    720      1.1  reinoud  */
    721      1.1  reinoud int
    722      1.1  reinoud udf_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
    723      1.1  reinoud {
    724      1.1  reinoud 	DPRINTF(NOTIMPL, ("udf_fhtovp called\n"));
    725      1.1  reinoud 	return EOPNOTSUPP;
    726      1.1  reinoud }
    727      1.1  reinoud 
    728      1.1  reinoud /* --------------------------------------------------------------------- */
    729      1.1  reinoud 
    730      1.1  reinoud /*
    731      1.1  reinoud  * Create an unique file handle. Its structure is opaque and won't be used by
    732      1.1  reinoud  * other subsystems. It should uniquely identify the file in the filingsystem
    733      1.1  reinoud  * and enough information to know if a file has been removed and/or resources
    734      1.1  reinoud  * have been recycled.
    735      1.1  reinoud  */
    736      1.1  reinoud int
    737      1.1  reinoud udf_vptofh(struct vnode *vp, struct fid *fid)
    738      1.1  reinoud {
    739      1.1  reinoud 	DPRINTF(NOTIMPL, ("udf_vptofh called\n"));
    740      1.1  reinoud 	return EOPNOTSUPP;
    741      1.1  reinoud }
    742      1.1  reinoud 
    743      1.1  reinoud /* --------------------------------------------------------------------- */
    744      1.1  reinoud 
    745      1.1  reinoud /*
    746      1.1  reinoud  * Create a filingsystem snapshot at the specified timestamp. Could be
    747      1.1  reinoud  * implemented by explicitly creating a new session or with spare room in the
    748      1.1  reinoud  * integrity descriptor space
    749      1.1  reinoud  */
    750      1.1  reinoud int
    751      1.1  reinoud udf_snapshot(struct mount *mp, struct vnode *vp, struct timespec *tm)
    752      1.1  reinoud {
    753      1.1  reinoud 	DPRINTF(NOTIMPL, ("udf_snapshot called\n"));
    754      1.1  reinoud 	return EOPNOTSUPP;
    755      1.1  reinoud }
    756      1.1  reinoud 
    757      1.1  reinoud 
    758