| 423 | |
| 424 | |
| 425 | USHORT PIO_init_data(thread_db* tdbb, jrd_file* main_file, FbStatusVector* status_vector, |
| 426 | ULONG startPage, USHORT initPages) |
| 427 | { |
| 428 | /************************************** |
| 429 | * |
| 430 | * P I O _ i n i t _ d a t a |
| 431 | * |
| 432 | ************************************** |
| 433 | * |
| 434 | * Functional description |
| 435 | * Initialize tail of file with zeros |
| 436 | * |
| 437 | **************************************/ |
| 438 | const char* const zero_buff = zeros().getBuffer(); |
| 439 | const FB_SIZE_T zero_buff_size = zeros().getSize(); |
| 440 | |
| 441 | Database* const dbb = tdbb->getDatabase(); |
| 442 | |
| 443 | EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::UNNECESSARY); |
| 444 | FileExtendLockGuard extLock(main_file->fil_ext_lock, false); |
| 445 | |
| 446 | // Fake buffer, used in seek_file. Page space ID doesn't matter there |
| 447 | // as we already know file to work with |
| 448 | BufferDesc bdb(dbb->dbb_bcb); |
| 449 | bdb.bdb_page = PageNumber(0, startPage); |
| 450 | |
| 451 | OVERLAPPED overlapped; |
| 452 | jrd_file* file = seek_file(main_file, &bdb, &overlapped); |
| 453 | |
| 454 | if (!file) |
| 455 | return 0; |
| 456 | |
| 457 | if (file->fil_min_page + 8 > startPage) |
| 458 | return 0; |
| 459 | |
| 460 | USHORT leftPages = initPages; |
| 461 | const ULONG initBy = MIN(file->fil_max_page - startPage, leftPages); |
| 462 | if (initBy < leftPages) |
| 463 | leftPages = initBy; |
| 464 | |
| 465 | for (ULONG i = startPage; i < startPage + initBy; ) |
| 466 | { |
| 467 | bdb.bdb_page = PageNumber(0, i); |
| 468 | USHORT write_pages = zero_buff_size / dbb->dbb_page_size; |
| 469 | if (write_pages > leftPages) |
| 470 | write_pages = leftPages; |
| 471 | |
| 472 | jrd_file* file1 = seek_file(main_file, &bdb, &overlapped); |
| 473 | fb_assert(file1 == file); |
| 474 | |
| 475 | const DWORD to_write = (DWORD) write_pages * dbb->dbb_page_size; |
| 476 | DWORD written; |
| 477 | BOOL ret = WriteFile(file->fil_desc, zero_buff, to_write, &written, &overlapped); |
| 478 | if (!ret) |
| 479 | { |
| 480 | if (GetLastError() == ERROR_IO_PENDING) |
| 481 | ret = GetOverlappedResult(file->fil_desc, &overlapped, &written, TRUE); |
| 482 | } |
nothing calls this directly
no test coverage detected