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