Lines Matching +full:page +full:- +full:offset

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
66 #include "page.h"
79 *-1 ==> ERROR
90 cp = bufp->page; /* Character pointer of p. */ in __big_insert()
93 key_data = (char *)key->data; in __big_insert()
94 key_size = key->size; in __big_insert()
95 val_data = (char *)val->data; in __big_insert()
96 val_size = val->size; in __big_insert()
99 for (space = FREESPACE(p) - BIGOVERHEAD; key_size; in __big_insert()
100 space = FREESPACE(p) - BIGOVERHEAD) { in __big_insert()
102 off = OFFSET(p) - move_bytes; in __big_insert()
104 key_size -= move_bytes; in __big_insert()
109 FREESPACE(p) = off - PAGE_META(n); in __big_insert()
110 OFFSET(p) = off; in __big_insert()
114 return (-1); in __big_insert()
123 * next page; otherwise the invariant that the in __big_insert()
124 * data must end on a page with FREESPACE in __big_insert()
125 * non-zero would fail. in __big_insert()
127 if (space == val_size && val_size == val->size) in __big_insert()
129 off = OFFSET(p) - move_bytes; in __big_insert()
132 val_size -= move_bytes; in __big_insert()
134 p[n - 2] = FULL_KEY_DATA; in __big_insert()
135 FREESPACE(p) = FREESPACE(p) - move_bytes; in __big_insert()
136 OFFSET(p) = off; in __big_insert()
139 p[n - 2] = FULL_KEY; in __big_insert()
142 p = (u_int16_t *)bufp->page; in __big_insert()
143 cp = bufp->page; in __big_insert()
144 bufp->flags |= BUF_MOD; in __big_insert()
148 for (space = FREESPACE(p) - BIGOVERHEAD; val_size; in __big_insert()
149 space = FREESPACE(p) - BIGOVERHEAD) { in __big_insert()
153 * same page as the key ends, FREESPACE is at least one. in __big_insert()
155 if (space == val_size && val_size == val->size) in __big_insert()
156 move_bytes--; in __big_insert()
157 off = OFFSET(p) - move_bytes; in __big_insert()
159 val_size -= move_bytes; in __big_insert()
164 FREESPACE(p) = off - PAGE_META(n); in __big_insert()
165 OFFSET(p) = off; in __big_insert()
170 return (-1); in __big_insert()
171 cp = bufp->page; in __big_insert()
175 bufp->flags |= BUF_MOD; in __big_insert()
181 * Called when bufp's page contains a partial key (index should be 1)
184 * free bufp because the page pointing to it is lost and we can't get rid
189 *-1 => ERROR
200 bp = (u_int16_t *)bufp->page; in __big_delete()
209 * If there is freespace left on a FULL_KEY_DATA page, then in __big_delete()
210 * the data is short and fits entirely on this page, and this in __big_delete()
211 * is the last page. in __big_delete()
215 pageno = bp[bp[0] - 1]; in __big_delete()
216 rbufp->flags |= BUF_MOD; in __big_delete()
222 return (-1); /* Error. */ in __big_delete()
223 bp = (u_int16_t *)rbufp->page; in __big_delete()
227 * If we get here then rbufp points to the last page of the big in __big_delete()
228 * key/data pair. Bufp points to the first one -- it should now be in __big_delete()
229 * empty pointing to the next page after this pair. Can't free it in __big_delete()
230 * because we don't have the page pointing to it. in __big_delete()
233 /* This is information from the last page of the pair. */ in __big_delete()
235 pageno = bp[n - 1]; in __big_delete()
237 /* Now, bp is the first page of the pair. */ in __big_delete()
238 bp = (u_int16_t *)bufp->page; in __big_delete()
240 /* There is an overflow page. */ in __big_delete()
243 bufp->ovfl = rbufp->ovfl; in __big_delete()
245 /* This is the last page. */ in __big_delete()
246 bufp->ovfl = NULL; in __big_delete()
247 n -= 2; in __big_delete()
249 FREESPACE(bp) = hashp->BSIZE - PAGE_META(n); in __big_delete()
250 OFFSET(bp) = hashp->BSIZE; in __big_delete()
252 bufp->flags |= BUF_MOD; in __big_delete()
258 hashp->NKEYS--; in __big_delete()
264 * -1 = get next overflow page
265 * -2 means key not found and this is big key/data
266 * -3 error
277 bp = (u_int16_t *)bufp->page; in __find_bigpair()
278 p = bufp->page; in __find_bigpair()
282 for (bytes = hashp->BSIZE - bp[ndx]; in __find_bigpair()
284 bytes = hashp->BSIZE - bp[ndx]) { in __find_bigpair()
286 return (-2); in __find_bigpair()
288 ksize -= bytes; in __find_bigpair()
291 return (-3); in __find_bigpair()
292 p = bufp->page; in __find_bigpair()
301 return (-2); in __find_bigpair()
307 * Given the buffer pointer of the first overflow page of a big pair,
310 * This will set bpp to the buffer header of the last page of the big pair.
311 * It will return the pageno of the overflow page following the last page
323 bp = (u_int16_t *)bufp->page; in __find_last_page()
328 * This is the last page if: the tag is FULL_KEY_DATA and in __find_last_page()
330 * is freespace on the page. in __find_last_page()
336 pageno = bp[n - 1]; in __find_last_page()
340 bp = (u_int16_t *)bufp->page; in __find_last_page()
351 * Return the data for the key/data pair that begins on this page at this
361 bp = (u_int16_t *)bufp->page; in __big_return()
363 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in __big_return()
365 return (-1); in __big_return()
366 bp = (u_int16_t *)bufp->page; in __big_return()
371 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in __big_return()
373 return (-1); in __big_return()
374 bp = (u_int16_t *)bufp->page; in __big_return()
376 save_addr = save_p->addr; in __big_return()
389 len = bp[1] - off; in __big_return()
391 save_addr = bufp->addr; in __big_return()
392 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in __big_return()
394 return (-1); in __big_return()
395 bp = (u_int16_t *)bufp->page; in __big_return()
397 /* The data is all on one page. */ in __big_return()
400 val->data = (u_char *)tp + off; in __big_return()
401 val->size = bp[1] - off; in __big_return()
405 hashp->cpage = NULL; in __big_return()
406 hashp->cbucket++; in __big_return()
407 hashp->cndx = 1; in __big_return()
409 hashp->cpage = __get_buf(hashp, in __big_return()
410 bp[bp[0] - 1], bufp, 0); in __big_return()
411 if (!hashp->cpage) in __big_return()
412 return (-1); in __big_return()
413 hashp->cndx = 1; in __big_return()
415 hashp->cpage->page)[0]) { in __big_return()
416 hashp->cbucket++; in __big_return()
417 hashp->cpage = NULL; in __big_return()
424 val->size = (size_t)collect_data(hashp, bufp, (int)len, set_current); in __big_return()
425 if (val->size == (size_t)-1) in __big_return()
426 return (-1); in __big_return()
427 if (save_p->addr != save_addr) { in __big_return()
430 return (-1); in __big_return()
432 memmove(hashp->tmp_buf, (save_p->page) + off, len); in __big_return()
433 val->data = (u_char *)hashp->tmp_buf; in __big_return()
449 p = bufp->page; in collect_data()
451 mylen = hashp->BSIZE - bp[1]; in collect_data()
452 save_addr = bufp->addr; in collect_data()
456 if (hashp->tmp_buf) in collect_data()
457 free(hashp->tmp_buf); in collect_data()
458 if ((hashp->tmp_buf = (char *)malloc(totlen)) == NULL) in collect_data()
459 return (-1); in collect_data()
461 hashp->cndx = 1; in collect_data()
463 hashp->cpage = NULL; in collect_data()
464 hashp->cbucket++; in collect_data()
466 hashp->cpage = in collect_data()
467 __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in collect_data()
468 if (!hashp->cpage) in collect_data()
469 return (-1); in collect_data()
470 else if (!((u_int16_t *)hashp->cpage->page)[0]) { in collect_data()
471 hashp->cbucket++; in collect_data()
472 hashp->cpage = NULL; in collect_data()
477 xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in collect_data()
480 return (-1); in collect_data()
482 if (bufp->addr != save_addr) { in collect_data()
484 return (-1); in collect_data()
486 memmove(&hashp->tmp_buf[len], (bufp->page) + bp[1], mylen); in collect_data()
496 key->size = (size_t)collect_key(hashp, bufp, 0, val, set); in __big_keydata()
497 if (key->size == (size_t)-1) in __big_keydata()
498 return (-1); in __big_keydata()
499 key->data = (u_char *)hashp->tmp_key; in __big_keydata()
515 p = bufp->page; in collect_key()
517 mylen = hashp->BSIZE - bp[1]; in collect_key()
519 save_addr = bufp->addr; in collect_key()
522 if (hashp->tmp_key != NULL) in collect_key()
523 free(hashp->tmp_key); in collect_key()
524 if ((hashp->tmp_key = (char *)malloc(totlen)) == NULL) in collect_key()
525 return (-1); in collect_key()
527 return (-1); in collect_key()
529 xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in collect_key()
532 return (-1); in collect_key()
534 if (bufp->addr != save_addr) { in collect_key()
535 errno = EINVAL; /* MIS -- OUT OF BUFFERS */ in collect_key()
536 return (-1); in collect_key()
538 memmove(&hashp->tmp_key[len], (bufp->page) + bp[1], mylen); in collect_key()
545 * -1 => error
550 BUFHEAD *np, /* Pointer to new bucket page */ in __big_split()
551 BUFHEAD *big_keyp, /* Pointer to first page containing the big key/data */ in __big_split()
565 return (-1); in __big_split()
568 if ( (ret->next_addr = __find_last_page(hashp, &big_keyp)) ) { in __big_split()
569 if (!(ret->nextp = in __big_split()
570 __get_buf(hashp, ret->next_addr, big_keyp, 0))) in __big_split()
571 return (-1); in __big_split()
573 ret->nextp = NULL; in __big_split()
577 assert(np->ovfl == NULL); in __big_split()
584 tmpp->flags |= BUF_MOD; in __big_split()
587 "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr, in __big_split()
588 (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0)); in __big_split()
590 tmpp->ovfl = bp; /* one of op/np point to big_keyp */ in __big_split()
591 tp = (u_int16_t *)tmpp->page; in __big_split()
596 off = OFFSET(tp); in __big_split()
601 OFFSET(tp) = off; in __big_split()
602 FREESPACE(tp) = free_space - OVFLSIZE; in __big_split()
606 * pointer to the last page of the big key_data pair. Make sure that in __big_split()
607 * big_keyp has no following page (2 elements) or create an empty in __big_split()
608 * following page. in __big_split()
611 ret->newp = np; in __big_split()
612 ret->oldp = op; in __big_split()
614 tp = (u_int16_t *)big_keyp->page; in __big_split()
615 big_keyp->flags |= BUF_MOD; in __big_split()
618 * There may be either one or two offsets on this page. If in __big_split()
619 * there is one, then the overflow page is linked on normally in __big_split()
621 * the second offset and needs to get stuffed in after the in __big_split()
622 * next overflow page is added. in __big_split()
626 off = OFFSET(tp); in __big_split()
627 tp[0] -= 2; in __big_split()
629 OFFSET(tp) = off; in __big_split()
632 return (-1); in __big_split()
638 ret->newp = tmpp; in __big_split()
640 ret->oldp = tmpp; in __big_split()