support setting atime on opened files

Assar assar at permabit.com
Tue Sep 28 21:18:20 GMT 2004


Hi.

Here's a patch (relative to samba-trunk), that I wrote when I figured
out that setting the access time on an open file did not work.
Feedback and comments much appreciated.

/assar

-------------- next part --------------
Index: source/smbd/close.c
===================================================================
--- source/smbd/close.c	(revision 2735)
+++ source/smbd/close.c	(working copy)
@@ -251,9 +251,9 @@
 	 * Ensure pending modtime is set after close.
 	 */
 
-	if(fsp->pending_modtime) {
+	if(fsp->pending_modtime || fsp->pending_accesstime) {
 		int saved_errno = errno;
-		set_filetime(conn, fsp->fsp_name, fsp->pending_modtime);
+		set_filetime(conn, fsp->fsp_name, fsp->pending_modtime, fsp->pending_accesstime);
 		errno = saved_errno;
 	}
 
Index: source/smbd/reply.c
===================================================================
--- source/smbd/reply.c	(revision 2735)
+++ source/smbd/reply.c	(working copy)
@@ -725,7 +725,7 @@
 	}
 
 	if (ok)
-		ok = set_filetime(conn,fname,mtime);
+		ok = set_filetime(conn,fname,mtime,0);
   
 	if (!ok) {
 		END_PROFILE(SMBsetatr);
@@ -2790,7 +2790,7 @@
 		mtime = make_unix_date3(inbuf+smb_vwv1);
 		
 		/* try and set the date */
-		set_filetime(conn, file_name, mtime);
+		set_filetime(conn, file_name, mtime, 0);
 
 	}  
 
@@ -2836,7 +2836,7 @@
   
 	nwritten = write_file(fsp,data,startpos,numtowrite);
 
-	set_filetime(conn, fsp->fsp_name,mtime);
+	set_filetime(conn, fsp->fsp_name,mtime,0);
   
 	/*
 	 * More insanity. W2K only closes the file if writelen > 0.
@@ -4117,6 +4117,7 @@
 	close_file(fsp1,False);
 
 	/* Ensure the modtime is set correctly on the destination file. */
+        fsp2->pending_accesstime = src_sbuf.st_atime;
 	fsp2->pending_modtime = src_sbuf.st_mtime;
 
 	/*
Index: source/smbd/trans2.c
===================================================================
--- source/smbd/trans2.c	(revision 2735)
+++ source/smbd/trans2.c	(working copy)
@@ -3089,6 +3089,7 @@
 	if (fsp) {
 		/* the pending modtime overrides the current modtime */
 		sbuf.st_mtime = fsp->pending_modtime;
+                sbuf.st_atime = fsp->pending_accesstime;
 	}
 
 	size = get_file_size(sbuf);
@@ -3646,6 +3647,11 @@
 				fsp->pending_modtime = tvs.modtime;
 			}
 
+			if (tvs.actime != (time_t)0 && tvs.actime != (time_t)-1) {
+				DEBUG(10,("call_trans2setfilepathinfo: setting pending accesstime to %s\n", ctime(&tvs.actime) ));
+				fsp->pending_accesstime = tvs.actime;
+			}
+
 		} else {
 
 			DEBUG(10,("call_trans2setfilepathinfo: setting utimes to modified values.\n"));
Index: source/smbd/dosmode.c
===================================================================
--- source/smbd/dosmode.c	(revision 2735)
+++ source/smbd/dosmode.c	(working copy)
@@ -478,14 +478,27 @@
  Change a filetime - possibly allowing DOS semantics.
 *******************************************************************/
 
-BOOL set_filetime(connection_struct *conn, char *fname, time_t mtime)
+BOOL set_filetime(connection_struct *conn, char *fname, time_t mtime, time_t atime)
 {
+        SMB_STRUCT_STAT sb;
 	struct utimbuf times;
+        int mtime_set = !null_mtime(mtime);
+        int atime_set = !null_mtime(atime);
+        int changes = mtime_set + atime_set;
 
-	if (null_mtime(mtime))
+	if (changes == 0)
 		return(True);
+        if (changes == 2) {
+                if(SMB_VFS_STAT(conn,fname,&sb) != 0)
+                        return -1;
+                if(!mtime_set)
+                        mtime = sb.st_mtime;
+                if(!atime_set)
+                        atime = sb.st_atime;
+        }
 
-	times.modtime = times.actime = mtime;
+	times.modtime = mtime;
+        times.actime  = atime;
 
 	if (file_utime(conn, fname, &times)) {
 		DEBUG(4,("set_filetime(%s) failed: %s\n",fname,strerror(errno)));
Index: source/include/smb.h
===================================================================
--- source/include/smb.h	(revision 2735)
+++ source/include/smb.h	(working copy)
@@ -405,6 +405,7 @@
 	int share_mode;
 	uint32 desired_access;
 	time_t pending_modtime;
+        time_t pending_accesstime;
 	int oplock_type;
 	int sent_oplock_break;
 	unsigned long file_id;


More information about the samba-technical mailing list