From eefeefdd0ec31e90e7805b38c5d0fcafc0edd8f3 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 30 Jan 2013 10:31:40 +0100 Subject: [PATCH] dosfs: Always release the buffers Release the buffers also if this is not the last reference to the file object since otherwise we may hold modified data indefinitely. --- cpukit/libfs/src/dosfs/fat_file.c | 47 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/cpukit/libfs/src/dosfs/fat_file.c b/cpukit/libfs/src/dosfs/fat_file.c index 3e2d60967c..7f05447187 100644 --- a/cpukit/libfs/src/dosfs/fat_file.c +++ b/cpukit/libfs/src/dosfs/fat_file.c @@ -191,45 +191,46 @@ fat_file_close( ) { int rc = RC_OK; - uint32_t key = 0; /* * if links_num field of fat-file descriptor is greater than 1 - * decrement the count of links and return + * decrement only the count of links */ if (fat_fd->links_num > 1) { fat_fd->links_num--; - return rc; - } - - key = fat_construct_key(fs_info, &fat_fd->dir_pos.sname); - - if (fat_fd->flags & FAT_FILE_REMOVED) - { - rc = fat_file_truncate(fs_info, fat_fd, 0); - if ( rc != RC_OK ) - return rc; - - _hash_delete(fs_info->rhash, key, fat_fd->ino, fat_fd); - - if ( fat_ino_is_unique(fs_info, fat_fd->ino) ) - fat_free_unique_ino(fs_info, fat_fd->ino); - - free(fat_fd); } else { - if (fat_ino_is_unique(fs_info, fat_fd->ino)) + uint32_t key = fat_construct_key(fs_info, &fat_fd->dir_pos.sname); + + if (fat_fd->flags & FAT_FILE_REMOVED) { - fat_fd->links_num = 0; + rc = fat_file_truncate(fs_info, fat_fd, 0); + if (rc == RC_OK) + { + _hash_delete(fs_info->rhash, key, fat_fd->ino, fat_fd); + + if (fat_ino_is_unique(fs_info, fat_fd->ino)) + fat_free_unique_ino(fs_info, fat_fd->ino); + + free(fat_fd); + } } else { - _hash_delete(fs_info->vhash, key, fat_fd->ino, fat_fd); - free(fat_fd); + if (fat_ino_is_unique(fs_info, fat_fd->ino)) + { + fat_fd->links_num = 0; + } + else + { + _hash_delete(fs_info->vhash, key, fat_fd->ino, fat_fd); + free(fat_fd); + } } } + /* * flush any modified "cached" buffer back to disk */