From 3d0c96c7f34204aa4386cd9c1cd4a3e7977d52a0 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 7 May 2012 16:31:15 +0200 Subject: Filesystem: PR1893: Fix write and truncate handler Space that grows due to truncate or write offsets beyond the current file size must be zero filled. --- cpukit/libfs/src/dosfs/fat.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'cpukit/libfs/src/dosfs/fat.c') diff --git a/cpukit/libfs/src/dosfs/fat.c b/cpukit/libfs/src/dosfs/fat.c index 39a7bacb24..a7030fc78c 100644 --- a/cpukit/libfs/src/dosfs/fat.c +++ b/cpukit/libfs/src/dosfs/fat.c @@ -263,6 +263,42 @@ _fat_block_write( return cmpltd; } +int +_fat_block_zero( + rtems_filesystem_mount_table_entry_t *mt_entry, + uint32_t start, + uint32_t offset, + uint32_t count) +{ + int rc = RC_OK; + fat_fs_info_t *fs_info = mt_entry->fs_info; + uint32_t blk = start; + uint32_t ofs = offset; + rtems_bdbuf_buffer *block = NULL; + uint32_t c = 0; + + while(count > 0) + { + c = MIN(count, (fs_info->vol.bps - ofs)); + + if (c == fs_info->vol.bps) + rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_GET, &block); + else + rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block); + if (rc != RC_OK) + return -1; + + memset((block->buffer + ofs), 0, c); + + fat_buf_mark_modified(fs_info); + + count -= c; + blk++; + ofs = 0; + } + return 0; +} + /* _fat_block_release -- * This function works around the hack that hold a bdbuf and does * not release it. -- cgit v1.2.3