delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/07/20/16:14:11

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,TBC
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Blake <ebb9 AT byu DOT net>
Subject: Re: MVFS results
Date: Mon, 20 Jul 2009 20:13:40 +0000 (UTC)
Lines: 111
Message-ID: <loom.20090720T200138-134@post.gmane.org>
References: <loom DOT 20090715T192219-408 AT post DOT gmane DOT org> <20090715204831 DOT GA27613 AT calimero DOT vinschen DOT de> <loom DOT 20090715T213245-387 AT post DOT gmane DOT org> <loom DOT 20090717T230701-727 AT post DOT gmane DOT org> <20090718101123 DOT GA8581 AT calimero DOT vinschen DOT de> <loom DOT 20090720T142924-486 AT post DOT gmane DOT org> <20090720153636 DOT GQ27613 AT calimero DOT vinschen DOT de> <loom DOT 20090720T154622-451 AT post DOT gmane DOT org> <20090720174912 DOT GT27613 AT calimero DOT vinschen DOT de>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Corinna Vinschen <corinna-cygwin <at> cygwin.com> writes:

> > Or maybe this is a case where we need a FlushFileBuffer call during the 
> > utimens_fs after all, in addition to closing the duplicate descriptor, so 
that 
> > the original handle no longer has any state that needs flushing which might 
> > inadvertently change timestamps.
> 
> That should be handled by the filesystem, in theory.

Indeed, procmon shows that the MVFS system is calling FlushFileBuffers to the 
backing store already, so that makes no difference.

> The easiest solution is probably not to use fchmod on MVFS, but to do
> the same trick in fchmod as in utimens:

SUCCESS!  The following patch works for both read-only and writeable files.  
Doing the work on the original handle is not enough - it has to be flushed to 
disk so as not to be lost by later state changes.  And doing the work on the 
duplicate is not enough, since based on the procmon output, it looks like MVFS 
caches information per handle, and with no reason to invalidate that cache, it 
will just overwrite the disk state on close.  But the combination of working on 
the duplicate handle to flush the change to disk, followed by repeating the 
action on the original handle, is enough to force MVFS to realize that we meant 
business.  And BOTH utimens and fchmod need this treatment (utimens alone fixed 
the writable file case, but not the read-only case).

No ChangeLog entry from me, and remember that you did the bulk of the work (I 
just did the testing).  And it still needs a good comment why we go to all the 
trouble on MVFS of doing the work on a duplicate handle first, only to repeat 
it on the original handle.


diff --git a/winsup/cygwin/fhandler_disk_file.cc 
b/winsup/cygwin/fhandler_disk_file.cc
index f2dd1ea..9ebf97f 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -779,7 +779,7 @@ fhandler_disk_file::fchmod (mode_t mode)
   extern int chmod_device (path_conv& pc, mode_t mode);
   int res = -1;
   int oret = 0;
-  NTSTATUS status;
+  NTSTATUS status = STATUS_SUCCESS;
   IO_STATUS_BLOCK io;

   if (pc.is_fs_special ())
@@ -845,7 +845,23 @@ fhandler_disk_file::fchmod (mode_t mode)
   if (S_ISSOCK (mode))
     pc |= (DWORD) FILE_ATTRIBUTE_SYSTEM;

-  status = NtSetAttributesFile (get_handle (), pc.file_attributes ());
+  if (pc.fs_is_mvfs () && !oret)
+    {
+      OBJECT_ATTRIBUTES attr;
+      HANDLE fh;
+
+      InitializeObjectAttributes (&attr, &ro_u_empty, pc.objcaseinsensitive (),
+				  get_handle (), NULL);
+      status = NtOpenFile (&fh, FILE_WRITE_ATTRIBUTES, &attr, &io,
+			   FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT);
+      if (NT_SUCCESS (status))
+	{
+	  NtSetAttributesFile (fh, pc.file_attributes ());
+	  NtClose (fh);
+	}
+    }
+  if (NT_SUCCESS (status))
+    status = NtSetAttributesFile (get_handle (), pc.file_attributes ());
   /* Correct NTFS security attributes have higher priority */
   if (!pc.has_acls ())
     {
@@ -1306,13 +1322,31 @@ fhandler_base::utimens_fs (const struct timespec *tvp)

   IO_STATUS_BLOCK io;
   FILE_BASIC_INFORMATION fbi;
+  NTSTATUS status = STATUS_SUCCESS;
   fbi.CreationTime.QuadPart = 0LL;
   fbi.LastAccessTime = lastaccess;
   fbi.LastWriteTime = lastwrite;
   fbi.ChangeTime.QuadPart = 0LL;
   fbi.FileAttributes = 0;
-  NTSTATUS status = NtSetInformationFile (get_handle (), &io, &fbi, sizeof fbi,
-					  FileBasicInformation);
+  if (pc.fs_is_mvfs () && !closeit)
+    {
+      OBJECT_ATTRIBUTES attr;
+      HANDLE fh;
+
+      InitializeObjectAttributes (&attr, &ro_u_empty, pc.objcaseinsensitive (),
+				  get_handle (), NULL);
+      status = NtOpenFile (&fh, FILE_WRITE_ATTRIBUTES, &attr, &io,
+			   FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT);
+      if (NT_SUCCESS (status))
+	{
+	  NtSetInformationFile (fh, &io, &fbi, sizeof fbi,
+				FileBasicInformation);
+	  NtClose (fh);
+	}
+    }
+  if (NT_SUCCESS (status))
+    status = NtSetInformationFile (get_handle (), &io, &fbi, sizeof fbi,
+				   FileBasicInformation);
   if (closeit)
     close_fs ();
   /* Opening a directory on a 9x share from a NT machine works(!), but
-- 
1.6.1.2





--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019