This is the mail archive of the
cygwin-cvs@cygwin.com
mailing list for the Cygwin project.
[newlib-cygwin] Fix stat.st_blocks for files compressed with CompactOS method
- From: Corinna Vinschen <corinna at sourceware dot org>
- To: cygwin-cvs at sourceware dot org
- Date: 22 Apr 2017 14:53:33 -0000
- Subject: [newlib-cygwin] Fix stat.st_blocks for files compressed with CompactOS method
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b8523353d7a934aff1b86a09c3c6858304ab005c
commit b8523353d7a934aff1b86a09c3c6858304ab005c
Author: Christian Franke <Christian.Franke@t-online.de>
Date: Sat Apr 22 14:50:58 2017 +0200
Fix stat.st_blocks for files compressed with CompactOS method
Always retrieve FileCompressionInformation for non-empty
files if FileStandardInformation returns 0 allocated blocks.
This fixes stat.st_blocks for files compressed with CompactOS method.
Signed-off-by: Christian Franke <franke@computer.org>
Diff:
---
winsup/cygwin/fhandler_disk_file.cc | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index fcbe15c..bf5f988 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -463,18 +463,25 @@ fhandler_base::fstat_helper (struct stat *buf)
buf->st_blksize = PREFERRED_IO_BLKSIZE;
- if (pfai->StandardInformation.AllocationSize.QuadPart >= 0LL)
+ if (buf->st_size == 0
+ && pfai->StandardInformation.AllocationSize.QuadPart == 0LL)
+ /* File is empty and no blocks are preallocated. */
+ buf->st_blocks = 0;
+ else if (pfai->StandardInformation.AllocationSize.QuadPart > 0LL)
/* A successful NtQueryInformationFile returns the allocation size
- correctly for compressed and sparse files as well. */
+ correctly for compressed and sparse files as well.
+ Allocation size 0 is ignored here because (at least) Windows 10
+ 1607 always returns 0 for CompactOS compressed files. */
buf->st_blocks = (pfai->StandardInformation.AllocationSize.QuadPart
+ S_BLKSIZE - 1) / S_BLKSIZE;
- else if (::has_attribute (attributes, FILE_ATTRIBUTE_COMPRESSED
- | FILE_ATTRIBUTE_SPARSE_FILE)
+ else if ((pfai->StandardInformation.AllocationSize.QuadPart == 0LL
+ || ::has_attribute (attributes, FILE_ATTRIBUTE_COMPRESSED
+ | FILE_ATTRIBUTE_SPARSE_FILE))
&& h && !is_fs_special ()
&& !NtQueryInformationFile (h, &st, (PVOID) &fci, sizeof fci,
FileCompressionInformation))
/* Otherwise we request the actual amount of bytes allocated for
- compressed and sparsed files. */
+ compressed, sparsed and CompactOS files. */
buf->st_blocks = (fci.CompressedFileSize.QuadPart + S_BLKSIZE - 1)
/ S_BLKSIZE;
else