From a9763b6cf65938440e924653cdbb9c65a9a91297 Mon Sep 17 00:00:00 2001 From: batt Date: Thu, 25 Sep 2008 16:35:18 +0000 Subject: [PATCH] Avoid flushing the same page twice. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1847 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/fs/battfs.c | 53 +++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/bertos/fs/battfs.c b/bertos/fs/battfs.c index 2f4eee43..f43a9ce9 100644 --- a/bertos/fs/battfs.c +++ b/bertos/fs/battfs.c @@ -508,6 +508,11 @@ bool battfs_init(struct BattFsSuper *disk) return true; } +bool batts_fsck(struct BattFsSuper *disk) +{ + +} + /** * Flush file \a fd. * \return 0 if ok, EOF on errors. @@ -613,36 +618,40 @@ static size_t battfs_write(struct KFile *fd, const void *_buf, size_t size) fdb->disk->cache_dirty = true; } setBufferHdr(fdb->disk, &curr_hdr); - flushBuffer(fdb->disk); - - /* Fill page buffer with 0 to avoid filling unused pages with garbage */ - for (pgaddr_t off = 0; off < fdb->disk->data_size; off++) - { - if (fdb->disk->bufferWrite(fdb->disk, off, &dummy, 1) != 1) - { - #warning TODO set error? - } - } /* Allocate the missing pages first. */ pgoff_t missing_pages = fd->seek_pos / fdb->disk->data_size - fdb->max_off; - LOG_INFO("missing pages: %d\n", missing_pages); - while (missing_pages--) + if (missing_pages) { - zero_bytes = MIN((kfile_off_t)fdb->disk->data_size, fd->seek_pos - fd->size); - /* Get the new page needed */ - if (!getNewPage(fdb->disk, (fdb->start - fdb->disk->page_array) + fdb->max_off + 1, fdb->inode, fdb->max_off + 1, &curr_hdr)) - return total_write; + LOG_INFO("missing pages: %d\n", missing_pages); + flushBuffer(fdb->disk); - /* Update size and free space left */ - fd->size += zero_bytes; - fdb->disk->free_bytes -= zero_bytes; + /* Fill page buffer with 0 to avoid filling unused pages with garbage */ + for (pgaddr_t off = 0; off < fdb->disk->data_size; off++) + { + if (fdb->disk->bufferWrite(fdb->disk, off, &dummy, 1) != 1) + { + #warning TODO set error? + } + } - curr_hdr.fill = zero_bytes; - setBufferHdr(fdb->disk, &curr_hdr); + while (missing_pages--) + { + zero_bytes = MIN((kfile_off_t)fdb->disk->data_size, fd->seek_pos - fd->size); + /* Get the new page needed */ + if (!getNewPage(fdb->disk, (fdb->start - fdb->disk->page_array) + fdb->max_off + 1, fdb->inode, fdb->max_off + 1, &curr_hdr)) + return total_write; + + /* Update size and free space left */ + fd->size += zero_bytes; + fdb->disk->free_bytes -= zero_bytes; - fdb->max_off++; + curr_hdr.fill = zero_bytes; + setBufferHdr(fdb->disk, &curr_hdr); + + fdb->max_off++; + } } } else if (!getBufferHdr(fdb->disk, &curr_hdr)) -- 2.25.1