2007-09-04 21:01:41 +00:00
|
|
|
/* Make a db.h that will be link-time compatible with Sleepycat's Berkeley DB. */
|
|
|
|
|
2007-09-05 17:47:14 +00:00
|
|
|
#include <db.h>
|
2007-09-04 21:01:41 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2007-09-04 21:18:09 +00:00
|
|
|
#include <assert.h>
|
2007-09-04 21:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define DECL_LIMIT 100
|
|
|
|
#define FIELD_LIMIT 100
|
|
|
|
struct fieldinfo {
|
|
|
|
char decl[DECL_LIMIT];
|
|
|
|
unsigned int off;
|
|
|
|
unsigned int size;
|
2007-09-05 17:40:16 +00:00
|
|
|
} fields[FIELD_LIMIT];
|
|
|
|
int field_counter=0;
|
2007-09-04 21:01:41 +00:00
|
|
|
|
|
|
|
int compare_fields (const void *av, const void *bv) {
|
|
|
|
const struct fieldinfo *a = av;
|
|
|
|
const struct fieldinfo *b = bv;
|
|
|
|
if (a->off < b->off) return -1;
|
|
|
|
if (a->off > b->off) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-05 17:40:16 +00:00
|
|
|
#define STRUCT_SETUP(typ, name, fstring) ({ snprintf(fields[field_counter].decl, DECL_LIMIT, fstring, #name); \
|
|
|
|
fields[field_counter].off = __builtin_offsetof(typ, name); \
|
|
|
|
{ typ dummy; \
|
|
|
|
fields[field_counter].size = sizeof(dummy.name); } \
|
|
|
|
field_counter++; })
|
2007-09-04 21:01:41 +00:00
|
|
|
|
2007-09-04 21:18:09 +00:00
|
|
|
FILE *outf;
|
|
|
|
void open_file (void) {
|
|
|
|
char fname[100];
|
2007-09-06 14:18:08 +00:00
|
|
|
#ifdef LOCAL
|
|
|
|
snprintf(fname, 100, "sample_offsets_local.h");
|
|
|
|
#else
|
2007-09-04 21:18:09 +00:00
|
|
|
snprintf(fname, 100, "sample_offsets_%d.h", __WORDSIZE);
|
2007-09-06 14:18:08 +00:00
|
|
|
#endif
|
2007-09-04 21:18:09 +00:00
|
|
|
outf = fopen(fname, "w");
|
|
|
|
assert(outf);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-05 18:59:12 +00:00
|
|
|
void sort_and_dump_fields (const char *structname, unsigned int sizeofstruct) {
|
2007-09-04 21:01:41 +00:00
|
|
|
int i;
|
2007-09-05 17:40:16 +00:00
|
|
|
qsort(fields, field_counter, sizeof(fields[0]), compare_fields);
|
|
|
|
fprintf(outf, "struct fieldinfo %s_fields%d[] = {\n", structname, __WORDSIZE);
|
|
|
|
for (i=0; i<field_counter; i++) {
|
2007-09-05 18:59:12 +00:00
|
|
|
fprintf(outf, " {\"%s\", %d, %d},\n", fields[i].decl, fields[i].off, fields[i].size);
|
2007-09-04 21:01:41 +00:00
|
|
|
}
|
2007-09-05 19:20:25 +00:00
|
|
|
fprintf(outf, " {0, %d, %d} /* size of whole struct */\n", sizeofstruct, sizeofstruct);
|
2007-09-04 21:18:09 +00:00
|
|
|
fprintf(outf, "};\n");
|
2007-09-04 21:01:41 +00:00
|
|
|
}
|
2007-09-05 17:40:16 +00:00
|
|
|
|
2007-09-05 20:26:46 +00:00
|
|
|
void sample_db_btree_stat_offsets (void) {
|
2007-09-05 19:11:52 +00:00
|
|
|
field_counter=0;
|
2007-09-05 20:26:46 +00:00
|
|
|
STRUCT_SETUP(DB_BTREE_STAT, bt_ndata, "u_int32_t %s");
|
|
|
|
STRUCT_SETUP(DB_BTREE_STAT, bt_nkeys, "u_int32_t %s");
|
|
|
|
sort_and_dump_fields("db_btree_stat", sizeof(DB_BTREE_STAT));
|
2007-09-05 19:11:52 +00:00
|
|
|
}
|
|
|
|
|
2007-09-05 19:16:43 +00:00
|
|
|
void sample_db_env_offsets (void) {
|
|
|
|
field_counter=0;
|
|
|
|
STRUCT_SETUP(DB_ENV, close, "int (*%s) (DB_ENV *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB_ENV, err, "void (*%s) (const DB_ENV *, int, const char *, ...)");
|
|
|
|
STRUCT_SETUP(DB_ENV, log_archive, "int (*%s) (DB_ENV *, char **[], u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB_ENV, log_flush, "int (*%s) (DB_ENV *, const DB_LSN *)");
|
|
|
|
STRUCT_SETUP(DB_ENV, open, "int (*%s) (DB_ENV *, const char *, u_int32_t, int)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_cachesize, "int (*%s) (DB_ENV *, u_int32_t, u_int32_t, int)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_data_dir, "int (*%s) (DB_ENV *, const char *)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_errcall, "void (*%s) (DB_ENV *, void (*)(const char *, char *))");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_errpfx, "void (*%s) (DB_ENV *, const char *)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_flags, "int (*%s) (DB_ENV *, u_int32_t, int)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_lg_bsize, "int (*%s) (DB_ENV *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_lg_dir, "int (*%s) (DB_ENV *, const char *)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_lg_max, "int (*%s) (DB_ENV *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_lk_detect, "int (*%s) (DB_ENV *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_lk_max, "int (*%s) (DB_ENV *, u_int32_t)");
|
2007-10-09 21:48:48 +00:00
|
|
|
//STRUCT_SETUP(DB_ENV, set_noticecall, "void (*%s) (DB_ENV *, void (*)(DB_ENV *, db_notices))");
|
2007-09-05 19:16:43 +00:00
|
|
|
STRUCT_SETUP(DB_ENV, set_tmp_dir, "int (*%s) (DB_ENV *, const char *)");
|
|
|
|
STRUCT_SETUP(DB_ENV, set_verbose, "int (*%s) (DB_ENV *, u_int32_t, int)");
|
|
|
|
STRUCT_SETUP(DB_ENV, txn_checkpoint, "int (*%s) (DB_ENV *, u_int32_t, u_int32_t, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB_ENV, txn_stat, "int (*%s) (DB_ENV *, DB_TXN_STAT **, u_int32_t)");
|
2007-09-05 20:16:26 +00:00
|
|
|
STRUCT_SETUP(DB_ENV, txn_begin, "int (*%s) (DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t)");
|
2007-09-05 19:16:43 +00:00
|
|
|
sort_and_dump_fields("db_env", sizeof(DB_ENV));
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:16:26 +00:00
|
|
|
void sample_db_key_range_offsets (void) {
|
|
|
|
field_counter=0;
|
|
|
|
STRUCT_SETUP(DB_KEY_RANGE, less, "double %s");
|
|
|
|
STRUCT_SETUP(DB_KEY_RANGE, equal, "double %s");
|
|
|
|
STRUCT_SETUP(DB_KEY_RANGE, greater, "double %s");
|
|
|
|
sort_and_dump_fields("db_key_range", sizeof(DB_ENV));
|
|
|
|
}
|
2007-09-05 19:11:52 +00:00
|
|
|
|
2007-09-05 20:16:26 +00:00
|
|
|
void sample_db_lsn_offsets (void) {
|
|
|
|
field_counter=0;
|
|
|
|
sort_and_dump_fields("db_lsn", sizeof(DB_LSN));
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:26:46 +00:00
|
|
|
void sample_db_offsets (void) {
|
|
|
|
/* Do these in alphabetical order. */
|
|
|
|
field_counter=0;
|
|
|
|
STRUCT_SETUP(DB,app_private, "void *%s");
|
|
|
|
STRUCT_SETUP(DB,close, "int (*%s) (DB*, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB,cursor, "int (*%s) (DB *, DB_TXN *, DBC **, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB,del, "int (*%s) (DB *, DB_TXN *, DBT *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB,get, "int (*%s) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB,key_range, "int (*%s) (DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB,open, "int (*%s) (DB *, DB_TXN *, const char *, const char *, DBTYPE, u_int32_t, int)");
|
|
|
|
STRUCT_SETUP(DB,put, "int (*%s) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB,remove, "int (*%s) (DB *, const char *, const char *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB,rename, "int (*%s) (DB *, const char *, const char *, const char *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB,set_bt_compare, "int (*%s) (DB *, int (*)(DB *, const DBT *, const DBT *))");
|
|
|
|
STRUCT_SETUP(DB,set_flags, "int (*%s) (DB *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB,stat, "int (*%s) (DB *, void *, u_int32_t)");
|
|
|
|
sort_and_dump_fields("db", sizeof(DB));
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:16:26 +00:00
|
|
|
void sample_db_txn_active_offsets (void) {
|
|
|
|
field_counter=0;
|
|
|
|
STRUCT_SETUP(DB_TXN_ACTIVE, lsn, "DB_LSN %s");
|
|
|
|
STRUCT_SETUP(DB_TXN_ACTIVE, txnid, "u_int32_t %s");
|
|
|
|
sort_and_dump_fields("db_txn_active", sizeof(DB_TXN_ACTIVE));
|
|
|
|
}
|
2007-09-05 19:11:52 +00:00
|
|
|
|
2007-09-05 20:26:46 +00:00
|
|
|
void sample_db_txn_offsets (void) {
|
|
|
|
field_counter=0;
|
|
|
|
STRUCT_SETUP(DB_TXN, commit, "int (*%s) (DB_TXN*, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DB_TXN, id, "u_int32_t (*%s) (DB_TXN *)");
|
2007-10-09 22:24:25 +00:00
|
|
|
STRUCT_SETUP(DB_TXN, abort, "int (*%s) (DB_TXN *)");
|
2007-09-05 20:26:46 +00:00
|
|
|
sort_and_dump_fields("db_txn", sizeof(DB_TXN));
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:24:17 +00:00
|
|
|
void sample_db_txn_stat_offsets (void) {
|
|
|
|
field_counter=0;
|
|
|
|
STRUCT_SETUP(DB_TXN_STAT, st_nactive, "u_int32_t %s");
|
|
|
|
STRUCT_SETUP(DB_TXN_STAT, st_txnarray, "DB_TXN_ACTIVE *%s");
|
|
|
|
sort_and_dump_fields("db_txn_stat", sizeof(DB_TXN_STAT));
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:26:46 +00:00
|
|
|
void sample_dbc_offsets (void) {
|
2007-09-05 20:24:17 +00:00
|
|
|
field_counter=0;
|
2007-09-05 20:26:46 +00:00
|
|
|
STRUCT_SETUP(DBC, c_close, "int (*%s) (DBC *)");
|
|
|
|
STRUCT_SETUP(DBC, c_del, "int (*%s) (DBC *, u_int32_t)");
|
|
|
|
STRUCT_SETUP(DBC, c_get, "int (*%s) (DBC *, DBT *, DBT *, u_int32_t)");
|
|
|
|
sort_and_dump_fields("dbc", sizeof(DBC));
|
2007-09-05 20:24:17 +00:00
|
|
|
}
|
2007-09-05 20:26:46 +00:00
|
|
|
|
|
|
|
void sample_dbt_offsets (void) {
|
|
|
|
field_counter=0;
|
2007-10-09 21:48:48 +00:00
|
|
|
//STRUCT_SETUP(DBT,app_private, "void*%s");
|
2007-09-05 20:26:46 +00:00
|
|
|
STRUCT_SETUP(DBT,data, "void*%s");
|
|
|
|
STRUCT_SETUP(DBT,flags, "u_int32_t %s");
|
|
|
|
STRUCT_SETUP(DBT,size, "u_int32_t %s");
|
|
|
|
STRUCT_SETUP(DBT,ulen, "u_int32_t %s");
|
|
|
|
sort_and_dump_fields("dbt", sizeof(DBT));
|
|
|
|
}
|
|
|
|
|
2007-09-04 21:01:41 +00:00
|
|
|
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
|
2007-09-04 21:18:09 +00:00
|
|
|
open_file();
|
|
|
|
fprintf(outf, "/* BDB offsets on a %d-bit machine */\n", __WORDSIZE);
|
2007-10-09 21:48:48 +00:00
|
|
|
fprintf(outf, "#define DB_VERSION_MAJOR_%d %d\n", __WORDSIZE, DB_VERSION_MAJOR);
|
|
|
|
fprintf(outf, "#define DB_VERSION_MINOR_%d %d\n", __WORDSIZE, DB_VERSION_MINOR);
|
|
|
|
fprintf(outf, "#define DB_VERSION_STRING_%d \"Berkeley DB Compatability Header %d.%d\"\n", __WORDSIZE, DB_VERSION_MAJOR, DB_VERSION_MINOR);
|
2007-09-05 20:24:17 +00:00
|
|
|
sample_db_btree_stat_offsets();
|
2007-09-05 19:16:43 +00:00
|
|
|
sample_db_env_offsets();
|
2007-09-05 20:16:26 +00:00
|
|
|
sample_db_key_range_offsets();
|
|
|
|
sample_db_lsn_offsets();
|
2007-09-05 20:24:17 +00:00
|
|
|
sample_db_offsets();
|
2007-09-05 20:16:26 +00:00
|
|
|
sample_db_txn_active_offsets();
|
2007-09-05 20:24:17 +00:00
|
|
|
sample_db_txn_offsets();
|
|
|
|
sample_db_txn_stat_offsets();
|
|
|
|
sample_dbc_offsets();
|
|
|
|
sample_dbt_offsets();
|
2007-09-04 21:01:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|