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