c++ - FAT32 in practice does not conform Microsoft's documentation -


i'm working on project in need read bpb of fat32 partition, based on that, verify partition indeed valid fat32 before doing else it.

according microsoft's documentation (in table starting on page 9), fields bpb_rootentcnt (located @ 0x17, size 2), , bpb_totsec16 (located @ 0x19, size 2) must both set 0 in case of fat32 partition. since official documentation clear this, assumed checking if these 0 idea verify partition valid fat32 (these 2 values not ones i'm using verification, these problematic ones).

i tried number of different storage devices, each formatted fat32 under different operating systems, , in every single case, these 2 fields have non-zero values!

why this? official documentation of fat32 states these fields must set zero. how can different formatting tools (including windows' built-in formatting option) ignore rule?

first thought program didn't work expected, think there no problems that. here's short, self-contained example, prints out value of these 2 fields of fat32 partition:

#include <iostream> #include <string> #include <cstdio> #include <unistd.h> using namespace std;  void printfat32fields(const string& vol) {     // unmount volume     system(("sudo umount -f "s + vol + " 1> /dev/null 2>&1"s).c_str());      // open     auto fp = fopen(vol.c_str(), "r");     if (!fp) {         perror("error");         throw runtime_error("the volume '"s + vol + "' cannot accessed!"s);     }     setbuf(fp, null);      uint16_t bpb_rootentcnt = 0x0;     uint16_t bpb_totsec16   = 0x0;      fseek(fp, 0x17, seek_set);     fread(&bpb_rootentcnt, 1, 2, fp);      fseek(fp, 0x19, seek_set);     fread(&bpb_totsec16, 1, 2, fp);      fclose(fp);      cout << bpb_rootentcnt << " " << bpb_totsec16 << endl; }  int main() {      if (getuid()) {         cout << "this program needs root privileges run!" << endl;         return 0;     }      try {         printfat32fields("path volume goes here");     } catch(runtime_error err) {         cout << err.what();     }      return 0; } 

this code works on os x, linux, , possibly other unix-like systems well, not windows. "path volume" has of course /dev/..., example /dev/disk1s1 on os x, or /dev/sda1 on linux.

so how can be? program prints out 2 non-zero values if give path of fat32 partition, while (according documentation) these values should zero.

it program :)
offsets bpb_rootentcnt , bpb_totsec16
not 0x17 (=23) , 0x19 (=25), 17 , 19.

to compare data such issues in future, it´s helpful first kb
dd in file , view hex editor. (and read more carefully...)


Comments