Home | History | Annotate | Line # | Download | only in udf
udf_vfsops.c revision 1.34
      1 /* $NetBSD: udf_vfsops.c,v 1.34 2008/01/24 17:32:54 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 __KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.34 2008/01/24 17:32:54 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_JUSTDEFINE(M_UDFMNT,   "UDF mount",	"UDF mount structures");
     81 MALLOC_JUSTDEFINE(M_UDFVOLD,  "UDF volspace",	"UDF volume space descriptors");
     82 MALLOC_JUSTDEFINE(M_UDFTEMP,  "UDF temp",	"UDF scrap space");
     83 struct pool udf_node_pool;
     84 
     85 /* supported functions predefined */
     86 VFS_PROTOS(udf);
     87 
     88 
     89 /* internal functions */
     90 static int udf_mountfs(struct vnode *, struct mount *, struct lwp *, struct udf_args *);
     91 #if 0
     92 static int update_mp(struct mount *, struct udf_args *);
     93 #endif
     94 
     95 
     96 /* handies */
     97 #define	VFSTOUDF(mp)	((struct udf_mount *)mp->mnt_data)
     98 
     99 
    100 /* --------------------------------------------------------------------- */
    101 
    102 /* predefine vnode-op list descriptor */
    103 extern const struct vnodeopv_desc udf_vnodeop_opv_desc;
    104 
    105 const struct vnodeopv_desc * const udf_vnodeopv_descs[] = {
    106 	&udf_vnodeop_opv_desc,
    107 	NULL,
    108 };
    109 
    110 
    111 /* vfsops descriptor linked in as anchor point for the filingsystem */
    112 struct vfsops udf_vfsops = {
    113 	MOUNT_UDF,			/* vfs_name */
    114 	sizeof (struct udf_args),
    115 	udf_mount,
    116 	udf_start,
    117 	udf_unmount,
    118 	udf_root,
    119 	(void *)eopnotsupp,		/* vfs_quotactl */
    120 	udf_statvfs,
    121 	udf_sync,
    122 	udf_vget,
    123 	udf_fhtovp,
    124 	udf_vptofh,
    125 	udf_init,
    126 	udf_reinit,
    127 	udf_done,
    128 	udf_mountroot,
    129 	udf_snapshot,
    130 	vfs_stdextattrctl,
    131 	(void *)eopnotsupp,		/* vfs_suspendctl */
    132 	udf_vnodeopv_descs,
    133 	0, /* int vfs_refcount   */
    134 	{ NULL, NULL, }, /* LIST_ENTRY(vfsops) */
    135 };
    136 VFS_ATTACH(udf_vfsops);
    137 
    138 
    139 /* --------------------------------------------------------------------- */
    140 
    141 /* file system starts here */
    142 void
    143 udf_init(void)
    144 {
    145 	size_t size;
    146 
    147 	malloc_type_attach(M_UDFMNT);
    148 	malloc_type_attach(M_UDFVOLD);
    149 	malloc_type_attach(M_UDFTEMP);
    150 
    151 	/* init hashtables and pools */
    152 	size = sizeof(struct udf_node);
    153 	pool_init(&udf_node_pool, size, 0, 0, 0, "udf_node_pool", NULL,
    154 	    IPL_NONE);
    155 }
    156 
    157 /* --------------------------------------------------------------------- */
    158 
    159 void
    160 udf_reinit(void)
    161 {
    162 	/* recreate hashtables */
    163 	/* reinit pool? */
    164 }
    165 
    166 /* --------------------------------------------------------------------- */
    167 
    168 void
    169 udf_done(void)
    170 {
    171 	/* remove hashtables and pools */
    172 	pool_destroy(&udf_node_pool);
    173 
    174 	malloc_type_detach(M_UDFMNT);
    175 	malloc_type_detach(M_UDFVOLD);
    176 	malloc_type_detach(M_UDFTEMP);
    177 }
    178 
    179 /* --------------------------------------------------------------------- */
    180 
    181 int
    182 udf_mountroot(void)
    183 {
    184 	return EOPNOTSUPP;
    185 }
    186 
    187 /* --------------------------------------------------------------------- */
    188 
    189 #define MPFREE(a, lst) \
    190 	if ((a)) free((a), lst);
    191 static void
    192 free_udf_mountinfo(struct mount *mp)
    193 {
    194 	struct udf_mount *ump;
    195 	int i;
    196 
    197 	if (!mp)
    198 		return;
    199 
    200 	ump = VFSTOUDF(mp);
    201 	if (ump) {
    202 		/* dereference all system nodes */
    203 		if (ump->metadata_file)
    204 			vrele(ump->metadata_file->vnode);
    205 		if (ump->metadatamirror_file)
    206 			vrele(ump->metadatamirror_file->vnode);
    207 		if (ump->metadatabitmap_file)
    208 			vrele(ump->metadatabitmap_file->vnode);
    209 
    210 		/* vflush all (system) nodes if any */
    211 		(void) vflush(mp, NULLVP, FORCECLOSE);
    212 
    213 		/* dispose of our descriptor pool */
    214 		if (ump->desc_pool) {
    215 			pool_destroy(ump->desc_pool);
    216 			free(ump->desc_pool, M_UDFMNT);
    217 		}
    218 
    219 		/* clear our data */
    220 		for (i = 0; i < UDF_ANCHORS; i++)
    221 			MPFREE(ump->anchors[i], M_UDFVOLD);
    222 		MPFREE(ump->primary_vol,      M_UDFVOLD);
    223 		MPFREE(ump->logical_vol,      M_UDFVOLD);
    224 		MPFREE(ump->unallocated,      M_UDFVOLD);
    225 		MPFREE(ump->implementation,   M_UDFVOLD);
    226 		MPFREE(ump->logvol_integrity, M_UDFVOLD);
    227 		for (i = 0; i < UDF_PARTITIONS; i++)
    228 			MPFREE(ump->partitions[i], M_UDFVOLD);
    229 		MPFREE(ump->fileset_desc,     M_UDFVOLD);
    230 		MPFREE(ump->vat_table,        M_UDFVOLD);
    231 		MPFREE(ump->sparing_table,    M_UDFVOLD);
    232 
    233 		mutex_destroy(&ump->ihash_lock);
    234 		mutex_destroy(&ump->get_node_lock);
    235 		free(ump, M_UDFMNT);
    236 	}
    237 }
    238 #undef MPFREE
    239 
    240 /* --------------------------------------------------------------------- */
    241 
    242 int
    243 udf_mount(struct mount *mp, const char *path,
    244 	  void *data, size_t *data_len)
    245 {
    246 	struct lwp *l = curlwp;
    247 	struct nameidata nd;
    248 	struct udf_args *args = data;
    249 	struct udf_mount *ump;
    250 	struct vnode *devvp;
    251 	int openflags, accessmode, error;
    252 
    253 	DPRINTF(CALL, ("udf_mount called\n"));
    254 
    255 	if (*data_len < sizeof *args)
    256 		return EINVAL;
    257 
    258 	if (mp->mnt_flag & MNT_GETARGS) {
    259 		/* request for the mount arguments */
    260 		ump = VFSTOUDF(mp);
    261 		if (ump == NULL)
    262 			return EINVAL;
    263 		*args = ump->mount_args;
    264 		*data_len = sizeof *args;
    265 		return 0;
    266 	}
    267 
    268 	/* handle request for updating mount parameters */
    269 	/* TODO can't update my mountpoint yet */
    270 	if (mp->mnt_flag & MNT_UPDATE) {
    271 		return EOPNOTSUPP;
    272 	}
    273 
    274 	/* OK, so we are asked to mount the device */
    275 
    276 	/* check/translate struct version */
    277 	/* TODO sanity checking other mount arguments */
    278 	if (args->version != 1) {
    279 		printf("mount_udf: unrecognized argument structure version\n");
    280 		return EINVAL;
    281 	}
    282 
    283 	/* lookup name to get its vnode */
    284 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, args->fspec);
    285 	error = namei(&nd);
    286 	if (error)
    287 		return error;
    288 	devvp = nd.ni_vp;
    289 
    290 #ifdef DEBUG
    291 	if (udf_verbose & UDF_DEBUG_VOLUMES)
    292 		vprint("UDF mount, trying to mount \n", devvp);
    293 #endif
    294 
    295 	/* check if its a block device specified */
    296 	if (devvp->v_type != VBLK) {
    297 		vrele(devvp);
    298 		return ENOTBLK;
    299 	}
    300 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    301 		vrele(devvp);
    302 		return ENXIO;
    303 	}
    304 
    305 	/* force read-only for now */
    306 	mp->mnt_flag |= MNT_RDONLY;
    307 
    308 	/*
    309 	 * If mount by non-root, then verify that user has necessary
    310 	 * permissions on the device.
    311 	 */
    312 	if (kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER, NULL)) {
    313 		accessmode = VREAD;
    314 		if ((mp->mnt_flag & MNT_RDONLY) == 0)
    315 			accessmode |= VWRITE;
    316 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    317 		error = VOP_ACCESS(devvp, accessmode, l->l_cred);
    318 		VOP_UNLOCK(devvp, 0);
    319 		if (error) {
    320 			vrele(devvp);
    321 			return error;
    322 		}
    323 	}
    324 
    325 	/*
    326 	 * Open device and try to mount it!
    327 	 */
    328 	if (mp->mnt_flag & MNT_RDONLY) {
    329 		openflags = FREAD;
    330 	} else {
    331 		openflags = FREAD | FWRITE;
    332 	}
    333 	error = VOP_OPEN(devvp, openflags, FSCRED);
    334 	if (error == 0) {
    335 		/* opened ok, try mounting */
    336 		error = udf_mountfs(devvp, mp, l, args);
    337 		if (error) {
    338 			free_udf_mountinfo(mp);
    339 			vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    340 			(void) VOP_CLOSE(devvp, openflags, NOCRED);
    341 			VOP_UNLOCK(devvp, 0);
    342 		}
    343 	}
    344 	if (error) {
    345 		/* devvp is still locked */
    346 		vrele(devvp);
    347 		return error;
    348 	}
    349 
    350 	/* register our mountpoint being on this device */
    351 	devvp->v_specmountpoint = mp;
    352 
    353 	/* successfully mounted */
    354 	DPRINTF(VOLUMES, ("udf_mount() successfull\n"));
    355 
    356 	return set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
    357 			mp->mnt_op->vfs_name, mp, l);
    358 }
    359 
    360 /* --------------------------------------------------------------------- */
    361 
    362 #ifdef DEBUG
    363 static void
    364 udf_unmount_sanity_check(struct mount *mp)
    365 {
    366 	struct vnode *vp;
    367 
    368 	printf("On unmount, i found the following nodes:\n");
    369 	TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
    370 		vprint("", vp);
    371 		if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) {
    372 			printf("  is locked\n");
    373 		}
    374 		if (vp->v_usecount > 1)
    375 			printf("  more than one usecount %d\n", vp->v_usecount);
    376 	}
    377 }
    378 #endif
    379 
    380 
    381 int
    382 udf_unmount(struct mount *mp, int mntflags)
    383 {
    384 	struct udf_mount *ump;
    385 	int error, flags, closeflags;
    386 
    387 	DPRINTF(CALL, ("udf_umount called\n"));
    388 
    389 	ump = VFSTOUDF(mp);
    390 	if (!ump)
    391 		panic("UDF unmount: empty ump\n");
    392 
    393 	flags = (mntflags & MNT_FORCE) ? FORCECLOSE : 0;
    394 	/* TODO remove these paranoid functions */
    395 #ifdef DEBUG
    396 	if (udf_verbose & UDF_DEBUG_LOCKING)
    397 		udf_unmount_sanity_check(mp);
    398 #endif
    399 
    400 	/*
    401 	 * By specifying SKIPSYSTEM we can skip vnodes marked with VV_SYSTEM.
    402 	 * This hardly documented feature allows us to exempt certain files
    403 	 * from being flushed.
    404 	 */
    405 	if ((error = vflush(mp, NULLVP, flags | SKIPSYSTEM)) != 0)
    406 		return error;
    407 
    408 #ifdef DEBUG
    409 	if (udf_verbose & UDF_DEBUG_LOCKING)
    410 		udf_unmount_sanity_check(mp);
    411 #endif
    412 
    413 	DPRINTF(VOLUMES, ("flush OK\n"));
    414 
    415 	/*
    416 	 * TODO close logical volume and close session if requested.
    417 	 */
    418 
    419 	/* close device */
    420 	DPRINTF(VOLUMES, ("closing device\n"));
    421 	if (mp->mnt_flag & MNT_RDONLY) {
    422 		closeflags = FREAD;
    423 	} else {
    424 		closeflags = FREAD | FWRITE;
    425 	}
    426 
    427 	/* devvp is still locked by us */
    428 	vn_lock(ump->devvp, LK_EXCLUSIVE | LK_RETRY);
    429 	error = VOP_CLOSE(ump->devvp, closeflags, NOCRED);
    430 	if (error)
    431 		printf("Error during closure of device! error %d, "
    432 		       "device might stay locked\n", error);
    433 	DPRINTF(VOLUMES, ("device close ok\n"));
    434 
    435 	/* clear our mount reference and release device node */
    436 	ump->devvp->v_specmountpoint = NULL;
    437 	vput(ump->devvp);
    438 
    439 	/* free up umt structure */
    440 	free_udf_mountinfo(mp);
    441 
    442 	/* free ump struct reference */
    443 	mp->mnt_data = NULL;
    444 	mp->mnt_flag &= ~MNT_LOCAL;
    445 
    446 	DPRINTF(VOLUMES, ("Fin unmount\n"));
    447 	return error;
    448 }
    449 
    450 /* --------------------------------------------------------------------- */
    451 
    452 /*
    453  * Helper function of udf_mount() that actually mounts the disc.
    454  */
    455 
    456 static int
    457 udf_mountfs(struct vnode *devvp, struct mount *mp,
    458 	    struct lwp *l, struct udf_args *args)
    459 {
    460 	struct udf_mount     *ump;
    461 	uint32_t sector_size, lb_size, bshift;
    462 	int    num_anchors, error, lst;
    463 
    464 	/* flush out any old buffers remaining from a previous use. */
    465 	if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)))
    466 		return error;
    467 
    468 	/* allocate udf part of mount structure; malloc always succeeds */
    469 	ump = malloc(sizeof(struct udf_mount), M_UDFMNT, M_WAITOK | M_ZERO);
    470 
    471 	/* init locks */
    472 	mutex_init(&ump->ihash_lock, MUTEX_DEFAULT, IPL_NONE);
    473 	mutex_init(&ump->get_node_lock, MUTEX_DEFAULT, IPL_NONE);
    474 
    475 	/* init `ino_t' to udf_node hash table */
    476 	for (lst = 0; lst < UDF_INODE_HASHSIZE; lst++) {
    477 		LIST_INIT(&ump->udf_nodes[lst]);
    478 	}
    479 
    480 	/* set up linkage */
    481 	mp->mnt_data    = ump;
    482 	ump->vfs_mountp = mp;
    483 
    484 	/* set up arguments and device */
    485 	ump->mount_args = *args;
    486 	ump->devvp      = devvp;
    487 	if ((error = udf_update_discinfo(ump))) {
    488 		printf("UDF mount: error inspecting fs node\n");
    489 		return error;
    490 	}
    491 
    492 	/* inspect sector size */
    493 	sector_size = ump->discinfo.sector_size;
    494 	bshift = 1;
    495 	while ((1 << bshift) < sector_size)
    496 		bshift++;
    497 	if ((1 << bshift) != sector_size) {
    498 		printf("UDF mount: "
    499 		       "hit NetBSD implementation fence on sector size\n");
    500 		return EIO;
    501 	}
    502 
    503 	/* read all anchors to get volume descriptor sequence */
    504 	num_anchors = udf_read_anchors(ump, args);
    505 	if (num_anchors == 0)
    506 		return ENOENT;
    507 
    508 	DPRINTF(VOLUMES, ("Read %d anchors on this disc, session %d\n",
    509 	    num_anchors, args->sessionnr));
    510 
    511 	/* read in volume descriptor sequence */
    512 	if ((error = udf_read_vds_space(ump))) {
    513 		printf("UDF mount: error reading volume space\n");
    514 		return error;
    515 	}
    516 
    517 	/* check consistency and completeness */
    518 	if ((error = udf_process_vds(ump, args))) {
    519 		printf( "UDF mount: disc not properly formatted"
    520 			"(bad VDS)\n");
    521 		return error;
    522 	}
    523 
    524 	/*
    525 	 * Initialise pool for descriptors associated with nodes. This is done
    526 	 * in lb_size units though currently lb_size is dictated to be
    527 	 * sector_size.
    528 	 */
    529 	lb_size = udf_rw32(ump->logical_vol->lb_size);
    530 	ump->desc_pool = malloc(sizeof(struct pool), M_UDFMNT, M_WAITOK);
    531 	memset(ump->desc_pool, 0, sizeof(struct pool));
    532 	pool_init(ump->desc_pool, lb_size, 0, 0, 0, "udf_desc_pool", NULL,
    533 	    IPL_NONE);
    534 
    535 	/* read vds support tables like VAT, sparable etc. */
    536 	if ((error = udf_read_vds_tables(ump, args))) {
    537 		printf( "UDF mount: error in format or damaged disc "
    538 			"(VDS tables failing)\n");
    539 		return error;
    540 	}
    541 
    542 	if ((error = udf_read_rootdirs(ump, args))) {
    543 		printf( "UDF mount: "
    544 			"disc not properly formatted or damaged disc "
    545 			"(rootdirs failing)\n");
    546 		return error;
    547 	}
    548 
    549 	/* setup rest of mount information */
    550 	mp->mnt_data = ump;
    551 	mp->mnt_stat.f_fsidx.__fsid_val[0] = (uint32_t) devvp->v_rdev;
    552 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_UDF);
    553 	mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
    554 	mp->mnt_stat.f_namemax = UDF_MAX_NAMELEN;
    555 	mp->mnt_flag |= MNT_LOCAL;
    556 
    557 	/* bshift is always equal to disc sector size */
    558 	mp->mnt_dev_bshift = bshift;
    559 	mp->mnt_fs_bshift  = bshift;
    560 
    561 	/* do we have to set this? */
    562 	devvp->v_specmountpoint = mp;
    563 
    564 	/* success! */
    565 	return 0;
    566 }
    567 
    568 /* --------------------------------------------------------------------- */
    569 
    570 int
    571 udf_start(struct mount *mp, int flags)
    572 {
    573 	/* do we have to do something here? */
    574 	return 0;
    575 }
    576 
    577 /* --------------------------------------------------------------------- */
    578 
    579 int
    580 udf_root(struct mount *mp, struct vnode **vpp)
    581 {
    582 	struct vnode *vp;
    583 	struct long_ad *dir_loc;
    584 	struct udf_mount *ump = VFSTOUDF(mp);
    585 	struct udf_node *root_dir;
    586 	int error;
    587 
    588 	DPRINTF(CALL, ("udf_root called\n"));
    589 
    590 	dir_loc = &ump->fileset_desc->rootdir_icb;
    591 	error = udf_get_node(ump, dir_loc, &root_dir);
    592 
    593 	if (!root_dir)
    594 		error = ENOENT;
    595 	if (error)
    596 		return error;
    597 
    598 	vp = root_dir->vnode;
    599 	root_dir->vnode->v_vflag |= VV_ROOT;
    600 
    601 	*vpp = vp;
    602 	return 0;
    603 }
    604 
    605 /* --------------------------------------------------------------------- */
    606 
    607 int
    608 udf_statvfs(struct mount *mp, struct statvfs *sbp)
    609 {
    610 	struct udf_mount *ump = VFSTOUDF(mp);
    611 	struct logvol_int_desc *lvid;
    612 	struct udf_logvol_info *impl;
    613 	uint64_t freeblks, sizeblks;
    614 	uint32_t *pos1, *pos2;
    615 	int part, num_part;
    616 
    617 	DPRINTF(CALL, ("udf_statvfs called\n"));
    618 	sbp->f_flag   = mp->mnt_flag;
    619 	sbp->f_bsize  = ump->discinfo.sector_size;
    620 	sbp->f_frsize = ump->discinfo.sector_size;
    621 	sbp->f_iosize = ump->discinfo.sector_size;
    622 
    623 	/* TODO integrity locking */
    624 	/* free and used space for mountpoint based on logvol integrity */
    625 	lvid = ump->logvol_integrity;
    626 	if (lvid) {
    627 		num_part = udf_rw32(lvid->num_part);
    628 		impl = (struct udf_logvol_info *) (lvid->tables + 2*num_part);
    629 
    630 		freeblks = sizeblks = 0;
    631 		for (part=0; part < num_part; part++) {
    632 			pos1 = &lvid->tables[0] + part;
    633 			pos2 = &lvid->tables[0] + num_part + part;
    634 			if (udf_rw32(*pos1) != (uint32_t) -1) {
    635 				freeblks += udf_rw32(*pos1);
    636 				sizeblks += udf_rw32(*pos2);
    637 			}
    638 		}
    639 		sbp->f_blocks = sizeblks;
    640 		sbp->f_bfree  = freeblks;
    641 		sbp->f_files  = udf_rw32(impl->num_files);
    642 		sbp->f_files += udf_rw32(impl->num_directories);
    643 
    644 		/* XXX read only for now XXX */
    645 		sbp->f_bavail = 0;
    646 		sbp->f_bresvd = 0;
    647 
    648 		/* tricky, next only aplies to ffs i think, so set to zero */
    649 		sbp->f_ffree  = 0;
    650 		sbp->f_favail = 0;
    651 		sbp->f_fresvd = 0;
    652 	}
    653 
    654 	copy_statvfs_info(sbp, mp);
    655 	return 0;
    656 }
    657 
    658 /* --------------------------------------------------------------------- */
    659 
    660 int
    661 udf_sync(struct mount *mp, int waitfor,
    662     kauth_cred_t cred)
    663 {
    664 	DPRINTF(CALL, ("udf_sync called\n"));
    665 	/* nothing to be done as upto now read-only */
    666 	return 0;
    667 }
    668 
    669 /* --------------------------------------------------------------------- */
    670 
    671 /*
    672  * Get vnode for the file system type specific file id ino for the fs. Its
    673  * used for reference to files by unique ID and for NFSv3.
    674  * (optional) TODO lookup why some sources state NFSv3
    675  */
    676 int
    677 udf_vget(struct mount *mp, ino_t ino,
    678     struct vnode **vpp)
    679 {
    680 	DPRINTF(NOTIMPL, ("udf_vget called\n"));
    681 	return EOPNOTSUPP;
    682 }
    683 
    684 /* --------------------------------------------------------------------- */
    685 
    686 /*
    687  * Lookup vnode for file handle specified
    688  */
    689 int
    690 udf_fhtovp(struct mount *mp, struct fid *fhp,
    691     struct vnode **vpp)
    692 {
    693 	DPRINTF(NOTIMPL, ("udf_fhtovp called\n"));
    694 	return EOPNOTSUPP;
    695 }
    696 
    697 /* --------------------------------------------------------------------- */
    698 
    699 /*
    700  * Create an unique file handle. Its structure is opaque and won't be used by
    701  * other subsystems. It should uniquely identify the file in the filingsystem
    702  * and enough information to know if a file has been removed and/or resources
    703  * have been recycled.
    704  */
    705 int
    706 udf_vptofh(struct vnode *vp, struct fid *fid,
    707     size_t *fh_size)
    708 {
    709 	DPRINTF(NOTIMPL, ("udf_vptofh called\n"));
    710 	return EOPNOTSUPP;
    711 }
    712 
    713 /* --------------------------------------------------------------------- */
    714 
    715 /*
    716  * Create a filingsystem snapshot at the specified timestamp. Could be
    717  * implemented by explicitly creating a new session or with spare room in the
    718  * integrity descriptor space
    719  */
    720 int
    721 udf_snapshot(struct mount *mp, struct vnode *vp,
    722     struct timespec *tm)
    723 {
    724 	DPRINTF(NOTIMPL, ("udf_snapshot called\n"));
    725 	return EOPNOTSUPP;
    726 }
    727 
    728 /* --------------------------------------------------------------------- */
    729 
    730 /*
    731  * If running a DEBUG kernel, provide an easy way to set the debug flags when
    732  * running into a problem.
    733  */
    734 
    735 #ifdef DEBUG
    736 #define UDF_VERBOSE_SYSCTLOPT 1
    737 
    738 SYSCTL_SETUP(sysctl_vfs_udf_setup, "sysctl vfs.udf subtree setup")
    739 {
    740 	/*
    741 	 * XXX the "24" below could be dynamic, thereby eliminating one
    742 	 * more instance of the "number to vfs" mapping problem, but
    743 	 * "24" is the order as taken from sys/mount.h
    744 	 */
    745 
    746 	sysctl_createv(clog, 0, NULL, NULL,
    747 		       CTLFLAG_PERMANENT,
    748 		       CTLTYPE_NODE, "vfs", NULL,
    749 		       NULL, 0, NULL, 0,
    750 		       CTL_VFS, CTL_EOL);
    751 	sysctl_createv(clog, 0, NULL, NULL,
    752 		       CTLFLAG_PERMANENT,
    753 		       CTLTYPE_NODE, "udf",
    754 		       SYSCTL_DESCR("OSTA Universal File System"),
    755 		       NULL, 0, NULL, 0,
    756 		       CTL_VFS, 24, CTL_EOL);
    757 
    758 	sysctl_createv(clog, 0, NULL, NULL,
    759 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    760 		       CTLTYPE_INT, "verbose",
    761 		       SYSCTL_DESCR("Bitmask for filesystem debugging"),
    762 		       NULL, 0, &udf_verbose, 0,
    763 		       CTL_VFS, 24, UDF_VERBOSE_SYSCTLOPT, CTL_EOL);
    764 }
    765 
    766 #endif /* DEBUG */
    767 
    768