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.28 2005/09/17 07:43:10 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/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 extern struct vnodeopv_entry_desc msdosfs_vnodeop_entries[];
75 #define MSDOSFS_DFLTBSIZE 4096
79 * XXX - The boot signature formatted by NEC PC-98 DOS looks like a
80 * garbage or a random value :-{
81 * If you want to use that broken-signatured media, define the
82 * following symbol even though PC/AT.
83 * (ex. mount PC-98 DOS formatted FD on PC/AT)
85 #define MSDOSFS_NOCHECKSIG
88 MALLOC_DEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOSFS mount structure");
89 static MALLOC_DEFINE(M_MSDOSFSFAT, "MSDOSFS FAT", "MSDOSFS file allocation table");
91 static int update_mp (struct mount *mp, struct msdosfs_args *argp);
92 static int mountmsdosfs (struct vnode *devvp, struct mount *mp,
93 struct thread *td, struct msdosfs_args *argp);
94 static int msdosfs_fhtovp (struct mount *, struct fid *,
96 static int msdosfs_checkexp (struct mount *, struct sockaddr *,
97 int *, struct ucred **);
98 static int msdosfs_mount (struct mount *, char *, caddr_t,
100 static int msdosfs_root (struct mount *, struct vnode **);
101 static int msdosfs_statfs (struct mount *, struct statfs *,
103 static int msdosfs_sync (struct mount *, int, struct thread *);
104 static int msdosfs_unmount (struct mount *, int, struct thread *);
105 static int msdosfs_vptofh (struct vnode *, struct fid *);
108 update_mp(struct mount *mp, 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;
159 * mp - path - addr in user space of mount point (ie /usr or whatever)
160 * data - addr in user space of mount params including the name of the block
161 * special file to treat as a filesystem.
164 msdosfs_mount(struct mount *mp, char *path, caddr_t data, struct thread *td)
166 struct vnode *devvp; /* vnode for blk device to mount */
167 struct msdosfs_args args; /* will hold data from mount request */
168 /* msdosfs specific mount control block */
169 struct msdosfsmount *pmp = NULL;
173 struct proc *p = td->td_proc;
174 struct nlookupdata nd;
178 error = copyin(data, (caddr_t)&args, sizeof(struct msdosfs_args));
181 if (args.magic != MSDOSFS_ARGSMAGIC)
184 * If updating, check whether changing from read-only to
185 * read/write; if there is no device name, that's all we do.
187 if (mp->mnt_flag & MNT_UPDATE) {
188 pmp = VFSTOMSDOSFS(mp);
190 if (!(pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_flag & MNT_RDONLY)) {
192 if (mp->mnt_flag & MNT_FORCE)
194 error = vflush(mp, 0, flags);
196 if (!error && (mp->mnt_flag & MNT_RELOAD))
197 /* not yet implemented */
201 if ((pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
203 * If upgrade to read-write by non-root, then verify
204 * that user has necessary permissions on the device.
206 if (p->p_ucred->cr_uid != 0) {
207 devvp = pmp->pm_devvp;
208 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
209 error = VOP_ACCESS(devvp, VREAD | VWRITE,
212 VOP_UNLOCK(devvp, 0, td);
215 VOP_UNLOCK(devvp, 0, td);
217 pmp->pm_flags &= ~MSDOSFSMNT_RONLY;
219 if (args.fspec == 0) {
220 #ifdef __notyet__ /* doesn't work correctly with current mountd XXX */
221 if (args.flags & MSDOSFSMNT_MNTOPT) {
222 pmp->pm_flags &= ~MSDOSFSMNT_MNTOPT;
223 pmp->pm_flags |= args.flags & MSDOSFSMNT_MNTOPT;
224 if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
225 pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
229 * Process export requests.
231 return (vfs_export(mp, &pmp->pm_export, &args.export));
235 * Not an update, or updating the name: look up the name
236 * and verify that it refers to a sensible block device.
239 error = nlookup_init(&nd, args.fspec, UIO_USERSPACE, NLC_FOLLOW);
241 error = nlookup(&nd);
243 error = cache_vref(nd.nl_ncp, nd.nl_cred, &devvp);
248 if (!vn_isdisk(devvp, &error)) {
253 * If mount by non-root, then verify that user has necessary
254 * permissions on the device.
256 if (p->p_ucred->cr_uid != 0) {
258 if ((mp->mnt_flag & MNT_RDONLY) == 0)
259 accessmode |= VWRITE;
260 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
261 error = VOP_ACCESS(devvp, accessmode, p->p_ucred, td);
266 VOP_UNLOCK(devvp, 0, td);
268 if ((mp->mnt_flag & MNT_UPDATE) == 0) {
269 error = mountmsdosfs(devvp, mp, td, &args);
270 #ifdef MSDOSFS_DEBUG /* only needed for the printf below */
271 pmp = VFSTOMSDOSFS(mp);
274 if (devvp != pmp->pm_devvp)
275 error = EINVAL; /* XXX needs translation */
284 error = update_mp(mp, &args);
286 msdosfs_unmount(mp, MNT_FORCE, td);
290 (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
292 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
293 (void) msdosfs_statfs(mp, &mp->mnt_stat, td);
295 printf("msdosfs_mount(): mp %p, pmp %p, inusemap %p\n", mp, pmp, pmp->pm_inusemap);
301 mountmsdosfs(struct vnode *devvp, struct mount *mp, struct thread *td,
302 struct msdosfs_args *argp)
304 struct msdosfsmount *pmp;
307 #ifndef __DragonFly__
308 struct partinfo dpart;
309 int bsize = 0, dtype = 0, tmp;
311 union bootsector *bsp;
312 struct byte_bpb33 *b33;
313 struct byte_bpb50 *b50;
314 struct byte_bpb710 *b710;
315 u_int8_t SecPerClust;
320 * Disallow multiple mounts of the same device.
321 * Disallow mounting of a device that is currently in use
322 * Flush out any old buffers remaining from a previous use.
324 error = vfs_mountedon(devvp);
327 if (count_udev(devvp->v_udev) > 0)
329 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
330 error = vinvalbuf(devvp, V_SAVE, td, 0, 0);
331 VOP_UNLOCK(devvp, 0, td);
335 ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
336 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
337 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, NULL, td);
338 VOP_UNLOCK(devvp, 0, td);
342 bp = NULL; /* both used in error_exit */
345 #ifndef __DragonFly__
346 if (argp->flags & MSDOSFSMNT_GEMDOSFS) {
348 * We need the disklabel to calculate the size of a FAT entry
349 * later on. Also make sure the partition contains a filesystem
350 * of type FS_MSDOS. This doesn't work for floppies, so we have
351 * to check for them too.
353 * At least some parts of the msdos fs driver seem to assume
354 * that the size of a disk block will always be 512 bytes.
357 error = VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, td);
360 tmp = dpart.part->p_fstype;
361 dtype = dpart.disklab->d_type;
362 bsize = dpart.disklab->d_secsize;
363 if (bsize != 512 || (dtype!=DTYPE_FLOPPY && tmp!=FS_MSDOS)) {
371 * Read the boot sector of the filesystem, and then check the
372 * boot signature. If not a dos boot sector then error out.
374 * NOTE: 2048 is a maximum sector size in current...
376 error = bread(devvp, 0, 2048, &bp);
379 bp->b_flags |= B_AGE;
380 bsp = (union bootsector *)bp->b_data;
381 b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
382 b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
383 b710 = (struct byte_bpb710 *)bsp->bs710.bsPBP;
385 #ifndef __DragonFly__
386 if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) {
388 #ifndef MSDOSFS_NOCHECKSIG
389 if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
390 || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
395 #ifndef __DragonFly__
399 pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK);
400 bzero((caddr_t)pmp, sizeof *pmp);
404 * Compute several useful quantities from the bpb in the
405 * bootsector. Copy in the dos 5 variant of the bpb then fix up
406 * the fields that are different between dos 5 and dos 3.3.
408 SecPerClust = b50->bpbSecPerClust;
409 pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec);
410 pmp->pm_ResSectors = getushort(b50->bpbResSectors);
411 pmp->pm_FATs = b50->bpbFATs;
412 pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts);
413 pmp->pm_Sectors = getushort(b50->bpbSectors);
414 pmp->pm_FATsecs = getushort(b50->bpbFATsecs);
415 pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack);
416 pmp->pm_Heads = getushort(b50->bpbHeads);
417 pmp->pm_Media = b50->bpbMedia;
419 /* calculate the ratio of sector size to DEV_BSIZE */
420 pmp->pm_BlkPerSec = pmp->pm_BytesPerSec / DEV_BSIZE;
422 #ifndef __DragonFly__
423 if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) {
425 /* XXX - We should probably check more values here */
426 if (!pmp->pm_BytesPerSec || !SecPerClust
428 || !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 63) {
432 #ifndef __DragonFly__
436 if (pmp->pm_Sectors == 0) {
437 pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
438 pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
440 pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs);
441 pmp->pm_HugeSectors = pmp->pm_Sectors;
443 if (pmp->pm_HugeSectors > 0xffffffff /
444 (pmp->pm_BytesPerSec / sizeof(struct direntry)) + 1) {
446 * We cannot deal currently with this size of disk
447 * due to fileid limitations (see msdosfs_getattr and
451 printf("mountmsdosfs(): disk too big, sorry\n");
455 if (pmp->pm_RootDirEnts == 0) {
456 if (bsp->bs710.bsBootSectSig2 != BOOTSIG2
457 || bsp->bs710.bsBootSectSig3 != BOOTSIG3
460 || getushort(b710->bpbFSVers)) {
462 printf("mountmsdosfs(): bad FAT32 filesystem\n");
465 pmp->pm_fatmask = FAT32_MASK;
468 pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs);
469 if (getushort(b710->bpbExtFlags) & FATMIRROR)
470 pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM;
472 pmp->pm_flags |= MSDOSFS_FATMIRROR;
474 pmp->pm_flags |= MSDOSFS_FATMIRROR;
477 * Check a few values (could do some more):
478 * - logical sector size: power of 2, >= block size
479 * - sectors per cluster: power of 2, >= 1
480 * - number of sectors: >= 1, <= size of partition
482 if ( (SecPerClust == 0)
483 || (SecPerClust & (SecPerClust - 1))
484 || (pmp->pm_BytesPerSec < DEV_BSIZE)
485 || (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1))
486 || (pmp->pm_HugeSectors == 0)
492 pmp->pm_HugeSectors *= pmp->pm_BlkPerSec;
493 pmp->pm_HiddenSects *= pmp->pm_BlkPerSec; /* XXX not used? */
494 pmp->pm_FATsecs *= pmp->pm_BlkPerSec;
495 SecPerClust *= pmp->pm_BlkPerSec;
497 pmp->pm_fatblk = pmp->pm_ResSectors * pmp->pm_BlkPerSec;
500 pmp->pm_rootdirblk = getulong(b710->bpbRootClust);
501 pmp->pm_firstcluster = pmp->pm_fatblk
502 + (pmp->pm_FATs * pmp->pm_FATsecs);
503 pmp->pm_fsinfo = getushort(b710->bpbFSInfo) * pmp->pm_BlkPerSec;
505 pmp->pm_rootdirblk = pmp->pm_fatblk +
506 (pmp->pm_FATs * pmp->pm_FATsecs);
507 pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry)
509 / DEV_BSIZE; /* in blocks */
510 pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize;
513 pmp->pm_maxcluster = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
515 pmp->pm_fatsize = pmp->pm_FATsecs * DEV_BSIZE; /* XXX not used? */
517 #ifndef __DragonFly__
518 if (argp->flags & MSDOSFSMNT_GEMDOSFS) {
519 if ((pmp->pm_maxcluster <= (0xff0 - 2))
520 && ((dtype == DTYPE_FLOPPY) || ((dtype == DTYPE_VNODE)
521 && ((pmp->pm_Heads == 1) || (pmp->pm_Heads == 2))))
523 pmp->pm_fatmask = FAT12_MASK;
527 pmp->pm_fatmask = FAT16_MASK;
533 if (pmp->pm_fatmask == 0) {
534 if (pmp->pm_maxcluster
535 <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) {
537 * This will usually be a floppy disk. This size makes
538 * sure that one fat entry will not be split across
541 pmp->pm_fatmask = FAT12_MASK;
545 pmp->pm_fatmask = FAT16_MASK;
551 clusters = (pmp->pm_fatsize / pmp->pm_fatmult) * pmp->pm_fatdiv;
552 if (pmp->pm_maxcluster >= clusters) {
553 printf("Warning: number of clusters (%ld) exceeds FAT "
554 "capacity (%ld)\n", pmp->pm_maxcluster + 1, clusters);
555 pmp->pm_maxcluster = clusters - 1;
560 pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec;
562 pmp->pm_fatblocksize = MSDOSFS_DFLTBSIZE;
564 pmp->pm_fatblocksec = pmp->pm_fatblocksize / DEV_BSIZE;
565 pmp->pm_bnshift = ffs(DEV_BSIZE) - 1;
568 * Compute mask and shift value for isolating cluster relative byte
569 * offsets and cluster numbers from a file offset.
571 pmp->pm_bpcluster = SecPerClust * DEV_BSIZE;
572 pmp->pm_crbomask = pmp->pm_bpcluster - 1;
573 pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1;
576 * Check for valid cluster size
577 * must be a power of 2
579 if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) {
585 * Release the bootsector buffer.
593 if (pmp->pm_fsinfo) {
596 if ((error = bread(devvp, pmp->pm_fsinfo, fsi_size(pmp), &bp)) != 0)
598 fp = (struct fsinfo *)bp->b_data;
599 if (!bcmp(fp->fsisig1, "RRaA", 4)
600 && !bcmp(fp->fsisig2, "rrAa", 4)
601 && !bcmp(fp->fsisig3, "\0\0\125\252", 4)
602 && !bcmp(fp->fsisig4, "\0\0\125\252", 4)) {
603 pmp->pm_nxtfree = getulong(fp->fsinxtfree);
604 if (pmp->pm_nxtfree == 0xffffffff)
605 pmp->pm_nxtfree = CLUST_FIRST;
613 * Check and validate (or perhaps invalidate?) the fsinfo structure?
615 if (pmp->pm_fsinfo && pmp->pm_nxtfree > pmp->pm_maxcluster) {
617 "Next free cluster in FSInfo (%lu) exceeds maxcluster (%lu)\n",
618 pmp->pm_nxtfree, pmp->pm_maxcluster);
624 * Allocate memory for the bitmap of allocated clusters, and then
627 pmp->pm_inusemap = malloc(((pmp->pm_maxcluster + N_INUSEBITS - 1)
629 * sizeof(*pmp->pm_inusemap),
630 M_MSDOSFSFAT, M_WAITOK);
633 * fillinusemap() needs pm_devvp.
636 pmp->pm_devvp = devvp;
639 * Have the inuse map filled in.
641 if ((error = fillinusemap(pmp)) != 0)
645 * If they want fat updates to be synchronous then let them suffer
646 * the performance degradation in exchange for the on disk copy of
647 * the fat being correct just about all the time. I suppose this
648 * would be a good thing to turn on if the kernel is still flakey.
650 if (mp->mnt_flag & MNT_SYNCHRONOUS)
651 pmp->pm_flags |= MSDOSFSMNT_WAITONFAT;
657 pmp->pm_flags |= MSDOSFSMNT_RONLY;
660 mp->mnt_data = (qaddr_t) pmp;
661 mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
662 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
663 mp->mnt_flag |= MNT_LOCAL;
664 vfs_add_vnodeops(mp, &mp->mnt_vn_norm_ops,
665 msdosfs_vnodeop_entries, 0);
666 dev->si_mountpoint = mp;
673 (void) VOP_CLOSE(devvp, ronly ? FREAD : FREAD | FWRITE, td);
675 if (pmp->pm_inusemap)
676 free(pmp->pm_inusemap, M_MSDOSFSFAT);
677 free(pmp, M_MSDOSFSMNT);
678 mp->mnt_data = (qaddr_t)0;
684 * Unmount the filesystem described by mp.
687 msdosfs_unmount(struct mount *mp, int mntflags, struct thread *td)
689 struct msdosfsmount *pmp;
693 if (mntflags & MNT_FORCE)
695 error = vflush(mp, 0, flags);
698 pmp = VFSTOMSDOSFS(mp);
699 pmp->pm_devvp->v_rdev->si_mountpoint = NULL;
702 struct vnode *vp = pmp->pm_devvp;
704 printf("msdosfs_umount(): just before calling VOP_CLOSE()\n");
705 printf("flag %08lx, usecount %d, writecount %d, holdcnt %ld\n",
706 vp->v_flag, vp->v_usecount, vp->v_writecount, vp->v_holdcnt);
707 printf("id %lu, mount %p, op %p\n",
708 vp->v_id, vp->v_mount, vp->v_op);
709 printf("freef %p, freeb %p, mount %p\n",
710 TAILQ_NEXT(vp, v_freelist), TAILQ_PREV(vp, v_freelist),
712 printf("cleanblkhd %p, dirtyblkhd %p, numoutput %ld, type %d\n",
713 RB_EMPTY(&vp->v_rbclean_tree),
714 RB_EMPTY(&vp->v_rbdirty_tree),
715 vp->v_numoutput, vp->v_type);
716 printf("union %p, tag %d, data[0] %08x, data[1] %08x\n",
717 vp->v_socket, vp->v_tag,
718 ((u_int *)vp->v_data)[0],
719 ((u_int *)vp->v_data)[1]);
722 error = VOP_CLOSE(pmp->pm_devvp,
723 (pmp->pm_flags&MSDOSFSMNT_RONLY) ? FREAD : FREAD | FWRITE,
725 vrele(pmp->pm_devvp);
726 free(pmp->pm_inusemap, M_MSDOSFSFAT);
727 free(pmp, M_MSDOSFSMNT);
728 mp->mnt_data = (qaddr_t)0;
729 mp->mnt_flag &= ~MNT_LOCAL;
734 msdosfs_root(struct mount *mp, struct vnode **vpp)
736 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
741 printf("msdosfs_root(); mp %p, pmp %p\n", mp, pmp);
743 error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep);
751 msdosfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
753 struct msdosfsmount *pmp;
755 pmp = VFSTOMSDOSFS(mp);
756 sbp->f_bsize = pmp->pm_bpcluster;
757 sbp->f_iosize = pmp->pm_bpcluster;
758 sbp->f_blocks = pmp->pm_maxcluster + 1;
759 sbp->f_bfree = pmp->pm_freeclustercount;
760 sbp->f_bavail = pmp->pm_freeclustercount;
761 sbp->f_files = pmp->pm_RootDirEnts; /* XXX */
762 sbp->f_ffree = 0; /* what to put in here? */
763 if (sbp != &mp->mnt_stat) {
764 sbp->f_type = mp->mnt_vfc->vfc_typenum;
765 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
767 strncpy(sbp->f_fstypename, mp->mnt_vfc->vfc_name, MFSNAMELEN);
778 static int msdosfs_sync_scan(struct mount *mp, struct vnode *vp, void *data);
781 msdosfs_sync(struct mount *mp, int waitfor, struct thread *td)
783 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
784 struct scaninfo scaninfo;
788 * If we ever switch to not updating all of the fats all the time,
789 * this would be the place to update them from the first one.
791 if (pmp->pm_fmod != 0) {
792 if (pmp->pm_flags & MSDOSFSMNT_RONLY)
793 panic("msdosfs_sync: rofs mod");
795 /* update fats here */
799 * Write back each (modified) denode.
801 scaninfo.allerror = 0;
804 while (scaninfo.rescan) {
806 vmntvnodescan(mp, VMSC_GETVP|VMSC_NOWAIT, NULL, msdosfs_sync_scan, &scaninfo);
810 * Flush filesystem control info.
812 if (waitfor != MNT_LAZY) {
813 vn_lock(pmp->pm_devvp, LK_EXCLUSIVE | LK_RETRY, td);
814 if ((error = VOP_FSYNC(pmp->pm_devvp, waitfor, td)) != 0)
815 scaninfo.allerror = error;
816 VOP_UNLOCK(pmp->pm_devvp, 0, td);
818 return (scaninfo.allerror);
822 msdosfs_sync_scan(struct mount *mp, struct vnode *vp, void *data)
824 struct scaninfo *info = data;
829 if (vp->v_type == VNON ||
831 (DE_ACCESS | DE_CREATE | DE_UPDATE | DE_MODIFIED)) == 0 &&
832 (RB_EMPTY(&vp->v_rbdirty_tree) || info->waitfor == MNT_LAZY))) {
835 if ((error = VOP_FSYNC(vp, info->waitfor, info->td)) != 0)
836 info->allerror = error;
841 msdosfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
843 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
844 struct defid *defhp = (struct defid *) fhp;
848 error = deget(pmp, defhp->defid_dirclust, defhp->defid_dirofs, &dep);
858 msdosfs_checkexp(struct mount *mp, struct sockaddr *nam, int *exflagsp,
859 struct ucred **credanonp)
861 struct msdosfsmount *pmp = VFSTOMSDOSFS(mp);
864 np = vfs_export_lookup(mp, &pmp->pm_export, nam);
867 *exflagsp = np->netc_exflags;
868 *credanonp = &np->netc_anon;
873 msdosfs_vptofh(struct vnode *vp, struct fid *fhp)
879 defhp = (struct defid *)fhp;
880 defhp->defid_len = sizeof(struct defid);
881 defhp->defid_dirclust = dep->de_dirclust;
882 defhp->defid_dirofs = dep->de_diroffset;
883 /* defhp->defid_gen = dep->de_gen; */
887 static struct vfsops msdosfs_vfsops = {
888 .vfs_mount = msdosfs_mount,
889 .vfs_unmount = msdosfs_unmount,
890 .vfs_root = msdosfs_root,
891 .vfs_statfs = msdosfs_statfs,
892 .vfs_sync = msdosfs_sync,
893 .vfs_fhtovp = msdosfs_fhtovp,
894 .vfs_checkexp = msdosfs_checkexp,
895 .vfs_vptofh = msdosfs_vptofh,
896 .vfs_init = msdosfs_init,
897 .vfs_uninit = msdosfs_uninit
900 VFS_SET(msdosfs_vfsops, msdos, 0);