--- linux-2.4.9/drivers/scsi/aic7xxx/aicasm/Makefile Fri May 4 15:16:28 2001 +++ linux/drivers/scsi/aic7xxx/aicasm/Makefile Thu Aug 16 21:02:33 2001 @@ -5,10 +5,20 @@ DEPHDRS= aicdb.h GENHDRS= y.tab.h aicdb.h +# Comment out the next line to use your system's local Berkeley DB functions. +CONFIG_AICASM_TRIVIALDB=y +ifeq ($(CONFIG_AICASM_TRIVIALDB),y) + HAVE_TRIVIALDB=true + GENSRCS += trivialdb.c +else + HAVE_TRIVIALDB=false + AICASM_DB=-ldb +endif + SRCS= ${GENSRCS} ${CSRCS} CLEANFILES= ${GENSRCS} ${GENHDRS} y.output # Override default kernel CFLAGS. This is a userland app. -AICASM_CFLAGS:= -I/usr/include -I. -ldb +AICASM_CFLAGS:= -I/usr/include -I. $(AICASM_DB) YFLAGS= -d NOMAN= noman @@ -31,7 +41,9 @@ $(AICASM_CC) $(AICASM_CFLAGS) $(SRCS) -o $(PROG) aicdb.h: - @if [ -e "/usr/include/db3/db_185.h" ]; then \ + if $(HAVE_TRIVIALDB) ; then \ + echo "#include \"trivialdb.h\"" > aicdb.h; \ + elif [ -e "/usr/include/db3/db_185.h" ]; then \ echo "#include " > aicdb.h; \ elif [ -e "/usr/include/db2/db_185.h" ]; then \ echo "#include " > aicdb.h; \ @@ -45,3 +57,4 @@ clean: rm -f $(CLEANFILES) $(PROG) + --- linux-2.4.9/drivers/scsi/aic7xxx/aicasm/trivialdb.h Thu Aug 16 20:56:40 2001 +++ linux/drivers/scsi/aic7xxx/aicasm/trivialdb.h Thu Aug 16 21:05:38 2001 @@ -0,0 +1,64 @@ +/* A trivial implemention of the "BerkeleyDB" database routines + used by aicasm. + + Copyright 2001 Yggdrasil Computing, Inc. + Written by Adam J. Richter . + + This file may be freely redistributed under the terms and conditions + of version 2 of the GNU General Public License, as publisehd by the + Free Software Foundation (Cambridge, Massachusetts). +*/ + +#ifndef TRIVIALDB_H +#define TRIVIALDB_H + +typedef struct { + void *data; + int size; +} DBT; + +enum seqtype { + R_FIRST=1, + R_NEXT, +}; + +enum db_result { + DB_SYSERROR=-1, + DB_OK=0, + DB_NOTFOUND=1, +}; + +enum db_opentype { DB_HASH }; /* not used */ + +struct dbchain; /* private */ + +typedef struct DB { + enum db_result (*get)(struct DB *db, + DBT *key, + DBT *data, + int flags); + + enum db_result (*put)(struct DB *db, + DBT *key, + DBT *data, + int flags); + + void (*del)(struct DB *db, + DBT *key, + int flags /* ignored */); + + enum db_result (*seq)(struct DB *db, + DBT *key, + DBT *data, + enum seqtype order); + + void (*close)(struct DB *db); + struct dbchain *chain; /* private */ + struct dbchain *seqnext; /* private */ +} DB; + +/* All parameters are ignored. They are just for compatability. */ +extern DB *dbopen(const char *filename, int openflags, int mode, + enum db_opentype type, void *openinfo); + +#endif /* TRIVIALDB_H */ --- linux-2.4.9/drivers/scsi/aic7xxx/aicasm/trivialdb.c Thu Aug 16 20:56:40 2001 +++ linux/drivers/scsi/aic7xxx/aicasm/trivialdb.c Thu Aug 16 21:05:38 2001 @@ -0,0 +1,149 @@ +/* A trivial implemention of the "BerkeleyDB" database routines + used by aicasm. + + Copyright 2001 Yggdrasil Computing, Inc. + Written by Adam J. Richter . + + This file may be freely redistributed under the terms and conditions + of version 2 of the GNU General Public License, as publisehd by the + Free Software Foundation (Cambridge, Massachusetts). +*/ + +#include +#include + +#include "trivialdb.h" + +#define ASSERT(condition) /* as nothing */ + +static enum db_result trivget(struct DB *db, DBT *key, DBT *data, int flags); +static enum db_result trivput(struct DB *db, DBT *key, DBT *data, int flags); +static void trivdel(struct DB *db, DBT *key, int flags /* ignored */); +static enum db_result trivseq(struct DB *db, DBT *key, DBT *data, + enum seqtype order); +static void trivclose(struct DB *db); + +static struct DB DB_template = { + get: trivget, + put: trivput, + del: trivdel, + seq: trivseq, + close: trivclose, + chain: NULL, + seqnext: NULL, +}; + +static void * +memdup(void *ptr, int size) +{ + void *result; + if ((result = malloc(size)) != NULL) { + memcpy(result, ptr, size); + } + return result; +} + +DB * +dbopen(const char *filename, int openflags, int mode, + enum db_opentype type, void *openinfo) { + return memdup(&DB_template, sizeof(DB)); +} + +/* Routines above this line do not care about the structure of dbchain. */ + +struct dbchain { + struct dbchain *next; + int keylen, datalen; + unsigned char key_data[0]; +}; + +#define KEY(chain) ((chain)->key_data) +#define DATA(chain) ((chain)->key_data + (chain)->keylen) + +static struct dbchain ** +find(struct dbchain **pChain, void *key, int keylen) +{ + while (*pChain != NULL && + ((*pChain)->keylen != keylen || + memcmp(KEY(*pChain), key, keylen) != 0)) { + + pChain = &(*pChain)->next; + } + return pChain; +} + +static enum db_result +copyout(DBT *dst, struct dbchain *src) +{ + void *copy; + if (src == NULL) + return DB_NOTFOUND; + + if ((copy = memdup(DATA(src), src->datalen)) == NULL) + return DB_SYSERROR; + + dst->size = src->datalen; + dst->data = copy; + return DB_OK; +} + +static enum db_result +trivget(struct DB *db, DBT *key, DBT *data, int flags) +{ + return copyout(data, *find(&db->chain, key->data, key->size)); +} + +static enum db_result +trivput(struct DB *db, DBT *key, DBT *data, int flags) +{ + struct dbchain *chain; + chain = malloc(sizeof (struct dbchain) + key->size + data->size); + if (chain == NULL) + return DB_SYSERROR; + + chain->keylen = key->size; + chain->datalen = data->size; + memcpy(KEY(chain), key->data, key->size); + memcpy(DATA(chain), data->data, data->size); + chain->next = db->chain; + db->chain = chain; + return DB_OK; +} + +static void +trivdel(struct DB *db, DBT *key, int flags /* ignored */) +{ + struct dbchain **pChain = find(&db->chain, key->data, key->size); + struct dbchain *chain = *pChain; + + if (chain != NULL) { + *pChain = chain->next; + free(chain); + } +} + +static enum db_result +trivseq(struct DB *db, DBT *key, DBT *data, enum seqtype order) +{ + if (order == R_FIRST) + db->seqnext = db->chain; + else { + ASSERT(db->seqnext != NULL); + db->seqnext = db->seqnext->next; + } + return copyout(data, db->seqnext); +} + +static void trivclose(struct DB *db) { + struct dbchain **pChain; + + pChain = &db->chain; + for(;;) { + struct dbchain *chain = *pChain; + if (chain == NULL) + return; + pChain = &chain->next; + free(chain); + } +} +