From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9773 invoked by alias); 23 Apr 2014 16:47:58 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 9758 invoked by uid 89); 23 Apr 2014 16:47:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.2 required=5.0 tests=AWL,BAYES_50 autolearn=ham version=3.3.2 X-HELO: mailbackend.panix.com Received: from mailbackend.panix.com (HELO mailbackend.panix.com) (166.84.1.89) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Apr 2014 16:47:56 +0000 Received: from compute01.cs.columbia.edu (compute01.cs.columbia.edu [128.59.11.31]) by mailbackend.panix.com (Postfix) with ESMTP id 957152E791 for ; Wed, 23 Apr 2014 12:47:54 -0400 (EDT) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="pU3EOVd0SL" Content-Transfer-Encoding: 7bit Message-ID: <21335.61113.963950.516021@compute01.cs.columbia.edu> Date: Wed, 23 Apr 2014 16:47:00 -0000 To: cygwin@cygwin.com Subject: Re: fstat st_size on open files on Parallels filesystem is wrong In-Reply-To: <20140423084056.GJ2339@calimero.vinschen.de> References: <21333.25325.11106.958642@compute01.cs.columbia.edu> <227151856.20140421223417@yandex.ru> <21333.26515.393838.380071@compute01.cs.columbia.edu> <20140422081628.GC2339@calimero.vinschen.de> <21334.55207.784319.488271@compute01.cs.columbia.edu> <20140423084056.GJ2339@calimero.vinschen.de> From: lennox@cs.columbia.edu X-SW-Source: 2014-04/txt/msg00523.txt.bz2 --pU3EOVd0SL Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit Content-length: 4633 On Wednesday, April 23 2014, "Corinna Vinschen" wrote to "cygwin at cygwin.com" saying: > Rather than calling GetFileInformationByHandle, try this > > #include > > [...] > > 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. Okay, looks like FileNetworkOpenInformation is succeeding, but returning a bad EndOfFile value. $ ./win32-size-test 'z:\foo' z:\foo: NtQueryInformationFile(FileNetworkOpenInformation): EndOfFile=0 z:\foo: NtQueryInformationFile(FileStandardInformation): EndOfFile=12 $ gdb --quiet --args ./win32-size-test.exe 'z:\foo' Reading symbols from /cygdrive/z/Emacs-Modtime/win32-size-test.exe...done. (gdb) break 82 Breakpoint 1 at 0x100401400: file win32-size-test.c, line 82. (gdb) run Starting program: /cygdrive/z/Emacs-Modtime/win32-size-test.exe z:\\foo [New Thread 10540.0x48dc] [New Thread 10540.0x39d4] z:\\foo: NtQueryInformationFile(FileNetworkOpenInformation): EndOfFile=0 z:\\foo: NtQueryInformationFile(FileStandardInformation): EndOfFile=12 Breakpoint 1, main (argc=2, argv=0x22aaf0) at win32-size-test.c:82 82 if (!CloseHandle(file)) { (gdb) p fnoi $1 = {CreationTime = {{LowPart = 1493948928, HighPart = 30367507}, u = { LowPart = 1493948928, HighPart = 30367507}, QuadPart = 130427450920000000}, LastAccessTime = {{LowPart = 1493948928, HighPart = 30367507}, u = {LowPart = 1493948928, HighPart = 30367507}, QuadPart = 130427450920000000}, LastWriteTime = {{LowPart = 1493948928, HighPart = 30367507}, u = {LowPart = 1493948928, HighPart = 30367507}, QuadPart = 130427450920000000}, ChangeTime = {{LowPart = 1493948928, HighPart = 30367507}, u = {LowPart = 1493948928, HighPart = 30367507}, QuadPart = 130427450920000000}, AllocationSize = {{LowPart = 12, HighPart = 0}, u = {LowPart = 12, HighPart = 0}, QuadPart = 12}, EndOfFile = {{LowPart = 0, HighPart = 0}, u = {LowPart = 0, HighPart = 0}, QuadPart = 0}, FileAttributes = 128} (gdb) p fsi $2 = {AllocationSize = {{LowPart = 12, HighPart = 0}, u = {LowPart = 12, HighPart = 0}, QuadPart = 12}, EndOfFile = {{LowPart = 12, HighPart = 0}, u = {LowPart = 12, HighPart = 0}, QuadPart = 12}, NumberOfLinks = 1, DeletePending = 0 '\000', Directory = 0 '\000'} At this point this is looking pretty clearly like a Parallels Tools bug. I'll report it to them. > 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 $ /usr/lib/csih/getVolInfo.exe /cygdrive/z/ Device Type : 7 Characteristics : 10 Volume Name : Serial Number : 0 Max Filenamelength : 255 Filesystemname : Flags : 3 FILE_CASE_SENSITIVE_SEARCH : TRUE FILE_CASE_PRESERVED_NAMES : TRUE FILE_UNICODE_ON_DISK : FALSE FILE_PERSISTENT_ACLS : FALSE FILE_FILE_COMPRESSION : FALSE FILE_VOLUME_QUOTAS : FALSE FILE_SUPPORTS_SPARSE_FILES : FALSE FILE_SUPPORTS_REPARSE_POINTS: FALSE FILE_SUPPORTS_REMOTE_STORAGE: FALSE FILE_VOLUME_IS_COMPRESSED : FALSE FILE_SUPPORTS_OBJECT_IDS : FALSE FILE_SUPPORTS_ENCRYPTION : FALSE FILE_NAMED_STREAMS : FALSE FILE_READ_ONLY_VOLUME : FALSE FILE_SEQUENTIAL_WRITE_ONCE : FALSE FILE_SUPPORTS_TRANSACTIONS : FALSE Here's my test code. Compiles with either Cygwin or mingw64 GCC, but not classic mingw or Visual Studio due to missing headers/declarations. Link with -lntdll. --pU3EOVd0SL Content-Type: text/plain; name="win32-size-test.c" Content-Disposition: inline; filename="win32-size-test.c" Content-Transfer-Encoding: 7bit Content-length: 2409 #include #include #include #include #if __LP64__ #define PRIuDWORD "u" #define PRIxDWORD "x" #else #define PRIuDWORD "lu" #define PRIxDWORD "lx" #endif static const char* geterr(DWORD err) { static char msg[1024]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)msg, sizeof(msg), NULL); return msg; } int main(int argc, char* argv[]) { int i; int exitstatus = 0; for (i = 1; i < argc; i++) { HANDLE file; DWORD err, bytesWritten; NTSTATUS ntstatus; IO_STATUS_BLOCK io; FILE_NETWORK_OPEN_INFORMATION fnoi; FILE_STANDARD_INFORMATION fsi; file = CreateFileA(argv[i], GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (file == INVALID_HANDLE_VALUE) { err = GetLastError(); fprintf(stderr, "%s: CreateFile: %s (err 0x%08" PRIxDWORD")\n", argv[i], geterr(err), err); exitstatus++; continue; } if (!WriteFile(file, "Hello world!\n", 12, &bytesWritten, NULL) || bytesWritten != 12) { err = GetLastError(); fprintf(stderr, "%s: WriteFile: %s (err 0x%08" PRIxDWORD ")\n", argv[i], geterr(err), err); CloseHandle(file); exitstatus++; continue; } ntstatus = NtQueryInformationFile (file, &io, &fnoi, sizeof fnoi, FileNetworkOpenInformation); if (!NT_SUCCESS (ntstatus)) { fprintf (stderr, "%s: NtQueryInformationFile(FileNetworkOpenInformation): %s (err 0x%08" PRIxDWORD ")\n", argv[i], geterr(ntstatus), ntstatus); } else { printf("%s: NtQueryInformationFile(FileNetworkOpenInformation): EndOfFile=%" PRIu64 "\n", argv[i], (uint64_t)fnoi.EndOfFile.QuadPart); } ntstatus = NtQueryInformationFile (file, &io, &fsi, sizeof fsi, FileStandardInformation); if (!NT_SUCCESS (ntstatus)) { fprintf (stderr, "%s: NtQueryInformationFile(FileStandardInformation): %s (err 0x%08" PRIxDWORD ")\n", argv[i], geterr(ntstatus), ntstatus); } else { printf("%s: NtQueryInformationFile(FileStandardInformation): EndOfFile=%" PRIu64 "\n", argv[i], (uint64_t)fsi.EndOfFile.QuadPart); } if (!CloseHandle(file)) { err = GetLastError(); fprintf(stderr, "%s: CloseHandle: %s (err %" PRIxDWORD ")\n", argv[i], geterr(err), err); exitstatus++; continue; } } return exitstatus; } --pU3EOVd0SL Content-Type: text/plain; charset=us-ascii Content-Description: .signature Content-Transfer-Encoding: 7bit Content-length: 49 -- Jonathan Lennox lennox at cs.columbia.edu --pU3EOVd0SL Content-Type: text/plain; charset=us-ascii Content-length: 218 -- 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 --pU3EOVd0SL--