读写FAT32引导程序映像文件在SD卡上的Win CE

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

本文关键字:Win CE SD FAT32 引导程序 映像 文件 读写      更新时间:2023-10-16

我试图在vc++ MFC中编写一个程序,允许我通过FAT32文件系统移动。但是,我很难理解和应用这些方程来收集FAT32引导扇区的正确数据。下面是关于读取和访问FAT32引导扇区的伪代码:

// 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);

我显示FAT32引导扇区数据如下:

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...

但是检索到的文件系统类型是"FAT16"而不是"FAT32",因为我使用Win XP SP3格式化了SD卡。

我完全不明白如何读/写FAT32引导扇区?如有其他方法,请告知。

有可能你有一个bug,由于以下原因:

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

看起来你正在为FAT32BOOTSECTOR分配空间,但你指定了sizeof(FAT16BOOTSECTOR)的大小,所以你可能会得到比你需要的更小的内存块,并且部分结构可能会被其他部分的代码损坏。