简体   繁体   English

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

[英]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. 我试图用VC ++ MFC编写一个程序,该程序可以使我在FAT32文件系统中移动。 However, I am having difficulty understanding and applying the equations to gather the correct data of FAT32 boot sector. 但是,我很难理解和应用公式来收集FAT32引导扇区的正确数据。 Below is pseudocode about read and access FAT32 boot sector: 以下是有关读取和访问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);

I am displaying the FAT32 boot sector data as below: 我正在显示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...

But the retrieved Filesystem type is "FAT16" not "FAT32" as I have formatted the SD card using Win XP SP3. 但是检索到的文件系统类型是“ FAT16”而不是“ FAT32”,因为我已经使用Win XP SP3格式化了SD卡。

I don't understand completely how to read/write the FAT32 boot sector? 我不完全了解如何读写FAT32引导扇区? 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. 看起来您正在为FAT32BOOTSECTOR分配空间,但您将所需的大小指定为sizeof(FAT16BOOTSECTOR) ,因此您可能会获得比所需的内存少的块,并且该结构的一部分可能会从sizeof(FAT16BOOTSECTOR)其他部分损坏编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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