diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2011-09-16 14:07:17 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2011-09-16 14:07:17 +0000 |
commit | f23910b3c45ab999d50acddfabb3f1cc2ca4f040 (patch) | |
tree | e3f36345049a20b9fd3bdf2eeb47582bfa2700e9 /nuttx/fs | |
parent | bf6eea145f4cabb59286a1dd7b627b329201e4ac (diff) |
Fix a stray write into the FAT
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3958 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/fs')
-rw-r--r-- | nuttx/fs/fat/fs_fat32.c | 4 | ||||
-rw-r--r-- | nuttx/fs/fat/fs_fat32dirent.c | 2 | ||||
-rw-r--r-- | nuttx/fs/fat/fs_fat32util.c | 32 |
3 files changed, 22 insertions, 16 deletions
diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c index 8a7f6e29a8..f7818d5519 100644 --- a/nuttx/fs/fat/fs_fat32.c +++ b/nuttx/fs/fat/fs_fat32.c @@ -728,8 +728,8 @@ static ssize_t fat_write(FAR struct file *filep, const char *buffer, nsectors = ff->ff_sectorsincluster; } - /* We are not sure of the state of the file buffer so - * the safest thing to do is write back any dirty, cached sector + /* We are not sure of the state of the sector cache so the + * safest thing to do is write back any dirty, cached sector * and invalidate the current cache content. */ diff --git a/nuttx/fs/fat/fs_fat32dirent.c b/nuttx/fs/fat/fs_fat32dirent.c index 7f3cc38d66..0627b9bba6 100644 --- a/nuttx/fs/fat/fs_fat32dirent.c +++ b/nuttx/fs/fat/fs_fat32dirent.c @@ -2505,7 +2505,7 @@ int fat_allocatedirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo for (i = fs->fs_fatsecperclus; i; i--) { ret = fat_hwwrite(fs, fs->fs_buffer, sector, 1); - if ( ret < 0) + if (ret < 0) { return ret; } diff --git a/nuttx/fs/fat/fs_fat32util.c b/nuttx/fs/fat/fs_fat32util.c index ca4137a5a8..12c1a4e5f2 100644 --- a/nuttx/fs/fat/fs_fat32util.c +++ b/nuttx/fs/fat/fs_fat32util.c @@ -882,6 +882,7 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno, off_t nextclust value = (uint8_t)nextcluster; } + fs->fs_buffer[fatindex] = value; /* With FAT12, the second byte of the cluster number may lie in @@ -904,6 +905,7 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno, off_t nextclust if (fat_fscacheread(fs, fatsector) < 0) { /* Read error */ + break; } } @@ -924,6 +926,7 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno, off_t nextclust value = (fs->fs_buffer[fatindex] & 0xf0) | ((nextcluster >> 8) & 0x0f); } + fs->fs_buffer[fatindex] = value; } break; @@ -937,6 +940,7 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno, off_t nextclust if (fat_fscacheread(fs, fatsector) < 0) { /* Read error */ + break; } FAT_PUTFAT16(fs->fs_buffer, fatindex, nextcluster & 0xffff); @@ -952,6 +956,7 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno, off_t nextclust if (fat_fscacheread(fs, fatsector) < 0) { /* Read error */ + break; } FAT_PUTFAT32(fs->fs_buffer, fatindex, nextcluster & 0x0fffffff); @@ -964,7 +969,7 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno, off_t nextclust /* Mark the modified sector as "dirty" and return success */ - fs->fs_dirty = 1; + fs->fs_dirty = true; return OK; } @@ -1067,8 +1072,8 @@ int32_t fat_extendchain(struct fat_mountpt_s *fs, uint32_t cluster) } else if (startsector < 2) { - /* Oops.. this cluster does not exist. */ + return 0; } else if (startsector < fs->fs_nclusters) @@ -1351,37 +1356,38 @@ int fat_fscacheflush(struct fat_mountpt_s *fs) */ if (fs->fs_dirty) - { + { /* Write the dirty sector */ ret = fat_hwwrite(fs, fs->fs_buffer, fs->fs_currentsector, 1); if (ret < 0) - { + { return ret; - } + } /* Does the sector lie in the FAT region? */ - if (fs->fs_currentsector < fs->fs_fatbase + fs->fs_nfatsects) - { + if (fs->fs_currentsector >= fs->fs_fatbase && + fs->fs_currentsector < fs->fs_fatbase + fs->fs_nfatsects) + { /* Yes, then make the change in the FAT copy as well */ int i; for (i = fs->fs_fatnumfats; i >= 2; i--) - { + { fs->fs_currentsector += fs->fs_nfatsects; ret = fat_hwwrite(fs, fs->fs_buffer, fs->fs_currentsector, 1); if (ret < 0) - { + { return ret; - } - } - } + } + } + } /* No longer dirty */ fs->fs_dirty = false; - } + } return OK; } |