Index: sys/fs/msdosfs/denode.h =================================================================== --- sys/fs/msdosfs/denode.h +++ sys/fs/msdosfs/denode.h @@ -194,6 +194,10 @@ (dep)->de_FileSize = getulong((dp)->deFileSize), \ (FAT32((dep)->de_pmp) ? DE_INTERNALIZE32((dep), (dp)) : 0)) +#define DE_EXTERNALIZE32(dp, dep) \ + putushort((dp)->deHighClust, (dep)->de_StartCluster >> 16) +#define DE_EXTERNALIZE16(dp, dep) \ + putushort((dp)->deHighClust, 0) #define DE_EXTERNALIZE(dp, dep) \ (memcpy((dp)->deName, (dep)->de_Name, 11), \ (dp)->deAttributes = (dep)->de_Attributes, \ @@ -207,13 +211,15 @@ putushort((dp)->deStartCluster, (dep)->de_StartCluster), \ putulong((dp)->deFileSize, \ ((dep)->de_Attributes & ATTR_DIRECTORY) ? 0 : (dep)->de_FileSize), \ - putushort((dp)->deHighClust, (dep)->de_StartCluster >> 16)) + (FAT32((dep)->de_pmp) ? DE_EXTERNALIZE32((dp), (dep)) : DE_EXTERNALIZE16((dp), (dep)))) #if defined(_KERNEL) || defined(MAKEFS) #define VTODE(vp) ((struct denode *)(vp)->v_data) #define DETOV(de) ((de)->de_vnode) +#ifdef _KERNEL + #define DETIMES(dep, acc, mod, cre) do { \ if ((dep)->de_flag & DE_UPDATE) { \ (dep)->de_flag |= DE_MODIFIED; \ @@ -262,9 +268,17 @@ int msdosfs_inactive(struct vop_inactive_args *); int msdosfs_reclaim(struct vop_reclaim_args *); +#endif /* _KERNEL */ + /* * Internal service routine prototypes. */ + +struct componentname; +struct direntry; +struct buf; +struct ucred; + int deget(struct msdosfsmount *, u_long, u_long, struct denode **); int uniqdosname(struct denode *, struct componentname *, u_char *); Index: sys/fs/msdosfs/direntry.h =================================================================== --- sys/fs/msdosfs/direntry.h +++ sys/fs/msdosfs/direntry.h @@ -133,7 +133,7 @@ #define DD_YEAR_MASK 0xFE00 /* year - 1980 */ #define DD_YEAR_SHIFT 9 -#if defined(_KERNEL) || defined(MAKEFS) +#ifdef _KERNEL struct mbnambuf { size_t nb_len; int nb_last_id; @@ -159,5 +159,5 @@ uint8_t winChksum(uint8_t *name); int winSlotCnt(const u_char *un, size_t unlen, struct msdosfsmount *pmp); size_t winLenFixup(const u_char *un, size_t unlen); -#endif /* _KERNEL || MAKEFS */ +#endif /* _KERNEL */ #endif /* !_FS_MSDOSFS_DIRENTRY_H_ */ Index: sys/fs/msdosfs/fat.h =================================================================== --- sys/fs/msdosfs/fat.h +++ sys/fs/msdosfs/fat.h @@ -94,6 +94,7 @@ */ #define DE_CLEAR 1 /* Zero out the blocks allocated */ +struct buf; int pcbmap(struct denode *dep, u_long findcn, daddr_t *bnp, u_long *cnp, int* sp); int clusterfree(struct msdosfsmount *pmp, u_long cn, u_long *oldcnp); int clusteralloc(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got); Index: sys/fs/msdosfs/msdosfs_fat.c =================================================================== --- sys/fs/msdosfs/msdosfs_fat.c +++ sys/fs/msdosfs/msdosfs_fat.c @@ -49,10 +49,20 @@ */ #include +#include +#ifndef MAKEFS #include #include #include #include +#else +#include +#include +#include + +#include "ffs/buf.h" +#include "msdos/msdosfs_extern.h" +#endif #include #include @@ -60,7 +70,12 @@ #include #include -#define FULL_RUN ((u_int)0xffffffff) +#define FULL_RUN ((u_int)0xffffffff) +#ifndef MAKEFS +#define SYNCHRONOUS_WRITES(pmp) (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS) +#else +#define SYNCHRONOUS_WRITES(pmp) 1 +#endif static int chainalloc(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, @@ -341,7 +356,7 @@ ((uint8_t *)bpn->b_data)[3] |= 0x80; else if (cleanfat == 32) ((uint8_t *)bpn->b_data)[7] |= 0x08; - if (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS) + if (SYNCHRONOUS_WRITES(pmp)) bwrite(bpn); else bdwrite(bpn); @@ -351,7 +366,7 @@ /* * Write out the first (or current) FAT last. */ - if (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS) + if (SYNCHRONOUS_WRITES(pmp)) bwrite(bp); else bdwrite(bp); @@ -967,7 +982,6 @@ u_long cn, got; struct msdosfsmount *pmp = dep->de_pmp; struct buf *bp; - daddr_t blkno; /* * Don't try to extend the root directory @@ -1047,6 +1061,8 @@ */ fc_setcache(dep, FC_LASTFC, frcn + got - 1, cn + got - 1); +#ifndef MAKEFS + daddr_t blkno; if (flags & DE_CLEAR) { while (got-- > 0) { /* @@ -1080,6 +1096,23 @@ bdwrite(bp); } } +#else + if ((flags & DE_CLEAR) && + (dep->de_Attributes & ATTR_DIRECTORY)) { + while (got-- > 0) { + bp = getblk(pmp->pm_devvp, + cntobn(pmp, cn++), + pmp->pm_bpcluster, 0, 0, 0); + clrbuf(bp); + if (bpp) { + *bpp = bp; + bpp = NULL; + } else { + bdwrite(bp); + } + } + } +#endif } return (0); Index: sys/fs/msdosfs/msdosfs_lookup.c =================================================================== --- sys/fs/msdosfs/msdosfs_lookup.c +++ sys/fs/msdosfs/msdosfs_lookup.c @@ -49,11 +49,18 @@ */ #include +#include +#ifndef MAKEFS #include #include #include #include #include +#else +#include +#include "ffs/buf.h" +#include "msdos/msdosfs_extern.h" +#endif #include #include @@ -61,6 +68,7 @@ #include #include +#ifndef MAKEFS static int msdosfs_lookup_(struct vnode *vdp, struct vnode **vpp, struct componentname *cnp, uint64_t *inum); @@ -584,6 +592,8 @@ return (0); } +#endif /* !MAKEFS */ + /* * dep - directory entry to copy into the directory * ddep - directory to add to @@ -648,7 +658,7 @@ brelse(bp); return error; } - ndep = bptoep(pmp, bp, ddep->de_fndoffset); + ndep = bptoep(pmp, bp, diroffset); DE_EXTERNALIZE(ndep, dep); @@ -677,7 +687,7 @@ return error; error = bread(pmp->pm_devvp, bn, blsize, - NOCRED, &bp); + NOCRED, &bp); if (error) { brelse(bp); return error; @@ -749,7 +759,7 @@ return (0); } for (dentp = (struct direntry *)bp->b_data; - (char *)dentp < bp->b_data + blsize; + (char *)dentp < (char *)bp->b_data + blsize; dentp++) { if (dentp->deName[0] != SLOT_DELETED && (dentp->deAttributes & ATTR_VOLUME) == 0) { @@ -1039,7 +1049,7 @@ return error; } for (dentp = (struct direntry *)bp->b_data; - (char *)dentp < bp->b_data + blsize; + (char *)dentp < (char *)bp->b_data + blsize; dentp++) { if (dentp->deName[0] == SLOT_EMPTY) { /* Index: sys/fs/msdosfs/msdosfsmount.h =================================================================== --- sys/fs/msdosfs/msdosfsmount.h +++ sys/fs/msdosfs/msdosfsmount.h @@ -51,7 +51,7 @@ #ifndef _MSDOSFS_MSDOSFSMOUNT_H_ #define _MSDOSFS_MSDOSFSMOUNT_H_ -#ifdef _KERNEL +#if defined(_KERNEL) || defined(MAKEFS) #include #include @@ -213,6 +213,10 @@ ? roottobn((pmp), (dirofs)) \ : cntobn((pmp), (dirclu))) +#endif /* _KERNEL || MAKEFS */ + +#ifndef MAKEFS + #define MSDOSFS_LOCK_MP(pmp) \ lockmgr(&(pmp)->pm_fatlock, LK_EXCLUSIVE, NULL) #define MSDOSFS_UNLOCK_MP(pmp) \ @@ -220,8 +224,6 @@ #define MSDOSFS_ASSERT_MP_LOCKED(pmp) \ lockmgr_assert(&(pmp)->pm_fatlock, KA_XLOCKED) -#endif /* _KERNEL */ - /* * Arguments to mount MSDOS filesystems. */ @@ -239,6 +241,7 @@ char *cs_local; /* Local Charset */ mode_t dirmask; /* dir mask to be applied for msdosfs perms */ }; +#endif /* * Msdosfs mount options: