Msdos fsync

Amit Khivesara amit.khivesara at utstar.com
Sat Feb 7 04:09:33 PST 2004


Hi,

The fsync for msdos does not seem to sync the FAT entries.
Hence the file can be corrupted if the syncer has not come in
and synced the entries.
If anyone is interested I have added a function fat_sync
to do this. This will allow the msdos fsync really "sync" the file.
The diffs are given below for kernel 4.1.1.

I am new to this mailing list.
If this is a unappropriate post, then let me know.


khivi



diff msdosfs/fat.h msdosfs.new/fat.h
106a107

 >> void fat_sync __P((struct vnode * , struct denode *dep));

diff msdosfs/msdosfs_fat.c msdosfs.new/msdosfs_fat.c
325a326,398

 >>  * Sync the fat cache in denode dep of all entries relating to file
 >>  */
 >> void
 >> fat_sync(vnode,dep)
 >>  struct vnode *vnode;
 >>  struct denode *dep;
 >> {
 >>     u_long cn;
 >>     u_long prevcn;
 >>
 >>     u_long byteoffset;
 >>     u_long bsize;
 >>     u_long bo;
 >>     u_long bn;
 >>  u_long bp_bn = -1;
 >>  int error;
 >>     struct buf *bp = NULL;
 >>     struct msdosfsmount *pmp = dep->de_pmp;
 >>
 >>     u_int pm_flags=pmp->pm_flags;
 >>     pmp->pm_flags |= MSDOSFSMNT_WAITONFAT;
 >>
 >>      cn=dep->de_StartCluster;
 >>      while (1){
 >>      /*
 >>       * Stop with all reserved clusters, not just with EOF.
 >>       */
 >>      if ((cn | ~pmp->pm_fatmask) >= CLUST_RSRVD)
 >>          goto hiteof;
 >>      byteoffset = FATOFS(pmp, cn);
 >>      fatblock(pmp, byteoffset, &bn, &bsize, &bo);
 >>      if (bn != bp_bn) {
 >>          if (bp) {
 >>                                 updatefats(pmp, bp, bp_bn);
 >>                         }
 >>          error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
 >>          if (error) {
 >>              brelse(bp);
 >>              goto func_ret;
 >>          }
 >>          bp_bn = bn;
 >>      }
 >>
 >>      prevcn = cn;
 >>      if (FAT32(pmp))
 >>          cn = getulong(&bp->b_data[bo]);
 >>      else
 >>          cn = getushort(&bp->b_data[bo]);
 >>      if (FAT12(pmp) && (prevcn & 1))
 >>          cn >>= 4;
 >>      cn &= pmp->pm_fatmask;
 >>
 >>      /*
 >>       * Force the special cluster numbers
 >>       * to be the same for all cluster sizes
 >>       * to let the rest of msdosfs handle
 >>       * all cases the same.
 >>       */
 >>      if ((cn | ~pmp->pm_fatmask) >= CLUST_RSRVD)
 >>          cn |= ~pmp->pm_fatmask;
 >>      }
 >>
 >>
 >> hiteof:
 >>     if (bp) {
 >>         updatefats(pmp, bp, bp_bn);
 >>     }
 >> func_ret:
 >>     pmp->pm_flags=pm_flags;
 >>     return;
 >> }
 >>
 >> /*

diff msdosfs/msdosfs_vnops.c msdosfs.new/msdosfs_vnops.c
869a870,872
 >>         fat_sync(vp,VTODE(vp));




More information about the freebsd-fs mailing list