From b8f6d4a649d44c98668d0080b8824a48816ae4b0 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sun, 29 Mar 2015 12:30:45 +0000 Subject: [PATCH] libminixfs: do not flush blocks that are in use This removes an implicit requirement for the way the libminixfs API is to be used, namely that a block is to be marked as dirty only once its contents have been fully updated, within a single get_block/put_block window. The requirement may not be appropriate for all file systems. Change-Id: I6a129d51b1a5e9aec1572039dc7c1c82dd795db5 --- minix/lib/libminixfs/cache.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/minix/lib/libminixfs/cache.c b/minix/lib/libminixfs/cache.c index 71e8e0349..b4b5e180c 100644 --- a/minix/lib/libminixfs/cache.c +++ b/minix/lib/libminixfs/cache.c @@ -732,7 +732,7 @@ void lmfs_flushdev(dev_t dev) /* Flush all dirty blocks for one device. */ register struct buf *bp; - static struct buf **dirty; /* static so it isn't on stack */ + static struct buf **dirty; static unsigned int dirtylistsize = 0; int ndirty; @@ -747,9 +747,13 @@ void lmfs_flushdev(dev_t dev) } for (bp = &buf[0], ndirty = 0; bp < &buf[nr_bufs]; bp++) { - if (!lmfs_isclean(bp) && bp->lmfs_dev == dev) { - dirty[ndirty++] = bp; - } + /* Do not flush dirty blocks that are in use (lmfs_count>0): the file + * system may mark the block as dirty before changing its contents, in + * which case the new contents could end up being lost. + */ + if (!lmfs_isclean(bp) && bp->lmfs_dev == dev && bp->lmfs_count == 0) { + dirty[ndirty++] = bp; + } } lmfs_rw_scattered(dev, dirty, ndirty, WRITING);