iPAQ 发表于 2012-3-8 09:43:21

[已解决]请问读写扇区时用DllStructCreate和WinAPI_SetFilePointerEx只能是512倍数

本帖最后由 iPAQ 于 2012-3-8 13:48 编辑

用Autoit读写扇区时发现以下两个函数:

$tBuffer = DllStructCreate("byte[512]")
_WinAPI_SetFilePointerEx($hHD,512,$FILE_BEGIN)

中的数据长度或偏移量位置都只能是512字节(一个扇区)的倍数,
然后执行_WinAPI_ReadFile读或_WinAPI_WriteFile写才成功,
设置成其他值,读取和写入都失败,$tBuffer指向的数据都还是0。

请问是否只能按照512字节为单位来读写?



; 分类里没有[已解决],不知咋办了,改标题了。

3mile 发表于 2012-3-8 12:02:43

Alignment and File Access Requirements

As previously discussed, an application must meet certain requirements when working with files opened with FILE_FLAG_NO_BUFFERING. The following specifics apply:

    File access sizes, including the optional file offset in the OVERLAPPED structure, if specified, must be for a number of bytes that is an integer multiple of the volume sector size. For example, if the sector size is 512 bytes, an application can request reads and writes of 512, 1,024, 1,536, or 2,048 bytes, but not of 335, 981, or 7,171 bytes.
    File access buffer addresses for read and write operations should be physical sector-aligned, which means aligned on addresses in memory that are integer multiples of the volume's physical sector size. Depending on the disk, this requirement may not be enforced.
详细见MSDN的说明:http://msdn.microsoft.com/en-us/library/cc644950%28v=vs.85%29.aspx

iPAQ 发表于 2012-3-8 13:44:05

谢谢3mile答复!

看来只能按扇区为最小单位读写了。
页: [1]
查看完整版本: [已解决]请问读写扇区时用DllStructCreate和WinAPI_SetFilePointerEx只能是512倍数