.NET Compact Framework中的簇大小

时间:2021-10-24 16:51:57

I'm trying to programatically determine the cluster size of a storage card, using C# / .NET Compact Framework, on Widows Mobile. For desktop Windows there's the GetDiskFreeSpace() function, but it doesn't exist in coredll.dll/Windows Mobile.

我正在尝试使用Widows Mobile上的C#/ .NET Compact Framework以编程方式确定存储卡的簇大小。对于桌面Windows,有GetDiskFreeSpace()函数,但它在coredll.dll / Windows Mobile中不存在。

Is there any other way I could find out the size of the cluster for a storage card?

有没有其他方法可以找出存储卡的群集大小?

2 个解决方案

#1


I haven't tried this myself, but you can try the CeGetVolumeInfo and check the dwBlockSize value. This looks like it could be the cluster size.

我自己没试过,但你可以尝试CeGetVolumeInfo并检查dwBlockSize值。这看起来可能是簇大小。

If that doesn't work then it gets a little more involved.

如果这不起作用,那么它会更多地涉及。

Storage cards are normally formatted in the FAT format.

存储卡通常以FAT格式格式化。

You need to access the low level routines in CE to read at a disk level and read the FAT BPB it determine what type of FAT and what the cluster size is.

您需要访问CE中的低级例程以读取磁盘级别并读取FAT BPB,它确定FAT的类型和簇大小。

Use Storage Manager functions FindFirstStore / FindNextStore to find the storage card you are after. Then open the storage card using the CreateFile API.

使用Storage Manager功能FindFirstStore / FindNextStore查找您所使用的存储卡。然后使用CreateFile API打开存储卡。

HANDLE hDisk(CreateFile(storeInfo.szDeviceName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL));

HANDLE hDisk(CreateFile(storeInfo.szDeviceName,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_WRITE | FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL));

Then you need to read the FAT BPB which is on the first sector for super disks (which would be the normal case for Storage Card formatted devices) or it's in MBR format.

然后你需要读取超级磁盘的第一个扇区上的FAT BPB(这是存储卡格式化设备的正常情况)或者它是MBR格式。

  SG_REQ req;
  DWORD cb;

  req.sr_start = 0;
  req.sr_num_sec = 1;
  req.sr_num_sg = 1;
  req.sr_status = 0;
  req.sr_callback = 0;
  req.sr_sglist[0].sb_buf = sectorBuffer;
  req.sr_sglist[0].sb_len = storeInfo.dwBytesPerSector;

  DeviceIoControl(hDisk, DISK_IOCTL_READ, &req, sizeof(req), 0, 0, &cb, 0);

Once you have the BPB you need to determine what fat format it is (FAT12/FAT16/FAT32) and then pull out the cluster size from it.

一旦你有BPB,你需要确定它的脂肪格式(FAT12 / FAT16 / FAT32),然后从中提取簇大小。

How you do the above in C# is up to you. I see in the storage manager reference it can go down to the partition level and you can query the partition type. That will tell you the FAT type so you don't need to figure it out.

如何在C#中执行上述操作取决于您。我在存储管理器参考中看到它可以下到分区级别,您可以查询分区类型。这将告诉你FAT类型,所以你不需要弄明白。

#2


This forum post gives some ideas of someone else having this problem.

这篇论坛帖子提供了其他人遇到此问题的一些想法。

#1


I haven't tried this myself, but you can try the CeGetVolumeInfo and check the dwBlockSize value. This looks like it could be the cluster size.

我自己没试过,但你可以尝试CeGetVolumeInfo并检查dwBlockSize值。这看起来可能是簇大小。

If that doesn't work then it gets a little more involved.

如果这不起作用,那么它会更多地涉及。

Storage cards are normally formatted in the FAT format.

存储卡通常以FAT格式格式化。

You need to access the low level routines in CE to read at a disk level and read the FAT BPB it determine what type of FAT and what the cluster size is.

您需要访问CE中的低级例程以读取磁盘级别并读取FAT BPB,它确定FAT的类型和簇大小。

Use Storage Manager functions FindFirstStore / FindNextStore to find the storage card you are after. Then open the storage card using the CreateFile API.

使用Storage Manager功能FindFirstStore / FindNextStore查找您所使用的存储卡。然后使用CreateFile API打开存储卡。

HANDLE hDisk(CreateFile(storeInfo.szDeviceName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL));

HANDLE hDisk(CreateFile(storeInfo.szDeviceName,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_WRITE | FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL));

Then you need to read the FAT BPB which is on the first sector for super disks (which would be the normal case for Storage Card formatted devices) or it's in MBR format.

然后你需要读取超级磁盘的第一个扇区上的FAT BPB(这是存储卡格式化设备的正常情况)或者它是MBR格式。

  SG_REQ req;
  DWORD cb;

  req.sr_start = 0;
  req.sr_num_sec = 1;
  req.sr_num_sg = 1;
  req.sr_status = 0;
  req.sr_callback = 0;
  req.sr_sglist[0].sb_buf = sectorBuffer;
  req.sr_sglist[0].sb_len = storeInfo.dwBytesPerSector;

  DeviceIoControl(hDisk, DISK_IOCTL_READ, &req, sizeof(req), 0, 0, &cb, 0);

Once you have the BPB you need to determine what fat format it is (FAT12/FAT16/FAT32) and then pull out the cluster size from it.

一旦你有BPB,你需要确定它的脂肪格式(FAT12 / FAT16 / FAT32),然后从中提取簇大小。

How you do the above in C# is up to you. I see in the storage manager reference it can go down to the partition level and you can query the partition type. That will tell you the FAT type so you don't need to figure it out.

如何在C#中执行上述操作取决于您。我在存储管理器参考中看到它可以下到分区级别,您可以查询分区类型。这将告诉你FAT类型,所以你不需要弄明白。

#2


This forum post gives some ideas of someone else having this problem.

这篇论坛帖子提供了其他人遇到此问题的一些想法。