X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FFilesystems%2FFAT%2Ffatio.c;h=340ccf82548a47da9a7621544fe17b741836f978;hb=f61ceab9841c9dabb0b0747c44107da68f75fde8;hp=ab49b30bde9acda70725c2d0e04b56b7083afb95;hpb=0ea39901119279ee9bb9cf8270b2a0d65cb7460f;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/Filesystems/FAT/fatio.c b/KernelLand/Modules/Filesystems/FAT/fatio.c index ab49b30b..340ccf82 100644 --- a/KernelLand/Modules/Filesystems/FAT/fatio.c +++ b/KernelLand/Modules/Filesystems/FAT/fatio.c @@ -5,7 +5,7 @@ * fatio.c * - FAT Manipulation and Cluster IO */ -#define DEBUG 1 +#define DEBUG 0 #include #include #include "common.h" @@ -35,7 +35,8 @@ Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 cluster) ofs = Disk->bootsect.resvSectCount*512; if(Disk->type == FAT12) { VFS_ReadAt(Disk->fileHandle, ofs+(cluster/2)*3, 3, &val); - val = (cluster & 1 ? val>>12 : val & 0xFFF); + LOG("3 bytes at 0x%x are (Uint32)0x%x", ofs+(cluster/2)*3, val); + val = (cluster & 1) ? (val>>12) : (val & 0xFFF); if(val == EOC_FAT12) val = -1; } else if(Disk->type == FAT16) { VFS_ReadAt(Disk->fileHandle, ofs+cluster*2, 2, &val); @@ -108,6 +109,7 @@ Uint32 FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous) } Mutex_Release(&Disk->lFAT); + LOG("Allocated cluster %x", ret); return ret; } else @@ -137,7 +139,7 @@ Uint32 FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous) // Search within the same block as the previous cluster first do { - VFS_ReadAt(Disk->fileHandle, base + block, block_size, sector_data); + VFS_ReadAt(Disk->fileHandle, base + block*block_size, block_size, sector_data); for( block_ofs = 0; block_ofs < ents_per_block_12; block_ofs ++ ) { Uint32 *valptr = (void*)( sector_data + block_ofs / 2 * 3 ); @@ -166,16 +168,21 @@ Uint32 FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous) VFS_WriteAt(Disk->fileHandle, base + block, block_size, sector_data); // Note the new cluster in the chain - VFS_ReadAt(Disk->fileHandle, base + (Previous>>1)*3, 3, &val); - if( ret & 1 ) { - val &= 0x000FFF; - val |= ret << 12; - } - else { - val &= 0xFFF000; - val |= ret << 0; + if( Previous != -1 ) + { + LOG("Updating cluster %x to point to %x (offset %x)", Previous, ret, + base + (Previous>>1)*3); + VFS_ReadAt(Disk->fileHandle, base + (Previous>>1)*3, 3, &val); + if( Previous & 1 ) { + val &= 0x000FFF; + val |= ret << 12; + } + else { + val &= 0xFFF000; + val |= ret << 0; + } + VFS_WriteAt(Disk->fileHandle, base + (Previous>>1)*3, 3, &val); } - VFS_WriteAt(Disk->fileHandle, base + (Previous>>1)*3, 3, &val); } break; case FAT16: @@ -190,6 +197,7 @@ Uint32 FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous) break; } Mutex_Release(&Disk->lFAT); + LOG("Allocated cluster %x", ret); return ret; #if CACHE_FAT }