[rtems commit] dosfs: Fix file extend
Sebastian Huber
sebh at rtems.org
Fri Feb 15 16:08:44 UTC 2013
Module: rtems
Branch: master
Commit: df8c2d77f60d21280e28aad115639a9f391a4657
Changeset: http://git.rtems.org/rtems/commit/?id=df8c2d77f60d21280e28aad115639a9f391a4657
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri Feb 15 16:53:53 2013 +0100
dosfs: Fix file extend
Only append a valid cluster chain (cluster added > 0), otherwise we
overwrite the root directory cluster (cluster 0) of a FAT12 or FAT16
with arbitrary data.
---
cpukit/libfs/src/dosfs/fat_file.c | 47 +++++++++++++++++++------------------
1 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/cpukit/libfs/src/dosfs/fat_file.c b/cpukit/libfs/src/dosfs/fat_file.c
index 7f05447..b71745f 100644
--- a/cpukit/libfs/src/dosfs/fat_file.c
+++ b/cpukit/libfs/src/dosfs/fat_file.c
@@ -637,42 +637,43 @@ fat_file_extend(
new_length -= (cls2add - cls_added) << fs_info->vol.bpc_log2;
}
- /* add new chain to the end of existed */
- if ( fat_fd->fat_file_size == 0 )
+ if (cls_added > 0)
{
- fat_fd->map.disk_cln = fat_fd->cln = chain;
- fat_fd->map.file_cln = 0;
- }
- else
- {
- if (fat_fd->map.last_cln != FAT_UNDEFINED_VALUE)
+ /* add new chain to the end of existing */
+ if ( fat_fd->fat_file_size == 0 )
{
- old_last_cl = fat_fd->map.last_cln;
+ fat_fd->map.disk_cln = fat_fd->cln = chain;
+ fat_fd->map.file_cln = 0;
}
else
{
- rc = fat_file_ioctl(fs_info, fat_fd, F_CLU_NUM,
- (fat_fd->fat_file_size - 1), &old_last_cl);
+ if (fat_fd->map.last_cln != FAT_UNDEFINED_VALUE)
+ {
+ old_last_cl = fat_fd->map.last_cln;
+ }
+ else
+ {
+ rc = fat_file_ioctl(fs_info, fat_fd, F_CLU_NUM,
+ (fat_fd->fat_file_size - 1), &old_last_cl);
+ if ( rc != RC_OK )
+ {
+ fat_free_fat_clusters_chain(fs_info, chain);
+ return rc;
+ }
+ }
+
+ rc = fat_set_fat_cluster(fs_info, old_last_cl, chain);
if ( rc != RC_OK )
{
fat_free_fat_clusters_chain(fs_info, chain);
return rc;
}
+ fat_buf_release(fs_info);
}
- rc = fat_set_fat_cluster(fs_info, old_last_cl, chain);
- if ( rc != RC_OK )
- {
- fat_free_fat_clusters_chain(fs_info, chain);
- return rc;
- }
- fat_buf_release(fs_info);
- }
-
- /* update number of the last cluster of the file if it changed */
- if (cls_added != 0)
- {
+ /* update number of the last cluster of the file */
fat_fd->map.last_cln = last_cl;
+
if (fat_fd->fat_file_type == FAT_DIRECTORY)
{
rc = fat_init_clusters_chain(fs_info, chain);
More information about the vc
mailing list