]> sourceware.org Git - newlib-cygwin.git/commitdiff
* fhandler_disk_file.cc (fhandler_disk_file::pread): Skip to non-atomic
authorCorinna Vinschen <corinna@vinschen.de>
Fri, 7 Jun 2013 08:28:25 +0000 (08:28 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Fri, 7 Jun 2013 08:28:25 +0000 (08:28 +0000)
code if mandatory locking is used on this descriptor.  Explain why.
(fhandler_disk_file::pwrite): Ditto.
* posix.sgml (std-notes): Extend description of file locking.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler_disk_file.cc
winsup/cygwin/posix.sgml

index 956d10087fad5978a62a0c2069f69ae021d2b005..23bcb4462796543b64459fa5fa1fdcd077e27347 100644 (file)
@@ -1,3 +1,10 @@
+2013-06-07  Corinna Vinschen  <corinna@vinschen.de>
+
+       * fhandler_disk_file.cc (fhandler_disk_file::pread): Skip to non-atomic
+       code if mandatory locking is used on this descriptor.  Explain why.
+       (fhandler_disk_file::pwrite): Ditto.
+       * posix.sgml (std-notes): Extend description of file locking.
+
 2013-06-06  Corinna Vinschen  <corinna@vinschen.de>
 
        * exceptions.cc (_cygtls::handle_SIGCONT): Simplify loop waiting for
index 075eac8ab0fe5a21b3a85205f8b0cf496d1151d3..018bcc98132d99bb3bf243b02b107afb51192c7b 100644 (file)
@@ -1575,8 +1575,9 @@ fhandler_disk_file::pread (void *buf, size_t count, off_t offset)
       return -1;
     }
 
-  /* In binary mode, we can use an atomic NtReadFile call. */
-  if (rbinary ())
+  /* In binary mode, we can use an atomic NtReadFile call.
+     Windows mandatory locking semantics disallow to use another HANDLE. */
+  if (rbinary () && !mandatory_locking ())
     {
       extern int __stdcall is_at_eof (HANDLE h);
       NTSTATUS status;
@@ -1647,8 +1648,9 @@ fhandler_disk_file::pwrite (void *buf, size_t count, off_t offset)
       return -1;
     }
 
-  /* In binary mode, we can use an atomic NtWriteFile call. */
-  if (wbinary ())
+  /* In binary mode, we can use an atomic NtWriteFile call.
+     Windows mandatory locking semantics disallow to use another HANDLE. */
+  if (wbinary () && !mandatory_locking ())
     {
       NTSTATUS status;
       IO_STATUS_BLOCK io;
index 21fe6ccabb2221265ff85b9eae89e308a9217b64..463383e9f544942f802dbc59030cad3051d99f32 100644 (file)
@@ -1467,10 +1467,32 @@ CLOCK_REALTIME and CLOCK_MONOTONIC.  <function>clock_setres</function>,
 <function>clock_settime</function>, and <function>timer_create</function>
 currently support only CLOCK_REALTIME.</para>
 
+<para>POSIX file locks via <function>fcntl</function> or
+<function>lockf</function>, as well as BSD <function>flock</function> locks
+are advisory locks.  They don't interact with Windows mandatory locks, nor
+do POSIX fcntl locks interfere with BSD flock locks or vice versa.</para>
+
 <para>BSD file locks created via <function>flock</function> are only
 propagated to the direct parent process, not to grand parents or sibling
-processes.  The locks are only valid in the creating process, its parent,
-and subsequently started child processes sharing the same file descriptor.
+processes.  The locks are only valid in the creating process, its parent
+process, and subsequently started child processes sharing the same file
+descriptor.</para>
+
+<para>In very rare circumstances an application would want to use Windows
+mandatory locks to interact with non-Cygwin Windows processes accessing the
+same file (databases, etc).  For these purposes, the entire locking mechanism
+(fcntl/flock/lockf) can be switched to Windows mandatory locks on a
+per-descriptor/per-process basis.  For this purpose, use the call
+
+<screen>
+  fcntl (fd, F_LCK_MANDATORY, 1);
+</screen>
+
+After that, all file locks on this descriptor will follow Windows mandatory
+record locking semantics: Locks are per-descriptor/per-process; locks are not
+propagated to child processes, not even via <function>execve</function>;
+no atmoic replacement of read locks with write locks and vice versa on the
+same descriptor; locks have to be unlocked exactly as they have been locked.
 </para>
 
 <para><function>fpclassify</function>, <function>isfinite</function>,
This page took 0.032861 seconds and 5 git commands to generate.