Access time bug fix

Oded Sharon at Exanet oded.sharon at exanet.com
Thu Apr 7 11:53:48 GMT 2005


Hello

I've encountered a bug which causes the access time not to get update on 
operations like move file.
The reason for the bug was that while if the access time was changed but 
modification time won't, pending_modtime was stored in memory, and later 
saved in set_filetime, however, no one bothered to do the same with when 
access time alone changes.

This patch should fix the problem.

Oded Sharon
Exanet

----
www.odedsharon.com

-------------- next part --------------
--- /vobs/vendor/smb/source/include/smb.h@@/main/local/9	2005-03-30 20:56:13.000000000 +0200
+++ /vobs/vendor/smb/source/include/smb.h@@/main/local/10	2005-04-03 16:29:43.000000000 +0300
@@ -408,6 +408,7 @@
 	int share_mode;
 	uint32 desired_access;
 	time_t pending_modtime;
+    time_t pending_actime;
 	int oplock_type;
 	int sent_oplock_break;
 	unsigned long file_id;
--- /vobs/vendor/smb/source/smbd/close.c@@/main/local/1	2005-04-03 16:29:46.000000000 +0300
+++ /vobs/vendor/smb/source/smbd/close.c@@/main/local/0	2005-04-03 16:29:02.000000000 +0300
@@ -251,11 +251,9 @@
 	 * Ensure pending modtime is set after close.
 	 */
 
-
-    DEBUG(6, ("before calling set_filetime with fsp->pending_modtime=%s, fsp->pending_actime=%s(%d)",ctime(&fsp->pending_modtime),ctime(&fsp->pending_actime),fsp->pending_actime));
-	if(fsp->pending_modtime || fsp->pending_actime) {
+	if(fsp->pending_modtime) {
 		int saved_errno = errno;
-		set_filetime(conn, fsp->fsp_name, fsp->pending_modtime,fsp->pending_actime);
+		set_filetime(conn, fsp->fsp_name, fsp->pending_modtime);
 		errno = saved_errno;
 	}
 
--- /vobs/vendor/smb/source/smbd/dosmode.c@@/main/local/1	2005-04-03 16:29:47.000000000 +0300
+++ /vobs/vendor/smb/source/smbd/dosmode.c@@/main/local/0	2005-04-03 16:29:04.000000000 +0300
@@ -478,30 +478,14 @@
  Change a filetime - possibly allowing DOS semantics.
 *******************************************************************/
 
-BOOL set_filetime(connection_struct *conn, char *fname, time_t mtime, time_t actime)
+BOOL set_filetime(connection_struct *conn, char *fname, time_t mtime)
 {
 	struct utimbuf times;
 
-    DEBUG(6,("set_filetime(%s) called with : mtime: %s ,actime: %s\n",fname,ctime(&mtime),ctime(&actime)));
-
-	if (null_mtime(mtime) && null_mtime(actime))
+	if (null_mtime(mtime))
 		return(True);
 
- 
-    if (null_mtime(mtime)) {
-         struct stat sbuf;
-         SMB_VFS_STAT(conn,fname,&sbuf);
-         mtime = sbuf.st_mtime;
-         times.actime = actime;
-    } else {
-        // not null mtime
-        if (null_mtime(actime)) 
-           times.actime = time(NULL);
-       else 
-           times.actime =  actime;
-    }
-
-	times.modtime = mtime;
+	times.modtime = times.actime = mtime;
 
 	if (file_utime(conn, fname, &times)) {
 		DEBUG(4,("set_filetime(%s) failed: %s\n",fname,strerror(errno)));
--- /vobs/vendor/smb/source/smbd/nttrans.c@@/main/local/6	2005-04-03 16:29:49.000000000 +0300
+++ /vobs/vendor/smb/source/smbd/nttrans.c@@/main/local/5	2005-03-30 20:56:26.000000000 +0200
@@ -1674,7 +1674,6 @@
 
 	/* Ensure the modtime is set correctly on the destination file. */
 	fsp2->pending_modtime = sbuf1.st_mtime;
-    fsp2->pending_actime = sbuf1.st_atime;
 
 	close_ret = close_file(fsp2,False);
 
--- /vobs/vendor/smb/source/smbd/nttrans.c@@/main/local/3	2004-11-28 09:31:45.000000000 +0200
+++ /vobs/vendor/smb/source/smbd/nttrans.c@@/main/local/2	2004-10-25 12:21:33.000000000 +0200
@@ -1802,7 +1802,6 @@
 	char *setup = *ppsetup;
 	files_struct *fsp;
 	uint32 flags;
-	uint32 max_parameter_count = IVAL(inbuf, smb_nt_MaxParameterCount);
 
         if(setup_count < 6)
 		return ERROR_DOS(ERRDOS,ERRbadfunc);
@@ -1818,7 +1817,7 @@
 	if((!fsp->is_directory) || (conn != fsp->conn))
 		return ERROR_DOS(ERRDOS,ERRbadfid);
 
-	if (!change_notify_set(inbuf, fsp, conn, flags, max_parameter_count))
+	if (!change_notify_set(inbuf, fsp, conn, flags))
 		return(UNIXERROR(ERRDOS,ERRbadfid));
 
 	DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
--- /vobs/vendor/smb/source/smbd/trans2.c@@/main/local/5	2004-12-06 13:56:46.000000000 +0200
+++ /vobs/vendor/smb/source/smbd/trans2.c@@/main/local/6	2005-04-03 16:29:53.000000000 +0300
@@ -3239,6 +3239,10 @@
 	if (fsp) {
 		/* the pending modtime overrides the current modtime */
 		sbuf.st_mtime = fsp->pending_modtime;
+        sbuf.st_atime = fsp->pending_actime;      
+
+        DEBUG(6, ("set sbuf.m_time and a_time with fsp->pending_modtime=%s, fsp->pending_actime=%s(%d)",ctime(&fsp->pending_modtime),ctime(&fsp->pending_actime),fsp->pending_actime));
+
 	}
 
 	size = get_file_size(sbuf);
@@ -3745,8 +3749,9 @@
 	}
 
 	/* get some defaults (no modifications) if any info is zero or -1. */
+
 	if (tvs.actime == (time_t)0 || tvs.actime == (time_t)-1)
-		tvs.actime = sbuf.st_atime;
+		tvs.actime = time(NULL);
 
 	if (tvs.modtime == (time_t)0 || tvs.modtime == (time_t)-1)
 		tvs.modtime = sbuf.st_mtime;
@@ -3796,6 +3801,12 @@
 				fsp->pending_modtime = tvs.modtime;
 			}
 
+            if (tvs.actime != (time_t)0 && tvs.actime != (time_t)-1) {
+                DEBUG(10,("call_trans2setfilepathinfo: setting pending_actime to %s(%d)\n", ctime(&tvs.actime),tvs.actime ));
+                fsp->pending_actime = tvs.actime;
+            }
+
+
 		} else {
 
 			DEBUG(10,("call_trans2setfilepathinfo: setting utimes to modified values.\n"));


More information about the samba-technical mailing list