【问题标题】:How to Calculate the number of bytes in a sector of the hard disk如何计算硬盘一个扇区的字节数
【发布时间】:2020-06-17 00:30:42
【问题描述】:

我想知道如何计算硬盘一个扇区的字节数

【问题讨论】:

    标签: operating-system virtual-memory


    【解决方案1】:

    对于 Linux,您可以使用以下命令:

    # cat /sys/block/sda/queue/hw_sector_size
    512
    

    /dev/sda 是您的硬盘设备名称。

    对于 Windows,您可以使用 IOCTL:IOCTL_DISK_GET_DRIVE_GEOMETRY https://docs.microsoft.com/en-us/windows/win32/api/winioctl/ni-winioctl-ioctl_disk_get_drive_geometry

    Windows 示例代码:

    {
        DISK_GEOMETRY diskGeometry;
        GET_LENGTH_INFORMATION lengthInfo;
        DWORD bytesReturned;
        BOOL ret;
    
        ret = DeviceIoControl( 
                              hDevice, // file handle to the physical device
                              IOCTL_DISK_GET_DRIVE_GEOMETRY, 
                              NULL,
                              0,
                              &diskGeometry,
                              sizeof(DISK_GEOMETRY),
                              &bytesReturned,
                              NULL);
        if (TRUE != ret) {
           // Log error and exit
        }
    
        bytesPerSector = diskGeometry.BytesPerSector;
    }
    

    【讨论】:

    • 谢谢..这个答案很有帮助
    猜你喜欢
    • 1970-01-01
    • 2017-09-05
    • 2015-12-29
    • 2013-07-06
    • 2021-09-10
    • 1970-01-01
    • 2013-03-18
    • 2013-07-15
    • 1970-01-01
    相关资源
    最近更新 更多