简体   繁体   中英

Reading/Writing FAT32 Bootloader image file on SD card for Win CE

I am trying to write a program in VC++ MFC that allows me to move through a FAT32 file system. However, I am having difficulty understanding and applying the equations to gather the correct data of FAT32 boot sector. Below is pseudocode about read and access FAT32 boot sector:

// First, allocate buffers for the sector data
if ((dst_data = (FAT32BOOTSECTOR *)VirtualAlloc(NULL,
      sizeof(FAT16BOOTSECTOR),  MEM_COMMIT, PAGE_READWRITE)) == NULL)

//Create destination drive
str.Format(_T("\\\\.\\%c:"), toupper(destDrive[2]));
      hDestinationDrive = CreateFile(str, GENERIC_READ |
      GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
      OPEN_EXISTING, 0, 0);

// Now read the boot sector of the destination drive to get it's drive params.
ReadFile(hDestinationDrive, dst_data, 512, &dwBytesRead, NULL);

I am displaying the FAT32 boot sector data as below:

Jump code: EB:3C:90
  OEM code: [MSDOS5.0]
  sector_size: 512
  sectors_per_cluster: 32
  reserved_sectors: 2
  number_of_fats: 2
  root_dir_entries: 512
  total_sectors_short: 0
  media_descriptor: 0xF8
  fat_size_sectors: 239
  sectors_per_track: 63
  number_of_heads: 255
  hidden_sectors: 129
  total_sectors_long: 1953663
  drive_number: 0x80
  current_head: 0x00
  boot_signature: 0x29
  volume_id: 0x1263EBDD
  Volume label: [NO NAME    ]
  Filesystem type: [FAT16   ]
  Boot sector signature: 0xAA55
  Remainder: 33, FFFFFFC9, FFFFFF8E, FFFFFFD1...

But the retrieved Filesystem type is "FAT16" not "FAT32" as I have formatted the SD card using Win XP SP3.

I don't understand completely how to read/write the FAT32 boot sector? Kindly let me know if any alternate method.

It's possible that you have a bug due to the following:

// First, allocate buffers for the sector data
if ((dst_data = (FAT32BOOTSECTOR *)VirtualAlloc(NULL,
      sizeof(FAT16BOOTSECTOR),  MEM_COMMIT, PAGE_READWRITE)) == NULL)

It looks like you're allocating space for a FAT32BOOTSECTOR but you specify the size you want as sizeof(FAT16BOOTSECTOR) , so you probably get a smaller chunk of memory than you require and part of the structure will be liable to corruption from other parts of the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM