2 /* $NetBSD: msdosfs_vfsops.c,v 1.51 1997/11/17 15:36:58 ws Exp $ */
5 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
6 * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
8 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by TooLs GmbH.
21 * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Written by Paul Popelka (paulp@uts.amdahl.com)
38 * You can do anything you want with this software, just don't say you wrote
39 * it, and don't remove this notice.
41 * This software is provided "as is".
43 * The author supplies this software to be publicly redistributed on the
44 * understanding that the author is not responsible for the correct
45 * functioning of this software in any circumstances and is not liable for
46 * any damages caused by this software.
51 #include <sys/param.h>
52 #include <sys/systm.h>
54 #include <sys/namei.h>
56 #include <sys/kernel.h>
57 #include <sys/vnode.h>
58 #include <sys/mount.h>
61 #include <sys/fcntl.h>
62 #include <sys/malloc.h>
63 #include <sys/stat.h> /* defines ALLPERMS */
64 #include <sys/iconv.h>
65 #include <sys/mutex.h>
67 #include <fs/msdosfs/bpb.h>
68 #include <fs/msdosfs/bootsect.h>
69 #include <fs/msdosfs/msdosfsmount.h>
70 #include <fs/msdosfs/direntry.h>
71 #include <fs/msdosfs/denode.h>
72 #include <fs/msdosfs/fat.h>
74 #include <geom/geom.h>
75 #include <geom/geom_vfs.h>
77 #include "opt_msdosfs.h"
79 /* List of mount options we support */
80 static const char *msdosfs_opts[] = {
83 "uid", "gid", "mask", "dirmask",
84 "shortname", "longname", "win95",
85 "kiconv", "cs_win", "cs_dos", "cs_local",
89 #define MSDOSFS_DFLTBSIZE 4096
93 * XXX - The boot signature formatted by NEC PC-98 DOS looks like a
94 * garbage or a random value :-{
95 * If you want to use that broken-signatured media, define the
96 * following symbol even though PC/AT.
97 * (ex. mount PC-98 DOS formatted FD on PC/AT)
99 #define MSDOSFS_NOCHECKSIG
102 MALLOC_DEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOSFS mount structure");
103 static MALLOC_DEFINE(M_MSDOSFSFAT, "MSDOSFS FAT", "MSDOSFS file allocation table");
105 struct iconv_functions *msdosfs_iconv = NULL;
107 static int update_mp(struct mount *mp, struct thread *td);
108 static int mountmsdosfs(struct vnode *devvp, struct mount *mp,
110 static vfs_fhtovp_t msdosfs_fhtovp;
111 static vfs_mount_t msdosfs_mount;
112 static vfs_root_t msdosfs_root;
113 static vfs_statfs_t msdosfs_statfs;
114 static vfs_sync_t msdosfs_sync;
115 static vfs_unmount_t msdosfs_unmount;
116 static vfs_vptofh_t msdosfs_vptofh;
118 /* Maximum length of a character set name (arbitrary). */
126 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
127 void *dos, *win, *local;
130 if (!vfs_getopt(mp->mnt_optnew, "kiconv", NULL, NULL)) {
131 if (msdosfs_iconv != NULL) {
132 error = vfs_getopt(mp->mnt_optnew,
133 "cs_win", &win, NULL);
135 error = vfs_getopt(mp->mnt_optnew,
136 "cs_local", &local, NULL);
138 error = vfs_getopt(mp->mnt_optnew,
139 "cs_dos", &dos, NULL);
141 msdosfs_iconv->open(win, local, &pmp->pm_u2w);
142 msdosfs_iconv->open(local, win, &pmp->pm_w2u);
143 msdosfs_iconv->open(dos, local, &pmp->pm_u2d);
144 msdosfs_iconv->open(local, dos, &pmp->pm_d2u);
156 if (1 == vfs_scanopt(mp->mnt_optnew, "gid", "%d", &v))
158 if (1 == vfs_scanopt(mp->mnt_optnew, "uid", "%d", &v))
160 if (1 == vfs_scanopt(mp->mnt_optnew, "mask", "%d", &v))
161 pmp->pm_mask = v & ALLPERMS;
162 if (1 == vfs_scanopt(mp->mnt_optnew, "dirmask", "%d", &v))
163 pmp->pm_dirmask = v & ALLPERMS;
164 vfs_flagopt(mp->mnt_optnew, "shortname",
165 &pmp->pm_flags, MSDOSFSMNT_SHORTNAME);
166 vfs_flagopt(mp->mnt_optnew, "longname",
167 &pmp->pm_flags, MSDOSFSMNT_LONGNAME);
168 vfs_flagopt(mp->mnt_optnew, "kiconv",
169 &pmp->pm_flags, MSDOSFSMNT_KICONV);
171 /* XXX: Can't use flagopt due to negative option */
172 if (!vfs_getopt(mp->mnt_optnew, "win95", NULL, NULL))
173 pmp->pm_flags &= ~MSDOSFSMNT_NOWIN95;
175 pmp->pm_flags |= MSDOSFSMNT_NOWIN95;
177 if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
178 pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
179 else if (!(pmp->pm_flags &
180 (MSDOSFSMNT_SHORTNAME | MSDOSFSMNT_LONGNAME))) {
181 struct vnode *rootvp;
184 * Try to divine whether to support Win'95 long filenames
187 pmp->pm_flags |= MSDOSFSMNT_LONGNAME;
190 msdosfs_root(mp, LK_EXCLUSIVE, &rootvp, td)) != 0)
192 pmp->pm_flags |= findwin95(VTODE(rootvp))
193 ? MSDOSFSMNT_LONGNAME
194 : MSDOSFSMNT_SHORTNAME;
202 msdosfs_cmount(struct mntarg *ma, void *data, int flags, struct thread *td)
204 struct msdosfs_args args;
209 error = copyin(data, &args, sizeof args);
213 ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
214 ma = mount_arg(ma, "export", &args.export, sizeof args.export);
215 ma = mount_argf(ma, "uid", "%d", args.uid);
216 ma = mount_argf(ma, "gid", "%d", args.gid);
217 ma = mount_argf(ma, "mask", "%d", args.mask);
218 ma = mount_argf(ma, "dirmask", "%d", args.dirmask);
220 ma = mount_argb(ma, args.flags & MSDOSFSMNT_SHORTNAME, "noshortname");
221 ma = mount_argb(ma, args.flags & MSDOSFSMNT_LONGNAME, "nolongname");
222 ma = mount_argb(ma, !(args.flags & MSDOSFSMNT_NOWIN95), "nowin95");
223 ma = mount_argb(ma, args.flags & MSDOSFSMNT_KICONV, "nokiconv");
225 ma = mount_argsu(ma, "cs_win", args.cs_win, MAXCSLEN);
226 ma = mount_argsu(ma, "cs_dos", args.cs_dos, MAXCSLEN);
227 ma = mount_argsu(ma, "cs_local", args.cs_local, MAXCSLEN);
229 error = kernel_mount(ma, flags);
235 * mp - path - addr in user space of mount point (ie /usr or whatever)
236 * data - addr in user space of mount params including the name of the block
237 * special file to treat as a filesystem.
240 msdosfs_mount(struct mount *mp, struct thread *td)
242 struct vnode *devvp; /* vnode for blk device to mount */
243 struct export_args export;
244 /* msdosfs specific mount control block */
245 struct msdosfsmount *pmp = NULL;
246 struct nameidata ndp;
251 if (vfs_filteropt(mp->mnt_optnew, msdosfs_opts))
255 * If updating, check whether changing from read-only to
256 * read/write; if there is no device name, that's all we do.
258 if (mp->mnt_flag & MNT_UPDATE) {
259 pmp = VFSTOMSDOSFS(mp);
261 error = vfs_copyopt(mp->mnt_optnew, "export",
262 &export, sizeof export);
263 if (error == 0 && export.ex_flags != 0) {
265 * Process export requests.
267 if ((export.ex_flags & MNT_EXPORTED) != 0 &&
268 (pmp->pm_flags & MSDOSFS_LARGEFS) != 0)
270 return (vfs_export(mp, &export));
272 if (!(pmp->pm_flags & MSDOSFSMNT_RONLY) &&
273 vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0)) {
274 error = VFS_SYNC(mp, MNT_WAIT, td);
278 if (mp->mnt_flag & MNT_FORCE)
280 error = vflush(mp, 0, flags, td);
285 g_access(pmp->pm_cp, 0, -1, 0);
288 } else if ((pmp->pm_flags & MSDOSFSMNT_RONLY) &&
289 !vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0)) {
291 * If upgrade to read-write by non-root, then verify
292 * that user has necessary permissions on the device.
295 devvp = pmp->pm_devvp;
296 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
297 error = VOP_ACCESS(devvp, VREAD | VWRITE,
300 VOP_UNLOCK(devvp, 0, td);
303 VOP_UNLOCK(devvp, 0, td);
307 error = g_access(pmp->pm_cp, 0, 1, 0);
313 /* Now that the volume is modifiable, mark it dirty. */
314 error = markvoldirty(pmp, 1);
318 vfs_flagopt(mp->mnt_optnew, "ro",
319 &pmp->pm_flags, MSDOSFSMNT_RONLY);
320 vfs_flagopt(mp->mnt_optnew, "ro",
321 &mp->mnt_flag, MNT_RDONLY);
322 if (vfs_getopt(mp->mnt_optnew, "from", NULL, NULL)) {
323 #ifdef __notyet__ /* doesn't work correctly with current mountd XXX */
324 if (args.flags & MSDOSFSMNT_MNTOPT) {
325 pmp->pm_flags &= ~MSDOSFSMNT_MNTOPT;
326 pmp->pm_flags |= args.flags & MSDOSFSMNT_MNTOPT;
327 if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
328 pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
334 * Not an update, or updating the name: look up the name
335 * and verify that it refers to a sensible disk device.
337 if (vfs_getopt(mp->mnt_optnew, "from", (void **)&from, NULL))
339 NDINIT(&ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, from, td);
344 NDFREE(&ndp, NDF_ONLY_PNBUF);
346 if (!vn_isdisk(devvp, &error)) {
351 * If mount by non-root, then verify that user has necessary
352 * permissions on the device.
356 if ((mp->mnt_flag & MNT_RDONLY) == 0)
357 accessmode |= VWRITE;
358 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
359 error = VOP_ACCESS(devvp, accessmode, td->td_ucred, td);
364 VOP_UNLOCK(devvp, 0, td);
366 if ((mp->mnt_flag & MNT_UPDATE) == 0) {
367 error = mountmsdosfs(devvp, mp, td);
368 #ifdef MSDOSFS_DEBUG /* only needed for the printf below */
369 pmp = VFSTOMSDOSFS(mp);
372 if (devvp != pmp->pm_devvp)
373 error = EINVAL; /* XXX needs translation */
382 error = update_mp(mp, td);
384 if ((mp->mnt_flag & MNT_UPDATE) == 0)
385 msdosfs_unmount(mp, MNT_FORCE, td);
389 vfs_mountedfrom(mp, from);
391 printf("msdosfs_mount(): mp %p, pmp %p, inusemap %p\n", mp, pmp, pmp->pm_inusemap);
397 mountmsdosfs(devvp, mp, td)
402 struct msdosfsmount *pmp;
404 struct cdev *dev = devvp->v_rdev;
405 union bootsector *bsp;
406 struct byte_bpb33 *b33;
407 struct byte_bpb50 *b50;
408 struct byte_bpb710 *b710;
409 u_int8_t SecPerClust;
412 struct g_consumer *cp;
415 ronly = !vfs_getopt(mp->mnt_optnew, "ro", NULL, NULL);
416 /* XXX: use VOP_ACCESS to check FS perms */
419 error = g_vfs_open(devvp, &cp, "msdos", ronly ? 0 : 1);
422 VOP_UNLOCK(devvp, 0, td);
426 bo = &devvp->v_bufobj;
427 bp = NULL; /* both used in error_exit */
431 * Read the boot sector of the filesystem, and then check the
432 * boot signature. If not a dos boot sector then error out.
434 * NOTE: 2048 is a maximum sector size in current...
436 error = bread(devvp, 0, 2048, NOCRED, &bp);
439 bp->b_flags |= B_AGE;
440 bsp = (union bootsector *)bp->b_data;
441 b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
442 b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
443 b710 = (struct byte_bpb710 *)bsp->bs710.bsBPB;
445 #ifndef MSDOSFS_NOCHECKSIG
446 if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
447 || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
453 pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK | M_ZERO);
459 * Compute several useful quantities from the bpb in the
460 * bootsector. Copy in the dos 5 variant of the bpb then fix up
461 * the fields that are different between dos 5 and dos 3.3.
463 SecPerClust = b50->bpbSecPerClust;
464 pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec);
465 if (pmp->pm_BytesPerSec < DEV_BSIZE) {
469 pmp->pm_ResSectors = getushort(b50->bpbResSectors);
470 pmp->pm_FATs = b50->bpbFATs;
471 pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts);
472 pmp->pm_Sectors = getushort(b50->bpbSectors);
473 pmp->pm_FATsecs = getushort(b50->bpbFATsecs);
474 pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack);
475 pmp->pm_Heads = getushort(b50->bpbHeads);
476 pmp->pm_Media = b50->bpbMedia;
478 /* calculate the ratio of sector size to DEV_BSIZE */
479 pmp->pm_BlkPerSec = pmp->pm_BytesPerSec / DEV_BSIZE;
481 /* XXX - We should probably check more values here */
482 if (!pmp->pm_BytesPerSec || !SecPerClust
485 || !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 255) {
487 || !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 63) {
493 if (pmp->pm_Sectors == 0) {
494 pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
495 pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
497 pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs);
498 pmp->pm_HugeSectors = pmp->pm_Sectors;
500 #ifndef MSDOSFS_LARGE
501 if (pmp->pm_HugeSectors > 0xffffffff /
502 (pmp->pm_BytesPerSec / sizeof(struct direntry)) + 1) {
504 * We cannot deal currently with this size of disk
505 * due to fileid limitations (see msdosfs_getattr and
509 printf("mountmsdosfs(): disk too big, sorry\n");
512 #endif /* !MSDOSFS_LARGE */
514 if (pmp->pm_RootDirEnts == 0) {
515 if (bsp->bs710.bsBootSectSig2 != BOOTSIG2
516 || bsp->bs710.bsBootSectSig3 != BOOTSIG3
519 || getushort(b710->bpbFSVers)) {
521 printf("mountmsdosfs(): bad FAT32 filesystem\n");
524 pmp->pm_fatmask = FAT32_MASK;
527 pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs);
528 if (getushort(b710->bpbExtFlags) & FATMIRROR)
529 pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM;
531 pmp->pm_flags |= MSDOSFS_FATMIRROR;
533 pmp->pm_flags |= MSDOSFS_FATMIRROR;
536 * Check a few values (could do some more):
537 * - logical sector size: power of 2, >= block size
538 * - sectors per cluster: power of 2, >= 1
539 * - number of sectors: >= 1, <= size of partition
540 * - number of FAT sectors: >= 1
542 if ( (SecPerClust == 0)
543 || (SecPerClust & (SecPerClust - 1))
544 || (pmp->pm_BytesPerSec < DEV_BSIZE)
545 || (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1))
546 || (pmp->pm_HugeSectors == 0)
547 || (pmp->pm_FATsecs == 0)
553 pmp->pm_HugeSectors *= pmp->pm_BlkPerSec;
554 pmp->pm_HiddenSects *= pmp->pm_BlkPerSec; /* XXX not used? */
555 pmp->pm_FATsecs *= pmp->pm_BlkPerSec;
556 SecPerClust *= pmp->pm_BlkPerSec;
558 pmp->pm_fatblk = pmp->pm_ResSectors * pmp->pm_BlkPerSec;
561 pmp->pm_rootdirblk = getulong(b710->bpbRootClust);
562 pmp->pm_firstcluster = pmp->pm_fatblk
563 + (pmp->pm_FATs * pmp->pm_FATsecs);
564 pmp->pm_fsinfo = getushort(b710->bpbFSInfo) * pmp->pm_BlkPerSec;
566 pmp->pm_rootdirblk = pmp->pm_fatblk +
567 (pmp->pm_FATs * pmp->pm_FATsecs);
568 pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry)
570 / DEV_BSIZE; /* in blocks */
571 pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize;
574 pmp->pm_maxcluster = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
576 pmp->pm_fatsize = pmp->pm_FATsecs * DEV_BSIZE; /* XXX not used? */
578 if (pmp->pm_fatmask == 0) {
579 if (pmp->pm_maxcluster
580 <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) {
582 * This will usually be a floppy disk. This size makes
583 * sure that one fat entry will not be split across
586 pmp->pm_fatmask = FAT12_MASK;
590 pmp->pm_fatmask = FAT16_MASK;
596 clusters = (pmp->pm_fatsize / pmp->pm_fatmult) * pmp->pm_fatdiv;
597 if (pmp->pm_maxcluster >= clusters) {
598 printf("Warning: number of clusters (%ld) exceeds FAT "
599 "capacity (%ld)\n", pmp->pm_maxcluster + 1, clusters);
600 pmp->pm_maxcluster = clusters - 1;
605 pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec;
607 pmp->pm_fatblocksize = MSDOSFS_DFLTBSIZE;
609 pmp->pm_fatblocksec = pmp->pm_fatblocksize / DEV_BSIZE;
610 pmp->pm_bnshift = ffs(DEV_BSIZE) - 1;
613 * Compute mask and shift value for isolating cluster relative byte
614 * offsets and cluster numbers from a file offset.
616 pmp->pm_bpcluster = SecPerClust * DEV_BSIZE;
617 pmp->pm_crbomask = pmp->pm_bpcluster - 1;
618 pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1;
621 * Check for valid cluster size
622 * must be a power of 2
624 if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) {
630 * Release the bootsector buffer.
638 if (pmp->pm_fsinfo) {
641 if ((error = bread(devvp, pmp->pm_fsinfo, fsi_size(pmp),
644 fp = (struct fsinfo *)bp->b_data;
645 if (!bcmp(fp->fsisig1, "RRaA", 4)
646 && !bcmp(fp->fsisig2, "rrAa", 4)
647 && !bcmp(fp->fsisig3, "\0\0\125\252", 4)
648 && !bcmp(fp->fsisig4, "\0\0\125\252", 4)) {
649 pmp->pm_nxtfree = getulong(fp->fsinxtfree);
650 if (pmp->pm_nxtfree == 0xffffffff)
651 pmp->pm_nxtfree = CLUST_FIRST;
659 * Check and validate (or perhaps invalidate?) the fsinfo structure?
661 if (pmp->pm_fsinfo && pmp->pm_nxtfree > pmp->pm_maxcluster) {
663 "Next free cluster in FSInfo (%lu) exceeds maxcluster (%lu)\n",
664 pmp->pm_nxtfree, pmp->pm_maxcluster);
670 * Allocate memory for the bitmap of allocated clusters, and then
673 pmp->pm_inusemap = malloc(howmany(pmp->pm_maxcluster + 1, N_INUSEBITS)
674 * sizeof(*pmp->pm_inusemap),
675 M_MSDOSFSFAT, M_WAITOK);
678 * fillinusemap() needs pm_devvp.
680 pmp->pm_devvp = devvp;
683 * Have the inuse map filled in.
685 if ((error = fillinusemap(pmp)) != 0)
689 * If they want fat updates to be synchronous then let them suffer
690 * the performance degradation in exchange for the on disk copy of
691 * the fat being correct just about all the time. I suppose this
692 * would be a good thing to turn on if the kernel is still flakey.
694 if (mp->mnt_flag & MNT_SYNCHRONOUS)
695 pmp->pm_flags |= MSDOSFSMNT_WAITONFAT;
701 pmp->pm_flags |= MSDOSFSMNT_RONLY;
703 /* Mark the volume dirty while it is mounted read/write. */
704 if ((error = markvoldirty(pmp, 1)) != 0)
708 mp->mnt_data = (qaddr_t) pmp;
709 mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
710 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
711 mp->mnt_flag |= MNT_LOCAL;
714 msdosfs_fileno_init(mp);
730 if (pmp->pm_inusemap)
731 free(pmp->pm_inusemap, M_MSDOSFSFAT);
732 free(pmp, M_MSDOSFSMNT);
733 mp->mnt_data = (qaddr_t)0;
739 * Unmount the filesystem described by mp.
742 msdosfs_unmount(mp, mntflags, td)
747 struct msdosfsmount *pmp;
751 if (mntflags & MNT_FORCE)
753 error = vflush(mp, 0, flags, td);
756 pmp = VFSTOMSDOSFS(mp);
757 if (pmp->pm_flags & MSDOSFSMNT_KICONV && msdosfs_iconv) {
759 msdosfs_iconv->close(pmp->pm_w2u);
761 msdosfs_iconv->close(pmp->pm_u2w);
763 msdosfs_iconv->close(pmp->pm_d2u);
765 msdosfs_iconv->close(pmp->pm_u2d);
768 /* If the volume was mounted read/write, mark it clean now. */
769 if ((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0) {
770 error = markvoldirty(pmp, 0);
771 if (error && (flags & FORCECLOSE) == 0)
776 struct vnode *vp = pmp->pm_devvp;
780 "msdosfs_umount(): just before calling VOP_CLOSE()\n");
781 printf("freef %p, freeb %p, mount %p\n",
782 TAILQ_NEXT(vp, v_freelist), vp->v_freelist.tqe_prev,
784 printf("cleanblkhd %p, dirtyblkhd %p, numoutput %ld, type %d\n",
785 TAILQ_FIRST(&vp->v_bufobj.bo_clean.bv_hd),
786 TAILQ_FIRST(&vp->v_bufobj.bo_dirty.bv_hd),
787 vp->v_bufobj.bo_numoutput, vp->v_type);
793 g_vfs_close(pmp->pm_cp, td);
796 vrele(pmp->pm_devvp);
797 free(pmp->pm_inusemap, M_MSDOSFSFAT);
799 msdosfs_fileno_free(mp);
801 free(pmp, M_MSDOSFSMNT);
802 mp->mnt_data = (qaddr_t)0;
803 mp->mnt_flag &= ~MNT_LOCAL;
808 msdosfs_root(mp, flags, vpp, td)
814 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
819 printf("msdosfs_root(); mp %p, pmp %p\n", mp, pmp);
821 error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep);
829 msdosfs_statfs(mp, sbp, td)
834 struct msdosfsmount *pmp;
836 pmp = VFSTOMSDOSFS(mp);
837 sbp->f_bsize = pmp->pm_bpcluster;
838 sbp->f_iosize = pmp->pm_bpcluster;
839 sbp->f_blocks = pmp->pm_maxcluster + 1;
840 sbp->f_bfree = pmp->pm_freeclustercount;
841 sbp->f_bavail = pmp->pm_freeclustercount;
842 sbp->f_files = pmp->pm_RootDirEnts; /* XXX */
843 sbp->f_ffree = 0; /* what to put in here? */
848 msdosfs_sync(mp, waitfor, td)
853 struct vnode *vp, *nvp;
855 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
856 int error, allerror = 0;
859 * If we ever switch to not updating all of the fats all the time,
860 * this would be the place to update them from the first one.
862 if (pmp->pm_fmod != 0) {
863 if (pmp->pm_flags & MSDOSFSMNT_RONLY)
864 panic("msdosfs_sync: rofs mod");
866 /* update fats here */
870 * Write back each (modified) denode.
874 MNT_VNODE_FOREACH(vp, mp, nvp) {
876 if (vp->v_type == VNON || (vp->v_iflag & VI_DOOMED)) {
883 (DE_ACCESS | DE_CREATE | DE_UPDATE | DE_MODIFIED)) == 0 &&
884 (vp->v_bufobj.bo_dirty.bv_cnt == 0 ||
885 waitfor == MNT_LAZY)) {
890 error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, td);
897 error = VOP_FSYNC(vp, waitfor, td);
900 VOP_UNLOCK(vp, 0, td);
907 * Flush filesystem control info.
909 if (waitfor != MNT_LAZY) {
910 vn_lock(pmp->pm_devvp, LK_EXCLUSIVE | LK_RETRY, td);
911 error = VOP_FSYNC(pmp->pm_devvp, waitfor, td);
914 VOP_UNLOCK(pmp->pm_devvp, 0, td);
920 msdosfs_fhtovp(mp, fhp, vpp)
925 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
926 struct defid *defhp = (struct defid *) fhp;
930 error = deget(pmp, defhp->defid_dirclust, defhp->defid_dirofs, &dep);
936 vnode_create_vobject(*vpp, dep->de_FileSize, curthread);
941 msdosfs_vptofh(vp, fhp)
949 defhp = (struct defid *)fhp;
950 defhp->defid_len = sizeof(struct defid);
951 defhp->defid_dirclust = dep->de_dirclust;
952 defhp->defid_dirofs = dep->de_diroffset;
953 /* defhp->defid_gen = dep->de_gen; */
957 static struct vfsops msdosfs_vfsops = {
958 .vfs_fhtovp = msdosfs_fhtovp,
959 .vfs_mount = msdosfs_mount,
960 .vfs_cmount = msdosfs_cmount,
961 .vfs_root = msdosfs_root,
962 .vfs_statfs = msdosfs_statfs,
963 .vfs_sync = msdosfs_sync,
964 .vfs_unmount = msdosfs_unmount,
965 .vfs_vptofh = msdosfs_vptofh,
968 VFS_SET(msdosfs_vfsops, msdosfs, 0);
969 MODULE_VERSION(msdosfs, 1);