1 /* $NetBSD: udf_vfsops.c,v 1.71 2015/08/24 08:31:56 hannken Exp $ */
4 * Copyright (c) 2006, 2008 Reinoud Zandijk
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.71 2015/08/24 08:31:56 hannken Exp $");
35 #if defined(_KERNEL_OPT)
36 #include "opt_compat_netbsd.h"
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/sysctl.h>
42 #include <sys/namei.h>
44 #include <sys/kernel.h>
45 #include <sys/vnode.h>
46 #include <miscfs/genfs/genfs.h>
47 #include <miscfs/specfs/specdev.h>
48 #include <sys/mount.h>
51 #include <sys/device.h>
52 #include <sys/disklabel.h>
53 #include <sys/ioctl.h>
54 #include <sys/malloc.h>
55 #include <sys/dirent.h>
58 #include <sys/kauth.h>
59 #include <sys/module.h>
61 #include <fs/udf/ecma167-udf.h>
62 #include <fs/udf/udf_mount.h>
63 #include <sys/dirhash.h>
67 #include "udf_bswap.h"
69 MODULE(MODULE_CLASS_VFS
, udf
, NULL
);
71 #define VTOI(vnode) ((struct udf_node *) vnode->v_data)
73 /* verbose levels of the udf filingsystem */
74 int udf_verbose
= UDF_DEBUGGING
;
77 MALLOC_JUSTDEFINE(M_UDFMNT
, "UDF mount", "UDF mount structures");
78 MALLOC_JUSTDEFINE(M_UDFVOLD
, "UDF volspace", "UDF volume space descriptors");
79 MALLOC_JUSTDEFINE(M_UDFTEMP
, "UDF temp", "UDF scrap space");
80 struct pool udf_node_pool
;
82 static struct sysctllog
*udf_sysctl_log
;
84 /* internal functions */
85 static int udf_mountfs(struct vnode
*, struct mount
*, struct lwp
*, struct udf_args
*);
88 /* --------------------------------------------------------------------- */
90 /* predefine vnode-op list descriptor */
91 extern const struct vnodeopv_desc udf_vnodeop_opv_desc
;
93 const struct vnodeopv_desc
* const udf_vnodeopv_descs
[] = {
94 &udf_vnodeop_opv_desc
,
99 /* vfsops descriptor linked in as anchor point for the filingsystem */
100 struct vfsops udf_vfsops
= {
101 .vfs_name
= MOUNT_UDF
,
102 .vfs_min_mount_data
= sizeof (struct udf_args
),
103 .vfs_mount
= udf_mount
,
104 .vfs_start
= udf_start
,
105 .vfs_unmount
= udf_unmount
,
106 .vfs_root
= udf_root
,
107 .vfs_quotactl
= (void *)eopnotsupp
,
108 .vfs_statvfs
= udf_statvfs
,
109 .vfs_sync
= udf_sync
,
110 .vfs_vget
= udf_vget
,
111 .vfs_loadvnode
= udf_loadvnode
,
112 .vfs_newvnode
= udf_newvnode
,
113 .vfs_fhtovp
= udf_fhtovp
,
114 .vfs_vptofh
= udf_vptofh
,
115 .vfs_init
= udf_init
,
116 .vfs_reinit
= udf_reinit
,
117 .vfs_done
= udf_done
,
118 .vfs_mountroot
= udf_mountroot
,
119 .vfs_snapshot
= udf_snapshot
,
120 .vfs_extattrctl
= vfs_stdextattrctl
,
121 .vfs_suspendctl
= (void *)eopnotsupp
,
122 .vfs_renamelock_enter
= genfs_renamelock_enter
,
123 .vfs_renamelock_exit
= genfs_renamelock_exit
,
124 .vfs_fsync
= (void *)eopnotsupp
,
125 .vfs_opv_descs
= udf_vnodeopv_descs
128 /* --------------------------------------------------------------------- */
130 /* file system starts here */
136 /* setup memory types */
137 malloc_type_attach(M_UDFMNT
);
138 malloc_type_attach(M_UDFVOLD
);
139 malloc_type_attach(M_UDFTEMP
);
141 /* init node pools */
142 size
= sizeof(struct udf_node
);
143 pool_init(&udf_node_pool
, size
, 0, 0, 0,
144 "udf_node_pool", NULL
, IPL_NONE
);
159 pool_destroy(&udf_node_pool
);
161 malloc_type_detach(M_UDFMNT
);
162 malloc_type_detach(M_UDFVOLD
);
163 malloc_type_detach(M_UDFTEMP
);
167 * If running a DEBUG kernel, provide an easy way to set the debug flags when
168 * running into a problem.
170 #define UDF_VERBOSE_SYSCTLOPT 1
173 udf_modcmd(modcmd_t cmd
, void *arg
)
175 const struct sysctlnode
*node
;
179 case MODULE_CMD_INIT
:
180 error
= vfs_attach(&udf_vfsops
);
184 * XXX the "24" below could be dynamic, thereby eliminating one
185 * more instance of the "number to vfs" mapping problem, but
186 * "24" is the order as taken from sys/mount.h
188 sysctl_createv(&udf_sysctl_log
, 0, NULL
, &node
,
191 SYSCTL_DESCR("OSTA Universal File System"),
193 CTL_VFS
, 24, CTL_EOL
);
195 sysctl_createv(&udf_sysctl_log
, 0, NULL
, &node
,
196 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
197 CTLTYPE_INT
, "verbose",
198 SYSCTL_DESCR("Bitmask for filesystem debugging"),
199 NULL
, 0, &udf_verbose
, 0,
200 CTL_VFS
, 24, UDF_VERBOSE_SYSCTLOPT
, CTL_EOL
);
203 case MODULE_CMD_FINI
:
204 error
= vfs_detach(&udf_vfsops
);
207 sysctl_teardown(&udf_sysctl_log
);
217 /* --------------------------------------------------------------------- */
225 /* --------------------------------------------------------------------- */
227 #define MPFREE(a, lst) \
228 if ((a)) free((a), lst);
230 free_udf_mountinfo(struct mount
*mp
)
232 struct udf_mount
*ump
;
241 for (i
= 0; i
< UDF_ANCHORS
; i
++)
242 MPFREE(ump
->anchors
[i
], M_UDFVOLD
);
243 MPFREE(ump
->primary_vol
, M_UDFVOLD
);
244 MPFREE(ump
->logical_vol
, M_UDFVOLD
);
245 MPFREE(ump
->unallocated
, M_UDFVOLD
);
246 MPFREE(ump
->implementation
, M_UDFVOLD
);
247 MPFREE(ump
->logvol_integrity
, M_UDFVOLD
);
248 for (i
= 0; i
< UDF_PARTITIONS
; i
++) {
249 MPFREE(ump
->partitions
[i
], M_UDFVOLD
);
250 MPFREE(ump
->part_unalloc_dscr
[i
], M_UDFVOLD
);
251 MPFREE(ump
->part_freed_dscr
[i
], M_UDFVOLD
);
253 MPFREE(ump
->metadata_unalloc_dscr
, M_UDFVOLD
);
255 MPFREE(ump
->fileset_desc
, M_UDFVOLD
);
256 MPFREE(ump
->sparing_table
, M_UDFVOLD
);
258 MPFREE(ump
->la_node_ad_cpy
, M_UDFMNT
);
259 MPFREE(ump
->la_pmapping
, M_TEMP
);
260 MPFREE(ump
->la_lmapping
, M_TEMP
);
262 mutex_destroy(&ump
->logvol_mutex
);
263 mutex_destroy(&ump
->allocate_mutex
);
264 mutex_destroy(&ump
->sync_lock
);
266 MPFREE(ump
->vat_table
, M_UDFVOLD
);
273 /* --------------------------------------------------------------------- */
275 /* if the system nodes exist, release them */
277 udf_release_system_nodes(struct mount
*mp
)
279 struct udf_mount
*ump
= VFSTOUDF(mp
);
282 /* if we haven't even got an ump, dont bother */
286 /* VAT partition support */
288 vrele(ump
->vat_node
->vnode
);
290 /* Metadata partition support */
291 if (ump
->metadata_node
)
292 vrele(ump
->metadata_node
->vnode
);
293 if (ump
->metadatamirror_node
)
294 vrele(ump
->metadatamirror_node
->vnode
);
295 if (ump
->metadatabitmap_node
)
296 vrele(ump
->metadatabitmap_node
->vnode
);
298 /* This flush should NOT write anything nor allow any node to remain */
299 if ((error
= vflush(ump
->vfs_mountp
, NULLVP
, 0)) != 0)
300 panic("Failure to flush UDF system vnodes\n");
305 udf_mount(struct mount
*mp
, const char *path
,
306 void *data
, size_t *data_len
)
308 struct lwp
*l
= curlwp
;
309 struct udf_args
*args
= data
;
310 struct udf_mount
*ump
;
312 int openflags
, accessmode
, error
;
314 DPRINTF(CALL
, ("udf_mount called\n"));
318 if (*data_len
< sizeof *args
)
321 if (mp
->mnt_flag
& MNT_GETARGS
) {
322 /* request for the mount arguments */
326 *args
= ump
->mount_args
;
327 *data_len
= sizeof *args
;
331 /* handle request for updating mount parameters */
332 /* TODO can't update my mountpoint yet */
333 if (mp
->mnt_flag
& MNT_UPDATE
) {
337 /* OK, so we are asked to mount the device */
339 /* check/translate struct version */
340 /* TODO sanity checking other mount arguments */
341 if (args
->version
!= 1) {
342 printf("mount_udf: unrecognized argument structure version\n");
346 /* lookup name to get its vnode */
347 error
= namei_simple_user(args
->fspec
,
348 NSM_FOLLOW_NOEMULROOT
, &devvp
);
353 if (udf_verbose
& UDF_DEBUG_VOLUMES
)
354 vprint("UDF mount, trying to mount \n", devvp
);
357 /* check if its a block device specified */
358 if (devvp
->v_type
!= VBLK
) {
362 if (bdevsw_lookup(devvp
->v_rdev
) == NULL
) {
368 * If mount by non-root, then verify that user has necessary
369 * permissions on the device.
372 if ((mp
->mnt_flag
& MNT_RDONLY
) == 0)
373 accessmode
|= VWRITE
;
374 vn_lock(devvp
, LK_EXCLUSIVE
| LK_RETRY
);
375 error
= kauth_authorize_system(l
->l_cred
, KAUTH_SYSTEM_MOUNT
,
376 KAUTH_REQ_SYSTEM_MOUNT_DEVICE
, mp
, devvp
, KAUTH_ARG(accessmode
));
384 * Open device and try to mount it!
386 if (mp
->mnt_flag
& MNT_RDONLY
) {
389 openflags
= FREAD
| FWRITE
;
391 vn_lock(devvp
, LK_EXCLUSIVE
| LK_RETRY
);
392 error
= VOP_OPEN(devvp
, openflags
, FSCRED
);
395 /* opened ok, try mounting */
396 error
= udf_mountfs(devvp
, mp
, l
, args
);
398 udf_release_system_nodes(mp
);
400 udf_discstrat_finish(VFSTOUDF(mp
));
401 free_udf_mountinfo(mp
);
402 vn_lock(devvp
, LK_EXCLUSIVE
| LK_RETRY
);
403 (void) VOP_CLOSE(devvp
, openflags
, NOCRED
);
408 /* devvp is still locked */
413 /* register our mountpoint being on this device */
414 spec_node_setmountedfs(devvp
, mp
);
416 /* successfully mounted */
417 DPRINTF(VOLUMES
, ("udf_mount() successfull\n"));
419 error
= set_statvfs_info(path
, UIO_USERSPACE
, args
->fspec
, UIO_USERSPACE
,
420 mp
->mnt_op
->vfs_name
, mp
, l
);
424 /* If we're not opened read-only, open its logical volume */
425 if ((mp
->mnt_flag
& MNT_RDONLY
) == 0) {
426 if ((error
= udf_open_logvol(VFSTOUDF(mp
))) != 0) {
427 printf( "mount_udf: can't open logical volume for "
428 "writing, downgrading access to read-only\n");
429 mp
->mnt_flag
|= MNT_RDONLY
;
430 /* FIXME we can't return error now on open failure */
438 /* --------------------------------------------------------------------- */
442 udf_sanity_selector(void *cl
, struct vnode
*vp
)
446 if (VOP_ISLOCKED(vp
) == LK_EXCLUSIVE
) {
447 printf(" is locked\n");
449 if (vp
->v_usecount
> 1)
450 printf(" more than one usecount %d\n", vp
->v_usecount
);
455 udf_unmount_sanity_check(struct mount
*mp
)
457 struct vnode_iterator
*marker
;
459 printf("On unmount, i found the following nodes:\n");
460 vfs_vnode_iterator_init(mp
, &marker
);
461 vfs_vnode_iterator_next(marker
, udf_sanity_selector
, NULL
);
462 vfs_vnode_iterator_destroy(marker
);
468 udf_unmount(struct mount
*mp
, int mntflags
)
470 struct udf_mount
*ump
;
471 int error
, flags
, closeflags
;
473 DPRINTF(CALL
, ("udf_umount called\n"));
477 panic("UDF unmount: empty ump\n");
479 flags
= (mntflags
& MNT_FORCE
) ? FORCECLOSE
: 0;
480 /* TODO remove these paranoid functions */
482 if (udf_verbose
& UDF_DEBUG_LOCKING
)
483 udf_unmount_sanity_check(mp
);
487 * By specifying SKIPSYSTEM we can skip vnodes marked with VV_SYSTEM.
488 * This hardly documented feature allows us to exempt certain files
489 * from being flushed.
491 if ((error
= vflush(mp
, NULLVP
, flags
| SKIPSYSTEM
)) != 0)
494 /* update nodes and wait for completion of writeout of system nodes */
495 udf_sync(mp
, FSYNC_WAIT
, NOCRED
);
498 if (udf_verbose
& UDF_DEBUG_LOCKING
)
499 udf_unmount_sanity_check(mp
);
502 /* flush again, to check if we are still busy for something else */
503 if ((error
= vflush(ump
->vfs_mountp
, NULLVP
, flags
| SKIPSYSTEM
)) != 0)
506 DPRINTF(VOLUMES
, ("flush OK on unmount\n"));
508 /* close logical volume and close session if requested */
509 if ((error
= udf_close_logvol(ump
, mntflags
)) != 0)
513 DPRINTF(VOLUMES
, ("FINAL sanity check\n"));
514 if (udf_verbose
& UDF_DEBUG_LOCKING
)
515 udf_unmount_sanity_check(mp
);
518 /* NOTE release system nodes should NOT write anything */
519 udf_release_system_nodes(mp
);
521 /* finalise disc strategy */
522 udf_discstrat_finish(ump
);
524 /* synchronise device caches */
525 (void) udf_synchronise_caches(ump
);
528 DPRINTF(VOLUMES
, ("closing device\n"));
529 if (mp
->mnt_flag
& MNT_RDONLY
) {
532 closeflags
= FREAD
| FWRITE
;
535 /* devvp is still locked by us */
536 vn_lock(ump
->devvp
, LK_EXCLUSIVE
| LK_RETRY
);
537 error
= VOP_CLOSE(ump
->devvp
, closeflags
, NOCRED
);
539 printf("Error during closure of device! error %d, "
540 "device might stay locked\n", error
);
541 DPRINTF(VOLUMES
, ("device close ok\n"));
543 /* clear our mount reference and release device node */
544 spec_node_setmountedfs(ump
->devvp
, NULL
);
548 free_udf_mountinfo(mp
);
550 /* free ump struct references */
552 mp
->mnt_flag
&= ~MNT_LOCAL
;
554 DPRINTF(VOLUMES
, ("Fin unmount\n"));
558 /* --------------------------------------------------------------------- */
561 * Helper function of udf_mount() that actually mounts the disc.
565 udf_mountfs(struct vnode
*devvp
, struct mount
*mp
,
566 struct lwp
*l
, struct udf_args
*args
)
568 struct udf_mount
*ump
;
569 uint32_t sector_size
, lb_size
, bshift
;
570 uint32_t logvol_integrity
;
571 int num_anchors
, error
;
573 /* flush out any old buffers remaining from a previous use. */
574 if ((error
= vinvalbuf(devvp
, V_SAVE
, l
->l_cred
, l
, 0, 0)))
577 /* setup basic mount information */
579 mp
->mnt_stat
.f_fsidx
.__fsid_val
[0] = (uint32_t) devvp
->v_rdev
;
580 mp
->mnt_stat
.f_fsidx
.__fsid_val
[1] = makefstype(MOUNT_UDF
);
581 mp
->mnt_stat
.f_fsid
= mp
->mnt_stat
.f_fsidx
.__fsid_val
[0];
582 mp
->mnt_stat
.f_namemax
= UDF_MAXNAMLEN
;
583 mp
->mnt_flag
|= MNT_LOCAL
;
584 // mp->mnt_iflag |= IMNT_MPSAFE;
586 /* allocate udf part of mount structure; malloc always succeeds */
587 ump
= malloc(sizeof(struct udf_mount
), M_UDFMNT
, M_WAITOK
| M_ZERO
);
590 mutex_init(&ump
->logvol_mutex
, MUTEX_DEFAULT
, IPL_NONE
);
591 mutex_init(&ump
->allocate_mutex
, MUTEX_DEFAULT
, IPL_NONE
);
592 mutex_init(&ump
->sync_lock
, MUTEX_DEFAULT
, IPL_NONE
);
594 /* init rbtree for nodes, ordered by their icb address (long_ad) */
595 udf_init_nodes_tree(ump
);
599 ump
->vfs_mountp
= mp
;
601 /* set up arguments and device */
602 ump
->mount_args
= *args
;
604 if ((error
= udf_update_discinfo(ump
))) {
605 printf("UDF mount: error inspecting fs node\n");
609 /* inspect sector size */
610 sector_size
= ump
->discinfo
.sector_size
;
612 while ((1 << bshift
) < sector_size
)
614 if ((1 << bshift
) != sector_size
) {
616 "hit NetBSD implementation fence on sector size\n");
620 /* temporary check to overcome sectorsize >= 8192 bytes panic */
621 if (sector_size
>= 8192) {
623 "hit implementation limit, sectorsize to big\n");
628 * Inspect if we're asked to mount read-write on a non recordable or
629 * closed sequential disc.
631 if ((mp
->mnt_flag
& MNT_RDONLY
) == 0) {
632 if ((ump
->discinfo
.mmc_cur
& MMC_CAP_RECORDABLE
) == 0) {
633 printf("UDF mount: disc is not recordable\n");
636 if (ump
->discinfo
.mmc_cur
& MMC_CAP_SEQUENTIAL
) {
637 if (ump
->discinfo
.disc_state
== MMC_STATE_FULL
) {
638 printf("UDF mount: disc is not appendable\n");
643 * TODO if the last session is closed check if there
644 * is enough space to open/close new session
647 /* double check if we're not mounting a pervious session RW */
648 if (args
->sessionnr
!= 0) {
649 printf("UDF mount: updating a previous session "
650 "not yet allowed\n");
655 /* initialise bootstrap disc strategy */
656 ump
->strategy
= &udf_strat_bootstrap
;
657 udf_discstrat_init(ump
);
659 /* read all anchors to get volume descriptor sequence */
660 num_anchors
= udf_read_anchors(ump
);
661 if (num_anchors
== 0)
664 DPRINTF(VOLUMES
, ("Read %d anchors on this disc, session %d\n",
665 num_anchors
, args
->sessionnr
));
667 /* read in volume descriptor sequence */
668 if ((error
= udf_read_vds_space(ump
))) {
669 printf("UDF mount: error reading volume space\n");
673 /* close down bootstrap disc strategy */
674 udf_discstrat_finish(ump
);
676 /* check consistency and completeness */
677 if ((error
= udf_process_vds(ump
))) {
678 printf( "UDF mount: disc not properly formatted"
683 /* switch to new disc strategy */
684 KASSERT(ump
->strategy
!= &udf_strat_bootstrap
);
685 udf_discstrat_init(ump
);
687 /* initialise late allocation administration space */
688 ump
->la_lmapping
= malloc(sizeof(uint64_t) * UDF_MAX_MAPPINGS
,
690 ump
->la_pmapping
= malloc(sizeof(uint64_t) * UDF_MAX_MAPPINGS
,
693 /* setup node cleanup extents copy space */
694 lb_size
= udf_rw32(ump
->logical_vol
->lb_size
);
695 ump
->la_node_ad_cpy
= malloc(lb_size
* UDF_MAX_ALLOC_EXTENTS
,
697 memset(ump
->la_node_ad_cpy
, 0, lb_size
* UDF_MAX_ALLOC_EXTENTS
);
699 /* setup rest of mount information */
702 /* bshift is allways equal to disc sector size */
703 mp
->mnt_dev_bshift
= bshift
;
704 mp
->mnt_fs_bshift
= bshift
;
706 /* note that the mp info needs to be initialised for reading! */
707 /* read vds support tables like VAT, sparable etc. */
708 if ((error
= udf_read_vds_tables(ump
))) {
709 printf( "UDF mount: error in format or damaged disc "
710 "(VDS tables failing)\n");
714 /* check if volume integrity is closed otherwise its dirty */
715 logvol_integrity
= udf_rw32(ump
->logvol_integrity
->integrity_type
);
716 if (logvol_integrity
!= UDF_INTEGRITY_CLOSED
) {
717 printf("UDF mount: file system is not clean; ");
718 printf("please fsck(8)\n");
722 /* read root directory */
723 if ((error
= udf_read_rootdirs(ump
))) {
724 printf( "UDF mount: "
725 "disc not properly formatted or damaged disc "
726 "(rootdirs failing)\n");
734 /* --------------------------------------------------------------------- */
737 udf_start(struct mount
*mp
, int flags
)
739 /* do we have to do something here? */
743 /* --------------------------------------------------------------------- */
746 udf_root(struct mount
*mp
, struct vnode
**vpp
)
749 struct long_ad
*dir_loc
;
750 struct udf_mount
*ump
= VFSTOUDF(mp
);
751 struct udf_node
*root_dir
;
754 DPRINTF(CALL
, ("udf_root called\n"));
756 dir_loc
= &ump
->fileset_desc
->rootdir_icb
;
757 error
= udf_get_node(ump
, dir_loc
, &root_dir
);
764 vp
= root_dir
->vnode
;
765 KASSERT(vp
->v_vflag
& VV_ROOT
);
771 /* --------------------------------------------------------------------- */
774 udf_statvfs(struct mount
*mp
, struct statvfs
*sbp
)
776 struct udf_mount
*ump
= VFSTOUDF(mp
);
777 struct logvol_int_desc
*lvid
;
778 struct udf_logvol_info
*impl
;
779 uint64_t freeblks
, sizeblks
;
782 DPRINTF(CALL
, ("udf_statvfs called\n"));
783 sbp
->f_flag
= mp
->mnt_flag
;
784 sbp
->f_bsize
= ump
->discinfo
.sector_size
;
785 sbp
->f_frsize
= ump
->discinfo
.sector_size
;
786 sbp
->f_iosize
= ump
->discinfo
.sector_size
;
788 mutex_enter(&ump
->allocate_mutex
);
790 udf_calc_freespace(ump
, &sizeblks
, &freeblks
);
792 sbp
->f_blocks
= sizeblks
;
793 sbp
->f_bfree
= freeblks
;
796 lvid
= ump
->logvol_integrity
;
797 num_part
= udf_rw32(lvid
->num_part
);
798 impl
= (struct udf_logvol_info
*) (lvid
->tables
+ 2*num_part
);
800 sbp
->f_files
= udf_rw32(impl
->num_files
);
801 sbp
->f_files
+= udf_rw32(impl
->num_directories
);
804 /* XXX read only for now XXX */
808 /* tricky, next only aplies to ffs i think, so set to zero */
813 mutex_exit(&ump
->allocate_mutex
);
815 copy_statvfs_info(sbp
, mp
);
819 /* --------------------------------------------------------------------- */
822 * TODO what about writing out free space maps, lvid etc? only on `waitfor'
823 * i.e. explicit syncing by the user?
827 udf_sync_writeout_system_files(struct udf_mount
*ump
, int clearflags
)
831 /* XXX lock for VAT en bitmaps? */
832 /* metadata nodes are written synchronous */
833 DPRINTF(CALL
, ("udf_sync: syncing metadata\n"));
834 if (ump
->lvclose
& UDF_WRITE_VAT
)
835 udf_writeout_vat(ump
);
838 if (ump
->lvclose
& UDF_WRITE_PART_BITMAPS
) {
839 /* writeout metadata spacetable if existing */
840 error
= udf_write_metadata_partition_spacetable(ump
, MNT_WAIT
);
842 printf( "udf_writeout_system_files : "
843 " writeout of metadata space bitmap failed\n");
845 /* writeout partition spacetables */
846 error
= udf_write_physical_partition_spacetables(ump
, MNT_WAIT
);
848 printf( "udf_writeout_system_files : "
849 "writeout of space tables failed\n");
850 if (!error
&& clearflags
)
851 ump
->lvclose
&= ~UDF_WRITE_PART_BITMAPS
;
859 udf_sync(struct mount
*mp
, int waitfor
, kauth_cred_t cred
)
861 struct udf_mount
*ump
= VFSTOUDF(mp
);
863 DPRINTF(CALL
, ("udf_sync called\n"));
864 /* if called when mounted readonly, just ignore */
865 if (mp
->mnt_flag
& MNT_RDONLY
)
868 if (ump
->syncing
&& !waitfor
) {
869 printf("UDF: skipping autosync\n");
877 udf_do_sync(ump
, cred
, waitfor
);
879 if (waitfor
== MNT_WAIT
)
880 udf_sync_writeout_system_files(ump
, true);
882 DPRINTF(CALL
, ("end of udf_sync()\n"));
888 /* --------------------------------------------------------------------- */
891 * Get vnode for the file system type specific file id ino for the fs. Its
892 * used for reference to files by unique ID and for NFSv3.
893 * (optional) TODO lookup why some sources state NFSv3
896 udf_vget(struct mount
*mp
, ino_t ino
,
899 DPRINTF(NOTIMPL
, ("udf_vget called\n"));
903 /* --------------------------------------------------------------------- */
906 * Lookup vnode for file handle specified
909 udf_fhtovp(struct mount
*mp
, struct fid
*fhp
,
912 DPRINTF(NOTIMPL
, ("udf_fhtovp called\n"));
916 /* --------------------------------------------------------------------- */
919 * Create an unique file handle. Its structure is opaque and won't be used by
920 * other subsystems. It should uniquely identify the file in the filingsystem
921 * and enough information to know if a file has been removed and/or resources
922 * have been recycled.
925 udf_vptofh(struct vnode
*vp
, struct fid
*fid
,
928 DPRINTF(NOTIMPL
, ("udf_vptofh called\n"));
932 /* --------------------------------------------------------------------- */
935 * Create a filingsystem snapshot at the specified timestamp. Could be
936 * implemented by explicitly creating a new session or with spare room in the
937 * integrity descriptor space
940 udf_snapshot(struct mount
*mp
, struct vnode
*vp
,
943 DPRINTF(NOTIMPL
, ("udf_snapshot called\n"));
947 /* --------------------------------------------------------------------- */