From abd448c3b2d3508465e48d9cfdb163ef88fc242e Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 2 Jun 2013 07:22:33 -0700 Subject: [PATCH] libc/db: Sync with FreeBSD - libc/db/hash: cap auto-tuned block size with a value that actually works - Consider flag == 0 as the same of flag == R_NEXT - Minor changes from Berkeley DB 1.86 and further improvements from OpenBSD - Allow O_SYNC and O_NOFOLLOW flags in dbopen() - Plug memory leaks and a potential NULL dereference - Simplify the logic when determining whether to zero out a db file to after open(). - When deleting a big key, the offset of an empty page should be bsize, not bsize-1 - Avoid overwriting the cursor page when the cursor page becomes the LRU page. - Fix for sequential retrieval failure when using large key/data pairs. - Fix a crash when iterating over a hash and removing its elements. - Only squeeze a short key/value pair onto a page with other complete key/value pairs - Return meaningful errno in overflow case - Save errno before calling _close(), which may clear it - Explicitly specify bit width for on-disk data structure. Obtained-from: FreeBSD --- include/db.h | 82 ++++----- include/mpool.h | 61 +++---- include/ndbm.h | 34 ++-- lib/libc/db/README | 9 +- lib/libc/db/btree/Makefile.inc | 3 +- lib/libc/db/btree/bt_close.c | 8 +- lib/libc/db/btree/bt_conv.c | 52 +++--- lib/libc/db/btree/bt_debug.c | 51 +++--- lib/libc/db/btree/bt_delete.c | 36 ++-- lib/libc/db/btree/bt_get.c | 4 +- lib/libc/db/btree/bt_open.c | 49 +++--- lib/libc/db/btree/bt_overflow.c | 18 +- lib/libc/db/btree/bt_page.c | 4 +- lib/libc/db/btree/bt_put.c | 26 +-- lib/libc/db/btree/bt_search.c | 18 +- lib/libc/db/btree/bt_seq.c | 24 ++- lib/libc/db/btree/bt_split.c | 36 ++-- lib/libc/db/btree/bt_utils.c | 19 +-- lib/libc/db/btree/btree.h | 91 +++++----- lib/libc/db/btree/extern.h | 64 ++++--- lib/libc/db/db/Makefile.inc | 3 +- lib/libc/db/db/db.c | 30 ++-- lib/libc/db/docs/hash.usenix.ps | 3 +- lib/libc/db/docs/libtp.usenix.ps | 3 +- lib/libc/db/hash/Makefile.inc | 3 +- lib/libc/db/hash/README | 5 +- lib/libc/db/hash/extern.h | 50 +++--- lib/libc/db/hash/hash.c | 158 ++++++++--------- lib/libc/db/hash/hash.h | 59 ++++--- lib/libc/db/hash/hash_bigkey.c | 154 +++++++++-------- lib/libc/db/hash/hash_buf.c | 63 ++++--- lib/libc/db/hash/hash_func.c | 116 ++++++------- lib/libc/db/hash/hash_log2.c | 10 +- lib/libc/db/hash/hash_page.c | 237 +++++++++++++------------- lib/libc/db/hash/ndbm.c | 24 +-- lib/libc/db/hash/page.h | 22 +-- lib/libc/db/man/btree.3 | 13 +- lib/libc/db/man/dbm.3 | 13 +- lib/libc/db/man/dbopen.3 | 27 ++- lib/libc/db/man/hash.3 | 15 +- lib/libc/db/man/mpool.3 | 68 ++++---- lib/libc/db/man/recno.3 | 13 +- lib/libc/db/mpool/mpool.c | 130 +++++++++----- lib/libc/db/mpool/mpool.libtp | 3 +- lib/libc/db/recno/Makefile.inc | 3 +- lib/libc/db/recno/extern.h | 36 ++-- lib/libc/db/recno/rec_close.c | 14 +- lib/libc/db/recno/rec_delete.c | 10 +- lib/libc/db/recno/rec_get.c | 43 +++-- lib/libc/db/recno/rec_open.c | 11 +- lib/libc/db/recno/rec_put.c | 33 ++-- lib/libc/db/recno/rec_search.c | 24 +-- lib/libc/db/recno/rec_seq.c | 6 +- lib/libc/db/recno/rec_utils.c | 12 +- lib/libc/db/recno/recno.h | 2 +- lib/libc/db/test/Makefile | 1 + lib/libc/db/test/btree.tests/main.c | 52 +++--- lib/libc/db/test/dbtest.c | 39 +++-- lib/libc/db/test/hash.tests/driver2.c | 3 +- lib/libc/db/test/hash.tests/tcreat3.c | 3 +- lib/libc/db/test/hash.tests/tdel.c | 3 +- lib/libc/db/test/hash.tests/thash4.c | 3 +- lib/libc/db/test/hash.tests/tread2.c | 3 +- lib/libc/db/test/hash.tests/tseq.c | 3 +- lib/libc/db/test/hash.tests/tverify.c | 3 +- sys/sys/param.h | 6 + 66 files changed, 1128 insertions(+), 1096 deletions(-) diff --git a/include/db.h b/include/db.h index f83976749d..20cd9955e4 100644 --- a/include/db.h +++ b/include/db.h @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)db.h 8.7 (Berkeley) 6/16/94 - * $DragonFly: src/include/db.h,v 1.4 2005/09/19 09:05:31 asmodai Exp $ + * $FreeBSD: head/include/db.h 203964 2010-02-16 19:39:50Z imp $ */ #ifndef _DB_H_ @@ -43,11 +43,11 @@ #define RET_SPECIAL 1 #define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ -typedef u_int32_t pgno_t; +typedef uint32_t pgno_t; #define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ -typedef u_int16_t indx_t; +typedef uint16_t indx_t; #define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ -typedef u_int32_t recno_t; +typedef uint32_t recno_t; /* Key/data structure -- a Data-Base Thang. */ typedef struct { @@ -96,14 +96,14 @@ typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; /* Access method description structure. */ typedef struct __db { DBTYPE type; /* Underlying db type. */ - int (*close) (struct __db *); - int (*del) (const struct __db *, const DBT *, u_int); - int (*get) (const struct __db *, const DBT *, DBT *, u_int); - int (*put) (const struct __db *, DBT *, const DBT *, u_int); - int (*seq) (const struct __db *, DBT *, DBT *, u_int); - int (*sync) (const struct __db *, u_int); + int (*close)(struct __db *); + int (*del)(const struct __db *, const DBT *, unsigned int); + int (*get)(const struct __db *, const DBT *, DBT *, unsigned int); + int (*put)(const struct __db *, DBT *, const DBT *, unsigned int); + int (*seq)(const struct __db *, DBT *, DBT *, unsigned int); + int (*sync)(const struct __db *, unsigned int); void *internal; /* Access method private. */ - int (*fd) (const struct __db *); + int (*fd)(const struct __db *); } DB; #define BTREEMAGIC 0x053162 @@ -112,16 +112,16 @@ typedef struct __db { /* Structure used to pass parameters to the btree routines. */ typedef struct { #define R_DUP 0x01 /* duplicate keys */ - u_long flags; - u_int cachesize; /* bytes to cache */ - int maxkeypage; /* maximum keys per page */ - int minkeypage; /* minimum keys per page */ - u_int psize; /* page size */ - int (*compare) /* comparison function */ - (const DBT *, const DBT *); - size_t (*prefix) /* prefix function */ - (const DBT *, const DBT *); - int lorder; /* byte order */ + unsigned long flags; + unsigned int cachesize; /* bytes to cache */ + int maxkeypage; /* maximum keys per page */ + int minkeypage; /* minimum keys per page */ + unsigned int psize; /* page size */ + int (*compare) /* comparison function */ + (const DBT *, const DBT *); + size_t (*prefix) /* prefix function */ + (const DBT *, const DBT *); + int lorder; /* byte order */ } BTREEINFO; #define HASHMAGIC 0x061561 @@ -129,12 +129,12 @@ typedef struct { /* Structure used to pass parameters to the hashing routines. */ typedef struct { - u_int bsize; /* bucket size */ - u_int ffactor; /* fill factor */ - u_int nelem; /* number of elements */ - u_int cachesize; /* bytes to cache */ - u_int32_t /* hash function */ - (*hash) (const void *, size_t); + unsigned int bsize; /* bucket size */ + unsigned int ffactor; /* fill factor */ + unsigned int nelem; /* number of elements */ + unsigned int cachesize; /* bytes to cache */ + uint32_t /* hash function */ + (*hash)(const void *, size_t); int lorder; /* byte order */ } HASHINFO; @@ -143,12 +143,12 @@ typedef struct { #define R_FIXEDLEN 0x01 /* fixed-length records */ #define R_NOKEY 0x02 /* key not required */ #define R_SNAPSHOT 0x04 /* snapshot the input */ - u_long flags; - u_int cachesize; /* bytes to cache */ - u_int psize; /* page size */ - int lorder; /* byte order */ - size_t reclen; /* record length (fixed-length records) */ - u_char bval; /* delimiting byte (variable-length records) */ + unsigned long flags; + unsigned int cachesize; /* bytes to cache */ + unsigned int psize; /* page size */ + int lorder; /* byte order */ + size_t reclen; /* record length (fixed-length records) */ + unsigned char bval; /* delimiting byte (variable-length records */ char *bfname; /* btree file name */ } RECNOINFO; @@ -160,14 +160,14 @@ typedef struct { * P_32_COPY swap from one location to another */ #define M_32_SWAP(a) { \ - u_int32_t _tmp = a; \ + uint32_t _tmp = a; \ ((char *)&a)[0] = ((char *)&_tmp)[3]; \ ((char *)&a)[1] = ((char *)&_tmp)[2]; \ ((char *)&a)[2] = ((char *)&_tmp)[1]; \ ((char *)&a)[3] = ((char *)&_tmp)[0]; \ } #define P_32_SWAP(a) { \ - u_int32_t _tmp = *(u_int32_t *)a; \ + uint32_t _tmp = *(uint32_t *)a; \ ((char *)a)[0] = ((char *)&_tmp)[3]; \ ((char *)a)[1] = ((char *)&_tmp)[2]; \ ((char *)a)[2] = ((char *)&_tmp)[1]; \ @@ -187,12 +187,12 @@ typedef struct { * P_16_COPY swap from one location to another */ #define M_16_SWAP(a) { \ - u_int16_t _tmp = a; \ + uint16_t _tmp = a; \ ((char *)&a)[0] = ((char *)&_tmp)[1]; \ ((char *)&a)[1] = ((char *)&_tmp)[0]; \ } #define P_16_SWAP(a) { \ - u_int16_t _tmp = *(u_int16_t *)a; \ + uint16_t _tmp = *(uint16_t *)a; \ ((char *)a)[0] = ((char *)&_tmp)[1]; \ ((char *)a)[1] = ((char *)&_tmp)[0]; \ } @@ -203,12 +203,14 @@ typedef struct { #endif __BEGIN_DECLS +#if __BSD_VISIBLE DB *dbopen(const char *, int, mode_t, DBTYPE, const void *); +#endif #ifdef __DBINTERFACE_PRIVATE -DB *__bt_open(const char *, int, int, const BTREEINFO *, int); -DB *__hash_open(const char *, int, int, const HASHINFO *, int); -DB *__rec_open(const char *, int, int, const RECNOINFO *, int); +DB *__bt_open(const char *, int, mode_t, const BTREEINFO *, int); +DB *__hash_open(const char *, int, mode_t, const HASHINFO *, int); +DB *__rec_open(const char *, int, mode_t, const RECNOINFO *, int); void __dbpanic(DB *); #endif __END_DECLS diff --git a/include/mpool.h b/include/mpool.h index a548779154..16ea23bc8f 100644 --- a/include/mpool.h +++ b/include/mpool.h @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,9 +26,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)mpool.h 8.2 (Berkeley) 7/14/94 - * $FreeBSD: src/include/mpool.h,v 1.5.6.2 2001/03/05 23:05:08 obrien Exp $ - * $DragonFly: src/include/mpool.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * @(#)mpool.h 8.4 (Berkeley) 11/2/95 + * $FreeBSD: head/include/mpool.h 203964 2010-02-16 19:39:50Z imp $ */ #ifndef _MPOOL_H_ @@ -48,7 +43,7 @@ * pool is handed an opaque MPOOL cookie which stores all of this information. */ #define HASHSIZE 128 -#define HASHKEY(pgno) ((pgno - 1) % HASHSIZE) +#define HASHKEY(pgno) ((pgno - 1 + HASHSIZE) % HASHSIZE) /* The BKT structures are the elements of the queues. */ typedef struct _bkt { @@ -59,6 +54,7 @@ typedef struct _bkt { #define MPOOL_DIRTY 0x01 /* page needs to be written */ #define MPOOL_PINNED 0x02 /* page is pinned into memory */ +#define MPOOL_INUSE 0x04 /* page address is valid */ u_int8_t flags; /* flags */ } BKT; @@ -69,37 +65,44 @@ typedef struct MPOOL { pgno_t curcache; /* current number of cached pages */ pgno_t maxcache; /* max number of cached pages */ pgno_t npages; /* number of pages in the file */ - u_long pagesize; /* file page size */ + unsigned long pagesize; /* file page size */ int fd; /* file descriptor */ /* page in conversion routine */ - void (*pgin) (void *, pgno_t, void *); + void (*pgin)(void *, pgno_t, void *); /* page out conversion routine */ - void (*pgout) (void *, pgno_t, void *); + void (*pgout)(void *, pgno_t, void *); void *pgcookie; /* cookie for page in/out routines */ #ifdef STATISTICS - u_long cachehit; - u_long cachemiss; - u_long pagealloc; - u_long pageflush; - u_long pageget; - u_long pagenew; - u_long pageput; - u_long pageread; - u_long pagewrite; + unsigned long cachehit; + unsigned long cachemiss; + unsigned long pagealloc; + unsigned long pageflush; + unsigned long pageget; + unsigned long pagenew; + unsigned long pageput; + unsigned long pageread; + unsigned long pagewrite; #endif } MPOOL; +#define MPOOL_IGNOREPIN 0x01 /* Ignore if the page is pinned. */ +#define MPOOL_PAGE_REQUEST 0x01 /* Allocate a new page with a + specific page number. */ +#define MPOOL_PAGE_NEXT 0x02 /* Allocate a new page with the next + page number. */ + __BEGIN_DECLS -MPOOL *mpool_open (void *, int, pgno_t, pgno_t); -void mpool_filter (MPOOL *, void (*)(void *, pgno_t, void *), +MPOOL *mpool_open(void *, int, pgno_t, pgno_t); +void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *), void (*)(void *, pgno_t, void *), void *); -void *mpool_new (MPOOL *, pgno_t *); -void *mpool_get (MPOOL *, pgno_t, u_int); -int mpool_put (MPOOL *, void *, u_int); -int mpool_sync (MPOOL *); -int mpool_close (MPOOL *); +void *mpool_new(MPOOL *, pgno_t *, unsigned int); +void *mpool_get(MPOOL *, pgno_t, unsigned int); +int mpool_delete(MPOOL *, void *); +int mpool_put(MPOOL *, void *, unsigned int); +int mpool_sync(MPOOL *); +int mpool_close(MPOOL *); #ifdef STATISTICS -void mpool_stat (MPOOL *); +void mpool_stat(MPOOL *); #endif __END_DECLS diff --git a/include/ndbm.h b/include/ndbm.h index e51242c4d2..19bf2cb67a 100644 --- a/include/ndbm.h +++ b/include/ndbm.h @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -34,7 +30,7 @@ * SUCH DAMAGE. * * @(#)ndbm.h 8.1 (Berkeley) 6/2/93 - * $DragonFly: src/include/ndbm.h,v 1.2 2003/11/14 01:01:43 dillon Exp $ + * $FreeBSD: head/include/ndbm.h 203964 2010-02-16 19:39:50Z imp $ */ #ifndef _NDBM_H_ @@ -64,17 +60,21 @@ typedef DB DBM; #define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE __BEGIN_DECLS -int dbm_clearerr (DBM *); -void dbm_close (DBM *); -int dbm_delete (DBM *, datum); -int dbm_error (DBM *); -datum dbm_fetch (DBM *, datum); -datum dbm_firstkey (DBM *); -long dbm_forder (DBM *, datum); -datum dbm_nextkey (DBM *); -DBM *dbm_open (const char *, int, int); -int dbm_store (DBM *, datum, datum, int); -int dbm_dirfno (DBM *); +int dbm_clearerr(DBM *); +void dbm_close(DBM *); +int dbm_delete(DBM *, datum); +int dbm_error(DBM *); +datum dbm_fetch(DBM *, datum); +datum dbm_firstkey(DBM *); +#if __BSD_VISIBLE +long dbm_forder(DBM *, datum); +#endif +datum dbm_nextkey(DBM *); +DBM *dbm_open(const char *, int, mode_t); +int dbm_store(DBM *, datum, datum, int); +#if __BSD_VISIBLE +int dbm_dirfno(DBM *); +#endif __END_DECLS #endif /* !_NDBM_H_ */ diff --git a/lib/libc/db/README b/lib/libc/db/README index bed2c92fa5..db98817024 100644 --- a/lib/libc/db/README +++ b/lib/libc/db/README @@ -1,4 +1,5 @@ # @(#)README 8.27 (Berkeley) 9/1/94 +# $FreeBSD: head/lib/libc/db/README 190482 2009-03-28 04:00:46Z delphij $ This is version 1.85 of the Berkeley DB code. @@ -30,11 +31,3 @@ man The unformatted manual pages. mpool The memory pool routines. recno The fixed/variable length record routines. test Test package. - -============================================ -Debugging: - -If you're running a memory checker (e.g. Purify) on DB, make sure that -you recompile it with "-DPURIFY" in the CFLAGS, first. By default, -allocated pages are not initialized by the DB code, and they will show -up as reads of uninitialized memory in the buffer write routines. diff --git a/lib/libc/db/btree/Makefile.inc b/lib/libc/db/btree/Makefile.inc index ea0a2fad98..285c02c743 100644 --- a/lib/libc/db/btree/Makefile.inc +++ b/lib/libc/db/btree/Makefile.inc @@ -1,6 +1,5 @@ # from @(#)Makefile.inc 8.2 (Berkeley) 7/14/94 -# $FreeBSD: src/lib/libc/db/btree/Makefile.inc,v 1.3 1999/08/27 23:58:16 peter Exp $ -# $DragonFly: src/lib/libc/db/btree/Makefile.inc,v 1.2 2003/06/17 04:26:41 dillon Exp $ +# $FreeBSD: head/lib/libc/db/btree/Makefile.inc 107052 2002-11-18 09:50:57Z ru $ .PATH: ${.CURDIR}/../libc/db/btree diff --git a/lib/libc/db/btree/bt_close.c b/lib/libc/db/btree/bt_close.c index 9572e29130..3252371b53 100644 --- a/lib/libc/db/btree/bt_close.c +++ b/lib/libc/db/btree/bt_close.c @@ -29,10 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/db/btree/bt_close.c,v 1.5 2000/01/27 23:06:05 jasone Exp $ - * $DragonFly: src/lib/libc/db/btree/bt_close.c,v 1.5 2005/09/19 09:20:37 asmodai Exp $ - * * @(#)bt_close.c 8.7 (Berkeley) 8/17/94 + * $FreeBSD: head/lib/libc/db/btree/bt_close.c 189291 2009-03-02 23:47:18Z delphij $ */ #include "namespace.h" @@ -48,7 +46,7 @@ #include #include "btree.h" -static int bt_meta (BTREE *); +static int bt_meta(BTREE *); /* * BT_CLOSE -- Close a btree. @@ -114,7 +112,7 @@ __bt_close(DB *dbp) * RET_SUCCESS, RET_ERROR. */ int -__bt_sync(const DB *dbp, u_int flags) +__bt_sync(const DB *dbp, unsigned int flags) { BTREE *t; int status; diff --git a/lib/libc/db/btree/bt_conv.c b/lib/libc/db/btree/bt_conv.c index 042bfb2e0c..cf006074a7 100644 --- a/lib/libc/db/btree/bt_conv.c +++ b/lib/libc/db/btree/bt_conv.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)bt_conv.c 8.5 (Berkeley) 8/17/94 - * $DragonFly: src/lib/libc/db/btree/bt_conv.c,v 1.6 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_conv.c 189291 2009-03-02 23:47:18Z delphij $ */ #include @@ -40,7 +40,7 @@ #include #include "btree.h" -static void mswap (PAGE *); +static void mswap(PAGE *); /* * __BT_BPGIN, __BT_BPGOUT -- @@ -57,7 +57,7 @@ __bt_pgin(void *t, pgno_t pg, void *pp) { PAGE *h; indx_t i, top; - u_char flags; + unsigned char flags; char *p; if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) @@ -81,11 +81,11 @@ __bt_pgin(void *t, pgno_t pg, void *pp) M_16_SWAP(h->linp[i]); p = (char *)GETBINTERNAL(h, i); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); p += sizeof(pgno_t); - if (*(u_char *)p & P_BIGKEY) { - p += sizeof(u_char); + if (*(unsigned char *)p & P_BIGKEY) { + p += sizeof(unsigned char); P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); @@ -96,19 +96,19 @@ __bt_pgin(void *t, pgno_t pg, void *pp) M_16_SWAP(h->linp[i]); p = (char *)GETBLEAF(h, i); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); - p += sizeof(u_int32_t); - flags = *(u_char *)p; + p += sizeof(uint32_t); + flags = *(unsigned char *)p; if (flags & (P_BIGKEY | P_BIGDATA)) { - p += sizeof(u_char); + p += sizeof(unsigned char); if (flags & P_BIGKEY) { P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); } if (flags & P_BIGDATA) { - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); @@ -122,7 +122,7 @@ __bt_pgout(void *t, pgno_t pg, void *pp) { PAGE *h; indx_t i, top; - u_char flags; + unsigned char flags; char *p; if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) @@ -138,11 +138,11 @@ __bt_pgout(void *t, pgno_t pg, void *pp) for (i = 0; i < top; i++) { p = (char *)GETBINTERNAL(h, i); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); p += sizeof(pgno_t); - if (*(u_char *)p & P_BIGKEY) { - p += sizeof(u_char); + if (*(unsigned char *)p & P_BIGKEY) { + p += sizeof(unsigned char); P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); @@ -153,19 +153,19 @@ __bt_pgout(void *t, pgno_t pg, void *pp) for (i = 0; i < top; i++) { p = (char *)GETBLEAF(h, i); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); - p += sizeof(u_int32_t); - flags = *(u_char *)p; + p += sizeof(uint32_t); + flags = *(unsigned char *)p; if (flags & (P_BIGKEY | P_BIGDATA)) { - p += sizeof(u_char); + p += sizeof(unsigned char); if (flags & P_BIGKEY) { P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); } if (flags & P_BIGDATA) { - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); @@ -195,15 +195,15 @@ mswap(PAGE *pg) p = (char *)pg; P_32_SWAP(p); /* magic */ - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); /* version */ - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); /* psize */ - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); /* free */ - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); /* nrecs */ - p += sizeof(u_int32_t); + p += sizeof(uint32_t); P_32_SWAP(p); /* flags */ - p += sizeof(u_int32_t); + p += sizeof(uint32_t); } diff --git a/lib/libc/db/btree/bt_debug.c b/lib/libc/db/btree/bt_debug.c index b7c05a8cb2..20068c0cf5 100644 --- a/lib/libc/db/btree/bt_debug.c +++ b/lib/libc/db/btree/bt_debug.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)bt_debug.c 8.5 (Berkeley) 8/17/94 - * $DragonFly: src/lib/libc/db/btree/bt_debug.c,v 1.4 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_debug.c 190498 2009-03-28 07:31:02Z delphij $ */ #include @@ -58,7 +58,7 @@ __bt_dump(DB *dbp) char *sep; t = dbp->internal; - fprintf(stderr, "%s: pgsz %d", + fprintf(stderr, "%s: pgsz %u", F_ISSET(t, B_INMEM) ? "memory" : "disk", t->bt_psize); if (F_ISSET(t, R_RECNO)) fprintf(stderr, " keys %u", t->bt_nrecs); @@ -80,10 +80,9 @@ __bt_dump(DB *dbp) } #undef X - for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) { + for (i = P_ROOT; + (h = mpool_get(t->bt_mp, i, MPOOL_IGNOREPIN)) != NULL; ++i) __bt_dpage(h); - mpool_put(t->bt_mp, h, 0); - } } /* @@ -132,10 +131,8 @@ __bt_dnpage(DB *dbp, pgno_t pgno) PAGE *h; t = dbp->internal; - if ((h = mpool_get(t->bt_mp, pgno, 0)) != NULL) { + if ((h = mpool_get(t->bt_mp, pgno, MPOOL_IGNOREPIN)) != NULL) __bt_dpage(h); - mpool_put(t->bt_mp, h, 0); - } } /* @@ -154,7 +151,7 @@ __bt_dpage(PAGE *h) indx_t cur, top; char *sep; - fprintf(stderr, " page %d: (", h->pgno); + fprintf(stderr, " page %u: (", h->pgno); #undef X #define X(flag, name) \ if (h->flags & flag) { \ @@ -171,7 +168,7 @@ __bt_dpage(PAGE *h) fprintf(stderr, ")\n"); #undef X - fprintf(stderr, "\tprev %2d next %2d", h->prevpg, h->nextpg); + fprintf(stderr, "\tprev %2u next %2u", h->prevpg, h->nextpg); if (h->flags & P_OVERFLOW) return; @@ -202,7 +199,7 @@ __bt_dpage(PAGE *h) fprintf(stderr, "big key page %u size %u/", *(pgno_t *)bl->bytes, - *(u_int32_t *)(bl->bytes + sizeof(pgno_t))); + *(uint32_t *)(bl->bytes + sizeof(pgno_t))); else if (bl->ksize) fprintf(stderr, "%.*s/", bl->ksize, bl->bytes); @@ -210,7 +207,7 @@ __bt_dpage(PAGE *h) fprintf(stderr, "big data page %u size %u", *(pgno_t *)(bl->bytes + bl->ksize), - *(u_int32_t *)(bl->bytes + bl->ksize + + *(uint32_t *)(bl->bytes + bl->ksize + sizeof(pgno_t))); else if (bl->dsize) fprintf(stderr, "%.*s", @@ -222,7 +219,7 @@ __bt_dpage(PAGE *h) fprintf(stderr, "big data page %u size %u", *(pgno_t *)rl->bytes, - *(u_int32_t *)(rl->bytes + sizeof(pgno_t))); + *(uint32_t *)(rl->bytes + sizeof(pgno_t))); else if (rl->dsize) fprintf(stderr, "%.*s", (int)rl->dsize, rl->bytes); @@ -243,18 +240,20 @@ __bt_dpage(PAGE *h) void __bt_stat(DB *dbp) { - extern u_long bt_cache_hit, bt_cache_miss, bt_pfxsaved, bt_rootsplit; - extern u_long bt_sortsplit, bt_split; + extern unsigned long bt_cache_hit, bt_cache_miss; + extern unsigned long bt_pfxsaved, bt_rootsplit; + extern unsigned long bt_sortsplit, bt_split; BTREE *t; PAGE *h; pgno_t i, pcont, pinternal, pleaf; - u_long ifree, lfree, nkeys; + unsigned long ifree, lfree, nkeys; int levels; t = dbp->internal; pcont = pinternal = pleaf = 0; nkeys = ifree = lfree = 0; - for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) { + for (i = P_ROOT; + (h = mpool_get(t->bt_mp, i, MPOOL_IGNOREPIN)) != NULL; ++i) switch (h->flags & P_TYPE) { case P_BINTERNAL: case P_RINTERNAL: @@ -271,45 +270,41 @@ __bt_stat(DB *dbp) ++pcont; break; } - mpool_put(t->bt_mp, h, 0); - } /* Count the levels of the tree. */ for (i = P_ROOT, levels = 0 ;; ++levels) { - h = mpool_get(t->bt_mp, i, 0); + h = mpool_get(t->bt_mp, i, MPOOL_IGNOREPIN); if (h->flags & (P_BLEAF|P_RLEAF)) { if (levels == 0) levels = 1; - mpool_put(t->bt_mp, h, 0); break; } i = F_ISSET(t, R_RECNO) ? GETRINTERNAL(h, 0)->pgno : GETBINTERNAL(h, 0)->pgno; - mpool_put(t->bt_mp, h, 0); } - fprintf(stderr, "%d level%s with %ld keys", + fprintf(stderr, "%d level%s with %lu keys", levels, levels == 1 ? "" : "s", nkeys); if (F_ISSET(t, R_RECNO)) - fprintf(stderr, " (%d header count)", t->bt_nrecs); + fprintf(stderr, " (%u header count)", t->bt_nrecs); fprintf(stderr, - "\n%u pages (leaf %d, internal %d, overflow %d)\n", + "\n%u pages (leaf %u, internal %u, overflow %u)\n", pinternal + pleaf + pcont, pleaf, pinternal, pcont); - fprintf(stderr, "%ld cache hits, %ld cache misses\n", + fprintf(stderr, "%lu cache hits, %lu cache misses\n", bt_cache_hit, bt_cache_miss); fprintf(stderr, "%lu splits (%lu root splits, %lu sort splits)\n", bt_split, bt_rootsplit, bt_sortsplit); pleaf *= t->bt_psize - BTDATAOFF; if (pleaf) fprintf(stderr, - "%.0f%% leaf fill (%ld bytes used, %ld bytes free)\n", + "%.0f%% leaf fill (%lu bytes used, %lu bytes free)\n", ((double)(pleaf - lfree) / pleaf) * 100, pleaf - lfree, lfree); pinternal *= t->bt_psize - BTDATAOFF; if (pinternal) fprintf(stderr, - "%.0f%% internal fill (%ld bytes used, %ld bytes free\n", + "%.0f%% internal fill (%lu bytes used, %lu bytes free\n", ((double)(pinternal - ifree) / pinternal) * 100, pinternal - ifree, ifree); if (bt_pfxsaved) diff --git a/lib/libc/db/btree/bt_delete.c b/lib/libc/db/btree/bt_delete.c index 2c30075285..2e65455566 100644 --- a/lib/libc/db/btree/bt_delete.c +++ b/lib/libc/db/btree/bt_delete.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)bt_delete.c 8.13 (Berkeley) 7/28/94 - * $DragonFly: src/lib/libc/db/btree/bt_delete.c,v 1.8 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_delete.c 189327 2009-03-04 00:58:04Z delphij $ */ #include @@ -42,11 +42,11 @@ #include #include "btree.h" -static int __bt_bdelete (BTREE *, const DBT *); -static int __bt_curdel (BTREE *, const DBT *, PAGE *, u_int); -static int __bt_pdelete (BTREE *, PAGE *); -static int __bt_relink (BTREE *, PAGE *); -static int __bt_stkacq (BTREE *, PAGE **, CURSOR *); +static int __bt_bdelete(BTREE *, const DBT *); +static int __bt_curdel(BTREE *, const DBT *, PAGE *, unsigned int); +static int __bt_pdelete(BTREE *, PAGE *); +static int __bt_relink(BTREE *, PAGE *); +static int __bt_stkacq(BTREE *, PAGE **, CURSOR *); /* * __bt_delete @@ -55,7 +55,7 @@ static int __bt_stkacq (BTREE *, PAGE **, CURSOR *); * Return RET_SPECIAL if the key is not found. */ int -__bt_delete(const DB *dbp, const DBT *key, u_int flags) +__bt_delete(const DB *dbp, const DBT *key, unsigned int flags) { BTREE *t; CURSOR *c; @@ -139,11 +139,11 @@ __bt_stkacq(BTREE *t, PAGE **hp, CURSOR *c) EPG *e; EPGNO *parent; PAGE *h; - indx_t idx = 0; + indx_t idx; pgno_t pgno; recno_t nextpg, prevpg; int exact, level; - + /* * Find the first occurrence of the key in the tree. Toss the * currently locked page so we don't hit an already-locked page. @@ -259,7 +259,7 @@ __bt_stkacq(BTREE *t, PAGE **hp, CURSOR *c) if ((h = mpool_get(t->bt_mp, prevpg, 0)) == NULL) return (1); } - + ret: mpool_put(t->bt_mp, h, 0); return ((*hp = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL); @@ -368,7 +368,7 @@ __bt_pdelete(BTREE *t, PAGE *h) PAGE *pg; EPGNO *parent; indx_t cnt, idx, *ip, offset; - u_int32_t nksize; + uint32_t nksize; char *from; /* @@ -387,7 +387,7 @@ __bt_pdelete(BTREE *t, PAGE *h) /* Get the parent page. */ if ((pg = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) return (RET_ERROR); - + idx = parent->index; bi = GETBINTERNAL(pg, idx); @@ -403,7 +403,7 @@ __bt_pdelete(BTREE *t, PAGE *h) * root page. If it's the rootpage, turn it back into an empty * leaf page. */ - if (NEXTINDEX(pg) == 1) + if (NEXTINDEX(pg) == 1) { if (pg->pgno == P_ROOT) { pg->lower = BTDATAOFF; pg->upper = t->bt_psize; @@ -413,7 +413,7 @@ __bt_pdelete(BTREE *t, PAGE *h) return (RET_ERROR); continue; } - else { + } else { /* Pack remaining key items at the end of the page. */ nksize = NBINTERNAL(bi->ksize); from = (char *)pg + pg->upper; @@ -456,11 +456,11 @@ __bt_pdelete(BTREE *t, PAGE *h) * RET_SUCCESS, RET_ERROR. */ int -__bt_dleaf(BTREE *t, const DBT *key, PAGE *h, u_int idx) +__bt_dleaf(BTREE *t, const DBT *key, PAGE *h, unsigned int idx) { BLEAF *bl; indx_t cnt, *ip, offset; - u_int32_t nbytes; + uint32_t nbytes; void *to; char *from; @@ -517,7 +517,7 @@ __bt_dleaf(BTREE *t, const DBT *key, PAGE *h, u_int idx) * RET_SUCCESS, RET_ERROR. */ static int -__bt_curdel(BTREE *t, const DBT *key, PAGE *h, u_int idx) +__bt_curdel(BTREE *t, const DBT *key, PAGE *h, unsigned int idx) { CURSOR *c; EPG e; @@ -548,7 +548,7 @@ __bt_curdel(BTREE *t, const DBT *key, PAGE *h, u_int idx) key = &c->key; } /* Check previous key, if not at the beginning of the page. */ - if (idx > 0) { + if (idx > 0) { e.page = h; e.index = idx - 1; if (__bt_cmp(t, key, &e) == 0) { diff --git a/lib/libc/db/btree/bt_get.c b/lib/libc/db/btree/bt_get.c index 8fb2536d04..f0a016b158 100644 --- a/lib/libc/db/btree/bt_get.c +++ b/lib/libc/db/btree/bt_get.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)bt_get.c 8.6 (Berkeley) 7/20/94 - * $DragonFly: src/lib/libc/db/btree/bt_get.c,v 1.4 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_get.c 189291 2009-03-02 23:47:18Z delphij $ */ #include @@ -55,7 +55,7 @@ * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. */ int -__bt_get(const DB *dbp, const DBT *key, DBT *data, u_int flags) +__bt_get(const DB *dbp, const DBT *key, DBT *data, unsigned int flags) { BTREE *t; EPG *e; diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c index 3106704e10..9e25674980 100644 --- a/lib/libc/db/btree/bt_open.c +++ b/lib/libc/db/btree/bt_open.c @@ -29,10 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/db/btree/bt_open.c,v 1.7.2.1 2000/11/02 10:30:07 kris Exp $ - * $DragonFly: src/lib/libc/db/btree/bt_open.c,v 1.6 2005/11/12 23:01:54 swildner Exp $ - * * @(#)bt_open.c 8.10 (Berkeley) 8/17/94 + * $FreeBSD: head/lib/libc/db/btree/bt_open.c 190498 2009-03-28 07:31:02Z delphij $ */ /* @@ -65,9 +63,9 @@ #define MINPSIZE 128 #endif -static int byteorder (void); -static int nroot (BTREE *); -static int tmp (void); +static int byteorder(void); +static int nroot(BTREE *); +static int tmp(void); /* * __BT_OPEN -- Open a btree. @@ -86,7 +84,7 @@ static int tmp (void); * */ DB * -__bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, +__bt_open(const char *fname, int flags, mode_t mode, const BTREEINFO *openinfo, int dflags) { struct stat sb; @@ -96,7 +94,7 @@ __bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, DB *dbp; pgno_t ncache; ssize_t nr; - int machine_lorder; + int machine_lorder, saved_errno; t = NULL; @@ -156,9 +154,8 @@ __bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, goto einval; /* Allocate and initialize DB and BTREE structures. */ - if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL) + if ((t = (BTREE *)calloc(1, sizeof(BTREE))) == NULL) goto err; - memset(t, 0, sizeof(BTREE)); t->bt_fd = -1; /* Don't close unopened fd on error. */ t->bt_lorder = b.lorder; t->bt_order = NOT; @@ -166,9 +163,8 @@ __bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, t->bt_pfx = b.prefix; t->bt_rfd = -1; - if ((t->bt_dbp = dbp = (DB *)malloc(sizeof(DB))) == NULL) + if ((t->bt_dbp = dbp = (DB *)calloc(1, sizeof(DB))) == NULL) goto err; - memset(t->bt_dbp, 0, sizeof(DB)); if (t->bt_lorder != machine_lorder) F_SET(t, B_NEEDSWAP); @@ -197,7 +193,7 @@ __bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, default: goto einval; } - + if ((t->bt_fd = _open(fname, flags, mode)) < 0) goto err; @@ -327,13 +323,15 @@ einval: errno = EINVAL; eftype: errno = EFTYPE; goto err; -err: if (t) { +err: saved_errno = errno; + if (t) { if (t->bt_dbp) free(t->bt_dbp); if (t->bt_fd != -1) _close(t->bt_fd); free(t); } + errno = saved_errno; return (NULL); } @@ -352,18 +350,25 @@ nroot(BTREE *t) PAGE *meta, *root; pgno_t npg; - if ((meta = mpool_get(t->bt_mp, 0, 0)) != NULL) { - mpool_put(t->bt_mp, meta, 0); - return (RET_SUCCESS); + if ((root = mpool_get(t->bt_mp, 1, 0)) != NULL) { + if (root->lower == 0 && + root->pgno == 0 && + root->linp[0] == 0) { + mpool_delete(t->bt_mp, root); + errno = EINVAL; + } else { + mpool_put(t->bt_mp, root, 0); + return (RET_SUCCESS); + } } if (errno != EINVAL) /* It's OK to not exist. */ return (RET_ERROR); errno = 0; - if ((meta = mpool_new(t->bt_mp, &npg)) == NULL) + if ((meta = mpool_new(t->bt_mp, &npg, MPOOL_PAGE_NEXT)) == NULL) return (RET_ERROR); - if ((root = mpool_new(t->bt_mp, &npg)) == NULL) + if ((root = mpool_new(t->bt_mp, &npg, MPOOL_PAGE_NEXT)) == NULL) return (RET_ERROR); if (npg != P_ROOT) @@ -407,11 +412,11 @@ tmp(void) static int byteorder(void) { - u_int32_t x; - u_char *p; + uint32_t x; + unsigned char *p; x = 0x01020304; - p = (u_char *)&x; + p = (unsigned char *)&x; switch (*p) { case 1: return (BIG_ENDIAN); diff --git a/lib/libc/db/btree/bt_overflow.c b/lib/libc/db/btree/bt_overflow.c index c95d223b45..38d6360979 100644 --- a/lib/libc/db/btree/bt_overflow.c +++ b/lib/libc/db/btree/bt_overflow.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)bt_overflow.c 8.5 (Berkeley) 7/16/94 - * $DragonFly: src/lib/libc/db/btree/bt_overflow.c,v 1.4 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_overflow.c 189387 2009-03-05 00:57:01Z delphij $ */ #include @@ -64,7 +64,7 @@ * * Parameters: * t: tree - * p: pointer to { pgno_t, u_int32_t } + * p: pointer to { pgno_t, uint32_t } * buf: storage address * bufsz: storage size * @@ -77,10 +77,10 @@ __ovfl_get(BTREE *t, void *p, size_t *ssz, void **buf, size_t *bufsz) PAGE *h; pgno_t pg; size_t nb, plen; - u_int32_t sz; + uint32_t sz; memmove(&pg, p, sizeof(pgno_t)); - memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t)); + memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(uint32_t)); *ssz = sz; #ifdef DEBUG @@ -89,7 +89,7 @@ __ovfl_get(BTREE *t, void *p, size_t *ssz, void **buf, size_t *bufsz) #endif /* Make the buffer bigger as necessary. */ if (*bufsz < sz) { - *buf = (char *)(*buf == NULL ? malloc(sz) : reallocf(*buf, sz)); + *buf = reallocf(*buf, sz); if (*buf == NULL) return (RET_ERROR); *bufsz = sz; @@ -132,7 +132,7 @@ __ovfl_put(BTREE *t, const DBT *dbt, pgno_t *pg) void *p; pgno_t npg; size_t nb, plen; - u_int32_t sz; + uint32_t sz; /* * Allocate pages and copy the key/data record into them. Store the @@ -171,7 +171,7 @@ __ovfl_put(BTREE *t, const DBT *dbt, pgno_t *pg) * * Parameters: * t: tree - * p: pointer to { pgno_t, u_int32_t } + * p: pointer to { pgno_t, uint32_t } * * Returns: * RET_ERROR, RET_SUCCESS @@ -182,10 +182,10 @@ __ovfl_delete(BTREE *t, void *p) PAGE *h; pgno_t pg; size_t plen; - u_int32_t sz; + uint32_t sz; memmove(&pg, p, sizeof(pgno_t)); - memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t)); + memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(uint32_t)); #ifdef DEBUG if (pg == P_INVALID || sz == 0) diff --git a/lib/libc/db/btree/bt_page.c b/lib/libc/db/btree/bt_page.c index 5d4cb5e8f3..2cc6739d28 100644 --- a/lib/libc/db/btree/bt_page.c +++ b/lib/libc/db/btree/bt_page.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)bt_page.c 8.3 (Berkeley) 7/14/94 - * $DragonFly: src/lib/libc/db/btree/bt_page.c,v 1.4 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_page.c 190498 2009-03-28 07:31:02Z delphij $ */ #include @@ -87,5 +87,5 @@ __bt_new(BTREE *t, pgno_t *npg) F_SET(t, B_METADIRTY); return (h); } - return (mpool_new(t->bt_mp, npg)); + return (mpool_new(t->bt_mp, npg, MPOOL_PAGE_NEXT)); } diff --git a/lib/libc/db/btree/bt_put.c b/lib/libc/db/btree/bt_put.c index 97e7117703..ad951cc5fa 100644 --- a/lib/libc/db/btree/bt_put.c +++ b/lib/libc/db/btree/bt_put.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)bt_put.c 8.8 (Berkeley) 7/26/94 - * $DragonFly: src/lib/libc/db/btree/bt_put.c,v 1.8 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_put.c 190484 2009-03-28 05:45:29Z delphij $ */ #include @@ -43,7 +43,7 @@ #include #include "btree.h" -static EPG *bt_fast (BTREE *, const DBT *, const DBT *, int *); +static EPG *bt_fast(BTREE *, const DBT *, const DBT *, int *); /* * __BT_PUT -- Add a btree item to the tree. @@ -59,15 +59,15 @@ static EPG *bt_fast (BTREE *, const DBT *, const DBT *, int *); * tree and R_NOOVERWRITE specified. */ int -__bt_put(const DB *dbp, DBT *key, const DBT *data, u_int flags) +__bt_put(const DB *dbp, DBT *key, const DBT *data, unsigned int flags) { BTREE *t; DBT tkey, tdata; - EPG *e = NULL; + EPG *e; PAGE *h; indx_t idx, nxtindex; pgno_t pg; - u_int32_t nbytes, tmp; + uint32_t nbytes, tmp; int dflags, exact, status; char *dest, db[NOVFLSIZE], kb[NOVFLSIZE]; @@ -96,7 +96,7 @@ __bt_put(const DB *dbp, DBT *key, const DBT *data, u_int flags) */ if (F_ISSET(&t->bt_cursor, CURS_INIT) && !F_ISSET(&t->bt_cursor, - CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE)) + CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE)) break; /* FALLTHROUGH */ default: @@ -122,7 +122,7 @@ storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) memmove(kb, &pg, sizeof(pgno_t)); tmp = key->size; memmove(kb + sizeof(pgno_t), - &tmp, sizeof(u_int32_t)); + &tmp, sizeof(uint32_t)); dflags |= P_BIGKEY; key = &tkey; } @@ -134,7 +134,7 @@ storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) memmove(db, &pg, sizeof(pgno_t)); tmp = data->size; memmove(db + sizeof(pgno_t), - &tmp, sizeof(u_int32_t)); + &tmp, sizeof(uint32_t)); dflags |= P_BIGDATA; data = &tdata; } @@ -194,7 +194,7 @@ delete: if (__bt_dleaf(t, key, h, idx) == RET_ERROR) { * into the offset array, shift the pointers up. */ nbytes = NBLEAFDBT(key->size, data->size); - if ((size_t)(h->upper - h->lower) < nbytes + sizeof(indx_t)) { + if ((uint32_t)(h->upper - h->lower) < nbytes + sizeof(indx_t)) { if ((status = __bt_split(t, h, key, data, dflags, nbytes, idx)) != RET_SUCCESS) return (status); @@ -243,7 +243,7 @@ success: } #ifdef STATISTICS -u_long bt_cache_hit, bt_cache_miss; +unsigned long bt_cache_hit, bt_cache_miss; #endif /* @@ -254,13 +254,13 @@ u_long bt_cache_hit, bt_cache_miss; * key: key to insert * * Returns: - * EPG for new record or NULL if not found. + * EPG for new record or NULL if not found. */ static EPG * bt_fast(BTREE *t, const DBT *key, const DBT *data, int *exactp) { PAGE *h; - u_int32_t nbytes; + uint32_t nbytes; int cmp; if ((h = mpool_get(t->bt_mp, t->bt_last.pgno, 0)) == NULL) { @@ -275,7 +275,7 @@ bt_fast(BTREE *t, const DBT *key, const DBT *data, int *exactp) * have to search to get split stack. */ nbytes = NBLEAFDBT(key->size, data->size); - if ((size_t)(h->upper - h->lower) < nbytes + sizeof(indx_t)) + if ((uint32_t)(h->upper - h->lower) < nbytes + sizeof(indx_t)) goto miss; if (t->bt_order == FORWARD) { diff --git a/lib/libc/db/btree/bt_search.c b/lib/libc/db/btree/bt_search.c index ba0b211b90..f680576cb5 100644 --- a/lib/libc/db/btree/bt_search.c +++ b/lib/libc/db/btree/bt_search.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)bt_search.c 8.8 (Berkeley) 7/31/94 - * $DragonFly: src/lib/libc/db/btree/bt_search.c,v 1.6 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_search.c 189292 2009-03-03 02:16:12Z delphij $ */ #include @@ -40,8 +40,8 @@ #include #include "btree.h" -static int __bt_snext (BTREE *, PAGE *, const DBT *, int *); -static int __bt_sprev (BTREE *, PAGE *, const DBT *, int *); +static int __bt_snext(BTREE *, PAGE *, const DBT *, int *); +static int __bt_sprev(BTREE *, PAGE *, const DBT *, int *); /* * __bt_search -- @@ -61,7 +61,7 @@ EPG * __bt_search(BTREE *t, const DBT *key, int *exactp) { PAGE *h; - indx_t base, index, lim; + indx_t base, idx, lim; pgno_t pg; int cmp; @@ -73,7 +73,7 @@ __bt_search(BTREE *t, const DBT *key, int *exactp) /* Do a binary search on the current page. */ t->bt_cur.page = h; for (base = 0, lim = NEXTINDEX(h); lim; lim >>= 1) { - t->bt_cur.index = index = base + (lim >> 1); + t->bt_cur.index = idx = base + (lim >> 1); if ((cmp = __bt_cmp(t, key, &t->bt_cur)) == 0) { if (h->flags & P_BLEAF) { *exactp = 1; @@ -82,7 +82,7 @@ __bt_search(BTREE *t, const DBT *key, int *exactp) goto next; } if (cmp > 0) { - base = index + 1; + base = idx + 1; --lim; } } @@ -118,10 +118,10 @@ __bt_search(BTREE *t, const DBT *key, int *exactp) * be a parent page for the key. If a split later occurs, the * inserted page will be to the right of the saved page. */ - index = base ? base - 1 : base; + idx = base ? base - 1 : base; -next: BT_PUSH(t, h->pgno, index); - pg = GETBINTERNAL(h, index)->pgno; +next: BT_PUSH(t, h->pgno, idx); + pg = GETBINTERNAL(h, idx)->pgno; mpool_put(t->bt_mp, h, 0); } } diff --git a/lib/libc/db/btree/bt_seq.c b/lib/libc/db/btree/bt_seq.c index 46a1aa9c78..01077f6894 100644 --- a/lib/libc/db/btree/bt_seq.c +++ b/lib/libc/db/btree/bt_seq.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)bt_seq.c 8.7 (Berkeley) 7/20/94 - * $DragonFly: src/lib/libc/db/btree/bt_seq.c,v 1.7 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_seq.c 189327 2009-03-04 00:58:04Z delphij $ */ #include @@ -43,9 +43,9 @@ #include #include "btree.h" -static int __bt_first (BTREE *, const DBT *, EPG *, int *); -static int __bt_seqadv (BTREE *, EPG *, int); -static int __bt_seqset (BTREE *, EPG *, DBT *, int); +static int __bt_first(BTREE *, const DBT *, EPG *, int *); +static int __bt_seqadv(BTREE *, EPG *, int); +static int __bt_seqset(BTREE *, EPG *, DBT *, int); /* * Sequential scan support. @@ -69,7 +69,7 @@ static int __bt_seqset (BTREE *, EPG *, DBT *, int); * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. */ int -__bt_seq(const DB *dbp, DBT *key, DBT *data, u_int flags) +__bt_seq(const DB *dbp, DBT *key, DBT *data, unsigned int flags) { BTREE *t; EPG e; @@ -84,7 +84,7 @@ __bt_seq(const DB *dbp, DBT *key, DBT *data, u_int flags) } /* - * If scan unitialized as yet, or starting at a specific record, set + * If scan uninitialized as yet, or starting at a specific record, set * the scan to a specific key. Both __bt_seqset and __bt_seqadv pin * the page the cursor references if they're successful. */ @@ -255,7 +255,7 @@ __bt_seqadv(BTREE *t, EPG *ep, int flags) return (RET_ERROR); /* - * Find the next/previous record in the tree and point the cursor at + * Find the next/previous record in the tree and point the cursor at * it. The cursor may not be moved until a new key has been found. */ switch (flags) { @@ -302,8 +302,6 @@ usecurrent: F_CLR(c, CURS_AFTER | CURS_BEFORE); } else --idx; break; - default: - return (RET_ERROR); } ep->page = h; @@ -347,7 +345,7 @@ __bt_first(BTREE *t, const DBT *key, EPG *erval, int *exactp) *erval = *ep; return (RET_SUCCESS); } - + /* * Walk backwards, as long as the entry matches and there are * keys left in the tree. Save a copy of each match in case @@ -420,10 +418,10 @@ __bt_first(BTREE *t, const DBT *key, EPG *erval, int *exactp) * Parameters: * t: the tree * pgno: page number - * index: page index + * idx: page index */ void -__bt_setcur(BTREE *t, pgno_t pgno, u_int index) +__bt_setcur(BTREE *t, pgno_t pgno, unsigned int idx) { /* Lose any already deleted key. */ if (t->bt_cursor.key.data != NULL) { @@ -435,6 +433,6 @@ __bt_setcur(BTREE *t, pgno_t pgno, u_int index) /* Update the cursor. */ t->bt_cursor.pg.pgno = pgno; - t->bt_cursor.pg.index = index; + t->bt_cursor.pg.index = idx; F_SET(&t->bt_cursor, CURS_INIT); } diff --git a/lib/libc/db/btree/bt_split.c b/lib/libc/db/btree/bt_split.c index 809c20beda..f9b6be6f53 100644 --- a/lib/libc/db/btree/bt_split.c +++ b/lib/libc/db/btree/bt_split.c @@ -29,11 +29,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)bt_split.c 8.9 (Berkeley) 7/26/94 - * $DragonFly: src/lib/libc/db/btree/bt_split.c,v 1.8 2005/11/19 20:46:32 swildner Exp $ + * @(#)bt_split.c 8.10 (Berkeley) 1/9/95 + * $FreeBSD: head/lib/libc/db/btree/bt_split.c 223262 2011-06-18 13:56:33Z benl $ */ #include +#include #include #include @@ -52,7 +53,7 @@ static int bt_rroot(BTREE *, PAGE *, PAGE *, PAGE *); static recno_t rec_total(PAGE *); #ifdef STATISTICS -u_long bt_rootsplit, bt_split, bt_sortsplit, bt_pfxsaved; +unsigned long bt_rootsplit, bt_split, bt_sortsplit, bt_pfxsaved; #endif /* @@ -72,7 +73,7 @@ u_long bt_rootsplit, bt_split, bt_sortsplit, bt_pfxsaved; */ int __bt_split(BTREE *t, PAGE *sp, const DBT *key, const DBT *data, int flags, - size_t ilen, u_int32_t argskip) + size_t ilen, uint32_t argskip) { BINTERNAL *bi; BLEAF *bl, *tbl; @@ -80,14 +81,11 @@ __bt_split(BTREE *t, PAGE *sp, const DBT *key, const DBT *data, int flags, EPGNO *parent; PAGE *h, *l, *r, *lchild, *rchild; indx_t nxtindex; - u_int16_t skip; - u_int32_t n, nbytes, nksize; + uint16_t skip; + uint32_t n, nbytes, nksize; int parentsplit; char *dest; - bi = NULL; - bl = NULL; - nksize = 0; /* * Split the page into two pages, l and r. The split routines return * a pointer to the page into which the key should be inserted and with @@ -205,7 +203,7 @@ __bt_split(BTREE *t, PAGE *sp, const DBT *key, const DBT *data, int flags, } /* Split the parent page if necessary or shift the indices. */ - if (h->upper - h->lower < nbytes + sizeof(indx_t)) { + if ((uint32_t)(h->upper - h->lower) < nbytes + sizeof(indx_t)) { sp = h; h = h->pgno == P_ROOT ? bt_root(t, h, &l, &r, &skip, nbytes) : @@ -376,9 +374,6 @@ bt_page(BTREE *t, PAGE *h, PAGE **lp, PAGE **rp, indx_t *skip, size_t ilen) mpool_put(t->bt_mp, r, 0); return (NULL); } -#ifdef PURIFY - memset(l, 0xff, t->bt_psize); -#endif l->pgno = h->pgno; l->nextpg = r->pgno; l->prevpg = h->prevpg; @@ -485,7 +480,7 @@ bt_rroot(BTREE *t, PAGE *h, PAGE *l, PAGE *r) WR_RINTERNAL(dest, l->flags & P_RLEAF ? NEXTINDEX(l) : rec_total(l), l->pgno); - h->linp[1] = h->upper -= NRINTERNAL; + __PAST_END(h->linp, 1) = h->upper -= NRINTERNAL; dest = (char *)h + h->upper; WR_RINTERNAL(dest, r->flags & P_RLEAF ? NEXTINDEX(r) : rec_total(r), r->pgno); @@ -517,7 +512,7 @@ bt_broot(BTREE *t, PAGE *h, PAGE *l, PAGE *r) { BINTERNAL *bi; BLEAF *bl; - u_int32_t nbytes; + uint32_t nbytes; char *dest; /* @@ -537,7 +532,7 @@ bt_broot(BTREE *t, PAGE *h, PAGE *l, PAGE *r) case P_BLEAF: bl = GETBLEAF(r, 0); nbytes = NBINTERNAL(bl->ksize); - h->linp[1] = h->upper -= nbytes; + __PAST_END(h->linp, 1) = h->upper -= nbytes; dest = (char *)h + h->upper; WR_BINTERNAL(dest, bl->ksize, r->pgno, 0); memmove(dest, bl->bytes, bl->ksize); @@ -553,7 +548,7 @@ bt_broot(BTREE *t, PAGE *h, PAGE *l, PAGE *r) case P_BINTERNAL: bi = GETBINTERNAL(r, 0); nbytes = NBINTERNAL(bi->ksize); - h->linp[1] = h->upper -= nbytes; + __PAST_END(h->linp, 1) = h->upper -= nbytes; dest = (char *)h + h->upper; memmove(dest, bi, nbytes); ((BINTERNAL *)dest)->pgno = r->pgno; @@ -597,10 +592,9 @@ bt_psplit(BTREE *t, PAGE *h, PAGE *l, PAGE *r, indx_t *pskip, size_t ilen) PAGE *rval; void *src; indx_t full, half, nxt, off, skip, top, used; - u_int32_t nbytes; + uint32_t nbytes; int bigkeycnt, isbigkey; - src = NULL; /* * Split the data to the left and right pages. Leave the skip index * open. Additionally, make some effort not to split on an overflow @@ -648,8 +642,8 @@ bt_psplit(BTREE *t, PAGE *h, PAGE *l, PAGE *r, indx_t *pskip, size_t ilen) * where we decide to try and copy too much onto the left page. * Make sure that doesn't happen. */ - if ((skip <= off && - used + nbytes + sizeof(indx_t) >= full) || nxt == top - 1) { + if ((skip <= off && used + nbytes + sizeof(indx_t) >= full) || + nxt == top - 1) { --off; break; } diff --git a/lib/libc/db/btree/bt_utils.c b/lib/libc/db/btree/bt_utils.c index 42c457001f..71f27c5b65 100644 --- a/lib/libc/db/btree/bt_utils.c +++ b/lib/libc/db/btree/bt_utils.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)bt_utils.c 8.8 (Berkeley) 7/20/94 - * $DragonFly: src/lib/libc/db/btree/bt_utils.c,v 1.5 2005/11/12 23:01:54 swildner Exp $ + * $FreeBSD: head/lib/libc/db/btree/bt_utils.c 189387 2009-03-05 00:57:01Z delphij $ */ #include @@ -81,8 +81,7 @@ __bt_ret(BTREE *t, EPG *e, DBT *key, DBT *rkey, DBT *data, DBT *rdata, int copy) key->data = rkey->data; } else if (copy || F_ISSET(t, B_DB_LOCK)) { if (bl->ksize > rkey->size) { - p = (void *)(rkey->data == NULL ? - malloc(bl->ksize) : realloc(rkey->data, bl->ksize)); + p = realloc(rkey->data, bl->ksize); if (p == NULL) return (RET_ERROR); rkey->data = p; @@ -108,9 +107,7 @@ dataonly: } else if (copy || F_ISSET(t, B_DB_LOCK)) { /* Use +1 in case the first record retrieved is 0 length. */ if (bl->dsize + 1 > rdata->size) { - p = (void *)(rdata->data == NULL ? - malloc(bl->dsize + 1) : - realloc(rdata->data, bl->dsize + 1)); + p = realloc(rdata->data, bl->dsize + 1); if (p == NULL) return (RET_ERROR); rdata->data = p; @@ -193,7 +190,7 @@ __bt_cmp(BTREE *t, const DBT *k1, EPG *e) * * Parameters: * a: DBT #1 - * b: DBT #2 + * b: DBT #2 * * Returns: * < 0 if a is < b @@ -204,12 +201,12 @@ int __bt_defcmp(const DBT *a, const DBT *b) { size_t len; - u_char *p1, *p2; + unsigned char *p1, *p2; /* * XXX * If a size_t doesn't fit in an int, this routine can lose. - * What we need is a integral type which is guaranteed to be + * What we need is an integral type which is guaranteed to be * larger than a size_t, and there is no such thing. */ len = MIN(a->size, b->size); @@ -224,7 +221,7 @@ __bt_defcmp(const DBT *a, const DBT *b) * * Parameters: * a: DBT #1 - * b: DBT #2 + * b: DBT #2 * * Returns: * Number of bytes needed to distinguish b from a. @@ -232,7 +229,7 @@ __bt_defcmp(const DBT *a, const DBT *b) size_t __bt_defpfx(const DBT *a, const DBT *b) { - u_char *p1, *p2; + unsigned char *p1, *p2; size_t cnt, len; cnt = 1; diff --git a/lib/libc/db/btree/btree.h b/lib/libc/db/btree/btree.h index 3541a42a8a..33311b8b1c 100644 --- a/lib/libc/db/btree/btree.h +++ b/lib/libc/db/btree/btree.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)btree.h 8.11 (Berkeley) 8/17/94 - * $DragonFly: src/lib/libc/db/btree/btree.h,v 1.4 2005/09/19 09:20:37 asmodai Exp $ + * $FreeBSD: head/lib/libc/db/btree/btree.h 189327 2009-03-04 00:58:04Z delphij $ */ /* Macros to set/clear/test flags. */ @@ -73,7 +73,7 @@ typedef struct _page { #define P_RLEAF 0x10 /* leaf page */ #define P_TYPE 0x1f /* type mask */ #define P_PRESERVE 0x20 /* never delete this chain of pages */ - u_int32_t flags; + uint32_t flags; indx_t lower; /* lower bound of free space on page */ indx_t upper; /* upper bound of free space on page */ @@ -83,7 +83,7 @@ typedef struct _page { /* First and next index. */ #define BTDATAOFF \ (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t) + \ - sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t)) + sizeof(uint32_t) + sizeof(indx_t) + sizeof(indx_t)) #define NEXTINDEX(p) (((p)->lower - BTDATAOFF) / sizeof(indx_t)) /* @@ -103,7 +103,7 @@ typedef struct _page { * manipulated on this system.) */ #define LALIGN(n) (((n) + sizeof(pgno_t) - 1) & ~(sizeof(pgno_t) - 1)) -#define NOVFLSIZE (sizeof(pgno_t) + sizeof(u_int32_t)) +#define NOVFLSIZE (sizeof(pgno_t) + sizeof(uint32_t)) /* * For the btree internal pages, the item is a key. BINTERNALs are {key, pgno} @@ -115,11 +115,11 @@ typedef struct _page { * some minor modifications of the above rule. */ typedef struct _binternal { - u_int32_t ksize; /* key size */ + uint32_t ksize; /* key size */ pgno_t pgno; /* page number stored on */ #define P_BIGDATA 0x01 /* overflow data */ #define P_BIGKEY 0x02 /* overflow key */ - u_char flags; + unsigned char flags; char bytes[1]; /* data */ } BINTERNAL; @@ -129,16 +129,17 @@ typedef struct _binternal { /* Get the number of bytes in the entry. */ #define NBINTERNAL(len) \ - LALIGN(sizeof(u_int32_t) + sizeof(pgno_t) + sizeof(u_char) + (len)) + LALIGN(sizeof(uint32_t) + sizeof(pgno_t) + \ + sizeof(unsigned char) + (len)) /* Copy a BINTERNAL entry to the page. */ #define WR_BINTERNAL(p, size, pgno, flags) { \ - *(u_int32_t *)p = size; \ - p += sizeof(u_int32_t); \ + *(uint32_t *)p = size; \ + p += sizeof(uint32_t); \ *(pgno_t *)p = pgno; \ p += sizeof(pgno_t); \ - *(u_char *)p = flags; \ - p += sizeof(u_char); \ + *(unsigned char *)p = flags; \ + p += sizeof(unsigned char); \ } /* @@ -167,9 +168,9 @@ typedef struct _rinternal { /* For the btree leaf pages, the item is a key and data pair. */ typedef struct _bleaf { - u_int32_t ksize; /* size of key */ - u_int32_t dsize; /* size of data */ - u_char flags; /* P_BIGDATA, P_BIGKEY */ + uint32_t ksize; /* size of key */ + uint32_t dsize; /* size of data */ + unsigned char flags; /* P_BIGDATA, P_BIGKEY */ char bytes[1]; /* data */ } BLEAF; @@ -182,17 +183,17 @@ typedef struct _bleaf { /* Get the number of bytes in the user's key/data pair. */ #define NBLEAFDBT(ksize, dsize) \ - LALIGN(sizeof(u_int32_t) + sizeof(u_int32_t) + sizeof(u_char) + \ - (ksize) + (dsize)) + LALIGN(sizeof(uint32_t) + sizeof(uint32_t) + \ + sizeof(unsigned char) + (ksize) + (dsize)) /* Copy a BLEAF entry to the page. */ #define WR_BLEAF(p, key, data, flags) { \ - *(u_int32_t *)p = key->size; \ - p += sizeof(u_int32_t); \ - *(u_int32_t *)p = data->size; \ - p += sizeof(u_int32_t); \ - *(u_char *)p = flags; \ - p += sizeof(u_char); \ + *(uint32_t *)p = key->size; \ + p += sizeof(uint32_t); \ + *(uint32_t *)p = data->size; \ + p += sizeof(uint32_t); \ + *(unsigned char *)p = flags; \ + p += sizeof(unsigned char); \ memmove(p, key->data, key->size); \ p += key->size; \ memmove(p, data->data, data->size); \ @@ -200,8 +201,8 @@ typedef struct _bleaf { /* For the recno leaf pages, the item is a data entry. */ typedef struct _rleaf { - u_int32_t dsize; /* size of data */ - u_char flags; /* P_BIGDATA */ + uint32_t dsize; /* size of data */ + unsigned char flags; /* P_BIGDATA */ char bytes[1]; } RLEAF; @@ -214,14 +215,14 @@ typedef struct _rleaf { /* Get the number of bytes from the user's data. */ #define NRLEAFDBT(dsize) \ - LALIGN(sizeof(u_int32_t) + sizeof(u_char) + (dsize)) + LALIGN(sizeof(uint32_t) + sizeof(unsigned char) + (dsize)) /* Copy a RLEAF entry to the page. */ #define WR_RLEAF(p, data, flags) { \ - *(u_int32_t *)p = data->size; \ - p += sizeof(u_int32_t); \ - *(u_char *)p = flags; \ - p += sizeof(u_char); \ + *(uint32_t *)p = data->size; \ + p += sizeof(uint32_t); \ + *(unsigned char *)p = flags; \ + p += sizeof(unsigned char); \ memmove(p, data->data, data->size); \ } @@ -278,7 +279,7 @@ typedef struct _cursor { #define CURS_AFTER 0x02 /* B: Unreturned cursor after key. */ #define CURS_BEFORE 0x04 /* B: Unreturned cursor before key. */ #define CURS_INIT 0x08 /* RB: Cursor initialized. */ - u_int8_t flags; + uint8_t flags; } CURSOR; /* @@ -287,14 +288,14 @@ typedef struct _cursor { * put or delete call modify the metadata. */ typedef struct _btmeta { - u_int32_t magic; /* magic number */ - u_int32_t version; /* version */ - u_int32_t psize; /* page size */ - u_int32_t free; /* page number of first free page */ - u_int32_t nrecs; /* R: number of records */ + uint32_t magic; /* magic number */ + uint32_t version; /* version */ + uint32_t psize; /* page size */ + uint32_t free; /* page number of first free page */ + uint32_t nrecs; /* R: number of records */ #define SAVEMETA (B_NODUPS | R_RECNO) - u_int32_t flags; /* bt_flags & SAVEMETA */ + uint32_t flags; /* bt_flags & SAVEMETA */ } BTMETA; /* The in-memory btree/recno data structure. */ @@ -309,8 +310,8 @@ typedef struct _btree { CURSOR bt_cursor; /* cursor */ #define BT_PUSH(t, p, i) { \ - t->bt_sp->pgno = p; \ - t->bt_sp->index = i; \ + t->bt_sp->pgno = p; \ + t->bt_sp->index = i; \ ++t->bt_sp; \ } #define BT_POP(t) (t->bt_sp == t->bt_stack ? NULL : --t->bt_sp) @@ -324,7 +325,7 @@ typedef struct _btree { int bt_fd; /* tree file descriptor */ pgno_t bt_free; /* next free page */ - u_int32_t bt_psize; /* page size */ + uint32_t bt_psize; /* page size */ indx_t bt_ovflsize; /* cut-off for key/data overflow */ int bt_lorder; /* byte order */ /* sorted order */ @@ -332,23 +333,23 @@ typedef struct _btree { EPGNO bt_last; /* last insert */ /* B: key comparison function */ - int (*bt_cmp) (const DBT *, const DBT *); + int (*bt_cmp)(const DBT *, const DBT *); /* B: prefix comparison function */ - size_t (*bt_pfx) (const DBT *, const DBT *); + size_t (*bt_pfx)(const DBT *, const DBT *); /* R: recno input function */ - int (*bt_irec) (struct _btree *, recno_t); + int (*bt_irec)(struct _btree *, recno_t); FILE *bt_rfp; /* R: record FILE pointer */ int bt_rfd; /* R: record file descriptor */ caddr_t bt_cmap; /* R: current point in mapped space */ caddr_t bt_smap; /* R: start of mapped space */ - caddr_t bt_emap; /* R: end of mapped space */ + caddr_t bt_emap; /* R: end of mapped space */ size_t bt_msize; /* R: size of mapped region. */ recno_t bt_nrecs; /* R: number of records */ size_t bt_reclen; /* R: fixed record length */ - u_char bt_bval; /* R: delimiting byte/pad character */ + unsigned char bt_bval; /* R: delimiting byte/pad character */ /* * NB: @@ -374,7 +375,7 @@ typedef struct _btree { #define B_DB_LOCK 0x04000 /* DB_LOCK specified. */ #define B_DB_SHMEM 0x08000 /* DB_SHMEM specified. */ #define B_DB_TXN 0x10000 /* DB_TXN specified. */ - u_int32_t flags; + uint32_t flags; } BTREE; #include "extern.h" diff --git a/lib/libc/db/btree/extern.h b/lib/libc/db/btree/extern.h index d18962f3c1..29d09b8071 100644 --- a/lib/libc/db/btree/extern.h +++ b/lib/libc/db/btree/extern.h @@ -27,45 +27,41 @@ * SUCH DAMAGE. * * @(#)extern.h 8.10 (Berkeley) 7/20/94 - * $DragonFly: src/lib/libc/db/btree/extern.h,v 1.5 2005/09/19 09:20:37 asmodai Exp $ + * $FreeBSD: head/lib/libc/db/btree/extern.h 165903 2007-01-09 00:28:16Z imp $ */ -#ifndef LIBC_DB_BTREE_EXTERN_H -#define LIBC_DB_BTREE_EXTERN_H -int __bt_close (DB *); -int __bt_cmp (BTREE *, const DBT *, EPG *); -int __bt_crsrdel (BTREE *, EPGNO *); -int __bt_defcmp (const DBT *, const DBT *); -size_t __bt_defpfx (const DBT *, const DBT *); -int __bt_delete (const DB *, const DBT *, u_int); -int __bt_dleaf (BTREE *, const DBT *, PAGE *, u_int); -int __bt_fd (const DB *); -int __bt_free (BTREE *, PAGE *); -int __bt_get (const DB *, const DBT *, DBT *, u_int); -PAGE *__bt_new (BTREE *, pgno_t *); -void __bt_pgin (void *, pgno_t, void *); -void __bt_pgout (void *, pgno_t, void *); -int __bt_push (BTREE *, pgno_t, int); -int __bt_put (const DB *dbp, DBT *, const DBT *, u_int); -int __bt_ret (BTREE *, EPG *, DBT *, DBT *, DBT *, DBT *, int); -EPG *__bt_search (BTREE *, const DBT *, int *); -int __bt_seq (const DB *, DBT *, DBT *, u_int); -void __bt_setcur (BTREE *, pgno_t, u_int); -int __bt_split (BTREE *, PAGE *, - const DBT *, const DBT *, int, size_t, u_int32_t); -int __bt_sync (const DB *, u_int); +int __bt_close(DB *); +int __bt_cmp(BTREE *, const DBT *, EPG *); +int __bt_crsrdel(BTREE *, EPGNO *); +int __bt_defcmp(const DBT *, const DBT *); +size_t __bt_defpfx(const DBT *, const DBT *); +int __bt_delete(const DB *, const DBT *, unsigned int); +int __bt_dleaf(BTREE *, const DBT *, PAGE *, unsigned int); +int __bt_fd(const DB *); +int __bt_free(BTREE *, PAGE *); +int __bt_get(const DB *, const DBT *, DBT *, unsigned int); +PAGE *__bt_new(BTREE *, pgno_t *); +void __bt_pgin(void *, pgno_t, void *); +void __bt_pgout(void *, pgno_t, void *); +int __bt_push(BTREE *, pgno_t, int); +int __bt_put(const DB *dbp, DBT *, const DBT *, unsigned int); +int __bt_ret(BTREE *, EPG *, DBT *, DBT *, DBT *, DBT *, int); +EPG *__bt_search(BTREE *, const DBT *, int *); +int __bt_seq(const DB *, DBT *, DBT *, unsigned int); +void __bt_setcur(BTREE *, pgno_t, unsigned int); +int __bt_split(BTREE *, PAGE *, + const DBT *, const DBT *, int, size_t, uint32_t); +int __bt_sync(const DB *, unsigned int); -int __ovfl_delete (BTREE *, void *); -int __ovfl_get (BTREE *, void *, size_t *, void **, size_t *); -int __ovfl_put (BTREE *, const DBT *, pgno_t *); +int __ovfl_delete(BTREE *, void *); +int __ovfl_get(BTREE *, void *, size_t *, void **, size_t *); +int __ovfl_put(BTREE *, const DBT *, pgno_t *); #ifdef DEBUG -void __bt_dnpage (DB *, pgno_t); -void __bt_dpage (PAGE *); -void __bt_dump (DB *); +void __bt_dnpage(DB *, pgno_t); +void __bt_dpage(PAGE *); +void __bt_dump(DB *); #endif #ifdef STATISTICS -void __bt_stat (DB *); -#endif - +void __bt_stat(DB *); #endif diff --git a/lib/libc/db/db/Makefile.inc b/lib/libc/db/db/Makefile.inc index 5db7e79643..94d00b5433 100644 --- a/lib/libc/db/db/Makefile.inc +++ b/lib/libc/db/db/Makefile.inc @@ -1,6 +1,5 @@ # from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $FreeBSD: src/lib/libc/db/db/Makefile.inc,v 1.3 1999/08/27 23:58:17 peter Exp $ -# $DragonFly: src/lib/libc/db/db/Makefile.inc,v 1.2 2003/06/17 04:26:41 dillon Exp $ +# $FreeBSD: head/lib/libc/db/db/Makefile.inc 107052 2002-11-18 09:50:57Z ru $ .PATH: ${.CURDIR}/../libc/db/db diff --git a/lib/libc/db/db/db.c b/lib/libc/db/db/db.c index 1989430e9a..c6ec6af329 100644 --- a/lib/libc/db/db/db.c +++ b/lib/libc/db/db/db.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)db.c 8.4 (Berkeley) 2/21/94 - * $DragonFly: src/lib/libc/db/db/db.c,v 1.4 2005/09/19 09:02:02 asmodai Exp $ + * $FreeBSD: head/lib/libc/db/db/db.c 190497 2009-03-28 07:26:00Z delphij $ */ #include @@ -39,26 +39,28 @@ #include +static int __dberr(void); + DB * dbopen(const char *fname, int flags, mode_t mode, DBTYPE type, const void *openinfo) { #define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) #define USE_OPEN_FLAGS \ - (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \ - O_RDWR | O_SHLOCK | O_TRUNC) + (O_CREAT | O_EXCL | O_EXLOCK | O_NOFOLLOW | O_NONBLOCK | \ + O_RDONLY | O_RDWR | O_SHLOCK | O_SYNC | O_TRUNC) if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) switch (type) { case DB_BTREE: return (__bt_open(fname, flags & USE_OPEN_FLAGS, - mode, openinfo, (int)flags & DB_FLAGS)); + mode, openinfo, flags & DB_FLAGS)); case DB_HASH: return (__hash_open(fname, flags & USE_OPEN_FLAGS, - mode, openinfo, (int)flags & DB_FLAGS)); + mode, openinfo, flags & DB_FLAGS)); case DB_RECNO: return (__rec_open(fname, flags & USE_OPEN_FLAGS, - mode, openinfo, (int)flags & DB_FLAGS)); + mode, openinfo, flags & DB_FLAGS)); } errno = EINVAL; return (NULL); @@ -80,10 +82,14 @@ void __dbpanic(DB *dbp) { /* The only thing that can succeed is a close. */ - dbp->del = (int (*)(const DB *, const DBT *, u_int))__dberr; - dbp->fd = (int (*)(const DB *))__dberr; - dbp->get = (int (*)(const DB *, const DBT *, DBT *, u_int))__dberr; - dbp->put = (int (*)(const DB *, DBT *, const DBT *, u_int))__dberr; - dbp->seq = (int (*)(const DB *, DBT *, DBT *, u_int))__dberr; - dbp->sync = (int (*)(const DB *, u_int))__dberr; + dbp->del = (int (*)(const struct __db *, const DBT *, + unsigned int))__dberr; + dbp->fd = (int (*)(const struct __db *))__dberr; + dbp->get = (int (*)(const struct __db *, const DBT *, DBT *, + unsigned int))__dberr; + dbp->put = (int (*)(const struct __db *, DBT *, const DBT *, + unsigned int))__dberr; + dbp->seq = (int (*)(const struct __db *, DBT *, DBT *, + unsigned int))__dberr; + dbp->sync = (int (*)(const struct __db *, unsigned int))__dberr; } diff --git a/lib/libc/db/docs/hash.usenix.ps b/lib/libc/db/docs/hash.usenix.ps index 0e58ebc4d4..0f98ab9b0f 100644 --- a/lib/libc/db/docs/hash.usenix.ps +++ b/lib/libc/db/docs/hash.usenix.ps @@ -7,8 +7,7 @@ % lib/psdit.pro -- prolog for psdit (ditroff) files % Copyright (c) 1984, 1985 Adobe Systems Incorporated. All Rights Reserved. % last edit: shore Sat Nov 23 20:28:03 1985 -% RCSID: $FreeBSD: src/lib/libc/db/docs/hash.usenix.ps,v 1.2 1999/08/28 05:03:14 peter Exp $ -% RCSID: $DragonFly: src/lib/libc/db/docs/hash.usenix.ps,v 1.2 2003/06/17 04:26:41 dillon Exp $ +% RCSID: $FreeBSD: head/lib/libc/db/docs/hash.usenix.ps 50488 1999-08-28 05:11:36Z peter $ % Changed by Edward Wang (edward@ucbarpa.berkeley.edu) to handle graphics, % 17 Feb, 87. diff --git a/lib/libc/db/docs/libtp.usenix.ps b/lib/libc/db/docs/libtp.usenix.ps index 613428f194..3762d05062 100644 --- a/lib/libc/db/docs/libtp.usenix.ps +++ b/lib/libc/db/docs/libtp.usenix.ps @@ -7,8 +7,7 @@ % lib/psdit.pro -- prolog for psdit (ditroff) files % Copyright (c) 1984, 1985 Adobe Systems Incorporated. All Rights Reserved. % last edit: shore Sat Nov 23 20:28:03 1985 -% RCSID: $FreeBSD: src/lib/libc/db/docs/libtp.usenix.ps,v 1.2 1999/08/28 05:03:15 peter Exp $ -% RCSID: $DragonFly: src/lib/libc/db/docs/libtp.usenix.ps,v 1.2 2003/06/17 04:26:41 dillon Exp $ +% RCSID: $FreeBSD: head/lib/libc/db/docs/libtp.usenix.ps 50488 1999-08-28 05:11:36Z peter $ % Changed by Edward Wang (edward@ucbarpa.berkeley.edu) to handle graphics, % 17 Feb, 87. diff --git a/lib/libc/db/hash/Makefile.inc b/lib/libc/db/hash/Makefile.inc index ab884f60d4..643df322f2 100644 --- a/lib/libc/db/hash/Makefile.inc +++ b/lib/libc/db/hash/Makefile.inc @@ -1,6 +1,5 @@ # from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $FreeBSD: src/lib/libc/db/hash/Makefile.inc,v 1.3.2.1 2001/10/02 11:15:38 ru Exp $ -# $DragonFly: src/lib/libc/db/hash/Makefile.inc,v 1.2 2003/06/17 04:26:41 dillon Exp $ +# $FreeBSD: head/lib/libc/db/hash/Makefile.inc 107052 2002-11-18 09:50:57Z ru $ .PATH: ${.CURDIR}/../libc/db/hash diff --git a/lib/libc/db/hash/README b/lib/libc/db/hash/README index f29ccf7e1b..158d12708b 100644 --- a/lib/libc/db/hash/README +++ b/lib/libc/db/hash/README @@ -1,4 +1,5 @@ # @(#)README 8.1 (Berkeley) 6/4/93 +# $FreeBSD: head/lib/libc/db/hash/README 190498 2009-03-28 07:31:02Z delphij $ This package implements a superset of the hsearch and dbm/ndbm libraries. @@ -44,10 +45,6 @@ Test Programs: NOTES: -The file search.h is provided for using the hsearch compatible interface -on BSD systems. On System V derived systems, search.h should appear in -/usr/include. - The man page ../man/db.3 explains the interface to the hashing system. The file hash.ps is a postscript copy of a paper explaining the history, implementation, and performance of the hash package. diff --git a/lib/libc/db/hash/extern.h b/lib/libc/db/hash/extern.h index a12c5eeb18..b0c3889f59 100644 --- a/lib/libc/db/hash/extern.h +++ b/lib/libc/db/hash/extern.h @@ -27,35 +27,35 @@ * SUCH DAMAGE. * * @(#)extern.h 8.4 (Berkeley) 6/16/94 - * $DragonFly: src/lib/libc/db/hash/extern.h,v 1.5 2005/09/19 09:20:37 asmodai Exp $ + * $FreeBSD: head/lib/libc/db/hash/extern.h 165903 2007-01-09 00:28:16Z imp $ */ -BUFHEAD *__add_ovflpage (HTAB *, BUFHEAD *); -int __addel (HTAB *, BUFHEAD *, const DBT *, const DBT *); -int __big_delete (HTAB *, BUFHEAD *); -int __big_insert (HTAB *, BUFHEAD *, const DBT *, const DBT *); -int __big_keydata (HTAB *, BUFHEAD *, DBT *, DBT *, int); -int __big_return (HTAB *, BUFHEAD *, int, DBT *, int); -int __big_split (HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, - int, u_int32_t, SPLIT_RETURN *); -int __buf_free (HTAB *, int, int); -void __buf_init (HTAB *, int); -u_int32_t __call_hash (HTAB *, const char *, int); -int __delpair (HTAB *, BUFHEAD *, int); -int __expand_table (HTAB *); -int __find_bigpair (HTAB *, BUFHEAD *, int, const char *, int); -u_int16_t __find_last_page (HTAB *, BUFHEAD **); -void __free_ovflpage (HTAB *, BUFHEAD *); -BUFHEAD *__get_buf (HTAB *, u_int32_t, BUFHEAD *, int); -int __get_page (HTAB *, char *, u_int32_t, int, int, int); -int __ibitmap (HTAB *, int, int, int); -u_int32_t __log2 (u_int32_t); -int __put_page (HTAB *, char *, u_int32_t, int, int); -void __reclaim_buf (HTAB *, BUFHEAD *); -int __split_page (HTAB *, u_int32_t, u_int32_t); +BUFHEAD *__add_ovflpage(HTAB *, BUFHEAD *); +int __addel(HTAB *, BUFHEAD *, const DBT *, const DBT *); +int __big_delete(HTAB *, BUFHEAD *); +int __big_insert(HTAB *, BUFHEAD *, const DBT *, const DBT *); +int __big_keydata(HTAB *, BUFHEAD *, DBT *, DBT *, int); +int __big_return(HTAB *, BUFHEAD *, int, DBT *, int); +int __big_split(HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, + int, uint32_t, SPLIT_RETURN *); +int __buf_free(HTAB *, int, int); +void __buf_init(HTAB *, int); +uint32_t __call_hash(HTAB *, char *, int); +int __delpair(HTAB *, BUFHEAD *, int); +int __expand_table(HTAB *); +int __find_bigpair(HTAB *, BUFHEAD *, int, char *, int); +uint16_t __find_last_page(HTAB *, BUFHEAD **); +void __free_ovflpage(HTAB *, BUFHEAD *); +BUFHEAD *__get_buf(HTAB *, uint32_t, BUFHEAD *, int); +int __get_page(HTAB *, char *, uint32_t, int, int, int); +int __ibitmap(HTAB *, int, int, int); +uint32_t __log2(uint32_t); +int __put_page(HTAB *, char *, uint32_t, int, int); +void __reclaim_buf(HTAB *, BUFHEAD *); +int __split_page(HTAB *, uint32_t, uint32_t); /* Default hash routine. */ -extern u_int32_t (*__default_hash) (const void *, size_t); +extern uint32_t (*__default_hash)(const void *, size_t); #ifdef HASH_STATISTICS extern int hash_accesses, hash_collisions, hash_expansions, hash_overflows; diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c index 641a95b52a..4fd99c9100 100644 --- a/lib/libc/db/hash/hash.c +++ b/lib/libc/db/hash/hash.c @@ -29,10 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/db/hash/hash.c,v 1.8 2000/01/27 23:06:08 jasone Exp $ - * $DragonFly: src/lib/libc/db/hash/hash.c,v 1.9 2005/11/12 23:01:55 swildner Exp $ - * * @(#)hash.c 8.9 (Berkeley) 6/16/94 + * $FreeBSD: head/lib/libc/db/hash/hash.c 206178 2010-04-05 10:12:21Z avg $ */ #include "namespace.h" @@ -57,15 +55,15 @@ static int alloc_segs(HTAB *, int); static int flush_meta(HTAB *); -static int hash_access(HTAB *, ACTION, const DBT *, DBT *); +static int hash_access(HTAB *, ACTION, DBT *, DBT *); static int hash_close(DB *); -static int hash_delete(const DB *, const DBT *, u_int32_t); +static int hash_delete(const DB *, const DBT *, uint32_t); static int hash_fd(const DB *); -static int hash_get(const DB *, const DBT *, DBT *, u_int32_t); -static int hash_put(const DB *, DBT *, const DBT *, u_int32_t); +static int hash_get(const DB *, const DBT *, DBT *, uint32_t); +static int hash_put(const DB *, DBT *, const DBT *, uint32_t); static void *hash_realloc(SEGMENT **, int, int); -static int hash_seq(const DB *, DBT *, DBT *, u_int32_t); -static int hash_sync(const DB *, u_int32_t); +static int hash_seq(const DB *, DBT *, DBT *, uint32_t); +static int hash_sync(const DB *, uint32_t); static int hdestroy(HTAB *); static HTAB *init_hash(HTAB *, const char *, const HASHINFO *); static int init_htab(HTAB *, int); @@ -91,9 +89,11 @@ int hash_accesses, hash_collisions, hash_expansions, hash_overflows; /************************** INTERFACE ROUTINES ***************************/ /* OPEN/CLOSE */ -extern DB * -__hash_open(const char *file, int flags, int mode, const HASHINFO * info, - int dflags __unused) +/* ARGSUSED */ +DB * +__hash_open(const char *file, int flags, mode_t mode, + const HASHINFO *info, /* Special directives for create */ + int dflags) { HTAB *hashp; struct stat statbuf; @@ -117,25 +117,15 @@ __hash_open(const char *file, int flags, int mode, const HASHINFO * info, */ hashp->flags = flags; - new_table = 0; - if (!file || (flags & O_TRUNC) || - (stat(file, &statbuf) && (errno == ENOENT))) { - if (errno == ENOENT) - errno = 0; /* Just in case someone looks at errno */ - new_table = 1; - } if (file) { if ((hashp->fp = _open(file, flags, mode)) == -1) RETURN_ERROR(errno, error0); - - /* if the .db file is empty, and we had permission to create - a new .db file, then reinitialize the database */ - if ((flags & O_CREAT) && - _fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0) - new_table = 1; - _fcntl(hashp->fp, F_SETFD, 1); - } + new_table = _fstat(hashp->fp, &statbuf) == 0 && + statbuf.st_size == 0 && (flags & O_ACCMODE) != O_RDONLY; + } else + new_table = 1; + if (new_table) { if (!(hashp = init_hash(hashp, file, info))) RETURN_ERROR(errno, error1); @@ -161,7 +151,7 @@ __hash_open(const char *file, int flags, int mode, const HASHINFO * info, if (hashp->VERSION != HASHVERSION && hashp->VERSION != OLDHASHVERSION) RETURN_ERROR(EFTYPE, error1); - if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY) + if ((int32_t)hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY) RETURN_ERROR(EFTYPE, error1); /* * Figure out how many segments we need. Max_Bucket is the @@ -170,7 +160,6 @@ __hash_open(const char *file, int flags, int mode, const HASHINFO * info, */ nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) / hashp->SGSIZE; - hashp->nsegs = 0; if (alloc_segs(hashp, nsegs)) /* * If alloc_segs fails, table will have been destroyed @@ -183,7 +172,7 @@ __hash_open(const char *file, int flags, int mode, const HASHINFO * info, (hashp->BSHIFT + BYTE_SHIFT); hashp->nmaps = bpages; - memset(&hashp->mapp[0], 0, bpages * sizeof(u_int32_t *)); + memset(&hashp->mapp[0], 0, bpages * sizeof(uint32_t *)); } /* Initialize Buffer Manager */ @@ -301,6 +290,8 @@ init_hash(HTAB *hashp, const char *file, const HASHINFO *info) if (stat(file, &statbuf)) return (NULL); hashp->BSIZE = statbuf.st_blksize; + if (hashp->BSIZE > MAX_BSIZE) + hashp->BSIZE = MAX_BSIZE; hashp->BSHIFT = __log2(hashp->BSIZE); } @@ -344,8 +335,7 @@ init_hash(HTAB *hashp, const char *file, const HASHINFO *info) static int init_htab(HTAB *hashp, int nelem) { - int nbuckets, nsegs; - int l2; + int nbuckets, nsegs, l2; /* * Divide number of elements by the fill factor and determine a @@ -425,6 +415,10 @@ hdestroy(HTAB *hashp) for (i = 0; i < hashp->nmaps; i++) if (hashp->mapp[i]) free(hashp->mapp[i]); + if (hashp->tmp_key) + free(hashp->tmp_key); + if (hashp->tmp_buf) + free(hashp->tmp_buf); if (hashp->fp != -1) _close(hashp->fp); @@ -445,7 +439,7 @@ hdestroy(HTAB *hashp) * -1 ERROR */ static int -hash_sync(const DB *dbp, u_int32_t flags) +hash_sync(const DB *dbp, uint32_t flags) { HTAB *hashp; @@ -492,8 +486,7 @@ flush_meta(HTAB *hashp) whdrp = &whdr; swap_header_copy(&hashp->hdr, whdrp); #endif - if ((lseek(fp, (off_t)0, SEEK_SET) == -1) || - ((wsize = _write(fp, whdrp, sizeof(HASHHDR))) == -1)) + if ((wsize = pwrite(fp, whdrp, sizeof(HASHHDR), (off_t)0)) == -1) return (-1); else if (wsize != sizeof(HASHHDR)) { @@ -519,21 +512,20 @@ flush_meta(HTAB *hashp) * -1 to indicate an internal ERROR (i.e. out of memory, etc) */ static int -hash_get(const DB *dbp, const DBT *key, DBT *data, u_int32_t flag) +hash_get(const DB *dbp, const DBT *key, DBT *data, uint32_t flag) { HTAB *hashp; hashp = (HTAB *)dbp->internal; if (flag) { - hashp->error = EINVAL; - errno = EINVAL; + hashp->error = errno = EINVAL; return (ERROR); } - return (hash_access(hashp, HASH_GET, key, data)); + return (hash_access(hashp, HASH_GET, (DBT *)key, data)); } static int -hash_put(const DB *dbp, DBT *key, const DBT *data, u_int32_t flag) +hash_put(const DB *dbp, DBT *key, const DBT *data, uint32_t flag) { HTAB *hashp; @@ -547,11 +539,12 @@ hash_put(const DB *dbp, DBT *key, const DBT *data, u_int32_t flag) return (ERROR); } return (hash_access(hashp, flag == R_NOOVERWRITE ? - HASH_PUTNEW : HASH_PUT, key, __DECONST(DBT *, data))); + HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data)); } static int -hash_delete(const DB *dbp, const DBT *key, u_int32_t flag) +hash_delete(const DB *dbp, const DBT *key, + uint32_t flag) /* Ignored */ { HTAB *hashp; @@ -564,21 +557,21 @@ hash_delete(const DB *dbp, const DBT *key, u_int32_t flag) hashp->error = errno = EPERM; return (ERROR); } - return (hash_access(hashp, HASH_DELETE, key, NULL)); + return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL)); } /* * Assume that hashp has been set in wrapper routine. */ static int -hash_access(HTAB *hashp, ACTION action, const DBT *key, DBT *val) +hash_access(HTAB *hashp, ACTION action, DBT *key, DBT *val) { BUFHEAD *rbufp; BUFHEAD *bufp, *save_bufp; - u_int16_t *bp; + uint16_t *bp; int n, ndx, off, size; - const char *kp; - u_int16_t pageno; + char *kp; + uint16_t pageno; #ifdef HASH_STATISTICS hash_accesses++; @@ -594,7 +587,7 @@ hash_access(HTAB *hashp, ACTION action, const DBT *key, DBT *val) /* Pin the bucket chain */ rbufp->flags |= BUF_PIN; - for (bp = (u_int16_t *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) + for (bp = (uint16_t *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) if (bp[1] >= REAL_KEY) { /* Real key/data pair */ if (size == off - *bp && @@ -613,7 +606,7 @@ hash_access(HTAB *hashp, ACTION action, const DBT *key, DBT *val) return (ERROR); } /* FOR LOOP INIT */ - bp = (u_int16_t *)rbufp->page; + bp = (uint16_t *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; @@ -635,7 +628,7 @@ hash_access(HTAB *hashp, ACTION action, const DBT *key, DBT *val) return (ERROR); } /* FOR LOOP INIT */ - bp = (u_int16_t *)rbufp->page; + bp = (uint16_t *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; @@ -669,12 +662,13 @@ found: save_bufp->flags &= ~BUF_PIN; return (ABNORMAL); case HASH_GET: - bp = (u_int16_t *)rbufp->page; + bp = (uint16_t *)rbufp->page; if (bp[ndx + 1] < REAL_KEY) { if (__big_return(hashp, rbufp, ndx, val, 0)) return (ERROR); } else { - val->data = (u_char *)rbufp->page + (int)bp[ndx + 1]; + val->data = (unsigned char *)rbufp->page + + (int)bp[ndx + 1]; val->size = bp[ndx] - bp[ndx + 1]; } break; @@ -697,12 +691,12 @@ found: } static int -hash_seq(const DB *dbp, DBT *key, DBT *data, u_int32_t flag) +hash_seq(const DB *dbp, DBT *key, DBT *data, uint32_t flag) { - u_int32_t bucket; + uint32_t bucket; BUFHEAD *bufp; HTAB *hashp; - u_int16_t *bp, ndx; + uint16_t *bp, ndx; hashp = (HTAB *)dbp->internal; if (flag && flag != R_FIRST && flag != R_NEXT) { @@ -717,7 +711,7 @@ hash_seq(const DB *dbp, DBT *key, DBT *data, u_int32_t flag) hashp->cndx = 1; hashp->cpage = NULL; } - +next_bucket: for (bp = NULL; !bp || !bp[0]; ) { if (!(bufp = hashp->cpage)) { for (bucket = hashp->cbucket; @@ -727,17 +721,27 @@ hash_seq(const DB *dbp, DBT *key, DBT *data, u_int32_t flag) if (!bufp) return (ERROR); hashp->cpage = bufp; - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; if (bp[0]) break; } hashp->cbucket = bucket; - if (hashp->cbucket > hashp->MAX_BUCKET) { + if ((uint32_t)hashp->cbucket > hashp->MAX_BUCKET) { hashp->cbucket = -1; return (ABNORMAL); } - } else - bp = (u_int16_t *)hashp->cpage->page; + } else { + bp = (uint16_t *)hashp->cpage->page; + if (flag == R_NEXT || flag == 0) { + hashp->cndx += 2; + if (hashp->cndx > bp[0]) { + hashp->cpage = NULL; + hashp->cbucket++; + hashp->cndx = 1; + goto next_bucket; + } + } + } #ifdef DEBUG assert(bp); @@ -748,7 +752,7 @@ hash_seq(const DB *dbp, DBT *key, DBT *data, u_int32_t flag) __get_buf(hashp, bp[hashp->cndx], bufp, 0); if (!bufp) return (ERROR); - bp = (u_int16_t *)(bufp->page); + bp = (uint16_t *)(bufp->page); hashp->cndx = 1; } if (!bp[0]) { @@ -761,17 +765,12 @@ hash_seq(const DB *dbp, DBT *key, DBT *data, u_int32_t flag) if (__big_keydata(hashp, bufp, key, data, 1)) return (ERROR); } else { - key->data = (u_char *)hashp->cpage->page + bp[ndx]; + if (hashp->cpage == 0) + return (ERROR); + key->data = (unsigned char *)hashp->cpage->page + bp[ndx]; key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx]; - data->data = (u_char *)hashp->cpage->page + bp[ndx + 1]; + data->data = (unsigned char *)hashp->cpage->page + bp[ndx + 1]; data->size = bp[ndx] - bp[ndx + 1]; - ndx += 2; - if (ndx > bp[0]) { - hashp->cpage = NULL; - hashp->cbucket++; - hashp->cndx = 1; - } else - hashp->cndx = ndx; } return (SUCCESS); } @@ -783,10 +782,10 @@ hash_seq(const DB *dbp, DBT *key, DBT *data, u_int32_t flag) * 0 ==> OK * -1 ==> Error */ -extern int +int __expand_table(HTAB *hashp) { - u_int32_t old_bucket, new_bucket; + uint32_t old_bucket, new_bucket; int dirsize, new_segnum, spare_ndx; #ifdef HASH_STATISTICS @@ -851,10 +850,10 @@ hash_realloc(SEGMENT **p_ptr, int oldsize, int newsize) return (p); } -extern u_int32_t -__call_hash(HTAB *hashp, const char *k, int len) +uint32_t +__call_hash(HTAB *hashp, char *k, int len) { - int n, bucket; + unsigned int n, bucket; n = hashp->hash(k, len); bucket = n & hashp->HIGH_MASK; @@ -883,15 +882,18 @@ alloc_segs(HTAB *hashp, int nsegs) errno = save_errno; return (-1); } + hashp->nsegs = nsegs; + if (nsegs == 0) + return (0); /* Allocate segments */ - if ((store = - (SEGMENT)calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT))) == NULL) { + if ((store = (SEGMENT)calloc(nsegs << hashp->SSHIFT, + sizeof(SEGMENT))) == NULL) { save_errno = errno; hdestroy(hashp); errno = save_errno; return (-1); } - for (i = 0; i < nsegs; i++, hashp->nsegs++) + for (i = 0; i < nsegs; i++) hashp->dir[i] = &store[i << hashp->SSHIFT]; return (0); } diff --git a/lib/libc/db/hash/hash.h b/lib/libc/db/hash/hash.h index f2d5588a1a..5abe901286 100644 --- a/lib/libc/db/hash/hash.h +++ b/lib/libc/db/hash/hash.h @@ -30,8 +30,7 @@ * SUCH DAMAGE. * * @(#)hash.h 8.3 (Berkeley) 5/31/94 - * $FreeBSD: src/lib/libc/db/hash/hash.h,v 1.4.8.1 2001/03/05 03:50:02 kris Exp $ - * $DragonFly: src/lib/libc/db/hash/hash.h,v 1.4 2005/09/19 09:20:37 asmodai Exp $ + * $FreeBSD: head/lib/libc/db/hash/hash.h 206178 2010-04-05 10:12:21Z avg $ */ /* Operations */ @@ -46,7 +45,7 @@ struct _bufhead { BUFHEAD *prev; /* LRU links */ BUFHEAD *next; /* LRU links */ BUFHEAD *ovfl; /* Overflow page buffer header */ - u_int32_t addr; /* Address of this page */ + uint32_t addr; /* Address of this page */ char *page; /* Actual page data */ char flags; #define BUF_MOD 0x0001 @@ -61,29 +60,29 @@ typedef BUFHEAD **SEGMENT; /* Hash Table Information */ typedef struct hashhdr { /* Disk resident portion */ - int magic; /* Magic NO for hash tables */ - int version; /* Version ID */ - u_int32_t lorder; /* Byte Order */ - int bsize; /* Bucket/Page Size */ - int bshift; /* Bucket shift */ - int dsize; /* Directory Size */ - int ssize; /* Segment Size */ - int sshift; /* Segment shift */ - int ovfl_point; /* Where overflow pages are being + int32_t magic; /* Magic NO for hash tables */ + int32_t version; /* Version ID */ + uint32_t lorder; /* Byte Order */ + int32_t bsize; /* Bucket/Page Size */ + int32_t bshift; /* Bucket shift */ + int32_t dsize; /* Directory Size */ + int32_t ssize; /* Segment Size */ + int32_t sshift; /* Segment shift */ + int32_t ovfl_point; /* Where overflow pages are being * allocated */ - int last_freed; /* Last overflow page freed */ - int max_bucket; /* ID of Maximum bucket in use */ - int high_mask; /* Mask to modulo into entire table */ - int low_mask; /* Mask to modulo into lower half of + int32_t last_freed; /* Last overflow page freed */ + uint32_t max_bucket; /* ID of Maximum bucket in use */ + uint32_t high_mask; /* Mask to modulo into entire table */ + uint32_t low_mask; /* Mask to modulo into lower half of * table */ - int ffactor; /* Fill factor */ - int nkeys; /* Number of keys in hash table */ - int hdrpages; /* Size of table header */ - int h_charkey; /* value of hash(CHARKEY) */ + uint32_t ffactor; /* Fill factor */ + int32_t nkeys; /* Number of keys in hash table */ + int32_t hdrpages; /* Size of table header */ + int32_t h_charkey; /* value of hash(CHARKEY) */ #define NCACHED 32 /* number of bit maps and spare * points */ - int spares[NCACHED];/* spare pages for overflow */ - u_int16_t bitmaps[NCACHED]; /* address of overflow page + int32_t spares[NCACHED];/* spare pages for overflow */ + uint16_t bitmaps[NCACHED]; /* address of overflow page * bitmaps */ } HASHHDR; @@ -92,7 +91,7 @@ typedef struct htab { /* Memory resident data structure */ int nsegs; /* Number of allocated segments */ int exsegs; /* Number of extra allocated * segments */ - u_int32_t /* Hash function */ + uint32_t /* Hash function */ (*hash)(const void *, size_t); int flags; /* Flag values */ int fp; /* File pointer */ @@ -108,7 +107,7 @@ typedef struct htab { /* Memory resident data structure */ int save_file; /* Indicates whether we need to flush * file at * exit */ - u_int32_t *mapp[NCACHED]; /* Pointers to page maps */ + uint32_t *mapp[NCACHED]; /* Pointers to page maps */ int nmaps; /* Initial number of bitmaps */ int nbufs; /* Number of buffers left to * allocate */ @@ -119,7 +118,7 @@ typedef struct htab { /* Memory resident data structure */ /* * Constants */ -#define MAX_BSIZE 65536 /* 2^16 */ +#define MAX_BSIZE 32768 /* 2^15 but should be 65536 */ #define MIN_BUFFERS 6 #define MINHDRSIZE 512 #define DEF_BUFSIZE 65536 /* 64 K */ @@ -136,13 +135,13 @@ typedef struct htab { /* Memory resident data structure */ #define BYTE_SHIFT 3 #define INT_TO_BYTE 2 #define INT_BYTE_SHIFT 5 -#define ALL_SET ((u_int32_t)0xFFFFFFFF) +#define ALL_SET ((uint32_t)0xFFFFFFFF) #define ALL_CLEAR 0 #define PTROF(X) ((BUFHEAD *)((ptrdiff_t)(X)&~0x3)) -#define ISMOD(X) ((u_int32_t)(ptrdiff_t)(X)&0x1) +#define ISMOD(X) ((uint32_t)(ptrdiff_t)(X)&0x1) #define DOMOD(X) ((X) = (char *)((ptrdiff_t)(X)|0x1)) -#define ISDISK(X) ((u_int32_t)(ptrdiff_t)(X)&0x2) +#define ISDISK(X) ((uint32_t)(ptrdiff_t)(X)&0x2) #define DODISK(X) ((X) = (char *)((ptrdiff_t)(X)|0x2)) #define BITS_PER_MAP 32 @@ -163,9 +162,9 @@ typedef struct htab { /* Memory resident data structure */ #define SPLITSHIFT 11 #define SPLITMASK 0x7FF -#define SPLITNUM(N) (((u_int32_t)(N)) >> SPLITSHIFT) +#define SPLITNUM(N) (((uint32_t)(N)) >> SPLITSHIFT) #define OPAGENUM(N) ((N) & SPLITMASK) -#define OADDR_OF(S,O) ((u_int32_t)((u_int32_t)(S) << SPLITSHIFT) + (O)) +#define OADDR_OF(S,O) ((uint32_t)((uint32_t)(S) << SPLITSHIFT) + (O)) #define BUCKET_TO_PAGE(B) \ (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__log2((B)+1)-1] : 0) diff --git a/lib/libc/db/hash/hash_bigkey.c b/lib/libc/db/hash/hash_bigkey.c index 2b7b31f654..324fae612a 100644 --- a/lib/libc/db/hash/hash_bigkey.c +++ b/lib/libc/db/hash/hash_bigkey.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)hash_bigkey.c 8.3 (Berkeley) 5/31/94 - * $DragonFly: src/lib/libc/db/hash/hash_bigkey.c,v 1.10 2006/08/03 16:40:46 swildner Exp $ + * $FreeBSD: head/lib/libc/db/hash/hash_bigkey.c 190494 2009-03-28 06:47:05Z delphij $ */ /* @@ -67,8 +67,8 @@ #include "page.h" #include "extern.h" -static int collect_key (HTAB *, BUFHEAD *, int, DBT *, int); -static int collect_data (HTAB *, BUFHEAD *, int, int); +static int collect_key(HTAB *, BUFHEAD *, int, DBT *, int); +static int collect_data(HTAB *, BUFHEAD *, int, int); /* * Big_insert @@ -79,16 +79,17 @@ static int collect_data (HTAB *, BUFHEAD *, int, int); * 0 ==> OK *-1 ==> ERROR */ -extern int +int __big_insert(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) { - u_int16_t *p; - int key_size, n, val_size; - u_int16_t space, move_bytes, off; + uint16_t *p; + int key_size, n; + unsigned int val_size; + uint16_t space, move_bytes, off; char *cp, *key_data, *val_data; cp = bufp->page; /* Character pointer of p. */ - p = (u_int16_t *)cp; + p = (uint16_t *)cp; key_data = (char *)key->data; key_size = key->size; @@ -114,20 +115,32 @@ __big_insert(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) return (-1); n = p[0]; if (!key_size) { - if (FREESPACE(p)) { - move_bytes = MIN(FREESPACE(p), val_size); + space = FREESPACE(p); + if (space) { + move_bytes = MIN(space, val_size); + /* + * If the data would fit exactly in the + * remaining space, we must overflow it to the + * next page; otherwise the invariant that the + * data must end on a page with FREESPACE + * non-zero would fail. + */ + if (space == val_size && val_size == val->size) + goto toolarge; off = OFFSET(p) - move_bytes; - p[n] = off; memmove(cp + off, val_data, move_bytes); val_data += move_bytes; val_size -= move_bytes; + p[n] = off; p[n - 2] = FULL_KEY_DATA; FREESPACE(p) = FREESPACE(p) - move_bytes; OFFSET(p) = off; - } else + } else { + toolarge: p[n - 2] = FULL_KEY; + } } - p = (u_int16_t *)bufp->page; + p = (uint16_t *)bufp->page; cp = bufp->page; bufp->flags |= BUF_MOD; } @@ -157,7 +170,7 @@ __big_insert(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) if (!bufp) return (-1); cp = bufp->page; - p = (u_int16_t *)cp; + p = (uint16_t *)cp; } else p[n] = FULL_KEY_DATA; bufp->flags |= BUF_MOD; @@ -176,16 +189,16 @@ __big_insert(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) * 0 => OK *-1 => ERROR */ -extern int +int __big_delete(HTAB *hashp, BUFHEAD *bufp) { BUFHEAD *last_bfp, *rbufp; - u_int16_t *bp, pageno; + uint16_t *bp, pageno; int key_done, n; rbufp = bufp; last_bfp = NULL; - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; pageno = 0; key_done = 0; @@ -208,7 +221,7 @@ __big_delete(HTAB *hashp, BUFHEAD *bufp) last_bfp = rbufp; if (!rbufp) return (-1); /* Error. */ - bp = (u_int16_t *)rbufp->page; + bp = (uint16_t *)rbufp->page; } /* @@ -223,7 +236,7 @@ __big_delete(HTAB *hashp, BUFHEAD *bufp) pageno = bp[n - 1]; /* Now, bp is the first page of the pair. */ - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; if (n > 2) { /* There is an overflow page. */ bp[1] = pageno; @@ -235,12 +248,12 @@ __big_delete(HTAB *hashp, BUFHEAD *bufp) n -= 2; bp[0] = n; FREESPACE(bp) = hashp->BSIZE - PAGE_META(n); - OFFSET(bp) = hashp->BSIZE - 1; + OFFSET(bp) = hashp->BSIZE; bufp->flags |= BUF_MOD; if (rbufp) __free_ovflpage(hashp, rbufp); - if (last_bfp != rbufp) + if (last_bfp && last_bfp != rbufp) __free_ovflpage(hashp, last_bfp); hashp->NKEYS--; @@ -253,16 +266,16 @@ __big_delete(HTAB *hashp, BUFHEAD *bufp) * -2 means key not found and this is big key/data * -3 error */ -extern int -__find_bigpair(HTAB *hashp, BUFHEAD *bufp, int ndx, const char *key, int size) +int +__find_bigpair(HTAB *hashp, BUFHEAD *bufp, int ndx, char *key, int size) { - u_int16_t *bp; + uint16_t *bp; char *p; int ksize; - u_int16_t bytes; - const char *kkey; + uint16_t bytes; + char *kkey; - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; p = bufp->page; ksize = size; kkey = key; @@ -278,7 +291,7 @@ __find_bigpair(HTAB *hashp, BUFHEAD *bufp, int ndx, const char *key, int size) if (!bufp) return (-3); p = bufp->page; - bp = (u_int16_t *)p; + bp = (uint16_t *)p; ndx = 1; } @@ -300,15 +313,15 @@ __find_bigpair(HTAB *hashp, BUFHEAD *bufp, int ndx, const char *key, int size) * of the pair; 0 if there isn't any (i.e. big pair is the last key in the * bucket) */ -extern u_int16_t +uint16_t __find_last_page(HTAB *hashp, BUFHEAD **bpp) { BUFHEAD *bufp; - u_int16_t *bp, pageno; + uint16_t *bp, pageno; int n; bufp = *bpp; - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; for (;;) { n = bp[0]; @@ -325,7 +338,7 @@ __find_last_page(HTAB *hashp, BUFHEAD **bpp) bufp = __get_buf(hashp, pageno, bufp, 0); if (!bufp) return (0); /* Need to indicate an error! */ - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; } *bpp = bufp; @@ -339,19 +352,19 @@ __find_last_page(HTAB *hashp, BUFHEAD **bpp) * Return the data for the key/data pair that begins on this page at this * index (index should always be 1). */ -extern int +int __big_return(HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current) { BUFHEAD *save_p; - u_int16_t *bp, len, off, save_addr; + uint16_t *bp, len, off, save_addr; char *tp; - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; while (bp[ndx + 1] == PARTIAL_KEY) { bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; ndx = 1; } @@ -359,7 +372,7 @@ __big_return(HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current) bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; save_p = bufp; save_addr = save_p->addr; off = bp[1]; @@ -380,12 +393,12 @@ __big_return(HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current) bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; } else { /* The data is all on one page. */ tp = (char *)bp; off = bp[bp[0]]; - val->data = (u_char *)tp + off; + val->data = (unsigned char *)tp + off; val->size = bp[1] - off; if (set_current) { if (bp[0] == 2) { /* No more buckets in @@ -399,7 +412,7 @@ __big_return(HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current) if (!hashp->cpage) return (-1); hashp->cndx = 1; - if (!((u_int16_t *) + if (!((uint16_t *) hashp->cpage->page)[0]) { hashp->cbucket++; hashp->cpage = NULL; @@ -409,8 +422,8 @@ __big_return(HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current) return (0); } - val->size = collect_data(hashp, bufp, (int)len, set_current); - if (val->size == -1) + val->size = (size_t)collect_data(hashp, bufp, (int)len, set_current); + if (val->size == (size_t)-1) return (-1); if (save_p->addr != save_addr) { /* We are pretty short on buffers. */ @@ -418,7 +431,7 @@ __big_return(HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current) return (-1); } memmove(hashp->tmp_buf, (save_p->page) + off, len); - val->data = (u_char *)hashp->tmp_buf; + val->data = (unsigned char *)hashp->tmp_buf; return (0); } /* @@ -428,14 +441,14 @@ __big_return(HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current) static int collect_data(HTAB *hashp, BUFHEAD *bufp, int len, int set) { - u_int16_t *bp; + uint16_t *bp; char *p; BUFHEAD *xbp; - u_int16_t save_addr; + uint16_t save_addr; int mylen, totlen; p = bufp->page; - bp = (u_int16_t *)p; + bp = (uint16_t *)p; mylen = hashp->BSIZE - bp[1]; save_addr = bufp->addr; @@ -455,7 +468,7 @@ collect_data(HTAB *hashp, BUFHEAD *bufp, int len, int set) __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!hashp->cpage) return (-1); - else if (!((u_int16_t *)hashp->cpage->page)[0]) { + else if (!((uint16_t *)hashp->cpage->page)[0]) { hashp->cbucket++; hashp->cpage = NULL; } @@ -478,13 +491,13 @@ collect_data(HTAB *hashp, BUFHEAD *bufp, int len, int set) /* * Fill in the key and data for this big pair. */ -extern int +int __big_keydata(HTAB *hashp, BUFHEAD *bufp, DBT *key, DBT *val, int set) { - key->size = collect_key(hashp, bufp, 0, val, set); - if (key->size == -1) + key->size = (size_t)collect_key(hashp, bufp, 0, val, set); + if (key->size == (size_t)-1) return (-1); - key->data = (u_char *)hashp->tmp_key; + key->data = (unsigned char *)hashp->tmp_key; return (0); } @@ -498,10 +511,10 @@ collect_key(HTAB *hashp, BUFHEAD *bufp, int len, DBT *val, int set) BUFHEAD *xbp; char *p; int mylen, totlen; - u_int16_t *bp, save_addr; + uint16_t *bp, save_addr; p = bufp->page; - bp = (u_int16_t *)p; + bp = (uint16_t *)p; mylen = hashp->BSIZE - bp[1]; save_addr = bufp->addr; @@ -528,26 +541,23 @@ collect_key(HTAB *hashp, BUFHEAD *bufp, int len, DBT *val, int set) } /* - * Parameters: - * op: Pointer to where to put keys that go in old bucket - * np: Pointer to new bucket page - * big_keyp: Pointer to first page containing the big key/data - * addr: Address of big_keyp - * obucket: Old Bucket * Returns: - * 0 => OK - * -1 => error + * 0 => OK + * -1 => error */ -extern int -__big_split(HTAB *hashp, BUFHEAD *op, BUFHEAD *np, BUFHEAD *big_keyp, - int addr, u_int32_t obucket, SPLIT_RETURN *ret) +int +__big_split(HTAB *hashp, + BUFHEAD *op, /* Pointer to where to put keys that go in old bucket */ + BUFHEAD *np, /* Pointer to new bucket page */ + BUFHEAD *big_keyp, /* Pointer to first page containing the big key/data */ + int addr, /* Address of big_keyp */ + uint32_t obucket, /* Old Bucket */ + SPLIT_RETURN *ret) { - BUFHEAD *tmpp; - u_int16_t *tp; - BUFHEAD *bp; + BUFHEAD *bp, *tmpp; DBT key, val; - u_int32_t change; - u_int16_t free_space, n, off; + uint32_t change; + uint16_t free_space, n, off, *tp; bp = big_keyp; @@ -579,14 +589,14 @@ __big_split(HTAB *hashp, BUFHEAD *op, BUFHEAD *np, BUFHEAD *big_keyp, (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0)); #endif tmpp->ovfl = bp; /* one of op/np point to big_keyp */ - tp = (u_int16_t *)tmpp->page; + tp = (uint16_t *)tmpp->page; #ifdef DEBUG assert(FREESPACE(tp) >= OVFLSIZE); #endif n = tp[0]; off = OFFSET(tp); free_space = FREESPACE(tp); - tp[++n] = (u_int16_t)addr; + tp[++n] = (uint16_t)addr; tp[++n] = OVFLPAGE; tp[0] = n; OFFSET(tp) = off; @@ -602,7 +612,7 @@ __big_split(HTAB *hashp, BUFHEAD *op, BUFHEAD *np, BUFHEAD *big_keyp, ret->newp = np; ret->oldp = op; - tp = (u_int16_t *)big_keyp->page; + tp = (uint16_t *)big_keyp->page; big_keyp->flags |= BUF_MOD; if (tp[0] > 2) { /* diff --git a/lib/libc/db/hash/hash_buf.c b/lib/libc/db/hash/hash_buf.c index 031195f656..0119daddf9 100644 --- a/lib/libc/db/hash/hash_buf.c +++ b/lib/libc/db/hash/hash_buf.c @@ -29,10 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/db/hash/hash_buf.c,v 1.4.8.1 2001/03/05 07:38:05 obrien Exp $ - * $DragonFly: src/lib/libc/db/hash/hash_buf.c,v 1.7 2005/11/19 20:46:32 swildner Exp $ - * * @(#)hash_buf.c 8.5 (Berkeley) 7/15/94 + * $FreeBSD: head/lib/libc/db/hash/hash_buf.c 190493 2009-03-28 06:40:48Z delphij $ */ /* @@ -67,7 +65,7 @@ #include "page.h" #include "extern.h" -static BUFHEAD *newbuf (HTAB *, u_int32_t, BUFHEAD *); +static BUFHEAD *newbuf(HTAB *, uint32_t, BUFHEAD *); /* Unlink B from its place in the lru */ #define BUF_REMOVE(B) { \ @@ -97,22 +95,19 @@ static BUFHEAD *newbuf (HTAB *, u_int32_t, BUFHEAD *); * CAVEAT: The buffer header accessed via prev_bp's ovfl field may no longer * be valid. Therefore, you must always verify that its address matches the * address you are seeking. - * - * Parameters: - * newpage: If prev_bp set, indicates a new overflow page */ -extern BUFHEAD * -__get_buf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp, int newpage) +BUFHEAD * +__get_buf(HTAB *hashp, uint32_t addr, + BUFHEAD *prev_bp, /* If prev_bp set, indicates a new overflow page. */ + int newpage) { BUFHEAD *bp; - u_int32_t is_disk_mask; + uint32_t is_disk_mask; int is_disk, segment_ndx; SEGMENT segp; is_disk = 0; is_disk_mask = 0; - segment_ndx = 0; - segp = NULL; if (prev_bp) { bp = prev_bp->ovfl; if (!bp || (bp->addr != addr)) @@ -155,35 +150,49 @@ __get_buf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp, int newpage) * If newbuf finds an error (returning NULL), it also sets errno. */ static BUFHEAD * -newbuf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp) +newbuf(HTAB *hashp, uint32_t addr, BUFHEAD *prev_bp) { BUFHEAD *bp; /* The buffer we're going to use */ BUFHEAD *xbp; /* Temp pointer */ BUFHEAD *next_xbp; SEGMENT segp; int segment_ndx; - u_int16_t oaddr, *shortp; + uint16_t oaddr, *shortp; oaddr = 0; bp = LRU; + + /* It is bad to overwrite the page under the cursor. */ + if (bp == hashp->cpage) { + BUF_REMOVE(bp); + MRU_INSERT(bp); + bp = LRU; + } + + /* If prev_bp is part of bp overflow, create a new buffer. */ + if (hashp->nbufs == 0 && prev_bp && bp->ovfl) { + BUFHEAD *ovfl; + + for (ovfl = bp->ovfl; ovfl ; ovfl = ovfl->ovfl) { + if (ovfl == prev_bp) { + hashp->nbufs++; + break; + } + } + } + /* * If LRU buffer is pinned, the buffer pool is too small. We need to * allocate more buffers. */ - if (hashp->nbufs || (bp->flags & BUF_PIN)) { + if (hashp->nbufs || (bp->flags & BUF_PIN) || bp == hashp->cpage) { /* Allocate a new one */ if ((bp = (BUFHEAD *)calloc(1, sizeof(BUFHEAD))) == NULL) return (NULL); -#ifdef PURIFY - memset(bp, 0xff, sizeof(BUFHEAD)); -#endif if ((bp->page = (char *)calloc(1, hashp->BSIZE)) == NULL) { free(bp); return (NULL); } -#ifdef PURIFY - memset(bp->page, 0xff, hashp->BSIZE); -#endif if (hashp->nbufs) hashp->nbufs--; } else { @@ -198,7 +207,7 @@ newbuf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp) * Set oaddr before __put_page so that you get it * before bytes are swapped. */ - shortp = (u_int16_t *)bp->page; + shortp = (uint16_t *)bp->page; if (shortp[0]) oaddr = shortp[shortp[0] - 1]; if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page, @@ -241,7 +250,7 @@ newbuf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp) (oaddr != xbp->addr)) break; - shortp = (u_int16_t *)xbp->page; + shortp = (uint16_t *)xbp->page; if (shortp[0]) /* set before __put_page */ oaddr = shortp[shortp[0] - 1]; @@ -270,7 +279,7 @@ newbuf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp) */ #ifdef DEBUG1 fprintf(stderr, "NEWBUF2: %d->ovfl was %d is now %d\n", - prev_bp->addr, (prev_bp->ovfl ? bp->ovfl->addr : 0), + prev_bp->addr, (prev_bp->ovfl ? prev_bp->ovfl->addr : 0), (bp ? bp->addr : 0)); #endif prev_bp->ovfl = bp; @@ -281,7 +290,7 @@ newbuf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp) return (bp); } -extern void +void __buf_init(HTAB *hashp, int nbytes) { BUFHEAD *bfp; @@ -304,7 +313,7 @@ __buf_init(HTAB *hashp, int nbytes) */ } -extern int +int __buf_free(HTAB *hashp, int do_free, int to_disk) { BUFHEAD *bp; @@ -335,7 +344,7 @@ __buf_free(HTAB *hashp, int do_free, int to_disk) return (0); } -extern void +void __reclaim_buf(HTAB *hashp, BUFHEAD *bp) { bp->ovfl = 0; diff --git a/lib/libc/db/hash/hash_func.c b/lib/libc/db/hash/hash_func.c index 95567b2bb9..8bc88b00f6 100644 --- a/lib/libc/db/hash/hash_func.c +++ b/lib/libc/db/hash/hash_func.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)hash_func.c 8.2 (Berkeley) 2/21/94 - * $DragonFly: src/lib/libc/db/hash/hash_func.c,v 1.8 2005/11/19 20:46:32 swildner Exp $ + * $FreeBSD: head/lib/libc/db/hash/hash_func.c 190498 2009-03-28 07:31:02Z delphij $ */ #include @@ -40,56 +40,57 @@ #include "page.h" #include "extern.h" -static u_int32_t hash1 (const void *, size_t) __unused; -static u_int32_t hash2 (const void *, size_t) __unused; -static u_int32_t hash3 (const void *, size_t) __unused; -static u_int32_t hash4 (const void *, size_t); +#ifdef notdef +static uint32_t hash1(const void *, size_t) __unused; +static uint32_t hash2(const void *, size_t) __unused; +static uint32_t hash3(const void *, size_t) __unused; +#endif +static uint32_t hash4(const void *, size_t); -/* Global default hash function */ -u_int32_t (*__default_hash) (const void *, size_t) = hash4; +/* Default hash function. */ +uint32_t (*__default_hash)(const void *, size_t) = hash4; +#ifdef notdef /* - * HASH FUNCTIONS - * * Assume that we've already split the bucket to which this key hashes, * calculate that bucket, and check that in fact we did already split it. * - * This came from ejb's hsearch. + * EJB's original hsearch hash. */ - #define PRIME1 37 #define PRIME2 1048583 -static u_int32_t -hash1(const void *keyarg, size_t len) +uint32_t +hash1(const void *key, size_t len) { - const u_char *key; - u_int32_t h; + uint32_t h; + uint8_t *k; + h = 0; + k = (uint8_t *)key; /* Convert string to integer */ - for (key = keyarg, h = 0; len--;) - h = h * PRIME1 ^ (*key++ - ' '); + while (len--) + h = h * PRIME1 ^ (*k++ - ' '); h %= PRIME2; return (h); } /* - * Phong's linear congruential hash + * Phong Vo's linear congruential hash */ #define dcharhash(h, c) ((h) = 0x63c63cd9*(h) + 0x9c39c33d + (c)) -static u_int32_t -hash2(const void *keyarg, size_t len) +uint32_t +hash2(const void *key, size_t len) { - const u_char *e, *key; - u_int32_t h; - u_char c; - - key = keyarg; - e = key + len; - for (h = 0; key != e;) { - c = *key++; - if (!c && key > e) + uint32_t h; + uint8_t *e, c, *k; + + k = (uint8_t *)key; + e = k + len; + for (h = 0; k != e;) { + c = *k++; + if (!c && k > e) break; dcharhash(h, c); } @@ -103,97 +104,84 @@ hash2(const void *keyarg, size_t len) * all 8 bytes. Essentially, this saves us 7 cmp & branch instructions. If * this routine is heavily used enough, it's worth the ugly coding. * - * OZ's original sdbm hash + * Ozan Yigit's original sdbm hash. */ -static u_int32_t -hash3(const void *keyarg, size_t len) +uint32_t +hash3(const void *key, size_t len) { - const u_char *key; - size_t loop; - u_int32_t h; + uint32_t n, loop; + uint8_t *k; -#define HASHC h = *key++ + 65599 * h +#define HASHC n = *k++ + 65599 * n - h = 0; - key = keyarg; + n = 0; + k = (uint8_t *)key; if (len > 0) { loop = (len + 8 - 1) >> 3; switch (len & (8 - 1)) { case 0: - do { + do { /* All fall throughs */ HASHC; - /* FALLTHROUGH */ case 7: HASHC; - /* FALLTHROUGH */ case 6: HASHC; - /* FALLTHROUGH */ case 5: HASHC; - /* FALLTHROUGH */ case 4: HASHC; - /* FALLTHROUGH */ case 3: HASHC; - /* FALLTHROUGH */ case 2: HASHC; - /* FALLTHROUGH */ case 1: HASHC; } while (--loop); } + } - return (h); + return (n); } +#endif /* notdef */ -/* Hash function from Chris Torek. */ -static u_int32_t -hash4(const void *keyarg, size_t len) +/* Chris Torek's hash function. */ +uint32_t +hash4(const void *key, size_t len) { - const u_char *key; - size_t loop; - u_int32_t h; + uint32_t h, loop; + const uint8_t *k; -#define HASH4a h = (h << 5) - h + *key++; -#define HASH4b h = (h << 5) + h + *key++; +#define HASH4a h = (h << 5) - h + *k++; +#define HASH4b h = (h << 5) + h + *k++; #define HASH4 HASH4b h = 0; - key = keyarg; + k = key; if (len > 0) { loop = (len + 8 - 1) >> 3; switch (len & (8 - 1)) { case 0: - do { + do { /* All fall throughs */ HASH4; - /* FALLTHROUGH */ case 7: HASH4; - /* FALLTHROUGH */ case 6: HASH4; - /* FALLTHROUGH */ case 5: HASH4; - /* FALLTHROUGH */ case 4: HASH4; - /* FALLTHROUGH */ case 3: HASH4; - /* FALLTHROUGH */ case 2: HASH4; - /* FALLTHROUGH */ case 1: HASH4; } while (--loop); } + } return (h); } diff --git a/lib/libc/db/hash/hash_log2.c b/lib/libc/db/hash/hash_log2.c index ace9c3a417..b07945e944 100644 --- a/lib/libc/db/hash/hash_log2.c +++ b/lib/libc/db/hash/hash_log2.c @@ -30,20 +30,18 @@ * SUCH DAMAGE. * * @(#)hash_log2.c 8.2 (Berkeley) 5/31/94 - * $DragonFly: src/lib/libc/db/hash/hash_log2.c,v 1.6 2005/11/19 20:46:32 swildner Exp $ + * $FreeBSD: head/lib/libc/db/hash/hash_log2.c 190484 2009-03-28 05:45:29Z delphij $ */ -#include - #include #include "hash.h" #include "page.h" #include "extern.h" -u_int32_t -__log2(u_int32_t num) +uint32_t +__log2(uint32_t num) { - u_int32_t i, limit; + uint32_t i, limit; limit = 1; for (i = 0; limit < num; limit = limit << 1, i++); diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index 449bfe82ce..a7849403a6 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -29,10 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/db/hash/hash_page.c,v 1.5 2000/01/27 23:06:08 jasone Exp $ - * $DragonFly: src/lib/libc/db/hash/hash_page.c,v 1.8 2005/11/19 20:46:32 swildner Exp $ - * * @(#)hash_page.c 8.7 (Berkeley) 8/16/94 + * $FreeBSD: head/lib/libc/db/hash/hash_page.c 190500 2009-03-28 07:44:08Z delphij $ */ /* @@ -71,20 +69,19 @@ #include "page.h" #include "extern.h" -static u_int32_t *fetch_bitmap (HTAB *, int); -static u_int32_t first_free (u_int32_t); -static int open_temp (HTAB *); -static u_int16_t overflow_page (HTAB *); -static void putpair (char *, const DBT *, const DBT *); -static void squeeze_key (u_int16_t *, const DBT *, const DBT *); -static int ugly_split - (HTAB *, u_int32_t, BUFHEAD *, BUFHEAD *, int, int); - -#define PAGE_INIT(P) { \ - ((u_int16_t *)(P))[0] = 0; \ - ((u_int16_t *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_int16_t); \ - ((u_int16_t *)(P))[2] = hashp->BSIZE; \ -} +static uint32_t *fetch_bitmap(HTAB *, int); +static uint32_t first_free(uint32_t); +static int open_temp(HTAB *); +static uint16_t overflow_page(HTAB *); +static void putpair(char *, const DBT *, const DBT *); +static void squeeze_key(uint16_t *, const DBT *, const DBT *); +static int ugly_split(HTAB *, uint32_t, BUFHEAD *, BUFHEAD *, int, int); + +#define PAGE_INIT(P) { \ + ((uint16_t *)(P))[0] = 0; \ + ((uint16_t *)(P))[1] = hashp->BSIZE - 3 * sizeof(uint16_t); \ + ((uint16_t *)(P))[2] = hashp->BSIZE; \ + } /* * This is called AFTER we have verified that there is room on the page for @@ -94,9 +91,9 @@ static int ugly_split static void putpair(char *p, const DBT *key, const DBT *val) { - u_int16_t *bp, n, off; + uint16_t *bp, n, off; - bp = (u_int16_t *)p; + bp = (uint16_t *)p; /* Enter the key first. */ n = bp[0]; @@ -112,7 +109,7 @@ putpair(char *p, const DBT *key, const DBT *val) /* Adjust page info. */ bp[0] = n; - bp[n + 1] = off - ((n + 3) * sizeof(u_int16_t)); + bp[n + 1] = off - ((n + 3) * sizeof(uint16_t)); bp[n + 2] = off; } @@ -121,14 +118,13 @@ putpair(char *p, const DBT *key, const DBT *val) * 0 OK * -1 error */ -extern int +int __delpair(HTAB *hashp, BUFHEAD *bufp, int ndx) { - u_int16_t *bp, newoff; + uint16_t *bp, newoff, pairlen; int n; - u_int16_t pairlen; - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; n = bp[0]; if (bp[ndx + 1] < REAL_KEY) @@ -156,10 +152,18 @@ __delpair(HTAB *hashp, BUFHEAD *bufp, int ndx) bp[i - 1] = bp[i + 1] + pairlen; } } + if (ndx == hashp->cndx) { + /* + * We just removed pair we were "pointing" to. + * By moving back the cndx we ensure subsequent + * hash_seq() calls won't skip over any entries. + */ + hashp->cndx -= 2; + } } /* Finally adjust the page data */ bp[n] = OFFSET(bp) + pairlen; - bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_int16_t); + bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(uint16_t); bp[0] = n - 2; hashp->NKEYS--; @@ -171,19 +175,19 @@ __delpair(HTAB *hashp, BUFHEAD *bufp, int ndx) * 0 ==> OK * -1 ==> Error */ -extern int -__split_page(HTAB *hashp, u_int32_t obucket, u_int32_t nbucket) +int +__split_page(HTAB *hashp, uint32_t obucket, uint32_t nbucket) { BUFHEAD *new_bufp, *old_bufp; - u_int16_t *ino; + uint16_t *ino; char *np; DBT key, val; int n, ndx, retval; - u_int16_t copyto, diff, off, moved; + uint16_t copyto, diff, off, moved; char *op; - copyto = (u_int16_t)hashp->BSIZE; - off = (u_int16_t)hashp->BSIZE; + copyto = (uint16_t)hashp->BSIZE; + off = (uint16_t)hashp->BSIZE; old_bufp = __get_buf(hashp, obucket, NULL, 0); if (old_bufp == NULL) return (-1); @@ -194,7 +198,7 @@ __split_page(HTAB *hashp, u_int32_t obucket, u_int32_t nbucket) old_bufp->flags |= (BUF_MOD | BUF_PIN); new_bufp->flags |= (BUF_MOD | BUF_PIN); - ino = (u_int16_t *)(op = old_bufp->page); + ino = (uint16_t *)(op = old_bufp->page); np = new_bufp->page; moved = 0; @@ -208,7 +212,7 @@ __split_page(HTAB *hashp, u_int32_t obucket, u_int32_t nbucket) return (retval); } - key.data = (u_char *)op + ino[n]; + key.data = (unsigned char *)op + ino[n]; key.size = off - ino[n]; if (__call_hash(hashp, key.data, key.size) == obucket) { @@ -225,7 +229,7 @@ __split_page(HTAB *hashp, u_int32_t obucket, u_int32_t nbucket) ndx += 2; } else { /* Switch page */ - val.data = (u_char *)op + ino[n + 1]; + val.data = (unsigned char *)op + ino[n + 1]; val.size = ino[n] - ino[n + 1]; putpair(np, &key, &val); moved += 2; @@ -236,13 +240,13 @@ __split_page(HTAB *hashp, u_int32_t obucket, u_int32_t nbucket) /* Now clean up the page */ ino[0] -= moved; - FREESPACE(ino) = copyto - sizeof(u_int16_t) * (ino[0] + 3); + FREESPACE(ino) = copyto - sizeof(uint16_t) * (ino[0] + 3); OFFSET(ino) = copyto; #ifdef DEBUG3 fprintf(stderr, "split %d/%d\n", - ((u_int16_t *)np)[0] / 2, - ((u_int16_t *)op)[0] / 2); + ((uint16_t *)np)[0] / 2, + ((uint16_t *)op)[0] / 2); #endif /* unpin both pages */ old_bufp->flags &= ~BUF_PIN; @@ -261,35 +265,35 @@ __split_page(HTAB *hashp, u_int32_t obucket, u_int32_t nbucket) * page or it might be a big key/data pair in which case we need to fix the * big key/data pair. * - * Parameters: - * obucket - Same as __split_page - * copyto - First byte on page which contains key/data values - * moved - Number of pairs moved to new page * Returns: * 0 ==> success * -1 ==> failure */ static int -ugly_split(HTAB *hashp, u_int32_t obucket, BUFHEAD *old_bufp, - BUFHEAD *new_bufp, int copyto, int moved) +ugly_split(HTAB *hashp, + uint32_t obucket, /* Same as __split_page. */ + BUFHEAD *old_bufp, + BUFHEAD *new_bufp, + int copyto, /* First byte on page which contains key/data values. */ + int moved) /* Number of pairs moved to new page. */ { BUFHEAD *bufp; /* Buffer header for ino */ - u_int16_t *ino; /* Page keys come off of */ - u_int16_t *np; /* New page */ - u_int16_t *op; /* Page keys go on to if they aren't moving */ + uint16_t *ino; /* Page keys come off of */ + uint16_t *np; /* New page */ + uint16_t *op; /* Page keys go on to if they aren't moving */ BUFHEAD *last_bfp; /* Last buf header OVFL needing to be freed */ DBT key, val; SPLIT_RETURN ret; - u_int16_t n, off, ov_addr, scopyto; + uint16_t n, off, ov_addr, scopyto; char *cino; /* Character value of ino */ bufp = old_bufp; - ino = (u_int16_t *)old_bufp->page; - np = (u_int16_t *)new_bufp->page; - op = (u_int16_t *)old_bufp->page; + ino = (uint16_t *)old_bufp->page; + np = (uint16_t *)new_bufp->page; + op = (uint16_t *)old_bufp->page; last_bfp = NULL; - scopyto = (u_int16_t)copyto; /* ANSI */ + scopyto = (uint16_t)copyto; /* ANSI */ n = ino[0] - 1; while (n < ino[0]) { @@ -300,16 +304,16 @@ ugly_split(HTAB *hashp, u_int32_t obucket, BUFHEAD *old_bufp, old_bufp = ret.oldp; if (!old_bufp) return (-1); - op = (u_int16_t *)old_bufp->page; + op = (uint16_t *)old_bufp->page; new_bufp = ret.newp; if (!new_bufp) return (-1); - np = (u_int16_t *)new_bufp->page; + np = (uint16_t *)new_bufp->page; bufp = ret.nextp; if (!bufp) return (0); cino = (char *)bufp->page; - ino = (u_int16_t *)cino; + ino = (uint16_t *)cino; last_bfp = ret.nextp; } else if (ino[n + 1] == OVFLPAGE) { ov_addr = ino[n]; @@ -319,14 +323,14 @@ ugly_split(HTAB *hashp, u_int32_t obucket, BUFHEAD *old_bufp, */ ino[0] -= (moved + 2); FREESPACE(ino) = - scopyto - sizeof(u_int16_t) * (ino[0] + 3); + scopyto - sizeof(uint16_t) * (ino[0] + 3); OFFSET(ino) = scopyto; bufp = __get_buf(hashp, ov_addr, bufp, 0); if (!bufp) return (-1); - ino = (u_int16_t *)bufp->page; + ino = (uint16_t *)bufp->page; n = 1; scopyto = hashp->BSIZE; moved = 0; @@ -339,9 +343,9 @@ ugly_split(HTAB *hashp, u_int32_t obucket, BUFHEAD *old_bufp, off = hashp->BSIZE; for (n = 1; (n < ino[0]) && (ino[n + 1] >= REAL_KEY); n += 2) { cino = (char *)ino; - key.data = (u_char *)cino + ino[n]; + key.data = (unsigned char *)cino + ino[n]; key.size = off - ino[n]; - val.data = (u_char *)cino + ino[n + 1]; + val.data = (unsigned char *)cino + ino[n + 1]; val.size = ino[n] - ino[n + 1]; off = ino[n + 1]; @@ -354,7 +358,7 @@ ugly_split(HTAB *hashp, u_int32_t obucket, BUFHEAD *old_bufp, __add_ovflpage(hashp, old_bufp); if (!old_bufp) return (-1); - op = (u_int16_t *)old_bufp->page; + op = (uint16_t *)old_bufp->page; putpair((char *)op, &key, &val); } old_bufp->flags |= BUF_MOD; @@ -367,7 +371,7 @@ ugly_split(HTAB *hashp, u_int32_t obucket, BUFHEAD *old_bufp, __add_ovflpage(hashp, new_bufp); if (!new_bufp) return (-1); - np = (u_int16_t *)new_bufp->page; + np = (uint16_t *)new_bufp->page; putpair((char *)np, &key, &val); } new_bufp->flags |= BUF_MOD; @@ -386,13 +390,13 @@ ugly_split(HTAB *hashp, u_int32_t obucket, BUFHEAD *old_bufp, * 0 ==> OK * 1 ==> failure */ -extern int +int __addel(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) { - u_int16_t *bp, *sop; + uint16_t *bp, *sop; int do_expand; - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; do_expand = 0; while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY)) /* Exception case */ @@ -404,18 +408,23 @@ __addel(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; - } else + bp = (uint16_t *)bufp->page; + } else if (bp[bp[0]] != OVFLPAGE) { + /* Short key/data pairs, no more pages */ + break; + } else { /* Try to squeeze key on this page */ - if (FREESPACE(bp) > PAIRSIZE(key, val)) { + if (bp[2] >= REAL_KEY && + FREESPACE(bp) >= PAIRSIZE(key, val)) { squeeze_key(bp, key, val); - return (0); + goto stats; } else { bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; + bp = (uint16_t *)bufp->page; } + } if (PAIRFITS(bp, key, val)) putpair(bufp->page, key, val); @@ -424,7 +433,7 @@ __addel(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) bufp = __add_ovflpage(hashp, bufp); if (!bufp) return (-1); - sop = (u_int16_t *)bufp->page; + sop = (uint16_t *)bufp->page; if (PAIRFITS(sop, key, val)) putpair((char *)sop, key, val); @@ -432,6 +441,7 @@ __addel(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) if (__big_insert(hashp, bufp, key, val)) return (-1); } +stats: bufp->flags |= BUF_MOD; /* * If the average number of keys per bucket exceeds the fill factor, @@ -450,15 +460,14 @@ __addel(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) * pointer on success * NULL on error */ -extern BUFHEAD * +BUFHEAD * __add_ovflpage(HTAB *hashp, BUFHEAD *bufp) { - u_int16_t *sp; - u_int16_t ndx, ovfl_num; + uint16_t *sp, ndx, ovfl_num; #ifdef DEBUG1 int tmp1, tmp2; #endif - sp = (u_int16_t *)bufp->page; + sp = (uint16_t *)bufp->page; /* Check if we are dynamically determining the fill factor */ if (hashp->FFACTOR == DEF_FFACTOR) { @@ -501,13 +510,12 @@ __add_ovflpage(HTAB *hashp, BUFHEAD *bufp) * 0 indicates SUCCESS * -1 indicates FAILURE */ -extern int -__get_page(HTAB *hashp, char *p, u_int32_t bucket, int is_bucket, int is_disk, - int is_bitmap) +int +__get_page(HTAB *hashp, char *p, uint32_t bucket, int is_bucket, int is_disk, + int is_bitmap) { - int fd, page, size; - int rsize; - u_int16_t *bp; + int fd, page, size, rsize; + uint16_t *bp; fd = hashp->fp; size = hashp->BSIZE; @@ -520,10 +528,9 @@ __get_page(HTAB *hashp, char *p, u_int32_t bucket, int is_bucket, int is_disk, page = BUCKET_TO_PAGE(bucket); else page = OADDR_TO_PAGE(bucket); - if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || - ((rsize = _read(fd, p, size)) == -1)) + if ((rsize = pread(fd, p, size, (off_t)page << hashp->BSHIFT)) == -1) return (-1); - bp = (u_int16_t *)p; + bp = (uint16_t *)p; if (!rsize) bp[0] = 0; /* We hit the EOF, so initialize a new page */ else @@ -558,11 +565,10 @@ __get_page(HTAB *hashp, char *p, u_int32_t bucket, int is_bucket, int is_disk, * 0 ==> OK * -1 ==>failure */ -extern int -__put_page(HTAB *hashp, char *p, u_int32_t bucket, int is_bucket, int is_bitmap) +int +__put_page(HTAB *hashp, char *p, uint32_t bucket, int is_bucket, int is_bitmap) { - int fd, page, size; - int wsize; + int fd, page, size, wsize; size = hashp->BSIZE; if ((hashp->fp == -1) && open_temp(hashp)) @@ -570,25 +576,23 @@ __put_page(HTAB *hashp, char *p, u_int32_t bucket, int is_bucket, int is_bitmap) fd = hashp->fp; if (hashp->LORDER != BYTE_ORDER) { - int i; - int max; + int i, max; if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) M_32_SWAP(((int *)p)[i]); } else { - max = ((u_int16_t *)p)[0] + 2; + max = ((uint16_t *)p)[0] + 2; for (i = 0; i <= max; i++) - M_16_SWAP(((u_int16_t *)p)[i]); + M_16_SWAP(((uint16_t *)p)[i]); } } if (is_bucket) page = BUCKET_TO_PAGE(bucket); else page = OADDR_TO_PAGE(bucket); - if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || - ((wsize = _write(fd, p, size)) == -1)) + if ((wsize = pwrite(fd, p, size, (off_t)page << hashp->BSHIFT)) == -1) /* Errno is set */ return (-1); if (wsize != size) { @@ -603,13 +607,13 @@ __put_page(HTAB *hashp, char *p, u_int32_t bucket, int is_bucket, int is_bitmap) * Initialize a new bitmap page. Bitmap pages are left in memory * once they are read in. */ -extern int +int __ibitmap(HTAB *hashp, int pnum, int nbits, int ndx) { - u_int32_t *ip; + uint32_t *ip; int clearbytes, clearints; - if ((ip = (u_int32_t *)malloc(hashp->BSIZE)) == NULL) + if ((ip = (uint32_t *)malloc(hashp->BSIZE)) == NULL) return (1); hashp->nmaps++; clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1; @@ -619,15 +623,15 @@ __ibitmap(HTAB *hashp, int pnum, int nbits, int ndx) hashp->BSIZE - clearbytes); ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK); SETBIT(ip, 0); - hashp->BITMAPS[ndx] = (u_int16_t)pnum; + hashp->BITMAPS[ndx] = (uint16_t)pnum; hashp->mapp[ndx] = ip; return (0); } -static u_int32_t -first_free(u_int32_t map) +static uint32_t +first_free(uint32_t map) { - u_int32_t i, mask; + uint32_t i, mask; mask = 0x1; for (i = 0; i < BITS_PER_MAP; i++) { @@ -638,17 +642,16 @@ first_free(u_int32_t map) return (i); } -static u_int16_t +static uint16_t overflow_page(HTAB *hashp) { - u_int32_t *freep; + uint32_t *freep; int max_free, offset, splitnum; - u_int16_t addr; + uint16_t addr; int bit, first_page, free_bit, free_page, i, in_use_bits, j; #ifdef DEBUG2 int tmp1, tmp2; #endif - freep = NULL; splitnum = hashp->OVFL_POINT; max_free = hashp->SPARES[splitnum]; @@ -658,7 +661,7 @@ overflow_page(HTAB *hashp) /* Look through all the free maps to find the first free block */ first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT); for ( i = first_page; i <= free_page; i++ ) { - if (!(freep = (u_int32_t *)hashp->mapp[i]) && + if (!(freep = (uint32_t *)hashp->mapp[i]) && !(freep = fetch_bitmap(hashp, i))) return (0); if (i == free_page) @@ -690,6 +693,7 @@ overflow_page(HTAB *hashp) if (offset > SPLITMASK) { if (++splitnum >= NCACHED) { _write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); + errno = EFBIG; return (0); } hashp->OVFL_POINT = splitnum; @@ -703,6 +707,7 @@ overflow_page(HTAB *hashp) free_page++; if (free_page >= NCACHED) { _write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); + errno = EFBIG; return (0); } /* @@ -728,6 +733,7 @@ overflow_page(HTAB *hashp) if (++splitnum >= NCACHED) { _write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); + errno = EFBIG; return (0); } hashp->OVFL_POINT = splitnum; @@ -771,8 +777,11 @@ found: /* Calculate the split number for this page */ for (i = 0; (i < splitnum) && (bit > hashp->SPARES[i]); i++); offset = (i ? bit - hashp->SPARES[i - 1] : bit); - if (offset >= SPLITMASK) + if (offset >= SPLITMASK) { + _write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); + errno = EFBIG; return (0); /* Out of overflow pages */ + } addr = OADDR_OF(i, offset); #ifdef DEBUG2 fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", @@ -786,19 +795,19 @@ found: /* * Mark this overflow page as free. */ -extern void +void __free_ovflpage(HTAB *hashp, BUFHEAD *obufp) { - u_int16_t addr; - u_int32_t *freep; + uint16_t addr; + uint32_t *freep; int bit_address, free_page, free_bit; - u_int16_t ndx; + uint16_t ndx; addr = obufp->addr; #ifdef DEBUG1 fprintf(stderr, "Freeing %d\n", addr); #endif - ndx = (((u_int16_t)addr) >> SPLITSHIFT); + ndx = (((uint16_t)addr) >> SPLITSHIFT); bit_address = (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1; if (bit_address < hashp->LAST_FREED) @@ -863,10 +872,10 @@ open_temp(HTAB *hashp) * an overflow pair, so we need to shift things. */ static void -squeeze_key(u_int16_t *sp, const DBT *key, const DBT *val) +squeeze_key(uint16_t *sp, const DBT *key, const DBT *val) { char *p; - u_int16_t free_space, n, off, pageno; + uint16_t free_space, n, off, pageno; p = (char *)sp; n = sp[0]; @@ -887,12 +896,12 @@ squeeze_key(u_int16_t *sp, const DBT *key, const DBT *val) OFFSET(sp) = off; } -static u_int32_t * +static uint32_t * fetch_bitmap(HTAB *hashp, int ndx) { if (ndx >= hashp->nmaps) return (NULL); - if ((hashp->mapp[ndx] = (u_int32_t *)malloc(hashp->BSIZE)) == NULL) + if ((hashp->mapp[ndx] = (uint32_t *)malloc(hashp->BSIZE)) == NULL) return (NULL); if (__get_page(hashp, (char *)hashp->mapp[ndx], hashp->BITMAPS[ndx], 0, 1, 1)) { diff --git a/lib/libc/db/hash/ndbm.c b/lib/libc/db/hash/ndbm.c index 88a430343a..8c4f9b8079 100644 --- a/lib/libc/db/hash/ndbm.c +++ b/lib/libc/db/hash/ndbm.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)ndbm.c 8.4 (Berkeley) 7/21/94 - * $DragonFly: src/lib/libc/db/hash/ndbm.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/hash/ndbm.c 165903 2007-01-09 00:28:16Z imp $ */ /* @@ -52,8 +52,8 @@ * *DBM on success * NULL on failure */ -extern DBM * -dbm_open(const char *file, int flags, int mode) +DBM * +dbm_open(const char *file, int flags, mode_t mode) { HASHINFO info; char path[MAXPATHLEN]; @@ -74,7 +74,7 @@ dbm_open(const char *file, int flags, int mode) return ((DBM *)__hash_open(path, flags, mode, &info, 0)); } -extern void +void dbm_close(DBM *db) { (db->close)(db); @@ -85,7 +85,7 @@ dbm_close(DBM *db) * DATUM on success * NULL on failure */ -extern datum +datum dbm_fetch(DBM *db, datum key) { datum retdata; @@ -109,7 +109,7 @@ dbm_fetch(DBM *db, datum key) * DATUM on success * NULL on failure */ -extern datum +datum dbm_firstkey(DBM *db) { int status; @@ -129,7 +129,7 @@ dbm_firstkey(DBM *db) * DATUM on success * NULL on failure */ -extern datum +datum dbm_nextkey(DBM *db) { int status; @@ -149,7 +149,7 @@ dbm_nextkey(DBM *db) * 0 on success * <0 failure */ -extern int +int dbm_delete(DBM *db, datum key) { int status; @@ -170,7 +170,7 @@ dbm_delete(DBM *db, datum key) * <0 failure * 1 if DBM_INSERT and entry exists */ -extern int +int dbm_store(DBM *db, datum key, datum data, int flags) { DBT dbtkey, dbtdata; @@ -183,7 +183,7 @@ dbm_store(DBM *db, datum key, datum data, int flags) (flags == DBM_INSERT) ? R_NOOVERWRITE : 0)); } -extern int +int dbm_error(DBM *db) { HTAB *hp; @@ -192,7 +192,7 @@ dbm_error(DBM *db) return (hp->error); } -extern int +int dbm_clearerr(DBM *db) { HTAB *hp; @@ -202,7 +202,7 @@ dbm_clearerr(DBM *db) return (0); } -extern int +int dbm_dirfno(DBM *db) { return(((HTAB *)db->internal)->fp); diff --git a/lib/libc/db/hash/page.h b/lib/libc/db/hash/page.h index a2fc2db754..af0b7a0475 100644 --- a/lib/libc/db/hash/page.h +++ b/lib/libc/db/hash/page.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)page.h 8.2 (Berkeley) 5/31/94 - * $DragonFly: src/lib/libc/db/hash/page.h,v 1.2 2005/09/19 09:20:37 asmodai Exp $ + * $FreeBSD: head/lib/libc/db/hash/page.h 189327 2009-03-04 00:58:04Z delphij $ */ /* @@ -48,7 +48,7 @@ * +--------+---------------------+ * | F R E E A R E A | * +--------------+---------------+ - * | <---- - - - | data | + * | <---- - - - | data | * +--------+-----+----+----------+ * | key | data | key | * +--------+----------+----------+ @@ -70,20 +70,20 @@ * You might as well do this up front. */ -#define PAIRSIZE(K,D) (2*sizeof(u_int16_t) + (K)->size + (D)->size) -#define BIGOVERHEAD (4*sizeof(u_int16_t)) -#define KEYSIZE(K) (4*sizeof(u_int16_t) + (K)->size); -#define OVFLSIZE (2*sizeof(u_int16_t)) -#define FREESPACE(P) ((P)[(P)[0]+1]) +#define PAIRSIZE(K,D) (2*sizeof(uint16_t) + (K)->size + (D)->size) +#define BIGOVERHEAD (4*sizeof(uint16_t)) +#define KEYSIZE(K) (4*sizeof(uint16_t) + (K)->size); +#define OVFLSIZE (2*sizeof(uint16_t)) +#define FREESPACE(P) ((P)[(P)[0]+1]) #define OFFSET(P) ((P)[(P)[0]+2]) -#define PAIRFITS(P,K,D) \ +#define PAIRFITS(P,K,D) \ (((P)[2] >= REAL_KEY) && \ (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P))) -#define PAGE_META(N) (((N)+3) * sizeof(u_int16_t)) +#define PAGE_META(N) (((N)+3) * sizeof(uint16_t)) typedef struct { BUFHEAD *newp; BUFHEAD *oldp; BUFHEAD *nextp; - u_int16_t next_addr; -} SPLIT_RETURN; + uint16_t next_addr; +} SPLIT_RETURN; diff --git a/lib/libc/db/man/btree.3 b/lib/libc/db/man/btree.3 index d1c3624cf6..f8c36230e6 100644 --- a/lib/libc/db/man/btree.3 +++ b/lib/libc/db/man/btree.3 @@ -26,8 +26,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)btree.3 8.4 (Berkeley) 8/18/94 -.\" $FreeBSD: src/lib/libc/db/man/btree.3,v 1.3.2.3 2003/03/15 15:11:05 trhodes Exp $ -.\" $DragonFly: src/lib/libc/db/man/btree.3,v 1.5 2007/08/18 20:48:47 swildner Exp $ +.\" $FreeBSD: head/lib/libc/db/man/btree.3 165903 2007-01-09 00:28:16Z imp $ .\" .Dd August 18, 1994 .Dt BTREE 3 @@ -67,11 +66,11 @@ is defined in the include file as follows: .Bd -literal typedef struct { - u_long flags; - u_int cachesize; + unsigned long flags; + unsigned int cachesize; int maxkeypage; int minkeypage; - u_int psize; + unsigned int psize; int (*compare)(const DBT *key1, const DBT *key2); size_t (*prefix)(const DBT *key1, const DBT *key2); int lorder; @@ -86,7 +85,7 @@ The flag value is specified by any of the following values: .Bl -tag -width indent .It Dv R_DUP -Permit duplicate keys in the tree, i.e. permit insertion if the key to be +Permit duplicate keys in the tree, i.e., permit insertion if the key to be inserted already exists in the tree. The default behavior, as described in .Xr dbopen 3 , @@ -144,7 +143,7 @@ Not currently implemented. .It Va minkeypage The minimum number of keys which will be stored on any single page. This value is used to determine which keys will be stored on overflow -pages, i.e. if a key or data item is longer than the pagesize divided +pages, i.e., if a key or data item is longer than the pagesize divided by the minkeypage value, it will be stored on overflow pages instead of in the page itself. If diff --git a/lib/libc/db/man/dbm.3 b/lib/libc/db/man/dbm.3 index 3b2cb865eb..585e7e4b99 100644 --- a/lib/libc/db/man/dbm.3 +++ b/lib/libc/db/man/dbm.3 @@ -13,12 +13,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libc/db/man/dbm.3,v 1.2.2.5 2003/03/15 15:11:05 trhodes Exp $ -.\" $DragonFly: src/lib/libc/db/man/dbm.3,v 1.5 2008/05/10 18:22:41 swildner Exp $ +.\" $FreeBSD: head/lib/libc/db/man/dbm.3 187918 2009-01-30 15:28:35Z gabor $ .\" -.\" Note: The date here should be updated whenever a non-trivial -.\" change is made to the manual page. -.Dd July 7, 1999 +.Dd April 16, 2006 .Dt DBM 3 .Os .Sh NAME @@ -39,7 +36,7 @@ .In fcntl.h .In ndbm.h .Ft DBM * -.Fn dbm_open "const char *base" "int flags" "int mode" +.Fn dbm_open "const char *base" "int flags" "mode_t mode" .Ft void .Fn dbm_close "DBM *db" .Ft int @@ -127,10 +124,6 @@ The .Fn dbm_close db function closes the database. -The -.Fn dbm_close -function -normally returns zero. .Pp The .Fn dbm_store db key data flags diff --git a/lib/libc/db/man/dbopen.3 b/lib/libc/db/man/dbopen.3 index 7b46278edd..71437c54e4 100644 --- a/lib/libc/db/man/dbopen.3 +++ b/lib/libc/db/man/dbopen.3 @@ -26,10 +26,9 @@ .\" SUCH DAMAGE. .\" .\" @(#)dbopen.3 8.5 (Berkeley) 1/2/94 -.\" $FreeBSD: src/lib/libc/db/man/dbopen.3,v 1.3.2.3 2003/02/23 19:45:52 trhodes Exp $ -.\" $DragonFly: src/lib/libc/db/man/dbopen.3,v 1.7 2007/12/23 15:31:28 swildner Exp $ +.\" $FreeBSD: head/lib/libc/db/man/dbopen.3 212492 2010-09-12 14:04:05Z gjb $ .\" -.Dd September 19, 2005 +.Dd September 10, 2010 .Dt DBOPEN 3 .Os .Sh NAME @@ -83,8 +82,8 @@ arguments are as specified to the .Xr open 2 routine, however, only the -.Dv O_CREAT , O_EXCL , O_EXLOCK , O_NONBLOCK , -.Dv O_RDONLY , O_RDWR , O_SHLOCK +.Dv O_CREAT , O_EXCL , O_EXLOCK , O_NOFOLLOW , O_NONBLOCK , +.Dv O_RDONLY , O_RDWR , O_SHLOCK , O_SYNC and .Dv O_TRUNC flags are meaningful. @@ -99,7 +98,7 @@ is not possible.) .\".Bl -tag -width indent .\".It Dv DB_LOCK .\"Do the necessary locking in the database to support concurrent access. -.\"If concurrent access isn't needed or the database is read-only this +.\"If concurrent access is not needed or the database is read-only this .\"flag should not be set, as it tends to have an associated performance .\"penalty. .\".It Dv DB_SHMEM @@ -155,14 +154,14 @@ least the following fields: .Bd -literal typedef struct { DBTYPE type; - int (*close)(const DB *db); - int (*del)(const DB *db, const DBT *key, u_int flags); + int (*close)(DB *db); + int (*del)(const DB *db, const DBT *key, unsigned int flags); int (*fd)(const DB *db); - int (*get)(const DB *db, DBT *key, DBT *data, u_int flags); + int (*get)(const DB *db, const DBT *key, DBT *data, unsigned int flags); int (*put)(const DB *db, DBT *key, const DBT *data, - u_int flags); - int (*sync)(const DB *db, u_int flags); - int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags); + unsigned int flags); + int (*sync)(const DB *db, unsigned int flags); + int (*seq)(const DB *db, DBT *key, DBT *data, unsigned int flags); } DB; .Ed .Pp @@ -336,7 +335,7 @@ or .Va sync routines. Modifications to the database during a sequential scan will be reflected -in the scan, i.e. records inserted behind the cursor will not be returned +in the scan, i.e., records inserted behind the cursor will not be returned while records inserted in front of the cursor will be returned. .Pp The @@ -542,7 +541,7 @@ The typedef is a mnemonic for .Dq "data base thang" , and was used -because no one could think of a reasonable name that wasn't already used. +because no one could think of a reasonable name that was not already used. .Pp The file descriptor interface is a kluge and will be deleted in a future version of the interface. diff --git a/lib/libc/db/man/hash.3 b/lib/libc/db/man/hash.3 index de49d49595..0e0a5e6e99 100644 --- a/lib/libc/db/man/hash.3 +++ b/lib/libc/db/man/hash.3 @@ -26,8 +26,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)hash.3 8.6 (Berkeley) 8/18/94 -.\" $FreeBSD: src/lib/libc/db/man/hash.3,v 1.4.2.3 2003/02/23 19:45:52 trhodes Exp $ -.\" $DragonFly: src/lib/libc/db/man/hash.3,v 1.6 2007/08/18 20:48:47 swildner Exp $ +.\" $FreeBSD: head/lib/libc/db/man/hash.3 231564 2012-02-12 18:29:56Z ed $ .\" .Dd August 18, 1994 .Dt HASH 3 @@ -64,11 +63,11 @@ is defined in the include file as follows: .Bd -literal typedef struct { - u_int bsize; - u_int ffactor; - u_int nelem; - u_int cachesize; - u_int32_t (*hash)(const void *, size_t); + unsigned int bsize; + unsigned int ffactor; + unsigned int nelem; + unsigned int cachesize; + uint32_t (*hash)(const void *, size_t); int lorder; } HASHINFO; .Ed @@ -81,7 +80,7 @@ The element defines the .Nm -table bucket size, and is, by default, 256 bytes. +table bucket size, and is, by default, 4096 bytes. It may be preferable to increase the page size for disk-resident tables and tables with large data items. .It Va ffactor diff --git a/lib/libc/db/man/mpool.3 b/lib/libc/db/man/mpool.3 index 1605b7e08a..ebc0eaf037 100644 --- a/lib/libc/db/man/mpool.3 +++ b/lib/libc/db/man/mpool.3 @@ -26,10 +26,9 @@ .\" SUCH DAMAGE. .\" .\" @(#)mpool.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/db/man/mpool.3,v 1.5.2.5 2003/02/23 19:45:52 trhodes Exp $ -.\" $DragonFly: src/lib/libc/db/man/mpool.3,v 1.5 2007/08/18 20:48:47 swildner Exp $ +.\" $FreeBSD: head/lib/libc/db/man/mpool.3 223214 2011-06-18 00:10:21Z delphij $ .\" -.Dd June 4, 1993 +.Dd June 17, 2011 .Dt MPOOL 3 .Os .Sh NAME @@ -50,11 +49,13 @@ .Fa "void *pgcookie" .Fc .Ft void * -.Fn mpool_new "MPOOL *mp" "pgno_t *pgnoaddr" +.Fn mpool_new "MPOOL *mp" "pgno_t *pgnoaddr" "unsigned int flags" +.Ft int +.Fn mpool_delete "MPOOL *mp" "void *page" .Ft void * -.Fn mpool_get "MPOOL *mp" "pgno_t pgno" "u_int flags" +.Fn mpool_get "MPOOL *mp" "pgno_t pgno" "unsigned int flags" .Ft int -.Fn mpool_put "MPOOL *mp" "void *pgaddr" "u_int flags" +.Fn mpool_put "MPOOL *mp" "void *pgaddr" "unsigned int flags" .Ft int .Fn mpool_sync "MPOOL *mp" .Ft int @@ -64,32 +65,16 @@ The .Nm library interface is intended to provide page oriented buffer management of files. -The buffers may be shared between processes. .Pp The .Fn mpool_open function initializes a memory pool. The .Fa key -argument is the byte string used to negotiate between multiple -processes wishing to share buffers. -If the file buffers are mapped in shared memory, all processes using -the same key will share the buffers. -If -.Fa key -is -.Dv NULL , -the buffers are mapped into private memory. +argument is currently ignored. The .Fa fd argument is a file descriptor for the underlying file, which must be seekable. -If -.Fa key -is -.No non\- Ns Dv NULL -and matches a file already being mapped, the -.Fa fd -argument is ignored. .Pp The .Fa pagesize @@ -118,11 +103,11 @@ Both functions are called with the .Fa pgcookie pointer, the page number and a pointer to the page to being read or written. .Pp -The +The function .Fn mpool_new -function takes an -.Ft MPOOL -pointer and an address as arguments. +takes an +.Dv MPOOL +pointer, an address, and a set of flags as arguments. If a new page can be allocated, a pointer to the page is returned and the page number is stored into the .Fa pgnoaddr @@ -132,6 +117,24 @@ Otherwise, is returned and .Va errno is set. +The flags value is formed by +.Tn OR Ns 'ing +the following values: +.Bl -tag -width Ds +.It Dv MPOOL_PAGE_REQUEST +Allocate a new page with a specific page number. +.It Dv MPOOL_PAGE_NEXT +Allocate a new page with the next page number. +.El +.Pp +The function +.Fn mpool_delete +deletes the specified page from a pool and frees the page. +It takes an +.Dv MPOOL +pointer and a page as arguments. +The page must have been generated by +.Fn mpool_new . .Pp The .Fn mpool_get @@ -146,7 +149,14 @@ is returned and is set. The .Fa flags -argument is not currently used. +argument is specified by +.Em or Ns 'ing +any of the following values: +.Bl -tag -width indent +.It Dv MPOOL_IGNOREPIN +The page returned is not pinned; +page will otherwise be pinned on return. +.El .Pp The .Fn mpool_put @@ -211,7 +221,7 @@ function may fail and set for the following: .Bl -tag -width Er .It Bq Er EINVAL -The requested record doesn't exist. +The requested record does not exist. .El .Pp The diff --git a/lib/libc/db/man/recno.3 b/lib/libc/db/man/recno.3 index 5a2c3727d1..40ae09e6b7 100644 --- a/lib/libc/db/man/recno.3 +++ b/lib/libc/db/man/recno.3 @@ -26,8 +26,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)recno.3 8.5 (Berkeley) 8/18/94 -.\" $FreeBSD: src/lib/libc/db/man/recno.3,v 1.4.2.2 2001/12/14 18:33:49 ru Exp $ -.\" $DragonFly: src/lib/libc/db/man/recno.3,v 1.5 2007/08/18 20:48:47 swildner Exp $ +.\" $FreeBSD: head/lib/libc/db/man/recno.3 165903 2007-01-09 00:28:16Z imp $ .\" .Dd August 18, 1994 .Dt RECNO 3 @@ -69,12 +68,12 @@ is defined in the include file as follows: .Bd -literal typedef struct { - u_long flags; - u_int cachesize; - u_int psize; + unsigned long flags; + unsigned int cachesize; + unsigned int psize; int lorder; size_t reclen; - u_char bval; + unsigned char bval; char *bfname; } RECNOINFO; .Ed @@ -189,7 +188,7 @@ field of the key should be the size of that type. Because there can be no meta-data associated with the underlying .Nm access method files, any changes made to the default values -(e.g. fixed record length or byte separator value) must be explicitly +(e.g.\& fixed record length or byte separator value) must be explicitly specified each time the file is opened. .Pp In the interface specified by diff --git a/lib/libc/db/mpool/mpool.c b/lib/libc/db/mpool/mpool.c index 4de6b81179..e81692c331 100644 --- a/lib/libc/db/mpool/mpool.c +++ b/lib/libc/db/mpool/mpool.c @@ -26,10 +26,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/db/mpool/mpool.c,v 1.5.2.1 2001/03/05 23:05:01 obrien Exp $ - * $DragonFly: src/lib/libc/db/mpool/mpool.c,v 1.7 2005/11/19 20:46:32 swildner Exp $ - * - * @(#)mpool.c 8.5 (Berkeley) 7/26/94 + * @(#)mpool.c 8.7 (Berkeley) 11/2/95 + * $FreeBSD: head/lib/libc/db/mpool/mpool.c 194804 2009-06-24 01:15:10Z delphij $ */ #include "namespace.h" @@ -49,16 +47,17 @@ #define __MPOOLINTERFACE_PRIVATE #include -static BKT *mpool_bkt (MPOOL *); -static BKT *mpool_look (MPOOL *, pgno_t); -static int mpool_write (MPOOL *, BKT *); +static BKT *mpool_bkt(MPOOL *); +static BKT *mpool_look(MPOOL *, pgno_t); +static int mpool_write(MPOOL *, BKT *); /* * mpool_open -- * Initialize a memory pool. */ +/* ARGSUSED */ MPOOL * -mpool_open(void *key __unused, int fd, pgno_t pagesize, pgno_t maxcache) +mpool_open(void *key, int fd, pgno_t pagesize, pgno_t maxcache) { struct stat sb; MPOOL *mp; @@ -96,7 +95,7 @@ mpool_open(void *key __unused, int fd, pgno_t pagesize, pgno_t maxcache) */ void mpool_filter(MPOOL *mp, void (*pgin)(void *, pgno_t, void *), - void (*pgout)(void *, pgno_t, void *), void *pgcookie) + void (*pgout) (void *, pgno_t, void *), void *pgcookie) { mp->pgin = pgin; mp->pgout = pgout; @@ -108,7 +107,7 @@ mpool_filter(MPOOL *mp, void (*pgin)(void *, pgno_t, void *), * Get a new page of memory. */ void * -mpool_new(MPOOL *mp, pgno_t *pgnoaddr) +mpool_new(MPOOL *mp, pgno_t *pgnoaddr, unsigned int flags) { struct _hqh *head; BKT *bp; @@ -127,8 +126,13 @@ mpool_new(MPOOL *mp, pgno_t *pgnoaddr) */ if ((bp = mpool_bkt(mp)) == NULL) return (NULL); - *pgnoaddr = bp->pgno = mp->npages++; - bp->flags = MPOOL_PINNED; + if (flags == MPOOL_PAGE_REQUEST) { + mp->npages++; + bp->pgno = *pgnoaddr; + } else + bp->pgno = *pgnoaddr = mp->npages++; + + bp->flags = MPOOL_PINNED | MPOOL_INUSE; head = &mp->hqh[HASHKEY(bp->pgno)]; TAILQ_INSERT_HEAD(head, bp, hq); @@ -136,24 +140,46 @@ mpool_new(MPOOL *mp, pgno_t *pgnoaddr) return (bp->page); } +int +mpool_delete(MPOOL *mp, void *page) +{ + struct _hqh *head; + BKT *bp; + + bp = (BKT *)((char *)page - sizeof(BKT)); + +#ifdef DEBUG + if (!(bp->flags & MPOOL_PINNED)) { + fprintf(stderr, + "mpool_delete: page %d not pinned\n", bp->pgno); + abort(); + } +#endif + + /* Remove from the hash and lru queues. */ + head = &mp->hqh[HASHKEY(bp->pgno)]; + TAILQ_REMOVE(head, bp, hq); + TAILQ_REMOVE(&mp->lqh, bp, q); + + free(bp); + mp->curcache--; + return (RET_SUCCESS); +} + /* * mpool_get * Get a page. */ +/* ARGSUSED */ void * -mpool_get(MPOOL *mp, pgno_t pgno, u_int flags __unused) +mpool_get(MPOOL *mp, pgno_t pgno, + unsigned int flags) /* XXX not used? */ { struct _hqh *head; BKT *bp; off_t off; int nr; - /* Check for attempt to retrieve a non-existent page. */ - if (pgno >= mp->npages) { - errno = EINVAL; - return (NULL); - } - #ifdef STATISTICS ++mp->pageget; #endif @@ -161,7 +187,7 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int flags __unused) /* Check for a page that is cached. */ if ((bp = mpool_look(mp, pgno)) != NULL) { #ifdef DEBUG - if (bp->flags & MPOOL_PINNED) { + if (!(flags & MPOOL_IGNOREPIN) && bp->flags & MPOOL_PINNED) { fprintf(stderr, "mpool_get: page %d already pinned\n", bp->pgno); abort(); @@ -187,20 +213,38 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int flags __unused) return (NULL); /* Read in the contents. */ + off = mp->pagesize * pgno; + if ((nr = pread(mp->fd, bp->page, mp->pagesize, off)) != (ssize_t)mp->pagesize) { + switch (nr) { + case -1: + /* errno is set for us by pread(). */ + free(bp); + mp->curcache--; + return (NULL); + case 0: + /* + * A zero-length read means you need to create a + * new page. + */ + memset(bp->page, 0, mp->pagesize); + break; + default: + /* A partial read is definitely bad. */ + free(bp); + mp->curcache--; + errno = EINVAL; + return (NULL); + } + } #ifdef STATISTICS ++mp->pageread; #endif - off = mp->pagesize * pgno; - nr = pread(mp->fd, bp->page, mp->pagesize, off); - if (nr != mp->pagesize) { - if (nr >= 0) - errno = EFTYPE; - return (NULL); - } /* Set the page number, pin the page. */ bp->pgno = pgno; - bp->flags = MPOOL_PINNED; + if (!(flags & MPOOL_IGNOREPIN)) + bp->flags = MPOOL_PINNED; + bp->flags |= MPOOL_INUSE; /* * Add the page to the head of the hash chain and the tail @@ -221,8 +265,9 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int flags __unused) * mpool_put * Return a page. */ +/* ARGSUSED */ int -mpool_put(MPOOL *mp __unused, void *page, u_int flags) +mpool_put(MPOOL *mp, void *page, unsigned int flags) { BKT *bp; @@ -238,7 +283,8 @@ mpool_put(MPOOL *mp __unused, void *page, u_int flags) } #endif bp->flags &= ~MPOOL_PINNED; - bp->flags |= flags & MPOOL_DIRTY; + if (flags & MPOOL_DIRTY) + bp->flags |= flags & MPOOL_DIRTY; return (RET_SUCCESS); } @@ -322,6 +368,7 @@ mpool_bkt(MPOOL *mp) bp->page = spage; } #endif + bp->flags = 0; return (bp); } @@ -329,11 +376,9 @@ new: if ((bp = (BKT *)calloc(1, sizeof(BKT) + mp->pagesize)) == NULL) return (NULL); #ifdef STATISTICS ++mp->pagealloc; -#endif -#if defined(DEBUG) || defined(PURIFY) - memset(bp, 0xff, sizeof(BKT) + mp->pagesize); #endif bp->page = (char *)bp + sizeof(BKT); + bp->flags = 0; ++mp->curcache; return (bp); } @@ -356,9 +401,18 @@ mpool_write(MPOOL *mp, BKT *bp) (mp->pgout)(mp->pgcookie, bp->pgno, bp->page); off = mp->pagesize * bp->pgno; - if (pwrite(mp->fd, bp->page, mp->pagesize, off) != mp->pagesize) + if (pwrite(mp->fd, bp->page, mp->pagesize, off) != (ssize_t)mp->pagesize) return (RET_ERROR); + /* + * Re-run through the input filter since this page may soon be + * accessed via the cache, and whatever the user's output filter + * did may screw things up if we don't let the input filter + * restore the in-core copy. + */ + if (mp->pgin) + (mp->pgin)(mp->pgcookie, bp->pgno, bp->page); + bp->flags &= ~MPOOL_DIRTY; return (RET_SUCCESS); } @@ -375,7 +429,8 @@ mpool_look(MPOOL *mp, pgno_t pgno) head = &mp->hqh[HASHKEY(pgno)]; TAILQ_FOREACH(bp, head, hq) - if (bp->pgno == pgno) { + if ((bp->pgno == pgno) && + ((bp->flags & MPOOL_INUSE) == MPOOL_INUSE)) { #ifdef STATISTICS ++mp->cachehit; #endif @@ -399,9 +454,9 @@ mpool_stat(MPOOL *mp) int cnt; char *sep; - fprintf(stderr, "%u pages in the file\n", mp->npages); + fprintf(stderr, "%lu pages in the file\n", mp->npages); fprintf(stderr, - "page size %lu, caching %u pages of %u page max cache\n", + "page size %lu, caching %lu pages of %lu page max cache\n", mp->pagesize, mp->curcache, mp->maxcache); fprintf(stderr, "%lu page puts, %lu page gets, %lu page new\n", mp->pageput, mp->pageget, mp->pagenew); @@ -428,7 +483,6 @@ mpool_stat(MPOOL *mp) cnt = 0; } else sep = ", "; - } fprintf(stderr, "\n"); } diff --git a/lib/libc/db/mpool/mpool.libtp b/lib/libc/db/mpool/mpool.libtp index ce65296c69..e51a963ff6 100644 --- a/lib/libc/db/mpool/mpool.libtp +++ b/lib/libc/db/mpool/mpool.libtp @@ -1,7 +1,6 @@ /****************************************************************************** -VERSION $FreeBSD: src/lib/libc/db/mpool/mpool.libtp,v 1.4 1999/08/27 23:58:23 peter Exp $ -VERSION $DragonFly: src/lib/libc/db/mpool/mpool.libtp,v 1.2 2003/06/17 04:26:42 dillon Exp $ +VERSION $FreeBSD: head/lib/libc/db/mpool/mpool.libtp 50476 1999-08-28 00:22:10Z peter $ PACKAGE: User Level Shared Memory Manager DESCRIPTION: diff --git a/lib/libc/db/recno/Makefile.inc b/lib/libc/db/recno/Makefile.inc index f60bb2f380..c0d150bf3d 100644 --- a/lib/libc/db/recno/Makefile.inc +++ b/lib/libc/db/recno/Makefile.inc @@ -1,6 +1,5 @@ # from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $FreeBSD: src/lib/libc/db/recno/Makefile.inc,v 1.3 1999/08/27 23:58:25 peter Exp $ -# $DragonFly: src/lib/libc/db/recno/Makefile.inc,v 1.2 2003/06/17 04:26:42 dillon Exp $ +# $FreeBSD: head/lib/libc/db/recno/Makefile.inc 107052 2002-11-18 09:50:57Z ru $ .PATH: ${.CURDIR}/../libc/db/recno diff --git a/lib/libc/db/recno/extern.h b/lib/libc/db/recno/extern.h index 2dcc785efc..d2c0a37ba3 100644 --- a/lib/libc/db/recno/extern.h +++ b/lib/libc/db/recno/extern.h @@ -27,25 +27,25 @@ * SUCH DAMAGE. * * @(#)extern.h 8.3 (Berkeley) 6/4/94 - * $DragonFly: src/lib/libc/db/recno/extern.h,v 1.4 2005/09/19 09:20:37 asmodai Exp $ + * $FreeBSD: head/lib/libc/db/recno/extern.h 165903 2007-01-09 00:28:16Z imp $ */ #include "../btree/extern.h" -int __rec_close (DB *); -int __rec_delete (const DB *, const DBT *, u_int); -int __rec_dleaf (BTREE *, PAGE *, u_int32_t); -int __rec_fd (const DB *); -int __rec_fmap (BTREE *, recno_t); -int __rec_fout (BTREE *); -int __rec_fpipe (BTREE *, recno_t); -int __rec_get (const DB *, const DBT *, DBT *, u_int); -int __rec_iput (BTREE *, recno_t, const DBT *, u_int); -int __rec_put (const DB *dbp, DBT *, const DBT *, u_int); -int __rec_ret (BTREE *, EPG *, recno_t, DBT *, DBT *); -EPG *__rec_search (BTREE *, recno_t, enum SRCHOP); -int __rec_seq (const DB *, DBT *, DBT *, u_int); -int __rec_sync (const DB *, u_int); -int __rec_vmap (BTREE *, recno_t); -int __rec_vout (BTREE *); -int __rec_vpipe (BTREE *, recno_t); +int __rec_close(DB *); +int __rec_delete(const DB *, const DBT *, unsigned int); +int __rec_dleaf(BTREE *, PAGE *, uint32_t); +int __rec_fd(const DB *); +int __rec_fmap(BTREE *, recno_t); +int __rec_fout(BTREE *); +int __rec_fpipe(BTREE *, recno_t); +int __rec_get(const DB *, const DBT *, DBT *, unsigned int); +int __rec_iput(BTREE *, recno_t, const DBT *, unsigned int); +int __rec_put(const DB *dbp, DBT *, const DBT *, unsigned int); +int __rec_ret(BTREE *, EPG *, recno_t, DBT *, DBT *); +EPG *__rec_search(BTREE *, recno_t, enum SRCHOP); +int __rec_seq(const DB *, DBT *, DBT *, unsigned int); +int __rec_sync(const DB *, unsigned int); +int __rec_vmap(BTREE *, recno_t); +int __rec_vout(BTREE *); +int __rec_vpipe(BTREE *, recno_t); diff --git a/lib/libc/db/recno/rec_close.c b/lib/libc/db/recno/rec_close.c index 94290f68c1..ffd9214668 100644 --- a/lib/libc/db/recno/rec_close.c +++ b/lib/libc/db/recno/rec_close.c @@ -27,8 +27,7 @@ * SUCH DAMAGE. * * @(#)rec_close.c 8.6 (Berkeley) 8/18/94 - * $FreeBSD: src/lib/libc/db/recno/rec_close.c,v 1.4 2000/01/27 23:06:11 jasone Exp $ - * $DragonFly: src/lib/libc/db/recno/rec_close.c,v 1.6 2005/11/19 20:46:32 swildner Exp $ + * $FreeBSD: head/lib/libc/db/recno/rec_close.c 190484 2009-03-28 05:45:29Z delphij $ */ #include "namespace.h" @@ -80,9 +79,10 @@ __rec_close(DB *dbp) if (F_ISSET(t, R_CLOSEFP)) { if (fclose(t->bt_rfp)) status = RET_ERROR; - } else + } else { if (_close(t->bt_rfd)) status = RET_ERROR; + } } if (__bt_close(dbp) == RET_ERROR) @@ -101,7 +101,7 @@ __rec_close(DB *dbp) * RET_SUCCESS, RET_ERROR. */ int -__rec_sync(const DB *dbp, u_int flags) +__rec_sync(const DB *dbp, unsigned int flags) { struct iovec iov[2]; BTREE *t; @@ -147,19 +147,19 @@ __rec_sync(const DB *dbp, u_int flags) status = (dbp->seq)(dbp, &key, &data, R_FIRST); while (status == RET_SUCCESS) { if (_write(t->bt_rfd, data.data, data.size) != - data.size) + (ssize_t)data.size) return (RET_ERROR); status = (dbp->seq)(dbp, &key, &data, R_NEXT); } } else { - iov[1].iov_base = (char *)&t->bt_bval; + iov[1].iov_base = &t->bt_bval; iov[1].iov_len = 1; status = (dbp->seq)(dbp, &key, &data, R_FIRST); while (status == RET_SUCCESS) { iov[0].iov_base = data.data; iov[0].iov_len = data.size; - if (_writev(t->bt_rfd, iov, 2) != data.size + 1) + if (_writev(t->bt_rfd, iov, 2) != (ssize_t)(data.size + 1)) return (RET_ERROR); status = (dbp->seq)(dbp, &key, &data, R_NEXT); } diff --git a/lib/libc/db/recno/rec_delete.c b/lib/libc/db/recno/rec_delete.c index 4a224e3ece..ea2c764da0 100644 --- a/lib/libc/db/recno/rec_delete.c +++ b/lib/libc/db/recno/rec_delete.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)rec_delete.c 8.7 (Berkeley) 7/14/94 - * $DragonFly: src/lib/libc/db/recno/rec_delete.c,v 1.6 2005/11/19 20:46:32 swildner Exp $ + * $FreeBSD: head/lib/libc/db/recno/rec_delete.c 189292 2009-03-03 02:16:12Z delphij $ */ #include @@ -42,7 +42,7 @@ #include #include "recno.h" -static int rec_rdelete (BTREE *, recno_t); +static int rec_rdelete(BTREE *, recno_t); /* * __REC_DELETE -- Delete the item(s) referenced by a key. @@ -56,7 +56,7 @@ static int rec_rdelete (BTREE *, recno_t); * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. */ int -__rec_delete(const DB *dbp, const DBT *key, u_int flags) +__rec_delete(const DB *dbp, const DBT *key, unsigned int flags) { BTREE *t; recno_t nrec; @@ -141,11 +141,11 @@ rec_rdelete(BTREE *t, recno_t nrec) * RET_SUCCESS, RET_ERROR. */ int -__rec_dleaf(BTREE *t, PAGE *h, u_int32_t idx) +__rec_dleaf(BTREE *t, PAGE *h, uint32_t idx) { RLEAF *rl; indx_t *ip, cnt, offset; - u_int32_t nbytes; + uint32_t nbytes; char *from; void *to; diff --git a/lib/libc/db/recno/rec_get.c b/lib/libc/db/recno/rec_get.c index ea7c6da457..1eb22d51a0 100644 --- a/lib/libc/db/recno/rec_get.c +++ b/lib/libc/db/recno/rec_get.c @@ -27,8 +27,7 @@ * SUCH DAMAGE. * * @(#)rec_get.c 8.9 (Berkeley) 8/18/94 - * $FreeBSD: src/lib/libc/db/recno/rec_get.c,v 1.2.6.2 2001/01/02 09:11:10 obrien Exp $ - * $DragonFly: src/lib/libc/db/recno/rec_get.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/recno/rec_get.c 189387 2009-03-05 00:57:01Z delphij $ */ #include @@ -56,7 +55,7 @@ * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. */ int -__rec_get(const DB *dbp, const DBT *key, DBT *data, u_int flags) +__rec_get(const DB *dbp, const DBT *key, DBT *data, unsigned int flags) { BTREE *t; EPG *e; @@ -117,12 +116,10 @@ __rec_fpipe(BTREE *t, recno_t top) recno_t nrec; size_t len; int ch; - u_char *p; + unsigned char *p; if (t->bt_rdata.size < t->bt_reclen) { - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_reclen) : - reallocf(t->bt_rdata.data, t->bt_reclen); + t->bt_rdata.data = reallocf(t->bt_rdata.data, t->bt_reclen); if (t->bt_rdata.data == NULL) return (RET_ERROR); t->bt_rdata.size = t->bt_reclen; @@ -172,7 +169,7 @@ __rec_vpipe(BTREE *t, recno_t top) size_t len; size_t sz; int bval, ch; - u_char *p; + unsigned char *p; bval = t->bt_bval; for (nrec = t->bt_nrecs; nrec < top; ++nrec) { @@ -180,7 +177,8 @@ __rec_vpipe(BTREE *t, recno_t top) sz = t->bt_rdata.size;; *p++ = ch, --sz) { if ((ch = getc(t->bt_rfp)) == EOF || ch == bval) { data.data = t->bt_rdata.data; - data.size = p - (u_char *)t->bt_rdata.data; + data.size = p - + (unsigned char *)t->bt_rdata.data; if (ch == EOF && data.size == 0) break; if (__rec_iput(t, nrec, &data, 0) @@ -189,14 +187,13 @@ __rec_vpipe(BTREE *t, recno_t top) break; } if (sz == 0) { - len = p - (u_char *)t->bt_rdata.data; + len = p - (unsigned char *)t->bt_rdata.data; t->bt_rdata.size += (sz = 256); - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_rdata.size) : - reallocf(t->bt_rdata.data, t->bt_rdata.size); + t->bt_rdata.data = reallocf(t->bt_rdata.data, + t->bt_rdata.size); if (t->bt_rdata.data == NULL) return (RET_ERROR); - p = (u_char *)t->bt_rdata.data + len; + p = (unsigned char *)t->bt_rdata.data + len; } } if (ch == EOF) @@ -224,13 +221,11 @@ __rec_fmap(BTREE *t, recno_t top) { DBT data; recno_t nrec; - u_char *sp, *ep, *p; + unsigned char *sp, *ep, *p; size_t len; if (t->bt_rdata.size < t->bt_reclen) { - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_reclen) : - reallocf(t->bt_rdata.data, t->bt_reclen); + t->bt_rdata.data = reallocf(t->bt_rdata.data, t->bt_reclen); if (t->bt_rdata.data == NULL) return (RET_ERROR); t->bt_rdata.size = t->bt_reclen; @@ -238,8 +233,8 @@ __rec_fmap(BTREE *t, recno_t top) data.data = t->bt_rdata.data; data.size = t->bt_reclen; - sp = (u_char *)t->bt_cmap; - ep = (u_char *)t->bt_emap; + sp = (unsigned char *)t->bt_cmap; + ep = (unsigned char *)t->bt_emap; for (nrec = t->bt_nrecs; nrec < top; ++nrec) { if (sp >= ep) { F_SET(t, R_EOF); @@ -271,12 +266,12 @@ int __rec_vmap(BTREE *t, recno_t top) { DBT data; - u_char *sp, *ep; + unsigned char *sp, *ep; recno_t nrec; int bval; - sp = (u_char *)t->bt_cmap; - ep = (u_char *)t->bt_emap; + sp = (unsigned char *)t->bt_cmap; + ep = (unsigned char *)t->bt_emap; bval = t->bt_bval; for (nrec = t->bt_nrecs; nrec < top; ++nrec) { @@ -285,7 +280,7 @@ __rec_vmap(BTREE *t, recno_t top) return (RET_SPECIAL); } for (data.data = sp; sp < ep && *sp != bval; ++sp); - data.size = sp - (u_char *)data.data; + data.size = sp - (unsigned char *)data.data; if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS) return (RET_ERROR); ++sp; diff --git a/lib/libc/db/recno/rec_open.c b/lib/libc/db/recno/rec_open.c index e1421d5c66..3b8f8cb7ed 100644 --- a/lib/libc/db/recno/rec_open.c +++ b/lib/libc/db/recno/rec_open.c @@ -30,8 +30,7 @@ * SUCH DAMAGE. * * @(#)rec_open.c 8.10 (Berkeley) 9/1/94 - * $FreeBSD: src/lib/libc/db/recno/rec_open.c,v 1.4 2000/01/27 23:06:11 jasone Exp $ - * $DragonFly: src/lib/libc/db/recno/rec_open.c,v 1.6 2005/11/19 20:46:32 swildner Exp $ + * $FreeBSD: head/lib/libc/db/recno/rec_open.c 189327 2009-03-04 00:58:04Z delphij $ */ #include "namespace.h" @@ -51,8 +50,8 @@ #include "recno.h" DB * -__rec_open(const char *fname, int flags, int mode, const RECNOINFO *openinfo, - int dflags) +__rec_open(const char *fname, int flags, mode_t mode, const RECNOINFO *openinfo, + int dflags) { BTREE *t; BTREEINFO btopeninfo; @@ -61,8 +60,6 @@ __rec_open(const char *fname, int flags, int mode, const RECNOINFO *openinfo, struct stat sb; int rfd, sverrno; - rfd = 0; - /* Open the user's file -- if this fails, we're done. */ if (fname != NULL && (rfd = _open(fname, flags, mode)) < 0) return (NULL); @@ -203,7 +200,7 @@ slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) if (openinfo && openinfo->flags & R_SNAPSHOT && !F_ISSET(t, R_EOF | R_INMEM) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) - goto err; + goto err; return (dbp); einval: errno = EINVAL; diff --git a/lib/libc/db/recno/rec_put.c b/lib/libc/db/recno/rec_put.c index 2ce35c8e43..09d8f7da44 100644 --- a/lib/libc/db/recno/rec_put.c +++ b/lib/libc/db/recno/rec_put.c @@ -27,8 +27,7 @@ * SUCH DAMAGE. * * @(#)rec_put.c 8.7 (Berkeley) 8/18/94 - * $FreeBSD: src/lib/libc/db/recno/rec_put.c,v 1.4.6.1 2001/01/02 05:13:25 peter Exp $ - * $DragonFly: src/lib/libc/db/recno/rec_put.c,v 1.5 2005/11/19 20:46:32 swildner Exp $ + * $FreeBSD: head/lib/libc/db/recno/rec_put.c 190484 2009-03-28 05:45:29Z delphij $ */ #include @@ -55,7 +54,7 @@ * already in the tree and R_NOOVERWRITE specified. */ int -__rec_put(const DB *dbp, DBT *key, const DBT *data, u_int flags) +__rec_put(const DB *dbp, DBT *key, const DBT *data, unsigned int flags) { BTREE *t; DBT fdata, tdata; @@ -167,7 +166,7 @@ einval: errno = EINVAL; t->bt_cursor.rcursor = nrec; break; } - + F_SET(t, R_MODIFIED); return (__rec_ret(t, NULL, nrec, key, NULL)); } @@ -184,14 +183,14 @@ einval: errno = EINVAL; * RET_ERROR, RET_SUCCESS */ int -__rec_iput(BTREE *t, recno_t nrec, const DBT *data, u_int flags) +__rec_iput(BTREE *t, recno_t nrec, const DBT *data, unsigned int flags) { DBT tdata; EPG *e; PAGE *h; - indx_t curindex, nxtindex; + indx_t idx, nxtindex; pgno_t pg; - u_int32_t nbytes; + uint32_t nbytes; int dflags, status; char *dest, db[NOVFLSIZE]; @@ -207,7 +206,7 @@ __rec_iput(BTREE *t, recno_t nrec, const DBT *data, u_int flags) tdata.data = db; tdata.size = NOVFLSIZE; *(pgno_t *)db = pg; - *(u_int32_t *)(db + sizeof(pgno_t)) = data->size; + *(uint32_t *)(db + sizeof(pgno_t)) = data->size; dflags = P_BIGDATA; data = &tdata; } else @@ -220,7 +219,7 @@ __rec_iput(BTREE *t, recno_t nrec, const DBT *data, u_int flags) return (RET_ERROR); h = e->page; - curindex = e->index; + idx = e->index; /* * Add the specified key/data pair to the tree. The R_IAFTER and @@ -230,13 +229,13 @@ __rec_iput(BTREE *t, recno_t nrec, const DBT *data, u_int flags) */ switch (flags) { case R_IAFTER: - ++curindex; + ++idx; break; case R_IBEFORE: break; default: if (nrec < t->bt_nrecs && - __rec_dleaf(t, h, curindex) == RET_ERROR) { + __rec_dleaf(t, h, idx) == RET_ERROR) { mpool_put(t->bt_mp, h, 0); return (RET_ERROR); } @@ -249,19 +248,19 @@ __rec_iput(BTREE *t, recno_t nrec, const DBT *data, u_int flags) * the offset array, shift the pointers up. */ nbytes = NRLEAFDBT(data->size); - if (h->upper - h->lower < nbytes + sizeof(indx_t)) { - status = __bt_split(t, h, NULL, data, dflags, nbytes, curindex); + if ((uint32_t)(h->upper - h->lower) < nbytes + sizeof(indx_t)) { + status = __bt_split(t, h, NULL, data, dflags, nbytes, idx); if (status == RET_SUCCESS) ++t->bt_nrecs; return (status); } - if (curindex < (nxtindex = NEXTINDEX(h))) - memmove(h->linp + curindex + 1, h->linp + curindex, - (nxtindex - curindex) * sizeof(indx_t)); + if (idx < (nxtindex = NEXTINDEX(h))) + memmove(h->linp + idx + 1, h->linp + idx, + (nxtindex - idx) * sizeof(indx_t)); h->lower += sizeof(indx_t); - h->linp[curindex] = h->upper -= nbytes; + h->linp[idx] = h->upper -= nbytes; dest = (char *)h + h->upper; WR_RLEAF(dest, data, dflags); diff --git a/lib/libc/db/recno/rec_search.c b/lib/libc/db/recno/rec_search.c index 544316f429..8048a22af8 100644 --- a/lib/libc/db/recno/rec_search.c +++ b/lib/libc/db/recno/rec_search.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)rec_search.c 8.4 (Berkeley) 7/14/94 - * $DragonFly: src/lib/libc/db/recno/rec_search.c,v 1.5 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/recno/rec_search.c 189327 2009-03-04 00:58:04Z delphij $ */ #include @@ -44,7 +44,7 @@ * Parameters: * t: tree to search * recno: key to find - * op: search operation + * op: search operation * * Returns: * EPG for matching record, if any, or the EPG for the location of the @@ -58,7 +58,7 @@ EPG * __rec_search(BTREE *t, recno_t recno, enum SRCHOP op) { - indx_t index; + indx_t idx; PAGE *h; EPGNO *parent; RINTERNAL *r; @@ -76,23 +76,23 @@ __rec_search(BTREE *t, recno_t recno, enum SRCHOP op) t->bt_cur.index = recno - total; return (&t->bt_cur); } - for (index = 0, top = NEXTINDEX(h);;) { - r = GETRINTERNAL(h, index); - if (++index == top || total + r->nrecs > recno) + for (idx = 0, top = NEXTINDEX(h);;) { + r = GETRINTERNAL(h, idx); + if (++idx == top || total + r->nrecs > recno) break; total += r->nrecs; } - BT_PUSH(t, pg, index - 1); - + BT_PUSH(t, pg, idx - 1); + pg = r->pgno; switch (op) { case SDELETE: - --GETRINTERNAL(h, (index - 1))->nrecs; + --GETRINTERNAL(h, (idx - 1))->nrecs; mpool_put(t->bt_mp, h, MPOOL_DIRTY); break; case SINSERT: - ++GETRINTERNAL(h, (index - 1))->nrecs; + ++GETRINTERNAL(h, (idx - 1))->nrecs; mpool_put(t->bt_mp, h, MPOOL_DIRTY); break; case SEARCH: @@ -111,8 +111,8 @@ err: sverrno = errno; --GETRINTERNAL(h, parent->index)->nrecs; else ++GETRINTERNAL(h, parent->index)->nrecs; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - } + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + } errno = sverrno; return (NULL); } diff --git a/lib/libc/db/recno/rec_seq.c b/lib/libc/db/recno/rec_seq.c index 2732d656fc..9e8dc0b330 100644 --- a/lib/libc/db/recno/rec_seq.c +++ b/lib/libc/db/recno/rec_seq.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)rec_seq.c 8.3 (Berkeley) 7/14/94 - * $DragonFly: src/lib/libc/db/recno/rec_seq.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/recno/rec_seq.c 189327 2009-03-04 00:58:04Z delphij $ */ #include @@ -53,7 +53,7 @@ * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. */ int -__rec_seq(const DB *dbp, DBT *key, DBT *data, u_int flags) +__rec_seq(const DB *dbp, DBT *key, DBT *data, unsigned int flags) { BTREE *t; EPG *e; @@ -99,7 +99,7 @@ __rec_seq(const DB *dbp, DBT *key, DBT *data, u_int flags) einval: errno = EINVAL; return (RET_ERROR); } - + if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) { if (!F_ISSET(t, R_EOF | R_INMEM) && (status = t->bt_irec(t, nrec)) != RET_SUCCESS) diff --git a/lib/libc/db/recno/rec_utils.c b/lib/libc/db/recno/rec_utils.c index 2451dde955..5b3f25c63c 100644 --- a/lib/libc/db/recno/rec_utils.c +++ b/lib/libc/db/recno/rec_utils.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)rec_utils.c 8.6 (Berkeley) 7/16/94 - * $DragonFly: src/lib/libc/db/recno/rec_utils.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/recno/rec_utils.c 189387 2009-03-05 00:57:01Z delphij $ */ #include @@ -48,7 +48,7 @@ * e: key/data pair to be returned * nrec: record number * key: user's key structure - * data: user's data structure + * data: user's data structure * * Returns: * RET_SUCCESS, RET_ERROR. @@ -64,9 +64,7 @@ __rec_ret(BTREE *t, EPG *e, recno_t nrec, DBT *key, DBT *data) /* We have to copy the key, it's not on the page. */ if (sizeof(recno_t) > t->bt_rkey.size) { - p = (void *)(t->bt_rkey.data == NULL ? - malloc(sizeof(recno_t)) : - realloc(t->bt_rkey.data, sizeof(recno_t))); + p = realloc(t->bt_rkey.data, sizeof(recno_t)); if (p == NULL) return (RET_ERROR); t->bt_rkey.data = p; @@ -94,9 +92,7 @@ dataonly: } else if (F_ISSET(t, B_DB_LOCK)) { /* Use +1 in case the first record retrieved is 0 length. */ if (rl->dsize + 1 > t->bt_rdata.size) { - p = (void *)(t->bt_rdata.data == NULL ? - malloc(rl->dsize + 1) : - realloc(t->bt_rdata.data, rl->dsize + 1)); + p = realloc(t->bt_rdata.data, rl->dsize + 1); if (p == NULL) return (RET_ERROR); t->bt_rdata.data = p; diff --git a/lib/libc/db/recno/recno.h b/lib/libc/db/recno/recno.h index 761db00b2e..b845dc0bb1 100644 --- a/lib/libc/db/recno/recno.h +++ b/lib/libc/db/recno/recno.h @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)recno.h 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/db/recno/recno.h,v 1.2 2005/09/19 09:20:37 asmodai Exp $ + * $FreeBSD: head/lib/libc/db/recno/recno.h 165903 2007-01-09 00:28:16Z imp $ */ enum SRCHOP { SDELETE, SINSERT, SEARCH}; /* Rec_search operation. */ diff --git a/lib/libc/db/test/Makefile b/lib/libc/db/test/Makefile index 0d1db95c78..45a48b92df 100644 --- a/lib/libc/db/test/Makefile +++ b/lib/libc/db/test/Makefile @@ -1,4 +1,5 @@ # @(#)Makefile 8.15 (Berkeley) 7/28/94 +# $FreeBSD: head/lib/libc/db/test/Makefile 81118 2001-08-03 21:45:54Z bde $ PROG= dbtest OBJS= dbtest.o strerror.o diff --git a/lib/libc/db/test/btree.tests/main.c b/lib/libc/db/test/btree.tests/main.c index 3f2dfb8e47..3990747b31 100644 --- a/lib/libc/db/test/btree.tests/main.c +++ b/lib/libc/db/test/btree.tests/main.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)main.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/db/test/btree.tests/main.c,v 1.8 2008/07/10 18:29:51 swildner Exp $ + * $FreeBSD: head/lib/libc/db/test/btree.tests/main.c 176380 2008-02-18 03:19:25Z kevlo $ */ #include @@ -47,37 +47,37 @@ typedef struct cmd_table { char *cmd; int nargs; int rconv; - void (*func) (DB *, char **); + void (*func)(DB *, char **); char *usage, *descrip; } cmd_table; int stopstop; DB *globaldb; -void append (DB *, char **); -void bstat (DB *, char **); -void cursor (DB *, char **); -void delcur (DB *, char **); -void delete (DB *, char **); -void dump (DB *, char **); -void first (DB *, char **); -void get (DB *, char **); -void help (DB *, char **); -void iafter (DB *, char **); -void ibefore (DB *, char **); -void icursor (DB *, char **); -void insert (DB *, char **); -void keydata (DBT *, DBT *); -void last (DB *, char **); -void list (DB *, char **); -void load (DB *, char **); -void mstat (DB *, char **); -void next (DB *, char **); -int parse (char *, char **, int); -void previous (DB *, char **); -void show (DB *, char **); -void usage (void); -void user (DB *); +void append(DB *, char **); +void bstat(DB *, char **); +void cursor(DB *, char **); +void delcur(DB *, char **); +void delete(DB *, char **); +void dump(DB *, char **); +void first(DB *, char **); +void get(DB *, char **); +void help(DB *, char **); +void iafter(DB *, char **); +void ibefore(DB *, char **); +void icursor(DB *, char **); +void insert(DB *, char **); +void keydata(DBT *, DBT *); +void last(DB *, char **); +void list(DB *, char **); +void load(DB *, char **); +void mstat(DB *, char **); +void next(DB *, char **); +int parse(char *, char **, int); +void previous(DB *, char **); +void show(DB *, char **); +void usage(void); +void user(DB *); cmd_table commands[] = { "?", 0, 0, help, "help", NULL, diff --git a/lib/libc/db/test/dbtest.c b/lib/libc/db/test/dbtest.c index 5769324ebf..d0124b85d0 100644 --- a/lib/libc/db/test/dbtest.c +++ b/lib/libc/db/test/dbtest.c @@ -26,10 +26,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) Copyright (c) 1992, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)dbtest.c 8.17 (Berkeley) 9/1/94 - * $FreeBSD: src/lib/libc/db/test/dbtest.c,v 1.3.8.1 2000/08/21 22:44:47 jhb Exp $ - * $DragonFly: src/lib/libc/db/test/dbtest.c,v 1.8 2008/07/10 18:29:51 swildner Exp $ + * $FreeBSD: head/lib/libc/db/test/dbtest.c 176380 2008-02-18 03:19:25Z kevlo $ */ #include @@ -48,22 +46,22 @@ enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; -void compare (DBT *, DBT *); -DBTYPE dbtype (char *); -void dump (DB *, int); -void err (const char *, ...) __printflike(1, 2); -void get (DB *, DBT *); -void getdata (DB *, DBT *, DBT *); -void put (DB *, DBT *, DBT *); -void rem (DB *, DBT *); -char *sflags (int); -void synk (DB *); -void *rfile (char *, size_t *); -void seq (DB *, DBT *); -u_int setflags (char *); -void *setinfo (DBTYPE, char *); -void usage (void); -void *xmalloc (char *, size_t); +void compare(DBT *, DBT *); +DBTYPE dbtype(char *); +void dump(DB *, int); +void err(const char *, ...) __printflike(1, 2); +void get(DB *, DBT *); +void getdata(DB *, DBT *, DBT *); +void put(DB *, DBT *, DBT *); +void rem(DB *, DBT *); +char *sflags(int); +void synk(DB *); +void *rfile(char *, size_t *); +void seq(DB *, DBT *); +u_int setflags(char *); +void *setinfo(DBTYPE, char *); +void usage(void); +void *xmalloc(char *, size_t); DBTYPE type; /* Database type. */ void *infop; /* Iflags. */ @@ -536,7 +534,7 @@ sflags(int flags) return ("UNKNOWN!"); } - + DBTYPE dbtype(char *s) { @@ -695,6 +693,7 @@ void err(const char *fmt, ...) { va_list ap; + va_start(ap, fmt); fprintf(stderr, "dbtest: "); vfprintf(stderr, fmt, ap); diff --git a/lib/libc/db/test/hash.tests/driver2.c b/lib/libc/db/test/hash.tests/driver2.c index 24349cda46..bc9e61efcf 100644 --- a/lib/libc/db/test/hash.tests/driver2.c +++ b/lib/libc/db/test/hash.tests/driver2.c @@ -29,9 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. * @(#)driver2.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/db/test/hash.tests/driver2.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/test/hash.tests/driver2.c 165903 2007-01-09 00:28:16Z imp $ */ /* diff --git a/lib/libc/db/test/hash.tests/tcreat3.c b/lib/libc/db/test/hash.tests/tcreat3.c index fd0ec33e43..62cd8ad488 100644 --- a/lib/libc/db/test/hash.tests/tcreat3.c +++ b/lib/libc/db/test/hash.tests/tcreat3.c @@ -29,9 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. * @(#)tcreat3.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/db/test/hash.tests/tcreat3.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/test/hash.tests/tcreat3.c 165903 2007-01-09 00:28:16Z imp $ */ #include diff --git a/lib/libc/db/test/hash.tests/tdel.c b/lib/libc/db/test/hash.tests/tdel.c index 34eb81044a..0f020ca07f 100644 --- a/lib/libc/db/test/hash.tests/tdel.c +++ b/lib/libc/db/test/hash.tests/tdel.c @@ -29,9 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. * @(#)tdel.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/db/test/hash.tests/tdel.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/test/hash.tests/tdel.c 165903 2007-01-09 00:28:16Z imp $ */ #include diff --git a/lib/libc/db/test/hash.tests/thash4.c b/lib/libc/db/test/hash.tests/thash4.c index 8da90f6051..07a027bde2 100644 --- a/lib/libc/db/test/hash.tests/thash4.c +++ b/lib/libc/db/test/hash.tests/thash4.c @@ -29,9 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. * @(#)thash4.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/db/test/hash.tests/thash4.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/test/hash.tests/thash4.c 165903 2007-01-09 00:28:16Z imp $ */ #include diff --git a/lib/libc/db/test/hash.tests/tread2.c b/lib/libc/db/test/hash.tests/tread2.c index b2614c0e6b..50e3f587e2 100644 --- a/lib/libc/db/test/hash.tests/tread2.c +++ b/lib/libc/db/test/hash.tests/tread2.c @@ -29,9 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. * @(#)tread2.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/db/test/hash.tests/tread2.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/test/hash.tests/tread2.c 165903 2007-01-09 00:28:16Z imp $ */ #include diff --git a/lib/libc/db/test/hash.tests/tseq.c b/lib/libc/db/test/hash.tests/tseq.c index 0dc72a03be..92f671c3ad 100644 --- a/lib/libc/db/test/hash.tests/tseq.c +++ b/lib/libc/db/test/hash.tests/tseq.c @@ -29,9 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. * @(#)tseq.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/db/test/hash.tests/tseq.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/test/hash.tests/tseq.c 165903 2007-01-09 00:28:16Z imp $ */ #include diff --git a/lib/libc/db/test/hash.tests/tverify.c b/lib/libc/db/test/hash.tests/tverify.c index f4eec93057..8cda62cc11 100644 --- a/lib/libc/db/test/hash.tests/tverify.c +++ b/lib/libc/db/test/hash.tests/tverify.c @@ -29,9 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. * @(#)tverify.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/db/test/hash.tests/tverify.c,v 1.4 2005/11/12 23:01:55 swildner Exp $ + * $FreeBSD: head/lib/libc/db/test/hash.tests/tverify.c 165903 2007-01-09 00:28:16Z imp $ */ #include diff --git a/sys/sys/param.h b/sys/sys/param.h index eb3d5b20de..c1626ab26d 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -339,4 +339,10 @@ void panic (const char *, ...) __dead2 __printflike(1, 2); #define ntohs(x) __ntohs(x) #endif +/* + * Access a variable length array that has been declared as a fixed + * length array. + */ +#define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset]) + #endif /* _SYS_PARAM_H_ */ -- 2.41.0