1 /* $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/msdosfs/Attic/msdosfs_vfsops.c,v 1.60.2.8 2004/03/02 09:43:04 tjr Exp $ */
2 /* $DragonFly: src/sys/vfs/msdosfs/msdosfs_vfsops.c,v 1.52 2008/09/17 21:44:24 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/nlookup.h>
57 #include <sys/kernel.h>
58 #include <sys/vnode.h>
59 #include <sys/iconv.h>
60 #include <sys/mount.h>
62 #include <sys/fcntl.h>
63 #include <sys/malloc.h>
64 #include <sys/stat.h> /* defines ALLPERMS */
65 #include <vm/vm_zone.h>
71 #include "msdosfsmount.h"
74 extern struct vop_ops msdosfs_vnode_vops;
75 struct iconv_functions *msdos_iconv;
77 #define MSDOSFS_DFLTBSIZE 4096
78 #define ENCODING_UNICODE "UTF-16BE"
81 * XXX - The boot signature formatted by NEC PC-98 DOS looks like a
82 * garbage or a random value :-{
83 * If you want to use that broken-signatured media, define the
84 * following symbol even though PC/AT.
85 * (ex. mount PC-98 DOS formatted FD on PC/AT)
87 #define MSDOSFS_NOCHECKSIG
90 MALLOC_DEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOSFS mount structure");
91 static MALLOC_DEFINE(M_MSDOSFSFAT, "MSDOSFS FAT", "MSDOSFS file allocation table");
93 static int update_mp (struct mount *mp, struct msdosfs_args *argp);
94 static int mountmsdosfs (struct vnode *devvp, struct mount *mp,
95 struct msdosfs_args *argp);
96 static int msdosfs_fhtovp (struct mount *, struct vnode *,
97 struct fid *, struct vnode **);
98 static int msdosfs_checkexp (struct mount *, struct sockaddr *,
99 int *, struct ucred **);
100 static int msdosfs_mount (struct mount *, char *, caddr_t,
102 static int msdosfs_root (struct mount *, struct vnode **);
103 static int msdosfs_statfs (struct mount *, struct statfs *,
105 static int msdosfs_sync (struct mount *, int);
106 static int msdosfs_unmount (struct mount *, int);
107 static int msdosfs_vptofh (struct vnode *, struct fid *);
110 update_mp(struct mount *mp, struct msdosfs_args *argp)
112 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
114 char cs_local[ICONV_CSNMAXLEN];
115 char cs_dos[ICONV_CSNMAXLEN];
117 pmp->pm_gid = argp->gid;
118 pmp->pm_uid = argp->uid;
119 pmp->pm_mask = argp->mask & ALLPERMS;
120 pmp->pm_flags |= argp->flags & MSDOSFSMNT_MNTOPT;
121 if (pmp->pm_flags & MSDOSFSMNT_KICONV && msdos_iconv) {
122 bcopy(argp->cs_local, cs_local, sizeof(cs_local));
123 bcopy(argp->cs_dos, cs_dos, sizeof(cs_dos));
124 kprintf("local: %s dos: %s\n",argp->cs_local, argp->cs_dos);
125 error = msdos_iconv->open(cs_local, ENCODING_UNICODE, &pmp->pm_w2u);
128 error = msdos_iconv->open(ENCODING_UNICODE, cs_local, &pmp->pm_u2w);
131 error = msdos_iconv->open(cs_dos, cs_local, &pmp->pm_u2d);
134 error = msdos_iconv->open(cs_local, cs_dos, &pmp->pm_d2u);
139 if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
140 pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
141 else if (!(pmp->pm_flags &
142 (MSDOSFSMNT_SHORTNAME | MSDOSFSMNT_LONGNAME))) {
143 struct vnode *rootvp;
146 * Try to divine whether to support Win'95 long filenames
149 pmp->pm_flags |= MSDOSFSMNT_LONGNAME;
151 if ((error = msdosfs_root(mp, &rootvp)) != 0)
153 pmp->pm_flags |= findwin95(VTODE(rootvp))
154 ? MSDOSFSMNT_LONGNAME
155 : MSDOSFSMNT_SHORTNAME;
163 * mp - path - addr in user space of mount point (ie /usr or whatever)
164 * data - addr in user space of mount params including the name of the block
165 * special file to treat as a filesystem.
168 msdosfs_mount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
170 struct vnode *devvp; /* vnode for blk device to mount */
171 struct msdosfs_args args; /* will hold data from mount request */
172 /* msdosfs specific mount control block */
173 struct msdosfsmount *pmp = NULL;
177 struct nlookupdata nd;
179 error = copyin(data, (caddr_t)&args, sizeof(struct msdosfs_args));
182 if (args.magic != MSDOSFS_ARGSMAGIC)
185 * If updating, check whether changing from read-only to
186 * read/write; if there is no device name, that's all we do.
188 if (mp->mnt_flag & MNT_UPDATE) {
189 pmp = VFSTOMSDOSFS(mp);
191 if (!(pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_flag & MNT_RDONLY)) {
193 if (mp->mnt_flag & MNT_FORCE)
195 error = vflush(mp, 0, flags);
197 devvp = pmp->pm_devvp;
198 VOP_OPEN(devvp, FREAD, FSCRED, NULL);
199 VOP_CLOSE(devvp, FREAD|FWRITE);
200 pmp->pm_flags |= MSDOSFSMNT_RONLY;
203 if (!error && (mp->mnt_flag & MNT_RELOAD))
204 /* not yet implemented */
208 if ((pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
210 * If upgrade to read-write by non-root, then verify
211 * that user has necessary permissions on the device.
213 devvp = pmp->pm_devvp;
214 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
215 if (cred->cr_uid != 0) {
216 error = VOP_EACCESS(devvp, VREAD | VWRITE, cred);
222 VOP_OPEN(devvp, FREAD|FWRITE, FSCRED, NULL);
223 VOP_CLOSE(devvp, FREAD);
225 pmp->pm_flags &= ~MSDOSFSMNT_RONLY;
227 if (args.fspec == 0) {
228 #ifdef __notyet__ /* doesn't work correctly with current mountd XXX */
229 if (args.flags & MSDOSFSMNT_MNTOPT) {
230 pmp->pm_flags &= ~MSDOSFSMNT_MNTOPT;
231 pmp->pm_flags |= args.flags & MSDOSFSMNT_MNTOPT;
232 if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
233 pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
237 * Process export requests.
239 return (vfs_export(mp, &pmp->pm_export, &args.export));
243 * Not an update, or updating the name: look up the name
244 * and verify that it refers to a sensible block device.
247 error = nlookup_init(&nd, args.fspec, UIO_USERSPACE, NLC_FOLLOW);
249 error = nlookup(&nd);
251 error = cache_vref(&nd.nl_nch, nd.nl_cred, &devvp);
256 if (!vn_isdisk(devvp, &error)) {
261 * If mount by non-root, then verify that user has necessary
262 * permissions on the device.
264 if (cred->cr_uid != 0) {
266 if ((mp->mnt_flag & MNT_RDONLY) == 0)
267 accessmode |= VWRITE;
268 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
269 error = VOP_EACCESS(devvp, accessmode, cred);
276 if ((mp->mnt_flag & MNT_UPDATE) == 0) {
277 error = mountmsdosfs(devvp, mp, &args);
278 #ifdef MSDOSFS_DEBUG /* only needed for the kprintf below */
279 pmp = VFSTOMSDOSFS(mp);
282 if (devvp != pmp->pm_devvp)
283 error = EINVAL; /* XXX needs translation */
292 error = update_mp(mp, &args);
294 msdosfs_unmount(mp, MNT_FORCE);
298 copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
299 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
300 msdosfs_statfs(mp, &mp->mnt_stat, cred);
302 kprintf("msdosfs_mount(): mp %p, pmp %p, inusemap %p\n", mp, pmp, pmp->pm_inusemap);
308 mountmsdosfs(struct vnode *devvp, struct mount *mp, struct msdosfs_args *argp)
310 struct msdosfsmount *pmp;
313 union bootsector *bsp;
314 struct byte_bpb33 *b33;
315 struct byte_bpb50 *b50;
316 struct byte_bpb710 *b710;
317 u_int8_t SecPerClust;
322 * Disallow multiple mounts of the same device.
323 * Disallow mounting of a device that is currently in use
324 * Flush out any old buffers remaining from a previous use.
326 error = vfs_mountedon(devvp);
329 if (vcount(devvp) > 0)
331 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
332 error = vinvalbuf(devvp, V_SAVE, 0, 0);
337 ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
338 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
339 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, NULL);
344 bp = NULL; /* both used in error_exit */
348 * Read the boot sector of the filesystem, and then check the
349 * boot signature. If not a dos boot sector then error out.
351 * NOTE: 2048 is a maximum sector size in current...
353 error = bread(devvp, 0, 2048, &bp);
356 bp->b_flags |= B_AGE;
357 bsp = (union bootsector *)bp->b_data;
358 b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
359 b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
360 b710 = (struct byte_bpb710 *)bsp->bs710.bsPBP;
362 #ifndef MSDOSFS_NOCHECKSIG
363 if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
364 || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
370 pmp = kmalloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK | M_ZERO);
374 * Compute several useful quantities from the bpb in the
375 * bootsector. Copy in the dos 5 variant of the bpb then fix up
376 * the fields that are different between dos 5 and dos 3.3.
378 SecPerClust = b50->bpbSecPerClust;
379 pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec);
380 pmp->pm_ResSectors = getushort(b50->bpbResSectors);
381 pmp->pm_FATs = b50->bpbFATs;
382 pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts);
383 pmp->pm_Sectors = getushort(b50->bpbSectors);
384 pmp->pm_FATsecs = getushort(b50->bpbFATsecs);
385 pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack);
386 pmp->pm_Heads = getushort(b50->bpbHeads);
387 pmp->pm_Media = b50->bpbMedia;
389 /* calculate the ratio of sector size to DEV_BSIZE */
390 pmp->pm_BlkPerSec = pmp->pm_BytesPerSec / DEV_BSIZE;
393 * We don't check pm_Heads nor pm_SecPerTrack, because
394 * these may not be set for EFI file systems. We don't
395 * use these anyway, so we're unaffected if they are
398 if (!pmp->pm_BytesPerSec || !SecPerClust) {
403 if (pmp->pm_Sectors == 0) {
404 pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
405 pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
407 pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs);
408 pmp->pm_HugeSectors = pmp->pm_Sectors;
411 if (pmp->pm_RootDirEnts == 0) {
414 || getushort(b710->bpbFSVers)) {
416 kprintf("mountmsdosfs(): bad FAT32 filesystem\n");
419 pmp->pm_fatmask = FAT32_MASK;
422 pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs);
423 if (getushort(b710->bpbExtFlags) & FATMIRROR)
424 pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM;
426 pmp->pm_flags |= MSDOSFS_FATMIRROR;
428 pmp->pm_flags |= MSDOSFS_FATMIRROR;
431 * Check a few values (could do some more):
432 * - logical sector size: power of 2, >= block size
433 * - sectors per cluster: power of 2, >= 1
434 * - number of sectors: >= 1, <= size of partition
436 if ( (SecPerClust == 0)
437 || (SecPerClust & (SecPerClust - 1))
438 || (pmp->pm_BytesPerSec < DEV_BSIZE)
439 || (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1))
440 || (pmp->pm_HugeSectors == 0)
446 pmp->pm_HugeSectors *= pmp->pm_BlkPerSec;
447 pmp->pm_HiddenSects *= pmp->pm_BlkPerSec; /* XXX not used? */
448 pmp->pm_FATsecs *= pmp->pm_BlkPerSec;
449 SecPerClust *= pmp->pm_BlkPerSec;
451 pmp->pm_fatblk = pmp->pm_ResSectors * pmp->pm_BlkPerSec;
454 pmp->pm_rootdirblk = getulong(b710->bpbRootClust);
455 pmp->pm_firstcluster = pmp->pm_fatblk
456 + (pmp->pm_FATs * pmp->pm_FATsecs);
457 pmp->pm_fsinfo = getushort(b710->bpbFSInfo) * pmp->pm_BlkPerSec;
459 pmp->pm_rootdirblk = pmp->pm_fatblk +
460 (pmp->pm_FATs * pmp->pm_FATsecs);
461 pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry)
463 / DEV_BSIZE; /* in blocks */
464 pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize;
467 pmp->pm_maxcluster = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
469 pmp->pm_fatsize = pmp->pm_FATsecs * DEV_BSIZE; /* XXX not used? */
471 if (pmp->pm_fatmask == 0) {
472 if (pmp->pm_maxcluster
473 <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) {
475 * This will usually be a floppy disk. This size makes
476 * sure that one fat entry will not be split across
479 pmp->pm_fatmask = FAT12_MASK;
483 pmp->pm_fatmask = FAT16_MASK;
489 clusters = (pmp->pm_fatsize / pmp->pm_fatmult) * pmp->pm_fatdiv;
490 if (pmp->pm_maxcluster >= clusters) {
491 kprintf("Warning: number of clusters (%ld) exceeds FAT "
492 "capacity (%ld)\n", pmp->pm_maxcluster + 1, clusters);
493 pmp->pm_maxcluster = clusters - 1;
498 pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec;
500 pmp->pm_fatblocksize = MSDOSFS_DFLTBSIZE;
502 pmp->pm_fatblocksec = pmp->pm_fatblocksize / DEV_BSIZE;
503 pmp->pm_bnshift = DEV_BSHIFT;
506 * Compute mask and shift value for isolating cluster relative byte
507 * offsets and cluster numbers from a file offset.
509 pmp->pm_bpcluster = SecPerClust * DEV_BSIZE;
510 pmp->pm_crbomask = pmp->pm_bpcluster - 1;
511 pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1;
514 * Check for valid cluster size
515 * must be a power of 2
517 if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) {
523 * Release the bootsector buffer.
531 if (pmp->pm_fsinfo) {
534 if ((error = bread(devvp, de_bntodoff(pmp, pmp->pm_fsinfo), fsi_size(pmp), &bp)) != 0)
536 fp = (struct fsinfo *)bp->b_data;
537 if (!bcmp(fp->fsisig1, "RRaA", 4)
538 && !bcmp(fp->fsisig2, "rrAa", 4)
539 && !bcmp(fp->fsisig3, "\0\0\125\252", 4)
540 && !bcmp(fp->fsisig4, "\0\0\125\252", 4)) {
541 pmp->pm_nxtfree = getulong(fp->fsinxtfree);
542 if (pmp->pm_nxtfree == 0xffffffff)
543 pmp->pm_nxtfree = CLUST_FIRST;
551 * Check and validate (or perhaps invalidate?) the fsinfo structure?
553 if (pmp->pm_fsinfo && pmp->pm_nxtfree > pmp->pm_maxcluster) {
555 "Next free cluster in FSInfo (%lu) exceeds maxcluster (%lu)\n",
556 pmp->pm_nxtfree, pmp->pm_maxcluster);
562 * Allocate memory for the bitmap of allocated clusters, and then
565 pmp->pm_inusemap = kmalloc(((pmp->pm_maxcluster + N_INUSEBITS - 1)
567 * sizeof(*pmp->pm_inusemap),
568 M_MSDOSFSFAT, M_WAITOK);
571 * fillinusemap() needs pm_devvp.
574 pmp->pm_devvp = devvp;
577 * Have the inuse map filled in.
579 if ((error = fillinusemap(pmp)) != 0)
583 * If they want fat updates to be synchronous then let them suffer
584 * the performance degradation in exchange for the on disk copy of
585 * the fat being correct just about all the time. I suppose this
586 * would be a good thing to turn on if the kernel is still flakey.
588 if (mp->mnt_flag & MNT_SYNCHRONOUS)
589 pmp->pm_flags |= MSDOSFSMNT_WAITONFAT;
595 pmp->pm_flags |= MSDOSFSMNT_RONLY;
598 mp->mnt_data = (qaddr_t) pmp;
599 mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
600 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
601 mp->mnt_flag |= MNT_LOCAL;
602 vfs_add_vnodeops(mp, &msdosfs_vnode_vops, &mp->mnt_vn_norm_ops);
603 dev->si_mountpoint = mp;
610 VOP_CLOSE(devvp, ronly ? FREAD : FREAD | FWRITE);
612 if (pmp->pm_inusemap)
613 kfree(pmp->pm_inusemap, M_MSDOSFSFAT);
614 kfree(pmp, M_MSDOSFSMNT);
615 mp->mnt_data = (qaddr_t)0;
621 * Unmount the filesystem described by mp.
624 msdosfs_unmount(struct mount *mp, int mntflags)
626 struct msdosfsmount *pmp;
630 if (mntflags & MNT_FORCE)
632 error = vflush(mp, 0, flags);
635 pmp = VFSTOMSDOSFS(mp);
636 pmp->pm_devvp->v_rdev->si_mountpoint = NULL;
637 if (pmp->pm_flags & MSDOSFSMNT_KICONV && msdos_iconv) {
639 msdos_iconv->close(pmp->pm_w2u);
641 msdos_iconv->close(pmp->pm_u2w);
643 msdos_iconv->close(pmp->pm_d2u);
645 msdos_iconv->close(pmp->pm_u2d);
649 struct vnode *vp = pmp->pm_devvp;
651 kprintf("msdosfs_umount(): just before calling VOP_CLOSE()\n");
652 kprintf("flag %08x, sysrefs %d, writecount %d, auxrefs %d\n",
653 vp->v_flag, vp->v_sysref.refcnt,
654 vp->v_writecount, vp->v_auxrefs);
655 kprintf("mount %p, op %p\n", vp->v_mount, vp->v_ops);
656 kprintf("mount %p\n", vp->v_mount);
657 kprintf("cleanblkhd %p, dirtyblkhd %p, numoutput %d, type %d\n",
658 RB_ROOT(&vp->v_rbclean_tree),
659 RB_ROOT(&vp->v_rbdirty_tree),
660 bio_track_active(&vp->v_track_write),
662 kprintf("union %p, tag %d, data[0] %08x, data[1] %08x\n",
663 vp->v_socket, vp->v_tag,
664 ((u_int *)vp->v_data)[0],
665 ((u_int *)vp->v_data)[1]);
668 error = VOP_CLOSE(pmp->pm_devvp,
669 (pmp->pm_flags&MSDOSFSMNT_RONLY) ? FREAD : FREAD | FWRITE);
670 vrele(pmp->pm_devvp);
671 kfree(pmp->pm_inusemap, M_MSDOSFSFAT);
672 kfree(pmp, M_MSDOSFSMNT);
673 mp->mnt_data = (qaddr_t)0;
674 mp->mnt_flag &= ~MNT_LOCAL;
679 msdosfs_root(struct mount *mp, struct vnode **vpp)
681 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
686 kprintf("msdosfs_root(); mp %p, pmp %p\n", mp, pmp);
688 error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep);
696 msdosfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
698 struct msdosfsmount *pmp;
700 pmp = VFSTOMSDOSFS(mp);
701 sbp->f_bsize = pmp->pm_bpcluster;
702 sbp->f_iosize = pmp->pm_bpcluster;
703 sbp->f_blocks = pmp->pm_maxcluster + 1;
704 sbp->f_bfree = pmp->pm_freeclustercount;
705 sbp->f_bavail = pmp->pm_freeclustercount;
706 sbp->f_files = pmp->pm_RootDirEnts; /* XXX */
707 sbp->f_ffree = 0; /* what to put in here? */
708 if (sbp != &mp->mnt_stat) {
709 sbp->f_type = mp->mnt_vfc->vfc_typenum;
710 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
712 strncpy(sbp->f_fstypename, mp->mnt_vfc->vfc_name, MFSNAMELEN);
722 static int msdosfs_sync_scan(struct mount *mp, struct vnode *vp, void *data);
725 msdosfs_sync(struct mount *mp, int waitfor)
727 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
728 struct scaninfo scaninfo;
732 * If we ever switch to not updating all of the fats all the time,
733 * this would be the place to update them from the first one.
735 if (pmp->pm_fmod != 0) {
736 if (pmp->pm_flags & MSDOSFSMNT_RONLY)
737 panic("msdosfs_sync: rofs mod");
739 /* update fats here */
743 * Write back each (modified) denode.
745 scaninfo.allerror = 0;
747 while (scaninfo.rescan) {
749 vmntvnodescan(mp, VMSC_GETVP|VMSC_NOWAIT, NULL, msdosfs_sync_scan, &scaninfo);
753 * Flush filesystem control info.
755 if (waitfor != MNT_LAZY) {
756 vn_lock(pmp->pm_devvp, LK_EXCLUSIVE | LK_RETRY);
757 if ((error = VOP_FSYNC(pmp->pm_devvp, waitfor, 0)) != 0)
758 scaninfo.allerror = error;
759 vn_unlock(pmp->pm_devvp);
761 return (scaninfo.allerror);
765 msdosfs_sync_scan(struct mount *mp, struct vnode *vp, void *data)
767 struct scaninfo *info = data;
772 if (vp->v_type == VNON || vp->v_type == VBAD ||
774 (DE_ACCESS | DE_CREATE | DE_UPDATE | DE_MODIFIED)) == 0 &&
775 (RB_EMPTY(&vp->v_rbdirty_tree) || info->waitfor == MNT_LAZY))) {
778 if ((error = VOP_FSYNC(vp, info->waitfor, 0)) != 0)
779 info->allerror = error;
784 msdosfs_fhtovp(struct mount *mp, struct vnode *rootvp,
785 struct fid *fhp, struct vnode **vpp)
787 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
788 struct defid *defhp = (struct defid *) fhp;
792 error = deget(pmp, defhp->defid_dirclust, defhp->defid_dirofs, &dep);
802 msdosfs_checkexp(struct mount *mp, struct sockaddr *nam, int *exflagsp,
803 struct ucred **credanonp)
805 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
808 np = vfs_export_lookup(mp, &pmp->pm_export, nam);
811 *exflagsp = np->netc_exflags;
812 *credanonp = &np->netc_anon;
817 msdosfs_vptofh(struct vnode *vp, struct fid *fhp)
823 defhp = (struct defid *)fhp;
824 defhp->defid_len = sizeof(struct defid);
825 defhp->defid_dirclust = dep->de_dirclust;
826 defhp->defid_dirofs = dep->de_diroffset;
827 /* defhp->defid_gen = dep->de_gen; */
831 static struct vfsops msdosfs_vfsops = {
832 .vfs_mount = msdosfs_mount,
833 .vfs_unmount = msdosfs_unmount,
834 .vfs_root = msdosfs_root,
835 .vfs_statfs = msdosfs_statfs,
836 .vfs_sync = msdosfs_sync,
837 .vfs_fhtovp = msdosfs_fhtovp,
838 .vfs_checkexp = msdosfs_checkexp,
839 .vfs_vptofh = msdosfs_vptofh,
840 .vfs_init = msdosfs_init,
841 .vfs_uninit = msdosfs_uninit
844 VFS_SET(msdosfs_vfsops, msdos, 0);
845 MODULE_VERSION(msdos, 1);