Home | History | Annotate | Line # | Download | only in udf
udf_vfsops.c revision 1.10
      1 /* $NetBSD: udf_vfsops.c,v 1.10 2006/08/21 22:23:09 reinoud 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.10 2006/08/21 22:23:09 reinoud 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 	udf_vnodeopv_descs,
    147 	/* int vfs_refcount   */
    148 	/* LIST_ENTRY(vfsops) */
    149 };
    150 VFS_ATTACH(udf_vfsops);
    151 
    152 
    153 /* --------------------------------------------------------------------- */
    154 
    155 /* file system starts here */
    156 void
    157 udf_init(void)
    158 {
    159 	size_t size;
    160 
    161 #ifdef _LKM
    162 	malloc_type_attach(M_UDFMNT);
    163 	malloc_type_attach(M_UDFVOLD);
    164 	malloc_type_attach(M_UDFTEMP);
    165 #endif
    166 
    167 	/* init hashtables and pools */
    168 	size = sizeof(struct udf_node);
    169 	pool_init(&udf_node_pool, size, 0, 0, 0, "udf_node_pool", NULL);
    170 }
    171 
    172 /* --------------------------------------------------------------------- */
    173 
    174 void
    175 udf_reinit(void)
    176 {
    177 	/* recreate hashtables */
    178 	/* reinit pool? */
    179 }
    180 
    181 /* --------------------------------------------------------------------- */
    182 
    183 void
    184 udf_done(void)
    185 {
    186 	/* remove hashtables and pools */
    187 	pool_destroy(&udf_node_pool);
    188 
    189 #ifdef _LKM
    190 	malloc_type_detach(M_UDFMNT);
    191 	malloc_type_detach(M_UDFVOLD);
    192 	malloc_type_detach(M_UDFTEMP);
    193 #endif
    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 	ump = VFSTOUDF(mp);
    215 	if (ump) {
    216 		/* dispose of our descriptor pool */
    217 		pool_destroy(&ump->desc_pool);
    218 
    219 		/* clear our data */
    220 		mp->mnt_data = NULL;
    221 		for (i = 0; i < UDF_ANCHORS; i++)
    222 			MPFREE(ump->anchors[i], M_UDFVOLD);
    223 		MPFREE(ump->primary_vol,      M_UDFVOLD);
    224 		MPFREE(ump->logical_vol,      M_UDFVOLD);
    225 		MPFREE(ump->unallocated,      M_UDFVOLD);
    226 		MPFREE(ump->implementation,   M_UDFVOLD);
    227 		MPFREE(ump->logvol_integrity, M_UDFVOLD);
    228 		for (i = 0; i < UDF_PARTITIONS; i++)
    229 			MPFREE(ump->partitions[i], M_UDFVOLD);
    230 		MPFREE(ump->fileset_desc,     M_UDFVOLD);
    231 		MPFREE(ump->vat_table,        M_UDFVOLD);
    232 		MPFREE(ump->sparing_table,    M_UDFVOLD);
    233 
    234 		free(ump, M_UDFMNT);
    235 	}
    236 }
    237 #undef MPFREE
    238 
    239 /* --------------------------------------------------------------------- */
    240 
    241 int
    242 udf_mount(struct mount *mp, const char *path,
    243 	  void *data, struct nameidata *ndp, struct lwp *l)
    244 {
    245 	struct udf_args args;
    246 	struct udf_mount *ump;
    247 	struct vnode *devvp;
    248 	int openflags, accessmode, error;
    249 
    250 	DPRINTF(CALL, ("udf_mount called\n"));
    251 
    252 	if (mp->mnt_flag & MNT_GETARGS) {
    253 		/* request for the mount arguments */
    254 		ump = VFSTOUDF(mp);
    255 		if (ump == NULL)
    256 			return EINVAL;
    257 		return copyout(&ump->mount_args, data, sizeof(args));
    258 	}
    259 
    260 	/* handle request for updating mount parameters */
    261 	/* TODO can't update my mountpoint yet */
    262 	if (mp->mnt_flag & MNT_UPDATE) {
    263 		return EOPNOTSUPP;
    264 	}
    265 
    266 	/* OK, so we are asked to mount the device/file! */
    267 	error = copyin(data, &args, sizeof(struct udf_args));
    268 	if (error)
    269 		return error;
    270 
    271 	/* check/translate struct version */
    272 	/* TODO sanity checking other mount arguments */
    273 	if (args.version != 1) {
    274 		printf("mount_udf: unrecognized argument structure version\n");
    275 		return EINVAL;
    276 	}
    277 
    278 	/* lookup name to get its vnode */
    279 	NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, args.fspec, l);
    280 	error = namei(ndp);
    281 	if (error)
    282 		return error;
    283 
    284 	/* devvp is *locked* now */
    285 	devvp = ndp->ni_vp;
    286 #ifdef DEBUG
    287 	if (udf_verbose & UDF_DEBUG_VOLUMES)
    288 		vprint("UDF mount, trying to mount \n", devvp);
    289 #endif
    290 
    291 	/* check if its a block device specified */
    292 	if (devvp->v_type != VBLK) {
    293 		vrele(devvp);
    294 		return ENOTBLK;
    295 	}
    296 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    297 		vrele(devvp);
    298 		return ENXIO;
    299 	}
    300 
    301 	/* force read-only for now */
    302 	mp->mnt_flag |= MNT_RDONLY;
    303 
    304 	/*
    305 	 * If mount by non-root, then verify that user has necessary
    306 	 * permissions on the device.
    307 	 */
    308 	if (kauth_cred_geteuid(l->l_cred) != 0) {
    309 		accessmode = VREAD;
    310 		if ((mp->mnt_flag & MNT_RDONLY) == 0)
    311 			accessmode |= VWRITE;
    312 		error = VOP_ACCESS(devvp, accessmode, l->l_cred, l);
    313 		if (error) {
    314 			vput(devvp);
    315 			return (error);
    316 		}
    317 	}
    318 
    319 	/*
    320 	 * Disallow multiple mounts of the same device.  Disallow mounting of
    321 	 * a device that is currently in use (except for root, which might
    322 	 * share swap device for miniroot).
    323 	 */
    324 	error = vfs_mountedon(devvp);
    325 	if (error) {
    326 		vput(devvp);
    327 		return error;
    328 	}
    329 	if ((vcount(devvp) > 1) && (devvp != rootvp)) {
    330 		vput(devvp);
    331 		return EBUSY;
    332 	}
    333 
    334 	/*
    335 	 * Open device and try to mount it!
    336 	 */
    337 	if (mp->mnt_flag & MNT_RDONLY) {
    338 		openflags = FREAD;
    339 	} else {
    340 		openflags = FREAD | FWRITE;
    341 	}
    342 	error = VOP_OPEN(devvp, openflags, FSCRED, l);
    343 	if (error == 0) {
    344 		/* opened ok, try mounting */
    345 		error = udf_mountfs(devvp, mp, l, &args);
    346 		if (error) {
    347 			free_udf_mountinfo(mp);
    348 			/* devvp is still locked */
    349 			(void) VOP_CLOSE(devvp, openflags, NOCRED, l);
    350 		}
    351 	}
    352 	if (error) {
    353 		/* devvp is still locked */
    354 		vput(devvp);
    355 		return error;
    356 	}
    357 
    358 	/* register our mountpoint being on this device */
    359 	devvp->v_specmountpoint = mp;
    360 
    361 	/* successfully mounted */
    362 	DPRINTF(VOLUMES, ("udf_mount() successfull\n"));
    363 
    364 	/* unlock it but dont deref it */
    365 	VOP_UNLOCK(devvp, 0);
    366 
    367 	return set_statvfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE, mp, l);
    368 }
    369 
    370 /* --------------------------------------------------------------------- */
    371 
    372 #ifdef DEBUG
    373 static void
    374 udf_unmount_sanity_check(struct mount *mp)
    375 {
    376 	struct vnode *vp;
    377 
    378 	printf("On unmount, i found the following nodes:\n");
    379 	LIST_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
    380 		vprint("", vp);
    381 		if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) {
    382 			printf("  is locked\n");
    383 		}
    384 		if (vp->v_usecount > 1)
    385 			printf("  more than one usecount %d\n", vp->v_usecount);
    386 	}
    387 }
    388 #endif
    389 
    390 
    391 int
    392 udf_unmount(struct mount *mp, int mntflags, struct lwp *l)
    393 {
    394 	struct udf_mount *ump;
    395 	int error, flags, closeflags;
    396 
    397 	DPRINTF(CALL, ("udf_umount called\n"));
    398 
    399 	/*
    400 	 * By specifying SKIPSYSTEM we can skip vnodes marked with VSYSTEM.
    401 	 * This hardly documented feature allows us to exempt certain files
    402 	 * from being flushed.
    403 	 */
    404 	flags = SKIPSYSTEM;	/* allow for system vnodes to stay alive */
    405 	if (mntflags & MNT_FORCE)
    406 		flags |= FORCECLOSE;
    407 
    408 	ump = VFSTOUDF(mp);
    409 	if (!ump)
    410 		panic("UDF unmount: empty ump\n");
    411 
    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 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    419 		return error;
    420 
    421 #ifdef DEBUG
    422 	if (udf_verbose & UDF_DEBUG_LOCKING)
    423 		udf_unmount_sanity_check(mp);
    424 #endif
    425 
    426 	DPRINTF(VOLUMES, ("flush OK\n"));
    427 
    428 	/*
    429 	 * TODO close logical volume and close session if requested.
    430 	 *
    431 	 * XXX no system nodes defined yet.  Code to reclaim them is calling
    432 	 * VOP_RECLAIM on the nodes themselves.
    433 	 */
    434 
    435 	/* close device */
    436 	DPRINTF(VOLUMES, ("closing device\n"));
    437 	if (mp->mnt_flag & MNT_RDONLY) {
    438 		closeflags = FREAD;
    439 	} else {
    440 		closeflags = FREAD | FWRITE;
    441 	}
    442 
    443 	/* devvp is still locked by us */
    444 	vn_lock(ump->devvp, LK_EXCLUSIVE | LK_RETRY);
    445 	error = VOP_CLOSE(ump->devvp, closeflags, NOCRED, l);
    446 	if (error)
    447 		printf("Error during closure of device! error %d, "
    448 		       "device might stay locked\n", error);
    449 	DPRINTF(VOLUMES, ("device close ok\n"));
    450 
    451 	/* clear our mount reference and release device node */
    452 	ump->devvp->v_specmountpoint = NULL;
    453 	vput(ump->devvp);
    454 
    455 	/* free ump struct */
    456 	mp->mnt_data = NULL;
    457 	mp->mnt_flag &= ~MNT_LOCAL;
    458 
    459 	/* free up umt structure */
    460 	free_udf_mountinfo(mp);
    461 
    462 	DPRINTF(VOLUMES, ("Fin unmount\n"));
    463 	return error;
    464 }
    465 
    466 /* --------------------------------------------------------------------- */
    467 
    468 /*
    469  * Helper function of udf_mount() that actually mounts the disc.
    470  */
    471 
    472 static int
    473 udf_mountfs(struct vnode *devvp, struct mount *mp,
    474 	    struct lwp *l, struct udf_args *args)
    475 {
    476 	struct udf_mount     *ump;
    477 	uint32_t sector_size, lb_size, bshift;
    478 	int    num_anchors, error, lst;
    479 
    480 	/* flush out any old buffers remaining from a previous use. */
    481 	if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)))
    482 		return error;
    483 
    484 	/* allocate udf part of mount structure; malloc allways succeeds */
    485 	ump = malloc(sizeof(struct udf_mount), M_UDFMNT, M_WAITOK);
    486 	memset(ump, 0, sizeof(struct udf_mount));
    487 
    488 	/* init locks */
    489 	simple_lock_init(&ump->ihash_slock);
    490 	lockinit(&ump->get_node_lock, PINOD, "udf_getnode", 0, 0);
    491 
    492 	/* init `ino_t' to udf_node hash table */
    493 	for (lst = 0; lst < UDF_INODE_HASHSIZE; lst++) {
    494 		LIST_INIT(&ump->udf_nodes[lst]);
    495 	}
    496 
    497 	/* set up linkage */
    498 	mp->mnt_data    = ump;
    499 	ump->vfs_mountp = mp;
    500 
    501 	/* set up arguments and device */
    502 	ump->mount_args = *args;
    503 	ump->devvp      = devvp;
    504 	if ((error = udf_update_discinfo(ump))) {
    505 		printf("UDF mount: error inspecting fs node\n");
    506 		return error;
    507 	}
    508 
    509 	/* inspect sector size */
    510 	sector_size = ump->discinfo.sector_size;
    511 	bshift = 1;
    512 	while ((1 << bshift) < sector_size)
    513 		bshift++;
    514 	if ((1 << bshift) != sector_size) {
    515 		printf("UDF mount: "
    516 		       "hit NetBSD implementation fence on sector size\n");
    517 		return EIO;
    518 	}
    519 
    520 	/* read all anchors to get volume descriptor sequence */
    521 	num_anchors = udf_read_anchors(ump, args);
    522 	if (num_anchors == 0)
    523 		return ENOENT;
    524 
    525 	DPRINTF(VOLUMES, ("Read %d anchors on this disc, session %d\n",
    526 	    num_anchors, args->sessionnr));
    527 
    528 	/* read in volume descriptor sequence */
    529 	if ((error = udf_read_vds_space(ump))) {
    530 		printf("UDF mount: error reading volume space\n");
    531 		return error;
    532 	}
    533 
    534 	/* check consistency and completeness */
    535 	if ((error = udf_process_vds(ump, args))) {
    536 		printf("UDF mount: disc not properly formatted\n");
    537 		return error;
    538 	}
    539 
    540 	/*
    541 	 * Initialise pool for descriptors associated with nodes. This is done
    542 	 * in lb_size units though currently lb_size is dictated to be
    543 	 * sector_size.
    544 	 */
    545 	lb_size = udf_rw32(ump->logical_vol->lb_size);
    546 	pool_init(&ump->desc_pool, lb_size, 0, 0, 0, "udf_desc_pool", NULL);
    547 
    548 	/* read vds support tables like VAT, sparable etc. */
    549 	if ((error = udf_read_vds_tables(ump, args))) {
    550 		printf("UDF mount: error in format or damaged disc\n");
    551 		return error;
    552 	}
    553 
    554 	if ((error = udf_read_rootdirs(ump, args))) {
    555 		printf("UDF mount: "
    556 		       "disc not properly formatted or damaged disc\n");
    557 		return error;
    558 	}
    559 
    560 	/* setup rest of mount information */
    561 	mp->mnt_data = ump;
    562 	mp->mnt_stat.f_fsidx.__fsid_val[0] = (uint32_t) devvp->v_rdev;
    563 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_UDF);
    564 	mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
    565 	mp->mnt_stat.f_namemax = UDF_MAX_NAMELEN;
    566 	mp->mnt_flag |= MNT_LOCAL;
    567 
    568 	/* bshift is allways equal to disc sector size */
    569 	mp->mnt_dev_bshift = bshift;
    570 	mp->mnt_fs_bshift  = bshift;
    571 
    572 	/* do we have to set this? */
    573 	devvp->v_specmountpoint = mp;
    574 
    575 	/* success! */
    576 	return 0;
    577 }
    578 
    579 /* --------------------------------------------------------------------- */
    580 
    581 int
    582 udf_start(struct mount *mp, int flags, struct lwp *l)
    583 {
    584 	/* do we have to do something here? */
    585 	return 0;
    586 }
    587 
    588 /* --------------------------------------------------------------------- */
    589 
    590 int
    591 udf_root(struct mount *mp, struct vnode **vpp)
    592 {
    593 	struct vnode *vp;
    594 	struct long_ad *dir_loc;
    595 	struct udf_mount *ump = VFSTOUDF(mp);
    596 	struct udf_node *root_dir;
    597 	int error;
    598 
    599 	DPRINTF(CALL, ("udf_root called\n"));
    600 
    601 	dir_loc = &ump->fileset_desc->rootdir_icb;
    602 	error = udf_get_node(ump, dir_loc, &root_dir);
    603 
    604 	if (!root_dir)
    605 		error = ENOENT;
    606 	if (error)
    607 		return error;
    608 
    609 	vp = root_dir->vnode;
    610 	simple_lock(&vp->v_interlock);
    611 		root_dir->vnode->v_flag |= VROOT;
    612 	simple_unlock(&vp->v_interlock);
    613 
    614 	*vpp = vp;
    615 	return 0;
    616 }
    617 
    618 /* --------------------------------------------------------------------- */
    619 
    620 int
    621 udf_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg, struct lwp *l)
    622 {
    623 	DPRINTF(NOTIMPL, ("udf_quotactl called\n"));
    624 	return EOPNOTSUPP;
    625 }
    626 
    627 /* --------------------------------------------------------------------- */
    628 
    629 int
    630 udf_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
    631 {
    632 	struct udf_mount *ump = VFSTOUDF(mp);
    633 	struct logvol_int_desc *lvid;
    634 	struct udf_logvol_info *impl;
    635 	uint64_t freeblks, sizeblks;
    636 	uint32_t *pos1, *pos2;
    637 	int part, num_part;
    638 
    639 	DPRINTF(CALL, ("udf_statvfs called\n"));
    640 	sbp->f_flag   = mp->mnt_flag;
    641 	sbp->f_bsize  = ump->discinfo.sector_size;
    642 	sbp->f_frsize = ump->discinfo.sector_size;
    643 	sbp->f_iosize = ump->discinfo.sector_size;
    644 
    645 	/* TODO integrity locking */
    646 	/* free and used space for mountpoint based on logvol integrity */
    647 	lvid = ump->logvol_integrity;
    648 	if (lvid) {
    649 		num_part = udf_rw32(lvid->num_part);
    650 		impl = (struct udf_logvol_info *) (lvid->tables + 2*num_part);
    651 
    652 		freeblks = sizeblks = 0;
    653 		for (part=0; part < num_part; part++) {
    654 			pos1 = &lvid->tables[0] + part;
    655 			pos2 = &lvid->tables[0] + num_part + part;
    656 			if (udf_rw32(*pos1) != (uint32_t) -1) {
    657 				freeblks += udf_rw32(*pos1);
    658 				sizeblks += udf_rw32(*pos2);
    659 			}
    660 		}
    661 		sbp->f_blocks = sizeblks;
    662 		sbp->f_bfree  = freeblks;
    663 		sbp->f_files  = udf_rw32(impl->num_files);
    664 		sbp->f_files += udf_rw32(impl->num_directories);
    665 
    666 		/* XXX read only for now XXX */
    667 		sbp->f_bavail = 0;
    668 		sbp->f_bresvd = 0;
    669 
    670 		/* tricky, next only aplies to ffs i think, so set to zero */
    671 		sbp->f_ffree  = 0;
    672 		sbp->f_favail = 0;
    673 		sbp->f_fresvd = 0;
    674 	}
    675 
    676 	copy_statvfs_info(sbp, mp);
    677 	return 0;
    678 }
    679 
    680 /* --------------------------------------------------------------------- */
    681 
    682 int
    683 udf_sync(struct mount *mp, int waitfor, kauth_cred_t cred, struct lwp *p)
    684 {
    685 	DPRINTF(CALL, ("udf_sync called\n"));
    686 	/* nothing to be done as upto now read-only */
    687 	return 0;
    688 }
    689 
    690 /* --------------------------------------------------------------------- */
    691 
    692 /*
    693  * Get vnode for the file system type specific file id ino for the fs. Its
    694  * used for reference to files by unique ID and for NFSv3.
    695  * (optional) TODO lookup why some sources state NFSv3
    696  */
    697 int
    698 udf_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
    699 {
    700 	DPRINTF(NOTIMPL, ("udf_vget called\n"));
    701 	return EOPNOTSUPP;
    702 }
    703 
    704 /* --------------------------------------------------------------------- */
    705 
    706 /*
    707  * Lookup vnode for file handle specified
    708  */
    709 int
    710 udf_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
    711 {
    712 	DPRINTF(NOTIMPL, ("udf_fhtovp called\n"));
    713 	return EOPNOTSUPP;
    714 }
    715 
    716 /* --------------------------------------------------------------------- */
    717 
    718 /*
    719  * Create an unique file handle. Its structure is opaque and won't be used by
    720  * other subsystems. It should uniquely identify the file in the filingsystem
    721  * and enough information to know if a file has been removed and/or resources
    722  * have been recycled.
    723  */
    724 int
    725 udf_vptofh(struct vnode *vp, struct fid *fid, 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, struct timespec *tm)
    740 {
    741 	DPRINTF(NOTIMPL, ("udf_snapshot called\n"));
    742 	return EOPNOTSUPP;
    743 }
    744