@@ -5420,6 +5420,8 @@ os_file_set_size(
5420
5420
5421
5421
fallback:
5422
5422
#else
5423
+ struct stat statbuf;
5424
+
5423
5425
if (is_sparse) {
5424
5426
bool success = !ftruncate (file, size);
5425
5427
if (!success) {
@@ -5433,10 +5435,17 @@ os_file_set_size(
5433
5435
# ifdef HAVE_POSIX_FALLOCATE
5434
5436
int err;
5435
5437
do {
5436
- os_offset_t current_size = os_file_get_size (file);
5437
- err = current_size >= size
5438
- ? 0 : posix_fallocate (file, current_size,
5438
+ if (fstat (file, &statbuf)) {
5439
+ err = errno;
5440
+ } else {
5441
+ os_offset_t current_size = statbuf.st_size ;
5442
+ if (current_size >= size) {
5443
+ return true ;
5444
+ }
5445
+ current_size &= ~os_offset_t (statbuf.st_blksize - 1 );
5446
+ err = posix_fallocate (file, current_size,
5439
5447
size - current_size);
5448
+ }
5440
5449
} while (err == EINTR
5441
5450
&& srv_shutdown_state <= SRV_SHUTDOWN_INITIATED);
5442
5451
@@ -5459,6 +5468,27 @@ os_file_set_size(
5459
5468
# endif /* HAVE_POSIX_ALLOCATE */
5460
5469
#endif /* _WIN32*/
5461
5470
5471
+ #ifdef _WIN32
5472
+ os_offset_t current_size = os_file_get_size (file);
5473
+ FILE_STORAGE_INFO info;
5474
+ if (GetFileInformationByHandleEx (file, FileStorageInfo, &info,
5475
+ sizeof info)) {
5476
+ if (info.LogicalBytesPerSector ) {
5477
+ current_size &= ~os_offset_t (info.LogicalBytesPerSector
5478
+ - 1 );
5479
+ }
5480
+ }
5481
+ #else
5482
+ if (fstat (file, &statbuf)) {
5483
+ return false ;
5484
+ }
5485
+ os_offset_t current_size = statbuf.st_size
5486
+ & ~os_offset_t (statbuf.st_blksize - 1 );
5487
+ #endif
5488
+ if (current_size >= size) {
5489
+ return true ;
5490
+ }
5491
+
5462
5492
/* Write up to 1 megabyte at a time. */
5463
5493
ulint buf_size = ut_min (
5464
5494
static_cast <ulint>(64 ),
@@ -5476,8 +5506,6 @@ os_file_set_size(
5476
5506
/* Write buffer full of zeros */
5477
5507
memset (buf, 0 , buf_size);
5478
5508
5479
- os_offset_t current_size = os_file_get_size (file);
5480
-
5481
5509
while (current_size < size
5482
5510
&& srv_shutdown_state <= SRV_SHUTDOWN_INITIATED) {
5483
5511
ulint n_bytes;
0 commit comments