在SD卡上读取/写入FAT32 Bootloader映像文件以获取Win CE

时间:2013-04-26 12:39:14

标签: c++ mfc

我正在尝试在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...

但检索到的Filesystem类型是“FAT16”而不是“FAT32”,因为我使用Win XP SP3格式化了SD卡。

我完全不了解如何读/写FAT32启动扇区?如果有其他替代方法,请告诉我。

1 个答案:

答案 0 :(得分:0)

由于以下原因,您可能会遇到错误:

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

看起来你正在为FAT32BOOTSECTOR分配空间,但你指定了你想要的大小为sizeof(FAT16BOOTSECTOR),所以你可能会得到比你需要的更小的内存块,部分结构将会容易受到代码其他部分的腐败。