I am trying to write a program in C that allows me to move through a FAT32 file system image. However, I am having difficulty understanding and applying the equations to gather the correct data. I am using a debian distribution of linux so little-endian form is maintained. Below is pseudocode from the Microsoft website about FAT32, calculating the next cluster to access of a directory or file:
ThisFATSecNum = BPB_ResvdSecCnt + (FATOffset / BPB_BytsPerSec);
ThisFATEntOffset = REM(FATOffset / BPB_BytsPerSec);
FAT32ClusEntryVal = FAT32ClusEntryVal & 0x0FFFFFFF;
*((DWORD *) &SecBuff[ThisFATEntOffset]) =
(*((DWORD *) &SecBuff[ThisFATEntOffset])) & 0xF0000000;
*((DWORD *) &SecBuff[ThisFATEntOffset]) =
(*((DWORD *) &SecBuff[ThisFATEntOffset])) | FAT32ClusEntryVal;
I do not fully understand what the SecBuff character array is doing or what it's accessing. DWORD is supposed to be a unsigned int and I'm not sure I understand the subsequent casts either. Any light shed is much appreciated.
If someone could also explain how we are supposed to move through the FAT32 filesystem based on clusters it would be greatly appreciated, it seems to me that going by reference of sectors is more effective even though cluster allocation ensures spatial locality. I don't fully understand how to do the byte reading to find the next cluster for files/folders.