哪个操作会更新上次访问时间?

问题描述 投票:0回答:1

假设给定的文件系统正在跟踪上次访问时间(aka atime-文件上的哪些操作导致atime更新?

据我所知:

  • 打开现有文件(以及随后关闭相关的句柄/ fd)不会不是更新atime
  • 读取/写入文件将更新atime(我想知道read-0-bytes操作是否执行此操作]
  • 读取文件安全描述符(通过相关的Win32 API)不会不是更新atime或其他文件属性

是否有详尽的操作列表来更新atime

windows winapi filesystems nfs ntfs
1个回答
0
投票

上次访问时间包括文件或目录的上一次写入读取自,或者对于可执行文件而言,上次<。

[其他操作,例如访问文件以检索要在资源管理器中显示的属性或其他查看器,访问文件以检索其图标等。不会更新上次访问时间。

参考“ 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(); }

因此,

读/写enter image description here字节不会更新上次访问时间

© www.soinside.com 2019 - 2024. All rights reserved.