r5731: Get delayed write semantics closer to W2K3. We need to store 2 times.
authorJeremy Allison <jra@samba.org>
Thu, 10 Mar 2005 21:43:58 +0000 (21:43 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:55:58 +0000 (10:55 -0500)
This may fix bug #2382.
Jeremy.

source/include/smb.h
source/smbd/close.c
source/smbd/fileio.c
source/smbd/files.c

index 85a700fcc7e6256e1921407f06181eacdaf62d23..91ec52df2375b7c7c3c52a1b67a4f1051852187a 100644 (file)
@@ -404,7 +404,9 @@ typedef struct files_struct {
        struct timeval open_time;
        int share_mode;
        uint32 desired_access;
+       BOOL pending_modtime_owner;
        time_t pending_modtime;
+       time_t last_write_time;
        int oplock_type;
        int sent_oplock_break;
        unsigned long file_id;
index 4445f2516bc4eecf0c1bb76cb9c332e30b19fda9..b3244432ff559be4a6146f2aedb017522f663808 100644 (file)
@@ -260,8 +260,10 @@ with error %s\n", fsp->fsp_name, strerror(errno) ));
         * Ensure pending modtime is set after close.
         */
 
-       if(fsp->pending_modtime) {
+       if(fsp->pending_modtime && fsp->pending_modtime_owner) {
                set_filetime(conn, fsp->fsp_name, fsp->pending_modtime);
+       } else if (fsp->last_write_time) {
+               set_filetime(conn, fsp->fsp_name, fsp->last_write_time);
        }
 
        DEBUG(2,("%s closed file %s (numopen=%d) %s\n",
index a21bd69a36c634c232e9477c91e967f03618aa30..3048c27fa25ee967de23ac2efdb6a2c6168a5017 100644 (file)
@@ -142,6 +142,12 @@ static ssize_t real_write_file(files_struct *fsp,char *data,SMB_OFF_T pos, size_
 
                if (fsp->pending_modtime) {
                        set_filetime(fsp->conn, fsp->fsp_name, fsp->pending_modtime);
+
+                       /* If we didn't get the "set modtime" call ourselves, we must
+                          store the last write time to restore on close. JRA. */
+                       if (!fsp->pending_modtime_owner) {
+                               fsp->last_write_time = time(NULL);
+                       }
                }
 
 /* Yes - this is correct - writes don't update this. JRA. */
index 547206815ed7bf360dc623cca07f18b0aad1b298..143c1196937585687f8d2dbc0ccc4cb48edf7ee3 100644 (file)
@@ -379,6 +379,7 @@ files_struct *file_find_print(void)
 
 /****************************************************************************
  Set a pending modtime across all files with a given dev/ino pair.
+ Record the owner of that modtime.
 ****************************************************************************/
 
 void fsp_set_pending_modtime(files_struct *tfsp, time_t pmod)
@@ -394,8 +395,11 @@ void fsp_set_pending_modtime(files_struct *tfsp, time_t pmod)
                                fsp->dev == tfsp->dev &&
                                fsp->inode == tfsp->inode ) {
                        fsp->pending_modtime = pmod;
+                       fsp->pending_modtime_owner = False;
                }
        }
+
+       tfsp->pending_modtime_owner = True;
 }
 
 /****************************************************************************