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