From 924f6d1bfdeddcd4c875dd398c179eaba4835739 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Fri, 26 Jun 2009 20:12:33 +0000 Subject: [PATCH] In case of "not sure" if the removable media has changed, the IBM PCDOS technical reference says to call BLDBPB if there are no used buffers, so we only do it then, instead of flushing the buffers. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1458 6ac86273-5f31-0410-b378-82cca8765d1b --- kernel/blockio.c | 18 ++++++++++++++++++ kernel/fatfs.c | 6 ++++-- kernel/proto.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/kernel/blockio.c b/kernel/blockio.c index 0c02db1..2840f2d 100644 --- a/kernel/blockio.c +++ b/kernel/blockio.c @@ -259,6 +259,24 @@ VOID setinvld(REG COUNT dsk) while (FP_OFF(bp) != FP_OFF(firstbuf)); } +/* Check if there is at least one dirty buffer */ +/* */ +BOOL dirty_buffers(REG COUNT dsk) +{ + struct buffer FAR *bp = firstbuf; + + do + { + if (bp->b_unit == dsk && + (bp->b_flag & (BFR_VALID | BFR_DIRTY)) == (BFR_VALID | BFR_DIRTY)) + return TRUE; + bp = b_next(bp); + } + while (FP_OFF(bp) != FP_OFF(firstbuf)); + return FALSE; +} + +/* */ /* */ /* Flush all buffers for a disk */ /* */ diff --git a/kernel/fatfs.c b/kernel/fatfs.c index c0efeaf..8fa565d 100644 --- a/kernel/fatfs.c +++ b/kernel/fatfs.c @@ -1687,8 +1687,10 @@ COUNT media_check(REG struct dpb FAR * dpbp) /* If it is forced or the media may have changed, */ /* rebuild the bpb */ case M_DONT_KNOW: - /* hazard: no error checking! */ - flush_buffers(dpbp->dpb_unit); + /* IBM PCDOS technical reference says to call BLDBPB if */ + /* there are no used buffers */ + if (dirty_buffers(dpbp->dpb_unit)) + return SUCCESS; /* If it definitely changed, don't know (falls through) */ /* or has been changed, rebuild the bpb. */ diff --git a/kernel/proto.h b/kernel/proto.h index fa93118..7430b77 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -38,6 +38,7 @@ struct buffer FAR *getblk(ULONG blkno, COUNT dsk, BOOL overwrite); #define getblock(blkno, dsk) getblk(blkno, dsk, FALSE); #define getblockOver(blkno, dsk) getblk(blkno, dsk, TRUE); VOID setinvld(REG COUNT dsk); +BOOL dirty_buffers(REG COUNT dsk); BOOL flush_buffers(REG COUNT dsk); BOOL flush(void); BOOL fill(REG struct buffer FAR * bp, ULONG blkno, COUNT dsk);