deviceiocontrol 和磁盘大小问题

发布于 2024-08-15 14:19:28 字数 851 浏览 2 评论 0原文

我正在使用 C# 和 pinvoke 来读取/写入原始 SD 卡。我需要使用deviceiocontrol获取总容量:

[StructLayout(LayoutKind.Sequential)]
public struct DISK_GEOMETRY
{
public long Cylinders;
public int MediaType;
public int TracksPerCylinder;
public int SectorsPerTrack;
public int BytesPerSector;
public long DiskSize
{
get
{
return Cylinders * (long)TracksPerCylinder * (long)SectorsPerTrack * (long)BytesPerSector;
}
}
}

...

uint dummy;
DISK_GEOMETRY diskGeo = new DISK_GEOMETRY();
DeviceIoControl(safeHandle, EIOControlCode.DiskGetDriveGeometry, IntPtr.Zero, 0,
                    ref diskGeo, (uint)Marshal.SizeOf(typeof(DISK_GEOMETRY)), out dummy, IntPtr.Zero);                
this.sectorSize = diskGeo.BytesPerSector;
this.bufferSize = this.sectorSize * 16384;
this.diskSize = diskGeo.DiskSize;

对于1 GiB的sd卡,diskGeo.DiskSize是1011709440。为什么?

I am using C# and pinvoke to read/write a raw sd card. I need to get the total capacity with deviceiocontrol:

[StructLayout(LayoutKind.Sequential)]
public struct DISK_GEOMETRY
{
public long Cylinders;
public int MediaType;
public int TracksPerCylinder;
public int SectorsPerTrack;
public int BytesPerSector;
public long DiskSize
{
get
{
return Cylinders * (long)TracksPerCylinder * (long)SectorsPerTrack * (long)BytesPerSector;
}
}
}

...

uint dummy;
DISK_GEOMETRY diskGeo = new DISK_GEOMETRY();
DeviceIoControl(safeHandle, EIOControlCode.DiskGetDriveGeometry, IntPtr.Zero, 0,
                    ref diskGeo, (uint)Marshal.SizeOf(typeof(DISK_GEOMETRY)), out dummy, IntPtr.Zero);                
this.sectorSize = diskGeo.BytesPerSector;
this.bufferSize = this.sectorSize * 16384;
this.diskSize = diskGeo.DiskSize;

With a sd card of 1 GiB, the diskGeo.DiskSize is 1011709440. Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千と千尋 2024-08-22 14:19:29

那是大约。 965MB,这是可用分区的实际大小。丢失的 59MB 是一个开销分区,其中包含 SD 版权保护机制等内容。根据文件格式(FAT16、FAT32 等),文件分配表等也可能会丢失空间。

That's approx. 965MB which is the actual size of the useable partition. The lost 59MB is an overhead partition which contains things like the SD Copyright Protection Mechanism. Also space may be lost to the file allocation table etc. depending on the file format (FAT16, FAT32, etc.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文