aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-01-25 09:25:41 -0800
committerH. Peter Anvin <hpa@zytor.com>2010-01-25 09:25:41 -0800
commite7dc052ed537428dc69fcf18ef354e9e00973003 (patch)
tree9425f91be353b221bd98885c9e8e78cf58286bb3
parent21ec7e06f96074a6dce3a256120e58a770bb7b1e (diff)
downloadsyslinux.git-e7dc052ed537428dc69fcf18ef354e9e00973003.tar.gz
syslinux.git-e7dc052ed537428dc69fcf18ef354e9e00973003.tar.xz
syslinux.git-e7dc052ed537428dc69fcf18ef354e9e00973003.zip
FAT: clean up cluster arithmetic
a) clean up the computation of the FAT12 FAT entry offset. b) the highest allocatable cluster is ...ff6, not ...ff0. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--core/fs/fat/fat.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/core/fs/fat/fat.c b/core/fs/fat/fat.c
index d77fcb12..ce3cae6a 100644
--- a/core/fs/fat/fat.c
+++ b/core/fs/fat/fat.c
@@ -54,13 +54,14 @@ static uint32_t get_next_cluster(struct fs_info *fs, uint32_t clust_num)
switch(FAT_SB(fs)->fat_type) {
case FAT12:
- fat_sector = (clust_num + clust_num / 2) >> SECTOR_SHIFT;
+ offset = clust_num + (clust_num >> 1);
+ fat_sector = offset >> SECTOR_SHIFT;
+ offset &= (1 << SECTOR_SHIFT) - 1;
cs = get_fat_sector(fs, fat_sector);
- offset = (clust_num * 3 / 2) & ((1 << SECTOR_SHIFT) - 1);
- if (offset == 0x1ff) {
+ if (offset == SECTOR_SIZE-1) {
/*
* we got the end of the one fat sector,
- * but we don't got we have(just one byte, we need two),
+ * but we have just one byte and we need two,
* so store the low part, then read the next fat
* sector, read the high part, then combine it.
*/
@@ -76,7 +77,7 @@ static uint32_t get_next_cluster(struct fs_info *fs, uint32_t clust_num)
next_cluster >>= 4; /* cluster number is ODD */
else
next_cluster &= 0x0fff; /* cluster number is EVEN */
- if (next_cluster > 0x0ff0)
+ if (next_cluster > 0x0ff6)
goto fail;
break;
@@ -85,7 +86,7 @@ static uint32_t get_next_cluster(struct fs_info *fs, uint32_t clust_num)
offset = clust_num & ((1 << (SECTOR_SHIFT-1)) -1);
cs = get_fat_sector(fs, fat_sector);
next_cluster = ((uint16_t *)cs->data)[offset];
- if (next_cluster > 0xfff0)
+ if (next_cluster > 0xfff6)
goto fail;
break;
@@ -94,7 +95,7 @@ static uint32_t get_next_cluster(struct fs_info *fs, uint32_t clust_num)
offset = clust_num & ((1 << (SECTOR_SHIFT-2)) -1);
cs = get_fat_sector(fs, fat_sector);
next_cluster = ((uint32_t *)cs->data)[offset] & 0x0fffffff;
- if (next_cluster > 0x0ffffff0)
+ if (next_cluster > 0x0ffffff6)
goto fail;
break;
}