This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
I'm adding a first patch for db30 support. I also need to update makedb.c but like to hear your comments before I continue. Andreas 2000-01-05 Andreas Jaeger <aj@suse.de> Add support for Berkeley db 3.0.x: * nss/nss_db/db-open.c (libdb_version): Add db30. (libdb_db_create): New variable. (load_db): Support db 3.0.x. (unload_db): Clear libdb_db_create. (internal_setent): Support db 3.0.x. * nss/nss_db/dummy-db.h (struct db30): New. (struct dbc30): New. Added DB30* flags. ============================================================ Index: nss/nss_db/dummy-db.h --- nss/nss_db/dummy-db.h 2000/01/04 17:48:37 1.3 +++ nss/nss_db/dummy-db.h 2000/01/05 09:06:42 @@ -173,3 +173,130 @@ #define DB27_FIRST 7 #define DB27_NEXT 15 #define DB27_NOOVERWRITE 17 + +/* Versions for 3.0, incompatible with version 2.x. */ +struct db30 +{ + size_t pgsize; + void (*db_feedback) (void *, int, int); + void *(*db_malloc) (size_t); + void *(*db_realloc) (void *, size_t); + int (*dup_compare) (const DBT *, const DBT *); + void *dbenv; + enum { dummy30 } type; + void *mpf; + void *mutexp; + u_int8_t fileid[20]; + int32_t log_fileid; + void *open_txn; + void *saved_open_fhp; + struct + { + void *tqh_first; + void **tqh_last; + } free_queue; + struct + { + void *tqh_first; + void **tqh_last; + } active_queue; + void *bt_internal; + void *cj_internal; + void *h_internal; + void *q_internal; + void *xa_internal; + /* Functions. */ + int (*close) (void *, uint32_t); + int (*cursor) (void *, void *, void **, uint32_t); + int (*del) (void *, void *, DBT *, uint32_t); + void (*err) (void *, int, const char *, ...); + void (*errx) (void *, const char *, ...); + int (*fd) (void *, int *); + int (*get) (void *, void *, DBT *, DBT *, uint32_t); + int (*get_byteswapped) (void *); + int (*get_type) (void *); + int (*join) (void *, void **, void **, uint32_t); + int (*open) (void *, const char *, const char *, int, uint32_t, int); + int (*put) (void *, void *, DBT *, DBT *, uint32_t); + int (*remove) (void *, const char *, const char *, uint32_t); + int (*set_cachesize) (void *, uint32_t, uint32_t, int); + int (*set_dup_compare) (void *, int (*)(const DBT *, const DBT *)); + void (*set_errcall) (void *, void (*)(const char *, char *)); + void (*set_errfile) (void *, void *); + void (*set_errpfx) (void *, const char *); + void (*set_feedback) (void *, void (*)(void *, int, int)); + int (*set_flags) (void *, uint32_t); + int (*set_lorder) (void *, int); + int (*set_malloc) (void *, void *(*)(size_t)); + int (*set_pagesize) (void *, uint32_t); + void (*set_paniccall) (void *, void (*)(void *, int)); + int (*set_realloc) (void *, void *(*)(void *, size_t)); + int (*stat) (void *, void *, void *(*)(size_t), uint32_t); + int (*sync) (void *, uint32_t); + int (*upgrade) (void *, const char *, uint32_t); + + int (*set_bt_compare) (void *, int (*)(const DBT *, const DBT *)); + int (*set_bt_maxkey) (void *, uint32_t); + int (*set_bt_minkey) (void *, uint32_t); + int (*set_bt_prefix) (void *, size_t (*)(const DBT *, const DBT *)); + + int (*set_h_ffactor) (void *, uint32_t); + int (*set_h_hash) (void *, uint32_t (*)(const void *, uint32_t)); + int (*set_h_nelem) (void *, uint32_t); + + int (*set_re_delim) (void *, int); + int (*set_re_len) (void *, uint32_t); + int (*set_re_pad) (void *, int); + int (*set_re_source) (void *, const char *); + + uint32_t am_ok; + uint32_t flags; +}; + + +struct dbc30 +{ + void *dbp; + void *txn; + struct + { + void *tqe_next; + void **tqe_prev; + } links; + uint32_t lid; /* Default process' locker id. */ + uint32_t locker; /* Locker for this operation. */ + DBT lock_dbt; /* DBT referencing lock. */ + struct + { + uint32_t pgno; + uint8_t fileid[20]; + } lock; + struct + { + size_t off; + uint32_t ndx; + uint32_t gen; + } mylock; + DBT rkey; + DBT rdata; + int (*c_close) (void *); + int (*c_del) (void *, uint32_t); + int (*c_dup) (void *, void **, uint32_t); + int (*c_get) (void *, DBT *, DBT *, uint32_t); + int (*c_put) (void *, DBT *, DBT *, uint32_t); + int (*c_am_close) (void *); + int (*c_am_destroy) (void *); + void *internal; + uint32_t flags; +}; + +/* Flags which changed. */ +#define DB30_TRUNCATE 0x020000 + +/* Access methods. */ +#define DB30_FIRST 9 +#define DB30_NEXT 17 +#define DB30_NOOVERWRITE 20 + +/* Permission flags are changed. */ +#define DB30_RDONLY 0x000010 ============================================================ Index: nss/nss_db/db-open.c --- nss/nss_db/db-open.c 2000/01/04 17:48:26 1.3 +++ nss/nss_db/db-open.c 2000/01/05 09:06:43 @@ -41,30 +41,42 @@ enum { nodb, db24, - db27 + db27, + db30 } libdb_version; static int (*libdb_db_open) (const char *, int, uint32_t, int, void *, void *, void **); +static int (*libdb_db_create) (void *, void *, uint32_t); + /* Locks the static variables in this file. */ __libc_lock_define_initialized (static, lock) /* Dynamically load the database library. - We try libdb2.so.3, maybe others in the future. */ + We try currently: + - libdb.so.3: the name used by glibc 2.1 + - libdb-3.0.so: the name used by db-3.0.x + and maybe others in the future. */ static int load_db (void) { - static const char *libnames[] = { "libdb.so.3" }; + static const char *libnames[] = { "libdb.so.3", "libdb-3.0.so" }; int x; - - for(x = 0; x < sizeof (libnames) / sizeof (libnames[0]); ++x) + + for (x = 0; x < sizeof (libnames) / sizeof (libnames[0]); ++x) { libdb_handle = dlopen (libnames[x], RTLD_LAZY); if (libdb_handle == NULL) continue; - libdb_db_open = dlsym (libdb_handle, "db_open"); - if (libdb_db_open != NULL) + /* db 3.0 has db_create instead of db_open. */ + libdb_db_create = dlsym (libdb_handle, "db_create"); + + if (libdb_db_create == NULL) + /* db 2.x uses db_open. */ + libdb_db_open = dlsym (libdb_handle, "db_open"); + + if (libdb_db_open != NULL || libdb_db_create != NULL) { /* Alright, we got a library. Now find out which version it is. */ const char *(*db_version) (int *, int *, int *); @@ -76,19 +88,34 @@ int major, minor, subminor; DL_CALL_FCT (db_version, (&major, &minor, &subminor)); - if (major == 2) + switch (major) { - /* We currently cannot handle other versions than the - 2.x series. */ - if (minor < 6 || (minor == 6 && subminor < 4)) - libdb_version = db24; - else - libdb_version = db27; + case 2: + /* Sanity check: Do we have db_open? */ + if (libdb_db_open != NULL) + { + if (minor < 6 || (minor == 6 && subminor < 4)) + libdb_version = db24; + else + libdb_version = db27; + } + break; + case 3: + /* Sanity check: Do we have db_create? */ + if (libdb_db_create != NULL) + libdb_version = db30; + break; + default: + break; } } if (libdb_version != nodb) return 0; + + /* Clear variables. */ + libdb_db_open = NULL; + libdb_db_create = NULL; } dlclose (libdb_handle); @@ -106,6 +133,7 @@ if (libdb_handle != NULL) { libdb_db_open = NULL; + libdb_db_create = NULL; libdb_version = nodb; dlclose (libdb_handle); } @@ -124,7 +152,7 @@ if (*dbp == NULL) { - if (libdb_db_open == NULL) + if (libdb_db_open == NULL && libdb_db_create == NULL) { __libc_lock_lock (lock); @@ -135,17 +163,39 @@ if (err != 0) return NSS_STATUS_UNAVAIL; } - - /* Open the database. Fortunately this interface seems to be the - same for all supported versions. */ - err = DL_CALL_FCT (libdb_db_open, - (file, DB_BTREE, DB_RDONLY, 0, NULL, NULL, &db)); - if (err != 0) + /* Open the database. */ + switch (libdb_version) { - __set_errno (err); - *dbp = NULL; - return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; + case db24: + case db27: + err = DL_CALL_FCT (libdb_db_open, + (file, DB_BTREE, DB_RDONLY, 0, NULL, NULL, &db)); + if (err != 0) + { + __set_errno (err); + return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; + } + break; + case db30: + err = DL_CALL_FCT (libdb_db_create, (&db, NULL, 0)); + if (err != 0) + { + __set_errno (err); + return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; + } + err = ((struct db30 *) db)->open (db, file, NULL, DB_BTREE, + DB30_RDONLY, 0); + if (err != 0) + { + __set_errno (err); + /* Free all resources. */ + ((struct db30 *) db)->close (db, 0); + return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; + } + break; + default: + abort (); } /* Construct the object we pass up. */ @@ -176,6 +226,15 @@ (*dbp)->get = (int (*) (void *, void *, void *, void *, uint32_t)) ((struct db27 *) db)->get; + break; + case db30: + (*dbp)->close = + (int (*) (void *, uint32_t)) ((struct db30 *) db)->close; + (*dbp)->fd = + (int (*) (void *, int *)) ((struct db30 *) db)->fd; + (*dbp)->get = + (int (*) (void *, void *, void *, void *, uint32_t)) + ((struct db30 *) db)->get; break; default: abort (); -- Andreas Jaeger SuSE Labs aj@suse.de private aj@arthur.rhein-neckar.de
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |