deviceiocontrol 和磁盘大小问题
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是大约。 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.)