假设给定的文件系统正在跟踪上次访问时间(aka atime
-文件上的哪些操作导致atime
更新?
据我所知:
atime
atime
(我想知道read-0-bytes
操作是否执行此操作]atime
或其他文件属性是否有详尽的操作列表来更新atime
?
上次访问时间包括文件或目录的上一次写入,读取自,或者对于可执行文件而言,上次<。
[其他操作,例如访问文件以检索要在资源管理器中显示的属性或其他查看器,访问文件以检索其图标等。不会更新上次访问时间。参考“ GetFileTime
- lpLastAccessTime
”,“ GetFileTime
”
更新:
添加读/写0字节和读/写1字节的测试结果。用于测试的代码:lpLastAccessTime
How do I access a file without updating its last-access time?。
void GetLastAccessTime(HANDLE hFile) { FILETIME ftAccess; SYSTEMTIME stUTC, stLocal; printf("Get last access time\n"); // Retrieve the file times for the file. if (!GetFileTime(hFile, NULL, &ftAccess, NULL)) return FALSE; // Convert the last-write time to local time. FileTimeToSystemTime(&ftAccess, &stUTC); SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal); // Build a string showing the date and time. wprintf( L"%02d/%02d/%d %02d:%02d \n", stLocal.wMonth, stLocal.wDay, stLocal.wYear, stLocal.wHour, stLocal.wMinute); } int main() { HANDLE tFile = INVALID_HANDLE_VALUE; FILETIME lastAccessTime = { 0 }; printf("Open file\n"); // Open file tFile = CreateFile(L"C:\\Users\\ritah\\Desktop\\test1.txt", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (INVALID_HANDLE_VALUE == tFile) { printf("CreateFile fails with error: %d\n", GetLastError()); getchar(); return 0; } printf("Sleep 60 seconds\n"); Sleep(60000); GetLastAccessTime(tFile); // Read 0 bytes printf("Read 0 bytes\n"); WCHAR redBuf[10]; DWORD redBytes = 0; if(!ReadFile(tFile, redBuf, 0, &redBytes, NULL)) { printf("ReadFile fails with error: %d\n", GetLastError()); getchar(); return 0; } printf("Sleep 60 seconds\n"); Sleep(60000); GetLastAccessTime(tFile); // Write 0 bytes printf("Write 0 bytes\n"); WCHAR writeBuf[] = L"write test"; DWORD writeBytes = 0; if(!WriteFile(tFile, writeBuf, 0, &writeBytes, NULL)) { printf("WriteFile fails with error: %d\n", GetLastError()); getchar(); return 0; } printf("Sleep 60 seconds\n"); Sleep(60000); GetLastAccessTime(tFile); getchar(); }
因此,