| 404 | |
| 405 | |
| 406 | bool 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 | } |
no test coverage detected