1 /* $FreeBSD: src/sys/msdosfs/msdosfs_vfsops.c,v 1.60.2.6 2002/09/12 21:33:38 trhodes Exp $ */
2 /* $DragonFly: src/sys/vfs/msdosfs/msdosfs_vfsops.c,v 1.11 2004/03/01 06:33:21 dillon Exp $ */
3 /* $NetBSD: msdosfs_vfsops.c,v 1.51 1997/11/17 15:36:58 ws Exp $ */
6 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
7 * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
9 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by TooLs GmbH.
22 * 4. The name of TooLs GmbH may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Written by Paul Popelka (paulp@uts.amdahl.com)
39 * You can do anything you want with this software, just don't say you wrote
40 * it, and don't remove this notice.
42 * This software is provided "as is".
44 * The author supplies this software to be publicly redistributed on the
45 * understanding that the author is not responsible for the correct
46 * functioning of this software in any circumstances and is not liable for
47 * any damages caused by this software.
52 #include <sys/param.h>
53 #include <sys/systm.h>
56 #include <sys/namei.h>
57 #include <sys/kernel.h>
58 #include <sys/vnode.h>
59 #include <sys/mount.h>
61 #include <sys/fcntl.h>
62 #include <sys/malloc.h>
63 #include <sys/stat.h> /* defines ALLPERMS */
64 #include <vm/vm_zone.h>
70 #include "msdosfsmount.h"
73 #define MSDOSFS_DFLTBSIZE 4096
77 * XXX - The boot signature formatted by NEC PC-98 DOS looks like a
78 * garbage or a random value :-{
79 * If you want to use that broken-signatured media, define the
80 * following symbol even though PC/AT.
81 * (ex. mount PC-98 DOS formatted FD on PC/AT)
83 #define MSDOSFS_NOCHECKSIG
86 MALLOC_DEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOSFS mount structure");
87 static MALLOC_DEFINE(M_MSDOSFSFAT, "MSDOSFS FAT", "MSDOSFS file allocation table");
89 static int update_mp (struct mount *mp, struct msdosfs_args *argp);
90 static int mountmsdosfs (struct vnode *devvp, struct mount *mp,
91 struct thread *td, struct msdosfs_args *argp);
92 static int msdosfs_fhtovp (struct mount *, struct fid *,
94 static int msdosfs_checkexp (struct mount *, struct sockaddr *,
95 int *, struct ucred **);
96 static int msdosfs_mount (struct mount *, char *, caddr_t,
97 struct nameidata *, struct thread *);
98 static int msdosfs_root (struct mount *, struct vnode **);
99 static int msdosfs_statfs (struct mount *, struct statfs *,
101 static int msdosfs_sync (struct mount *, int, struct thread *);
102 static int msdosfs_unmount (struct mount *, int, struct thread *);
103 static int msdosfs_vptofh (struct vnode *, struct fid *);
108 struct msdosfs_args *argp;
110 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
113 pmp->pm_gid = argp->gid;
114 pmp->pm_uid = argp->uid;
115 pmp->pm_mask = argp->mask & ALLPERMS;
116 pmp->pm_flags |= argp->flags & MSDOSFSMNT_MNTOPT;
117 if (pmp->pm_flags & MSDOSFSMNT_U2WTABLE) {
118 bcopy(argp->u2w, pmp->pm_u2w, sizeof(pmp->pm_u2w));
119 bcopy(argp->d2u, pmp->pm_d2u, sizeof(pmp->pm_d2u));
120 bcopy(argp->u2d, pmp->pm_u2d, sizeof(pmp->pm_u2d));
122 if (pmp->pm_flags & MSDOSFSMNT_ULTABLE) {
123 bcopy(argp->ul, pmp->pm_ul, sizeof(pmp->pm_ul));
124 bcopy(argp->lu, pmp->pm_lu, sizeof(pmp->pm_lu));
127 #ifndef __DragonFly__
129 * GEMDOS knows nothing (yet) about win95
131 if (pmp->pm_flags & MSDOSFSMNT_GEMDOSFS)
132 pmp->pm_flags |= MSDOSFSMNT_NOWIN95;
135 if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
136 pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
137 else if (!(pmp->pm_flags &
138 (MSDOSFSMNT_SHORTNAME | MSDOSFSMNT_LONGNAME))) {
139 struct vnode *rootvp;
142 * Try to divine whether to support Win'95 long filenames
145 pmp->pm_flags |= MSDOSFSMNT_LONGNAME;
147 if ((error = msdosfs_root(mp, &rootvp)) != 0)
149 pmp->pm_flags |= findwin95(VTODE(rootvp))
150 ? MSDOSFSMNT_LONGNAME
151 : MSDOSFSMNT_SHORTNAME;
158 #ifndef __DragonFly__
163 struct thread *td = curthread; /* XXX */
166 struct msdosfs_args args;
168 if (root_device->dv_class != DV_DISK)
172 * Get vnodes for swapdev and rootdev.
174 if (bdevvp(rootdev, &rootvp))
175 panic("msdosfs_mountroot: can't setup rootvp");
177 mp = malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK);
178 bzero((char *)mp, (u_long)sizeof(struct mount));
179 mp->mnt_op = &msdosfs_vfsops;
181 TAILQ_INIT(&mp->mnt_nvnodelist);
182 TAILQ_INIT(&mp->mnt_reservedvnlist);
189 if ((error = mountmsdosfs(rootvp, mp, p, &args)) != 0) {
194 if ((error = update_mp(mp, &args)) != 0) {
195 (void)msdosfs_unmount(mp, 0, p);
200 if ((error = vfs_lock(mp)) != 0) {
201 (void)msdosfs_unmount(mp, 0, p);
206 TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
207 mp->mnt_vnodecovered = NULLVP;
208 (void) copystr("/", mp->mnt_stat.f_mntonname, MNAMELEN - 1,
210 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
211 (void) copystr(ROOTNAME, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
213 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
214 (void)msdosfs_statfs(mp, &mp->mnt_stat, p);
221 * mp - path - addr in user space of mount point (ie /usr or whatever)
222 * data - addr in user space of mount params including the name of the block
223 * special file to treat as a filesystem.
226 msdosfs_mount(mp, path, data, ndp, td)
230 struct nameidata *ndp;
233 struct vnode *devvp; /* vnode for blk device to mount */
234 struct msdosfs_args args; /* will hold data from mount request */
235 /* msdosfs specific mount control block */
236 struct msdosfsmount *pmp = NULL;
240 struct proc *p = td->td_proc;
244 error = copyin(data, (caddr_t)&args, sizeof(struct msdosfs_args));
247 if (args.magic != MSDOSFS_ARGSMAGIC)
250 * If updating, check whether changing from read-only to
251 * read/write; if there is no device name, that's all we do.
253 if (mp->mnt_flag & MNT_UPDATE) {
254 pmp = VFSTOMSDOSFS(mp);
256 if (!(pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_flag & MNT_RDONLY)) {
258 if (mp->mnt_flag & MNT_FORCE)
260 error = vflush(mp, 0, flags);
262 if (!error && (mp->mnt_flag & MNT_RELOAD))
263 /* not yet implemented */
267 if ((pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
269 * If upgrade to read-write by non-root, then verify
270 * that user has necessary permissions on the device.
272 if (p->p_ucred->cr_uid != 0) {
273 devvp = pmp->pm_devvp;
274 vn_lock(devvp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
275 error = VOP_ACCESS(devvp, VREAD | VWRITE,
278 VOP_UNLOCK(devvp, NULL, 0, td);
281 VOP_UNLOCK(devvp, NULL, 0, td);
283 pmp->pm_flags &= ~MSDOSFSMNT_RONLY;
285 if (args.fspec == 0) {
286 #ifdef __notyet__ /* doesn't work correctly with current mountd XXX */
287 if (args.flags & MSDOSFSMNT_MNTOPT) {
288 pmp->pm_flags &= ~MSDOSFSMNT_MNTOPT;
289 pmp->pm_flags |= args.flags & MSDOSFSMNT_MNTOPT;
290 if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
291 pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
295 * Process export requests.
297 return (vfs_export(mp, &pmp->pm_export, &args.export));
301 * Not an update, or updating the name: look up the name
302 * and verify that it refers to a sensible block device.
304 NDINIT(ndp, NAMEI_LOOKUP, CNP_FOLLOW, UIO_USERSPACE, args.fspec, td);
309 NDFREE(ndp, NDF_ONLY_PNBUF);
311 if (!vn_isdisk(devvp, &error)) {
316 * If mount by non-root, then verify that user has necessary
317 * permissions on the device.
319 if (p->p_ucred->cr_uid != 0) {
321 if ((mp->mnt_flag & MNT_RDONLY) == 0)
322 accessmode |= VWRITE;
323 vn_lock(devvp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
324 error = VOP_ACCESS(devvp, accessmode, p->p_ucred, td);
329 VOP_UNLOCK(devvp, NULL, 0, td);
331 if ((mp->mnt_flag & MNT_UPDATE) == 0) {
332 error = mountmsdosfs(devvp, mp, td, &args);
333 #ifdef MSDOSFS_DEBUG /* only needed for the printf below */
334 pmp = VFSTOMSDOSFS(mp);
337 if (devvp != pmp->pm_devvp)
338 error = EINVAL; /* XXX needs translation */
347 error = update_mp(mp, &args);
349 msdosfs_unmount(mp, MNT_FORCE, td);
353 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
354 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
355 (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
357 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
358 (void) msdosfs_statfs(mp, &mp->mnt_stat, td);
360 printf("msdosfs_mount(): mp %p, pmp %p, inusemap %p\n", mp, pmp, pmp->pm_inusemap);
366 mountmsdosfs(devvp, mp, td, argp)
370 struct msdosfs_args *argp;
372 struct msdosfsmount *pmp;
374 dev_t dev = devvp->v_rdev;
375 #ifndef __DragonFly__
376 struct partinfo dpart;
377 int bsize = 0, dtype = 0, tmp;
379 union bootsector *bsp;
380 struct byte_bpb33 *b33;
381 struct byte_bpb50 *b50;
382 struct byte_bpb710 *b710;
383 u_int8_t SecPerClust;
388 * Disallow multiple mounts of the same device.
389 * Disallow mounting of a device that is currently in use
390 * (except for root, which might share swap device for miniroot).
391 * Flush out any old buffers remaining from a previous use.
393 error = vfs_mountedon(devvp);
396 if (vcount(devvp) > 1 && devvp != rootvp)
398 vn_lock(devvp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
399 error = vinvalbuf(devvp, V_SAVE, td, 0, 0);
400 VOP_UNLOCK(devvp, NULL, 0, td);
404 ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
405 vn_lock(devvp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
406 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, td);
407 VOP_UNLOCK(devvp, NULL, 0, td);
411 bp = NULL; /* both used in error_exit */
414 #ifndef __DragonFly__
415 if (argp->flags & MSDOSFSMNT_GEMDOSFS) {
417 * We need the disklabel to calculate the size of a FAT entry
418 * later on. Also make sure the partition contains a filesystem
419 * of type FS_MSDOS. This doesn't work for floppies, so we have
420 * to check for them too.
422 * At least some parts of the msdos fs driver seem to assume
423 * that the size of a disk block will always be 512 bytes.
426 error = VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, td);
429 tmp = dpart.part->p_fstype;
430 dtype = dpart.disklab->d_type;
431 bsize = dpart.disklab->d_secsize;
432 if (bsize != 512 || (dtype!=DTYPE_FLOPPY && tmp!=FS_MSDOS)) {
440 * Read the boot sector of the filesystem, and then check the
441 * boot signature. If not a dos boot sector then error out.
443 * NOTE: 2048 is a maximum sector size in current...
445 error = bread(devvp, 0, 2048, &bp);
448 bp->b_flags |= B_AGE;
449 bsp = (union bootsector *)bp->b_data;
450 b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
451 b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
452 b710 = (struct byte_bpb710 *)bsp->bs710.bsPBP;
454 #ifndef __DragonFly__
455 if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) {
457 #ifndef MSDOSFS_NOCHECKSIG
458 if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
459 || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
464 #ifndef __DragonFly__
468 pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK);
469 bzero((caddr_t)pmp, sizeof *pmp);
473 * Compute several useful quantities from the bpb in the
474 * bootsector. Copy in the dos 5 variant of the bpb then fix up
475 * the fields that are different between dos 5 and dos 3.3.
477 SecPerClust = b50->bpbSecPerClust;
478 pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec);
479 pmp->pm_ResSectors = getushort(b50->bpbResSectors);
480 pmp->pm_FATs = b50->bpbFATs;
481 pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts);
482 pmp->pm_Sectors = getushort(b50->bpbSectors);
483 pmp->pm_FATsecs = getushort(b50->bpbFATsecs);
484 pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack);
485 pmp->pm_Heads = getushort(b50->bpbHeads);
486 pmp->pm_Media = b50->bpbMedia;
488 /* calculate the ratio of sector size to DEV_BSIZE */
489 pmp->pm_BlkPerSec = pmp->pm_BytesPerSec / DEV_BSIZE;
491 #ifndef __DragonFly__
492 if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) {
494 /* XXX - We should probably check more values here */
495 if (!pmp->pm_BytesPerSec || !SecPerClust
496 || !pmp->pm_Heads || pmp->pm_Heads > 255
498 || !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 255) {
500 || !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 63) {
505 #ifndef __DragonFly__
509 if (pmp->pm_Sectors == 0) {
510 pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
511 pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
513 pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs);
514 pmp->pm_HugeSectors = pmp->pm_Sectors;
516 if (pmp->pm_HugeSectors > 0xffffffff /
517 (pmp->pm_BytesPerSec / sizeof(struct direntry)) + 1) {
519 * We cannot deal currently with this size of disk
520 * due to fileid limitations (see msdosfs_getattr and
524 printf("mountmsdosfs(): disk too big, sorry\n");
528 if (pmp->pm_RootDirEnts == 0) {
529 if (bsp->bs710.bsBootSectSig2 != BOOTSIG2
530 || bsp->bs710.bsBootSectSig3 != BOOTSIG3
533 || getushort(b710->bpbFSVers)) {
535 printf("mountmsdosfs(): bad FAT32 filesystem\n");
538 pmp->pm_fatmask = FAT32_MASK;
541 pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs);
542 if (getushort(b710->bpbExtFlags) & FATMIRROR)
543 pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM;
545 pmp->pm_flags |= MSDOSFS_FATMIRROR;
547 pmp->pm_flags |= MSDOSFS_FATMIRROR;
550 * Check a few values (could do some more):
551 * - logical sector size: power of 2, >= block size
552 * - sectors per cluster: power of 2, >= 1
553 * - number of sectors: >= 1, <= size of partition
555 if ( (SecPerClust == 0)
556 || (SecPerClust & (SecPerClust - 1))
557 || (pmp->pm_BytesPerSec < DEV_BSIZE)
558 || (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1))
559 || (pmp->pm_HugeSectors == 0)
565 pmp->pm_HugeSectors *= pmp->pm_BlkPerSec;
566 pmp->pm_HiddenSects *= pmp->pm_BlkPerSec; /* XXX not used? */
567 pmp->pm_FATsecs *= pmp->pm_BlkPerSec;
568 SecPerClust *= pmp->pm_BlkPerSec;
570 pmp->pm_fatblk = pmp->pm_ResSectors * pmp->pm_BlkPerSec;
573 pmp->pm_rootdirblk = getulong(b710->bpbRootClust);
574 pmp->pm_firstcluster = pmp->pm_fatblk
575 + (pmp->pm_FATs * pmp->pm_FATsecs);
576 pmp->pm_fsinfo = getushort(b710->bpbFSInfo) * pmp->pm_BlkPerSec;
578 pmp->pm_rootdirblk = pmp->pm_fatblk +
579 (pmp->pm_FATs * pmp->pm_FATsecs);
580 pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry)
582 / DEV_BSIZE; /* in blocks */
583 pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize;
586 pmp->pm_maxcluster = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
588 pmp->pm_fatsize = pmp->pm_FATsecs * DEV_BSIZE; /* XXX not used? */
590 #ifndef __DragonFly__
591 if (argp->flags & MSDOSFSMNT_GEMDOSFS) {
592 if ((pmp->pm_maxcluster <= (0xff0 - 2))
593 && ((dtype == DTYPE_FLOPPY) || ((dtype == DTYPE_VNODE)
594 && ((pmp->pm_Heads == 1) || (pmp->pm_Heads == 2))))
596 pmp->pm_fatmask = FAT12_MASK;
600 pmp->pm_fatmask = FAT16_MASK;
606 if (pmp->pm_fatmask == 0) {
607 if (pmp->pm_maxcluster
608 <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) {
610 * This will usually be a floppy disk. This size makes
611 * sure that one fat entry will not be split across
614 pmp->pm_fatmask = FAT12_MASK;
618 pmp->pm_fatmask = FAT16_MASK;
624 clusters = (pmp->pm_fatsize / pmp->pm_fatmult) * pmp->pm_fatdiv;
625 if (pmp->pm_maxcluster >= clusters) {
626 printf("Warning: number of clusters (%ld) exceeds FAT "
627 "capacity (%ld)\n", pmp->pm_maxcluster + 1, clusters);
628 pmp->pm_maxcluster = clusters - 1;
633 pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec;
635 pmp->pm_fatblocksize = MSDOSFS_DFLTBSIZE;
637 pmp->pm_fatblocksec = pmp->pm_fatblocksize / DEV_BSIZE;
638 pmp->pm_bnshift = ffs(DEV_BSIZE) - 1;
641 * Compute mask and shift value for isolating cluster relative byte
642 * offsets and cluster numbers from a file offset.
644 pmp->pm_bpcluster = SecPerClust * DEV_BSIZE;
645 pmp->pm_crbomask = pmp->pm_bpcluster - 1;
646 pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1;
649 * Check for valid cluster size
650 * must be a power of 2
652 if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) {
658 * Release the bootsector buffer.
666 if (pmp->pm_fsinfo) {
669 if ((error = bread(devvp, pmp->pm_fsinfo, fsi_size(pmp), &bp)) != 0)
671 fp = (struct fsinfo *)bp->b_data;
672 if (!bcmp(fp->fsisig1, "RRaA", 4)
673 && !bcmp(fp->fsisig2, "rrAa", 4)
674 && !bcmp(fp->fsisig3, "\0\0\125\252", 4)
675 && !bcmp(fp->fsisig4, "\0\0\125\252", 4))
676 pmp->pm_nxtfree = getulong(fp->fsinxtfree);
684 * Check and validate (or perhaps invalidate?) the fsinfo structure?
686 if (pmp->pm_fsinfo && pmp->pm_nxtfree > pmp->pm_maxcluster) {
688 "Next free cluster in FSInfo (%lu) exceeds maxcluster (%lu)\n",
689 pmp->pm_nxtfree, pmp->pm_maxcluster);
695 * Allocate memory for the bitmap of allocated clusters, and then
698 pmp->pm_inusemap = malloc(((pmp->pm_maxcluster + N_INUSEBITS - 1)
700 * sizeof(*pmp->pm_inusemap),
701 M_MSDOSFSFAT, M_WAITOK);
704 * fillinusemap() needs pm_devvp.
707 pmp->pm_devvp = devvp;
710 * Have the inuse map filled in.
712 if ((error = fillinusemap(pmp)) != 0)
716 * If they want fat updates to be synchronous then let them suffer
717 * the performance degradation in exchange for the on disk copy of
718 * the fat being correct just about all the time. I suppose this
719 * would be a good thing to turn on if the kernel is still flakey.
721 if (mp->mnt_flag & MNT_SYNCHRONOUS)
722 pmp->pm_flags |= MSDOSFSMNT_WAITONFAT;
728 pmp->pm_flags |= MSDOSFSMNT_RONLY;
731 mp->mnt_data = (qaddr_t) pmp;
732 mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
733 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
734 mp->mnt_flag |= MNT_LOCAL;
735 devvp->v_specmountpoint = mp;
742 (void) VOP_CLOSE(devvp, ronly ? FREAD : FREAD | FWRITE, td);
744 if (pmp->pm_inusemap)
745 free(pmp->pm_inusemap, M_MSDOSFSFAT);
746 free(pmp, M_MSDOSFSMNT);
747 mp->mnt_data = (qaddr_t)0;
753 * Unmount the filesystem described by mp.
756 msdosfs_unmount(mp, mntflags, td)
761 struct msdosfsmount *pmp;
765 if (mntflags & MNT_FORCE)
767 error = vflush(mp, 0, flags);
770 pmp = VFSTOMSDOSFS(mp);
771 pmp->pm_devvp->v_specmountpoint = NULL;
774 struct vnode *vp = pmp->pm_devvp;
776 printf("msdosfs_umount(): just before calling VOP_CLOSE()\n");
777 printf("flag %08lx, usecount %d, writecount %d, holdcnt %ld\n",
778 vp->v_flag, vp->v_usecount, vp->v_writecount, vp->v_holdcnt);
779 printf("id %lu, mount %p, op %p\n",
780 vp->v_id, vp->v_mount, vp->v_op);
781 printf("freef %p, freeb %p, mount %p\n",
782 vp->v_freelist.tqe_next, vp->v_freelist.tqe_prev,
784 printf("cleanblkhd %p, dirtyblkhd %p, numoutput %ld, type %d\n",
785 TAILQ_FIRST(&vp->v_cleanblkhd),
786 TAILQ_FIRST(&vp->v_dirtyblkhd),
787 vp->v_numoutput, vp->v_type);
788 printf("union %p, tag %d, data[0] %08x, data[1] %08x\n",
789 vp->v_socket, vp->v_tag,
790 ((u_int *)vp->v_data)[0],
791 ((u_int *)vp->v_data)[1]);
794 error = VOP_CLOSE(pmp->pm_devvp,
795 (pmp->pm_flags&MSDOSFSMNT_RONLY) ? FREAD : FREAD | FWRITE,
797 vrele(pmp->pm_devvp);
798 free(pmp->pm_inusemap, M_MSDOSFSFAT);
799 free(pmp, M_MSDOSFSMNT);
800 mp->mnt_data = (qaddr_t)0;
801 mp->mnt_flag &= ~MNT_LOCAL;
806 msdosfs_root(mp, vpp)
810 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
815 printf("msdosfs_root(); mp %p, pmp %p\n", mp, pmp);
817 error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep);
825 msdosfs_statfs(mp, sbp, td)
830 struct msdosfsmount *pmp;
832 pmp = VFSTOMSDOSFS(mp);
833 sbp->f_bsize = pmp->pm_bpcluster;
834 sbp->f_iosize = pmp->pm_bpcluster;
835 sbp->f_blocks = pmp->pm_maxcluster + 1;
836 sbp->f_bfree = pmp->pm_freeclustercount;
837 sbp->f_bavail = pmp->pm_freeclustercount;
838 sbp->f_files = pmp->pm_RootDirEnts; /* XXX */
839 sbp->f_ffree = 0; /* what to put in here? */
840 if (sbp != &mp->mnt_stat) {
841 sbp->f_type = mp->mnt_vfc->vfc_typenum;
842 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
843 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
845 strncpy(sbp->f_fstypename, mp->mnt_vfc->vfc_name, MFSNAMELEN);
856 static int msdosfs_sync_scan(struct mount *mp, struct vnode *vp,
857 lwkt_tokref_t vlock, void *data);
860 msdosfs_sync(mp, waitfor, td)
865 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
866 struct scaninfo scaninfo;
870 * If we ever switch to not updating all of the fats all the time,
871 * this would be the place to update them from the first one.
873 if (pmp->pm_fmod != 0) {
874 if (pmp->pm_flags & MSDOSFSMNT_RONLY)
875 panic("msdosfs_sync: rofs mod");
877 /* update fats here */
881 * Write back each (modified) denode.
883 scaninfo.allerror = 0;
886 while (scaninfo.rescan) {
888 vmntvnodescan(mp, NULL, msdosfs_sync_scan, &scaninfo);
892 * Flush filesystem control info.
894 if (waitfor != MNT_LAZY) {
895 vn_lock(pmp->pm_devvp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
896 if ((error = VOP_FSYNC(pmp->pm_devvp, waitfor, td)) != 0)
897 scaninfo.allerror = error;
898 VOP_UNLOCK(pmp->pm_devvp, NULL, 0, td);
900 return (scaninfo.allerror);
903 static int msdosfs_sync_scan(struct mount *mp, struct vnode *vp,
904 lwkt_tokref_t vlock, void *data)
906 struct scaninfo *info = data;
911 if (vp->v_type == VNON ||
913 (DE_ACCESS | DE_CREATE | DE_UPDATE | DE_MODIFIED)) == 0 &&
914 (TAILQ_EMPTY(&vp->v_dirtyblkhd) || info->waitfor == MNT_LAZY))) {
915 lwkt_reltoken(vlock);
918 error = vget(vp, vlock, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, info->td);
924 if ((error = VOP_FSYNC(vp, info->waitfor, info->td)) != 0)
925 info->allerror = error;
926 VOP_UNLOCK(vp, NULL, 0, info->td);
932 msdosfs_fhtovp(mp, fhp, vpp)
937 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
938 struct defid *defhp = (struct defid *) fhp;
942 error = deget(pmp, defhp->defid_dirclust, defhp->defid_dirofs, &dep);
952 msdosfs_checkexp(mp, nam, exflagsp, credanonp)
954 struct sockaddr *nam;
956 struct ucred **credanonp;
958 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
961 np = vfs_export_lookup(mp, &pmp->pm_export, nam);
964 *exflagsp = np->netc_exflags;
965 *credanonp = &np->netc_anon;
970 msdosfs_vptofh(vp, fhp)
978 defhp = (struct defid *)fhp;
979 defhp->defid_len = sizeof(struct defid);
980 defhp->defid_dirclust = dep->de_dirclust;
981 defhp->defid_dirofs = dep->de_diroffset;
982 /* defhp->defid_gen = dep->de_gen; */
986 static struct vfsops msdosfs_vfsops = {
1003 VFS_SET(msdosfs_vfsops, msdos, 0);