MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / Identify

Function Identify

Kernel/src/fs/fat32.cpp:11–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9namespace 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);

Callers

nothing calls this directly

Calls 3

kmallocFunction · 0.85
kfreeFunction · 0.85
ReadBlockMethod · 0.45

Tested by

no test coverage detected