This is the mail archive of the cygwin 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]
Other format: [Raw text]

Re: fstat st_size on open files on Parallels filesystem is wrong


On Apr 22 16:57, lennox@cs.columbia.edu wrote:
> On Tuesday, April 22 2014, "Corinna Vinschen" wrote to "cygwin at cygwin.com" saying:
> > On Apr 21 14:46, lennox at cs.columbia.edu wrote:
> > > [...]
> > > This is using Posix APIs -- open() / write() -- not C APIs, fopen() /
> > > fwrite(), so there shouldn't be a buffer?  Notice that the test behaves as I
> > > expect for a file on NTFS.
> > > 
> > > Adding a call to fsync() prior to the fstat() call doesn't change anything.
> > 
> > This is actually a bad sign.  The problem you're describing occurs on
> > NFS, too.  If you write to the file, a subsequent call to fetch stat
> > attributes does not return the actual size of the file, but the size at
> > the time the handle has been opened.
> > 
> > However, on NFS, a call to FlushFileBuffers helps to kick stat back into
> > shape.  That's the Win32 function called from fsync as well.  What is
> > Cygwin supposed to do if that doesn't work?
> 
> Okay, interesting further investigation.
> 
> The Parallels filesystem appears to work correctly when I repeat the test
> case using Windows kernel32 APIs -- specifically, FileInformationByHandle --
> so something's different between the kernel32 APIs and the ntdll APIs that
> Cygwin uses.
> 
> Sample code for Win32 test attached.  Works identically with Cygwin, MinGW,
> or Visual C++.
> 
> Just spitballing here, but -- I see that cygwin's file_get_fnoi function
> (which is where fhandler_base::fstat_by_handle gets its size parameter)
> tries NtQueryInformationFile(FileNetworkOpenInformation) before
> NtQueryInformationFile(FileStandardInformation).  Is it possible that the
> Parallels filesystem isn't filling out all fields of that API properly?  Is
> there a straightforward way I could debug this?

You could use the same functions.  Since you had a look into the sources
anyway, you probably saw the comments:

  /* Some FSes (Netapps) don't implement FileNetworkOpenInformation. */
  [...call NtQueryInformationFile(FileNetworkOpenInformation) unless
      the skip_network_open_inf flag is given...]
  if (status == STATUS_INVALID_PARAMETER)
     /* Apart from accessing Netapps, this also occurs when accessing SMB
	share root dirs hosted on NT4. */
     [...call NtQueryInformationFile(FileBasicInformation) and
              NtQueryInformationFile(FileStandardInformation)...]

Rather than calling GetFileInformationByHandle, try this

  #include <winternl.h>

  [...]

  NTSTATUS status;
  IO_STATUS_BLOCK io;
  FILE_NETWORK_OPEN_INFORMATION fnoi;
  
  status = NtQueryInformationFile (file, &io, &fnoi, sizeof fnoi,
				   FileNetworkOpenInformation);
  if (!NT_SUCCESS (status))
    {
      fprintf (stderr, "NtQueryInformationFile: 0x%08x\n", status);
      [...]
    }
  printf("%s: NtQueryInformationFile: nFileSize=%" PRIu64 "\n",
	 argv[i], fnoi.EndOfFile.QuadPart);

Maybe that's really the problem.  If so, either the EndOfFile info
is wrong, or (more likely) the call to NtQueryInformationFile returns
with a non-0 status code, which would be interesting to know.  It's
probably not STATUS_INVALID_PARAMETER, otherwise you probably wouldn't
have seen a problem at all.

Replacing the above call with

  FILE_STANDARD_INFORMATION fsi;
  status = NtQueryInformationFile (file, &io, &fsi, sizeof fsi,
				   FileStandardInformation);
  [...]
  printf("%s: NtQueryInformationFile: nFileSize=%" PRIu64 "\n",
	 argv[i], fsi.EndOfFile.QuadPart);

should then give the correct result.

Also, to add handling for the Parallels filesystem to Cygwin, I'd
need the info printed by the getVolInfo tool from the csih package:

  $ /usr/lib/csih/getVolInfo /cygdrive/z


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgpMjp28kHntC.pgp
Description: PGP signature


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