This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

WriteFile() whacks st_atime patch


Attached is a cleaned up version of the WriteFile() patch that I
previously posted to cygwin-developers:

    http://www.cygwin.com/ml/cygwin-developers/2001-09/msg00076.html

Note that this version only affects disk files.  Additionally, I verified
that mutt finds new mail even when not configured with --enable-buffy-size
(Use file size attribute instead of access time).

I ran some tests to determine the performance impact.  On my machine,
the GetFileTime()/SetFileTime() pair will add approximately 200 us to
every write.  I don't know whether or not better Posix conformance is
worth this performance hit?

Unfortunately, I did not address the race condition between a writer
and a reader.  If the reader happens to read while the writer is between
the GetFileTime() and SetFileTime() in fhandler_disk_file::raw_write(),
then the new functionality will actually whack st_atime!  So, is it
better to whack st_atime on every write or only on the occasion when
the above mentioned race condition occurs?

Given the above problems, I have very mixed feelings about this patch.
Is it worth pursuing or should I dropped it?

Thanks,
Jason
Index: fhandler.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
retrieving revision 1.81
diff -u -p -r1.81 fhandler.cc
--- fhandler.cc	2001/09/07 21:32:04	1.81
+++ fhandler.cc	2001/09/10 17:42:53
@@ -1479,6 +1479,25 @@ fhandler_disk_file::lock (int cmd, struc
   return 0;
 }
 
+/* Cover function to WriteFile to provide Posix interface and semantics
+   (as much as possible).
+   
+   Specifically, raw_write() resets the last access time to what it was
+   before the write.  This is necessary since WriteFile() sets the last
+   access time.  FIXME: Unfortunately, the race condition of a real read
+   occurring between the GetFileTime() and SetFileTime() is not handled.  */
+
+int
+fhandler_disk_file::raw_write (const void *ptr, size_t len)
+{
+  FILETIME access;
+  BOOL status = GetFileTime (get_handle(), 0, &access, 0);
+  int bytes_written = fhandler_base::raw_write(ptr, len);
+  if (bytes_written > 0 && status)
+    SetFileTime (get_handle(), 0, &access, 0);
+  return bytes_written;
+}
+
 /**********************************************************************/
 /* /dev/null */
 
Index: fhandler.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler.h,v
retrieving revision 1.75
diff -u -p -r1.75 fhandler.h
--- fhandler.h	2001/09/01 05:17:34	1.75
+++ fhandler.h	2001/09/10 17:42:53
@@ -561,6 +561,7 @@ public:
   int lock (int, struct flock *);
   BOOL is_device () { return FALSE; }
   int fstat (struct stat *buf);
+  int raw_write (const void *ptr, size_t ulen);
 
   HANDLE mmap (caddr_t *addr, size_t len, DWORD access, int flags, off_t off);
   int munmap (HANDLE h, caddr_t addr, size_t len);
Mon Sep 10 15:26:49 2001  Jason Tishler <jason@tishler.net>

	* fhandler.cc (fhandler_disk_file::raw_write): New method.  Attempt
	to improve Posix conformance by reseting st_atime.
	* fhandler.h (fhandler_disk_file): Declare new method 'raw_write'.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]