diff options
author | Christian Franke <Christian.Franke@t-online.de> | 2017-04-22 14:50:58 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2017-04-22 16:12:36 +0200 |
commit | b8523353d7a934aff1b86a09c3c6858304ab005c (patch) | |
tree | bd21ddb566f481ad0ec6fcfe7a4a12a11bf01280 | |
parent | 8e0876727b9ae339ef1c2526e6b15cf4e29396ca (diff) | |
download | cygnal-b8523353d7a934aff1b86a09c3c6858304ab005c.tar.gz cygnal-b8523353d7a934aff1b86a09c3c6858304ab005c.tar.bz2 cygnal-b8523353d7a934aff1b86a09c3c6858304ab005c.zip |
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>
-rw-r--r-- | winsup/cygwin/fhandler_disk_file.cc | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index fcbe15c1e..bf5f988c2 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 |