| 9 | namespace fs::FAT32{ |
| 10 | |
| 11 | int Identify(PartitionDevice* part){ |
| 12 | fat32_boot_record_t* bootRecord = (fat32_boot_record_t*)kmalloc(512); |
| 13 | |
| 14 | if(part->ReadBlock(0, 512, (uint8_t*)bootRecord)){ // Read Volume Boot Record (First sector of partition) |
| 15 | return -1; // Disk Error |
| 16 | } |
| 17 | |
| 18 | int isFat = 0; |
| 19 | |
| 20 | if(bootRecord->ebr.signature == 0x28 || bootRecord->ebr.signature == 0x29){ |
| 21 | uint32_t dataSectors = bootRecord->bpb.largeSectorCount - (bootRecord->bpb.reservedSectors + (bootRecord->ebr.sectorsPerFAT * bootRecord->bpb.fatCount)); |
| 22 | uint32_t clusters = dataSectors / bootRecord->bpb.sectorsPerCluster; |
| 23 | |
| 24 | if(clusters > 65525) isFat = 1; |
| 25 | } |
| 26 | |
| 27 | kfree(bootRecord); |
| 28 | |
| 29 | return isFat; |
| 30 | } |
| 31 | |
| 32 | uint64_t Fat32Volume::ClusterToLBA(uint32_t cluster){ |
| 33 | return (bootRecord->bpb.reservedSectors + bootRecord->bpb.fatCount * bootRecord->ebr.sectorsPerFAT) + cluster * bootRecord->bpb.sectorsPerCluster - (2 * bootRecord->bpb.sectorsPerCluster); |