Bug 4394 - Samba does not properly handle setting access time via SetFileTime
Samba does not properly handle setting access time via SetFileTime
Status: ASSIGNED
Product: Samba 3.0
Classification: Unclassified
Component: File Services
3.0.24
Other Linux
: P3 normal
: none
Assigned To: Samba Bugzilla Account
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-02-13 12:06 UTC by David Shaw
Modified: 2007-03-01 21:40 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Shaw 2007-02-13 12:06:37 UTC
The Win32 call SetFileTime() allows setting file access time, creation time,
and modification time.  Samba allows modification time to be changed, but not access time.

If SetFileTime is used to set *only* the atime (passing NULL for the other times), then the atime is not set.  If SetFileTime is used to set both atime and mtime, then the atime (and mtime) is set correctly but to the same value.

This has been noted occasionally in the past:
http://archive.netbsd.se/?ml=samba-technical&a=2004-09&m=365643
http://lists.samba.org/archive/samba-technical/2005-April/040308.html
Comment 1 Jeremy Allison 2007-03-01 18:45:53 UTC
Do you have a win32 test program I can use to ensure we do
the correct thing here ?
That would help before I apply either of these patches.
Jeremy.
Comment 2 David Shaw 2007-03-01 21:40:53 UTC
Something like this should do it.  This creates a file "thefile.txt".  If all is well SetFileTime-wise, the access time (and only the access time) of this file will be set to January 1, 2000.

#include <windows.h>
#include <stdio.h>

int
main(int argc,char *argv[])
{
  HANDLE handle;
  SYSTEMTIME stime={2000,1,0,1,12,0,0,0};
  FILETIME ftime;

  if(SystemTimeToFileTime(&stime,&ftime)==0)
    {
      printf("Can't parse time\n");
      exit(1);
    }

  handle=CreateFile("thefile.txt",
		    GENERIC_READ | GENERIC_WRITE,
		    FILE_SHARE_READ | FILE_SHARE_DELETE,
		    NULL,
		    CREATE_ALWAYS,
		    FILE_ATTRIBUTE_NORMAL,
		    NULL);

  if(handle==INVALID_HANDLE_VALUE)
    {
      printf("Can't create file\n");
      exit(1);
    }

  if(SetFileTime(handle,NULL,&ftime,NULL)==0)
    {
      printf("Can't set atime\n");
      exit(1);
    }

  CloseHandle(handle);

  return 0;
}