From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: fstat st_size on open files on Parallels filesystem is wrong
Date: Wed, 23 Apr 2014 08:41:00 -0000 [thread overview]
Message-ID: <20140423084056.GJ2339@calimero.vinschen.de> (raw)
In-Reply-To: <21334.55207.784319.488271@compute01.cs.columbia.edu>
[-- Attachment #1: Type: text/plain, Size: 3896 bytes --]
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 #2: Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2014-04-23 8:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-21 18:27 lennox
2014-04-21 18:35 ` Andrey Repin
2014-04-21 18:46 ` lennox
2014-04-22 8:16 ` Corinna Vinschen
2014-04-22 16:09 ` lennox
2014-04-22 20:57 ` lennox
2014-04-23 8:41 ` Corinna Vinschen [this message]
2014-04-23 16:47 ` lennox
2014-04-23 17:24 ` Corinna Vinschen
2015-10-08 16:16 ` Jonathan Lennox
2015-10-21 11:07 ` Corinna Vinschen
2015-11-02 9:38 ` Jonathan Lennox
2015-11-02 11:23 ` Corinna Vinschen
2015-11-02 13:08 ` Jonathan Lennox
2015-11-02 14:06 ` Corinna Vinschen
2015-11-02 22:05 ` Jonathan Lennox
2015-11-03 12:19 ` Corinna Vinschen
2015-11-04 6:35 ` Jonathan Lennox
2015-11-04 9:45 ` Corinna Vinschen
2015-11-02 12:52 ` cyg Simple
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140423084056.GJ2339@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).