我尝试向后移动文件中的位置,只有当我移动512个字节时它才有效,为什么?
_file = CreateFile(path,
GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING
, NULL);
// THIS one works
LARGE_INTEGER distToMove = {-512};
if(SetFilePointerEx(_file, distToMove, NULL, FILE_CURRENT) == FALSE)
{
// I got #87 error with GetLastError()
}
// This one does NOT work
LARGE_INTEGER distToMove = {-3};
if(SetFilePointerEx(_file, distToMove, NULL, FILE_CURRENT) == FALSE)
{
// I got #87 error with GetLastError()
}
答案 0 :(得分:4)
请查看此处的文档:http://msdn.microsoft.com/en-us/library/windows/desktop/cc644950%28v=vs.85%29.aspx
基本上,如果以无缓冲模式打开文件,则必须仅在磁盘扇区中移动(在Windows API文档中称为卷扇区大小。)在您的情况下,这些恰好是512;但请注意,具有4Kn的现代磁盘驱动器具有4096字节的扇区,因此您确实需要首先检查扇区大小(或者只是删除NO_BUFFERING标志。)