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

Which operations update last access time?

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

据我所知:

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

上次访问时间包括文件或目录上次写入读取的时间,或者,在可执行文件,运行.

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

参考“GetFileTime - lpLastAccessTime", "How do I access a file without updating its last-access time?

更新:添加read/write0字节和read/write1字节的测试结果。

用于测试的代码:

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;

    // 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;

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

因此,read/write 0 字节不会更新上次访问时间