diff options
Diffstat (limited to 'firmware/drivers/fat.c')
-rw-r--r-- | firmware/drivers/fat.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 694a7727c3..74f61c2552 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -466,13 +466,11 @@ static int update_fat_entry(unsigned int entry, unsigned int val) | |||
466 | 466 | ||
467 | LDEBUGF("update_fat_entry(%x,%x)\n",entry,val); | 467 | LDEBUGF("update_fat_entry(%x,%x)\n",entry,val); |
468 | 468 | ||
469 | #ifdef TEST_FAT | ||
470 | if (entry==val) | 469 | if (entry==val) |
471 | panicf("Creating FAT loop: %x,%x\n",entry,val); | 470 | panicf("Creating FAT loop: %x,%x\n",entry,val); |
472 | 471 | ||
473 | if ( entry < 2 ) | 472 | if ( entry < 2 ) |
474 | panicf("Updating reserved FAT entry %d.\n",entry); | 473 | panicf("Updating reserved FAT entry %d.\n",entry); |
475 | #endif | ||
476 | 474 | ||
477 | sec = cache_fat_sector(sector); | 475 | sec = cache_fat_sector(sector); |
478 | if (!sec) | 476 | if (!sec) |
@@ -491,6 +489,8 @@ static int update_fat_entry(unsigned int entry, unsigned int val) | |||
491 | fat_bpb.fsinfo.freecount++; | 489 | fat_bpb.fsinfo.freecount++; |
492 | } | 490 | } |
493 | 491 | ||
492 | LDEBUGF("update_fat_entry: %d free clusters\n", fat_bpb.fsinfo.freecount); | ||
493 | |||
494 | /* don't change top 4 bits */ | 494 | /* don't change top 4 bits */ |
495 | sec[offset] &= SWAB32(0xf0000000); | 495 | sec[offset] &= SWAB32(0xf0000000); |
496 | sec[offset] |= SWAB32(val & 0x0fffffff); | 496 | sec[offset] |= SWAB32(val & 0x0fffffff); |
@@ -873,13 +873,14 @@ static void update_dir_entry( struct fat_file* file, int size ) | |||
873 | unsigned short* clusptr; | 873 | unsigned short* clusptr; |
874 | int err; | 874 | int err; |
875 | 875 | ||
876 | LDEBUGF("update_dir_entry(cluster:%x entry:%d size:%d)\n", | 876 | LDEBUGF("update_dir_entry(cluster:%x entry:%d sector:%x size:%d)\n", |
877 | file->firstcluster,file->direntry,size); | 877 | file->firstcluster,file->direntry,sector,size); |
878 | 878 | ||
879 | if ( file->direntry >= (SECTOR_SIZE / DIR_ENTRY_SIZE) ) { | 879 | if ( file->direntry >= (SECTOR_SIZE / DIR_ENTRY_SIZE) ) |
880 | DEBUGF("update_dir_entry(): Illegal entry %d!\n",file->direntry); | 880 | panicf("update_dir_entry(): Illegal entry %d!\n",file->direntry); |
881 | return; | 881 | |
882 | } | 882 | if ( file->direntry < 0 ) |
883 | panicf("update_dir_entry(): Illegal entry %d!\n",file->direntry); | ||
883 | 884 | ||
884 | err = ata_read_sectors(sector, 1, buf); | 885 | err = ata_read_sectors(sector, 1, buf); |
885 | if (err) | 886 | if (err) |
@@ -949,7 +950,7 @@ int fat_open(unsigned int startcluster, | |||
949 | 950 | ||
950 | /* remember where the file's dir entry is located */ | 951 | /* remember where the file's dir entry is located */ |
951 | file->dirsector = dir->cached_sec; | 952 | file->dirsector = dir->cached_sec; |
952 | file->direntry = (dir->entry % DIR_ENTRIES_PER_SECTOR) - 1; | 953 | file->direntry = dir->entry - 1; |
953 | LDEBUGF("fat_open(%x), entry %d\n",startcluster,file->direntry); | 954 | LDEBUGF("fat_open(%x), entry %d\n",startcluster,file->direntry); |
954 | return 0; | 955 | return 0; |
955 | } | 956 | } |
@@ -1013,7 +1014,8 @@ int fat_closewrite(struct fat_file *file, int size) | |||
1013 | else | 1014 | else |
1014 | update_fat_entry(endcluster, FAT_EOF_MARK); | 1015 | update_fat_entry(endcluster, FAT_EOF_MARK); |
1015 | 1016 | ||
1016 | update_dir_entry(file, size); | 1017 | if (file->dirsector) |
1018 | update_dir_entry(file, size); | ||
1017 | flush_fat(); | 1019 | flush_fat(); |
1018 | 1020 | ||
1019 | #ifdef TEST_FAT | 1021 | #ifdef TEST_FAT |
@@ -1043,13 +1045,14 @@ int fat_remove(struct fat_file* file) | |||
1043 | 1045 | ||
1044 | LDEBUGF("fat_remove(%x)\n",last); | 1046 | LDEBUGF("fat_remove(%x)\n",last); |
1045 | 1047 | ||
1046 | while ( last != FAT_EOF_MARK ) { | 1048 | while ( last ) { |
1047 | LDEBUGF("Freeing cluster %x\n",last); | ||
1048 | next = get_next_cluster(last); | 1049 | next = get_next_cluster(last); |
1049 | update_fat_entry(last,0); | 1050 | update_fat_entry(last,0); |
1050 | last = next; | 1051 | last = next; |
1051 | } | 1052 | } |
1052 | update_dir_entry(file, -1); | 1053 | update_dir_entry(file, -1); |
1054 | file->dirsector = 0; | ||
1055 | file->firstcluster = 0; | ||
1053 | 1056 | ||
1054 | return 0; | 1057 | return 0; |
1055 | } | 1058 | } |