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

Function PAG_replace_entry_first

src/jrd/pag.cpp:406–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

404
405
406bool PAG_replace_entry_first(thread_db* tdbb, header_page* header,
407 USHORT type, USHORT len, const UCHAR* entry)
408{
409/***********************************************
410 *
411 * P A G _ r e p l a c e _ e n t r y _ f i r s t
412 *
413 ***********************************************
414 *
415 * Functional description
416 * Replace an entry in the header page so it will become first entry
417 * This will be used mainly for the clumplets used for backup purposes
418 * because they are needed to be read without page lock
419 * Will not follow to hdr_next_page
420 * Will not journal changes made to page. => obsolete
421 * RETURNS
422 * true - modified page
423 * false - nothing done
424 *
425 **************************************/
426 SET_TDBB(tdbb);
427 Database* dbb = tdbb->getDatabase();
428 CHECK_DBB(dbb);
429
430 err_post_if_database_is_readonly(dbb);
431
432 UCHAR* p = header->hdr_data;
433 while (*p != HDR_end && *p != type) {
434 p += 2u + p[1];
435 }
436
437 // Remove item if found it somewhere
438 if (*p != HDR_end)
439 {
440 const USHORT shift = p[1] + 2u;
441 memmove(p, p + shift, header->hdr_end - (p - (UCHAR*) header) - shift + 1); // to preserve HDR_end
442 header->hdr_end -= shift;
443 }
444
445 if (!entry) {
446 return false; // We were asked just to remove item. We finished.
447 }
448
449 // Check if we got enough space
450 if (dbb->dbb_page_size - header->hdr_end <= len + 2) {
451 BUGCHECK(251);
452 }
453
454 // Actually add the item
455 fb_assert(len <= MAX_UCHAR);
456 memmove(header->hdr_data + len + 2, header->hdr_data, header->hdr_end - HDR_SIZE + 1);
457 header->hdr_data[0] = type;
458 header->hdr_data[1] = len;
459 memcpy(header->hdr_data + 2, entry, len);
460 header->hdr_end += len + 2;
461
462 return true;
463}

Callers 2

beginBackupMethod · 0.85
setDifferenceMethod · 0.85

Calls 4

SET_TDBBFunction · 0.85
CHECK_DBBFunction · 0.85
getDatabaseMethod · 0.80

Tested by

no test coverage detected