MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / PIO_init_data

Function PIO_init_data

src/jrd/os/posix/unix.cpp:589–655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

587
588
589USHORT PIO_init_data(thread_db* tdbb, jrd_file* main_file, FbStatusVector* status_vector,
590 ULONG startPage, USHORT initPages)
591{
592/**************************************
593 *
594 * P I O _ i n i t _ d a t a
595 *
596 **************************************
597 *
598 * Functional description
599 * Initialize tail of file with zeros
600 *
601 **************************************/
602 const char* const zero_buff = zeros().getBuffer();
603 const size_t zero_buff_size = zeros().getSize();
604
605 Database* const dbb = tdbb->getDatabase();
606
607 // Fake buffer, used in seek_file. Page space ID have no matter there
608 // as we already know file to work with
609 BufferDesc bdb(dbb->dbb_bcb);
610 bdb.bdb_page = PageNumber(0, startPage);
611
612 FB_UINT64 offset;
613
614 EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::UNNECESSARY);
615
616 jrd_file* file = seek_file(main_file, &bdb, &offset, status_vector);
617
618 if (!file)
619 return 0;
620
621 if (file->fil_min_page + 8 > startPage)
622 return 0;
623
624 USHORT leftPages = initPages;
625 const ULONG initBy = MIN(file->fil_max_page - startPage, leftPages);
626 if (initBy < leftPages)
627 leftPages = initBy;
628
629 for (ULONG i = startPage; i < startPage + initBy; )
630 {
631 bdb.bdb_page = PageNumber(0, i);
632 USHORT write_pages = zero_buff_size / dbb->dbb_page_size;
633 if (write_pages > leftPages)
634 write_pages = leftPages;
635
636 SLONG to_write = write_pages * dbb->dbb_page_size;
637 SINT64 written;
638
639 for (int r = 0; r < IO_RETRY; r++)
640 {
641 if (!(file = seek_file(file, &bdb, &offset, status_vector)))
642 return false;
643 if ((written = os_utils::pwrite(file->fil_desc, zero_buff, to_write, LSEEK_OFFSET_CAST offset)) == to_write)
644 break;
645 if (written < 0 && !SYSCALL_INTERRUPTED(errno))
646 return unix_error("write", file, isc_io_write_err, status_vector);

Callers 2

extendDatabaseMethod · 0.50
ensureDiskSpaceFunction · 0.50

Calls 7

unix_errorFunction · 0.85
getDatabaseMethod · 0.80
seek_fileFunction · 0.70
pwriteFunction · 0.70
PageNumberClass · 0.50
getBufferMethod · 0.45
getSizeMethod · 0.45

Tested by

no test coverage detected