Samba 2.0.6, MKS' touch.exe, and file/dir time stamps

Michael C. Adler Michael.Adler at compaq.com
Tue Dec 21 03:09:18 GMT 1999


This patch breaks "copy!"  Change MAX to MIN and I think you are set.

I assume 2.0.6 changed from MAX to MIN because I noticed that copy from
a real NTFS drive to a Samba drive caused the date to be set to the
changed time instead of the write time.  This broke tools like robocopy
and made even dir show the wrong time by default when compared to the NT
behavior.

The change does appear to have broken touch (in the NT resource kit). 
Some other versions of touch continued to work.

I tried the experiment of taking Paul's code and changing MAX back to
MIN.  Magic!  I didn't test it, but I assume that touch from the NT
resource kit sets one of the two parameters to either 0 or -1 and the
other to the current time.

Paul's check for 0/-1 combined with MIN appears to break the fewest
programs.

The code that takes MIN of the two values needs a big comment!  When I
submitted the change I had the following comment (actually, I suggested
ignoring changed time completely, which appears to have gone too far):

/*
 * Use only the write time, not the creation time.  Unix has no place
 * to store both times.  Write time on NT appears to be the time the
 * data in the file was last modified.  Create time may be updated when
 * a file is copied to a new location even when the write date is
 * preserved.  Tools like robocopy depend on modtime holding the write
 * time.
 */

It would need to be reworded to reflect our new understanding of the way
it works.

-Michael


Jeremy Allison wrote:
> 
> Gert-Jan Vons wrote:
> >
> > Hello all,
> >
> > we are experiencing problems with samba 2.0.6 and the MKS touch command.
> >
> > during our builds, we touch files and directories so that our make
> > dependencies work correctly. Unfortunately, it seems that MKS' touch.exe
> > doesn't actually change the time stamp of a file or directory. The
> > command returns without an error, but the timestamp does not change.
> >
> 
> Paul Eggert just sent in a wonderful patch to fix this
> correctly (I wish I had written it :-).
> 
> If you have had problems with timestamps being incorrectly
> set with any Samba 2.0.x server I suggest you apply this
> patch (which I have committed to the CVS tree) and let me
> know if this fixes the problem.
> 
> Thanks (and a *big* thanks to Paul !),
> 
>         Jeremy Allison,
>         Samba Team.
> 
> ------------------cut here-------------------------------
> Index: smbd/trans2.c
> ===================================================================
> RCS file: /data/cvs/samba/source/smbd/trans2.c,v
> retrieving revision 1.105.2.30
> diff -u -r1.105.2.30 trans2.c
> --- trans2.c    1999/11/24 00:15:45     1.105.2.30
> +++ trans2.c    1999/12/20 21:40:41
> @@ -1694,14 +1694,25 @@
> 
>      case SMB_SET_FILE_BASIC_INFO:
>      {
> +      /* Patch to do this correctly from Paul Eggert <eggert at twinsun.com>. */
> +      time_t write_time;
> +      time_t changed_time;
> +
>        /* Ignore create time at offset pdata. */
> 
>        /* access time */
>        tvs.actime = interpret_long_date(pdata+8);
> +
> +      write_time = interpret_long_date(pdata+16);
> +      changed_time = interpret_long_date(pdata+24);
> +
> +      tvs.modtime = MAX(write_time, changed_time);
> 
> -      /* write time + changed time, combined. */
> -      tvs.modtime=MIN(interpret_long_date(pdata+16),
> -                      interpret_long_date(pdata+24));
> +      /* Prefer a defined time to an undefined one. */
> +      if (tvs.modtime == (time_t)0 || tvs.modtime == (time_t)-1)
> +       tvs.modtime = (write_time == (time_t)0 || write_time == (time_t)-1
> +                      ? changed_time
> +                      : write_time);
> 
>  #if 0 /* Needs more testing... */
>        /* Test from Luke to prevent Win95 from
> ------------------cut here-------------------------------
> 
> --
> --------------------------------------------------------
> Buying an operating system without source is like buying
> a self-assembly Space Shuttle with no instructions.
> --------------------------------------------------------


More information about the samba-technical mailing list