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