Deleted Added
full compact
hash_page.c (55837) hash_page.c (56698)
1/*-
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Margo Seltzer.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 19 unchanged lines hidden (view full) ---

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
1/*-
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Margo Seltzer.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 19 unchanged lines hidden (view full) ---

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $FreeBSD: head/lib/libc/db/hash/hash_page.c 55837 2000-01-12 09:23:48Z jasone $
36 * $FreeBSD: head/lib/libc/db/hash/hash_page.c 56698 2000-01-27 23:07:25Z jasone $
37 */
38
39#if defined(LIBC_SCCS) && !defined(lint)
40static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94";
41#endif /* LIBC_SCCS and not lint */
42
43/*
44 * PACKAGE: hashing

--- 489 unchanged lines hidden (view full) ---

534 PAGE_INIT(p);
535 return (0);
536 }
537 if (is_bucket)
538 page = BUCKET_TO_PAGE(bucket);
539 else
540 page = OADDR_TO_PAGE(bucket);
541 if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) ||
37 */
38
39#if defined(LIBC_SCCS) && !defined(lint)
40static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94";
41#endif /* LIBC_SCCS and not lint */
42
43/*
44 * PACKAGE: hashing

--- 489 unchanged lines hidden (view full) ---

534 PAGE_INIT(p);
535 return (0);
536 }
537 if (is_bucket)
538 page = BUCKET_TO_PAGE(bucket);
539 else
540 page = OADDR_TO_PAGE(bucket);
541 if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) ||
542 ((rsize = _libc_read(fd, p, size)) == -1))
542 ((rsize = _read(fd, p, size)) == -1))
543 return (-1);
544 bp = (u_int16_t *)p;
545 if (!rsize)
546 bp[0] = 0; /* We hit the EOF, so initialize a new page */
547 else
548 if (rsize != size) {
549 errno = EFTYPE;
550 return (-1);

--- 54 unchanged lines hidden (view full) ---

605 M_16_SWAP(((u_int16_t *)p)[i]);
606 }
607 }
608 if (is_bucket)
609 page = BUCKET_TO_PAGE(bucket);
610 else
611 page = OADDR_TO_PAGE(bucket);
612 if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) ||
543 return (-1);
544 bp = (u_int16_t *)p;
545 if (!rsize)
546 bp[0] = 0; /* We hit the EOF, so initialize a new page */
547 else
548 if (rsize != size) {
549 errno = EFTYPE;
550 return (-1);

--- 54 unchanged lines hidden (view full) ---

605 M_16_SWAP(((u_int16_t *)p)[i]);
606 }
607 }
608 if (is_bucket)
609 page = BUCKET_TO_PAGE(bucket);
610 else
611 page = OADDR_TO_PAGE(bucket);
612 if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) ||
613 ((wsize = _libc_write(fd, p, size)) == -1))
613 ((wsize = _write(fd, p, size)) == -1))
614 /* Errno is set */
615 return (-1);
616 if (wsize != size) {
617 errno = EFTYPE;
618 return (-1);
619 }
620 return (0);
621}

--- 87 unchanged lines hidden (view full) ---

709 hashp->LAST_FREED = hashp->SPARES[splitnum];
710 hashp->SPARES[splitnum]++;
711 offset = hashp->SPARES[splitnum] -
712 (splitnum ? hashp->SPARES[splitnum - 1] : 0);
713
714#define OVMSG "HASH: Out of overflow pages. Increase page size\n"
715 if (offset > SPLITMASK) {
716 if (++splitnum >= NCACHED) {
614 /* Errno is set */
615 return (-1);
616 if (wsize != size) {
617 errno = EFTYPE;
618 return (-1);
619 }
620 return (0);
621}

--- 87 unchanged lines hidden (view full) ---

709 hashp->LAST_FREED = hashp->SPARES[splitnum];
710 hashp->SPARES[splitnum]++;
711 offset = hashp->SPARES[splitnum] -
712 (splitnum ? hashp->SPARES[splitnum - 1] : 0);
713
714#define OVMSG "HASH: Out of overflow pages. Increase page size\n"
715 if (offset > SPLITMASK) {
716 if (++splitnum >= NCACHED) {
717 (void)_libc_write(STDERR_FILENO, OVMSG, sizeof(OVMSG) -
718 1);
717 (void)_write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1);
719 return (0);
720 }
721 hashp->OVFL_POINT = splitnum;
722 hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1];
723 hashp->SPARES[splitnum-1]--;
724 offset = 1;
725 }
726
727 /* Check if we need to allocate a new bitmap page */
728 if (free_bit == (hashp->BSIZE << BYTE_SHIFT) - 1) {
729 free_page++;
730 if (free_page >= NCACHED) {
718 return (0);
719 }
720 hashp->OVFL_POINT = splitnum;
721 hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1];
722 hashp->SPARES[splitnum-1]--;
723 offset = 1;
724 }
725
726 /* Check if we need to allocate a new bitmap page */
727 if (free_bit == (hashp->BSIZE << BYTE_SHIFT) - 1) {
728 free_page++;
729 if (free_page >= NCACHED) {
731 (void)_libc_write(STDERR_FILENO, OVMSG, sizeof(OVMSG) -
732 1);
730 (void)_write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1);
733 return (0);
734 }
735 /*
736 * This is tricky. The 1 indicates that you want the new page
737 * allocated with 1 clear bit. Actually, you are going to
738 * allocate 2 pages from this map. The first is going to be
739 * the map page, the second is the overflow page we were
740 * looking for. The init_bitmap routine automatically, sets

--- 7 unchanged lines hidden (view full) ---

748 return (0);
749 hashp->SPARES[splitnum]++;
750#ifdef DEBUG2
751 free_bit = 2;
752#endif
753 offset++;
754 if (offset > SPLITMASK) {
755 if (++splitnum >= NCACHED) {
731 return (0);
732 }
733 /*
734 * This is tricky. The 1 indicates that you want the new page
735 * allocated with 1 clear bit. Actually, you are going to
736 * allocate 2 pages from this map. The first is going to be
737 * the map page, the second is the overflow page we were
738 * looking for. The init_bitmap routine automatically, sets

--- 7 unchanged lines hidden (view full) ---

746 return (0);
747 hashp->SPARES[splitnum]++;
748#ifdef DEBUG2
749 free_bit = 2;
750#endif
751 offset++;
752 if (offset > SPLITMASK) {
753 if (++splitnum >= NCACHED) {
756 (void)_libc_write(STDERR_FILENO, OVMSG,
754 (void)_write(STDERR_FILENO, OVMSG,
757 sizeof(OVMSG) - 1);
758 return (0);
759 }
760 hashp->OVFL_POINT = splitnum;
761 hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1];
762 hashp->SPARES[splitnum-1]--;
763 offset = 0;
764 }

--- 101 unchanged lines hidden (view full) ---

866 sigset_t set, oset;
867 static char namestr[] = "_hashXXXXXX";
868
869 /* Block signals; make sure file goes away at process exit. */
870 (void)sigfillset(&set);
871 (void)sigprocmask(SIG_BLOCK, &set, &oset);
872 if ((hashp->fp = mkstemp(namestr)) != -1) {
873 (void)unlink(namestr);
755 sizeof(OVMSG) - 1);
756 return (0);
757 }
758 hashp->OVFL_POINT = splitnum;
759 hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1];
760 hashp->SPARES[splitnum-1]--;
761 offset = 0;
762 }

--- 101 unchanged lines hidden (view full) ---

864 sigset_t set, oset;
865 static char namestr[] = "_hashXXXXXX";
866
867 /* Block signals; make sure file goes away at process exit. */
868 (void)sigfillset(&set);
869 (void)sigprocmask(SIG_BLOCK, &set, &oset);
870 if ((hashp->fp = mkstemp(namestr)) != -1) {
871 (void)unlink(namestr);
874 (void)_libc_fcntl(hashp->fp, F_SETFD, 1);
872 (void)_fcntl(hashp->fp, F_SETFD, 1);
875 }
876 (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL);
877 return (hashp->fp != -1 ? 0 : -1);
878}
879
880/*
881 * We have to know that the key will fit, but the last entry on the page is
882 * an overflow pair, so we need to shift things.

--- 66 unchanged lines hidden ---
873 }
874 (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL);
875 return (hashp->fp != -1 ? 0 : -1);
876}
877
878/*
879 * We have to know that the key will fit, but the last entry on the page is
880 * an overflow pair, so we need to shift things.

--- 66 unchanged lines hidden ---