aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-03-24 16:33:52 +0000
committerRon Yorston <rmy@pobox.com>2020-03-24 16:43:39 +0000
commit87a56761cf04eca49295f95f353f252a53b33a46 (patch)
tree39f8005eb5b11e8e2a52ac0ff4b79be40d6e3461
parentf9569be1e5ca929d68e28064be3ffadcb0aff784 (diff)
downloadbusybox-w32-87a56761cf04eca49295f95f353f252a53b33a46.tar.gz
busybox-w32-87a56761cf04eca49295f95f353f252a53b33a46.tar.bz2
busybox-w32-87a56761cf04eca49295f95f353f252a53b33a46.zip
win32: stat(2): return correct st_blocks for compressed/sparse files
Use GetCompressedFileSize to obtain the actual number of blocks for compressed or sparse files. Use this to return a more accurate value for st_blocks.
-rw-r--r--win32/mingw.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index d6cd25107..894388b64 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -504,6 +504,8 @@ static int do_lstat(int follow, const char *file_name, struct mingw_stat *buf)
504 int err = EINVAL; 504 int err = EINVAL;
505 WIN32_FILE_ATTRIBUTE_DATA fdata; 505 WIN32_FILE_ATTRIBUTE_DATA fdata;
506 WIN32_FIND_DATAA findbuf; 506 WIN32_FIND_DATAA findbuf;
507 DWORD low, high;
508 off64_t size;
507#if ENABLE_FEATURE_EXTRA_FILE_DATA 509#if ENABLE_FEATURE_EXTRA_FILE_DATA
508 DWORD flags; 510 DWORD flags;
509 BY_HANDLE_FILE_INFORMATION hdata; 511 BY_HANDLE_FILE_INFORMATION hdata;
@@ -572,12 +574,22 @@ static int do_lstat(int follow, const char *file_name, struct mingw_stat *buf)
572 } 574 }
573#endif 575#endif
574 576
577 /* Get actual size of compressed/sparse files */
578 low = GetCompressedFileSize(file_name, &high);
579 if ((low == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) ||
580 S_ISDIR(buf->st_mode)) {
581 size = buf->st_size;
582 }
583 else {
584 size = low | (((off64_t)high)<<32);
585 }
586
575 /* 587 /*
576 * Assume a block is 4096 bytes and calculate number of 512 byte 588 * Assume a block is 4096 bytes and calculate number of 512 byte
577 * sectors. 589 * sectors.
578 */ 590 */
579 buf->st_blksize = 4096; 591 buf->st_blksize = 4096;
580 buf->st_blocks = ((buf->st_size+4095)>>12)<<3; 592 buf->st_blocks = ((size+4095)>>12)<<3;
581 return 0; 593 return 0;
582 } 594 }
583 errno = err; 595 errno = err;