xref: /minix3/external/bsd/nvi/dist/common/db1.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*
2*84d9c625SLionel Sambuc  * DB1->3 compatibility layer
3*84d9c625SLionel Sambuc  */
4*84d9c625SLionel Sambuc 
5*84d9c625SLionel Sambuc #include "config.h"
6*84d9c625SLionel Sambuc 
7*84d9c625SLionel Sambuc #include <assert.h>
8*84d9c625SLionel Sambuc #include <errno.h>
9*84d9c625SLionel Sambuc #include <stdlib.h>
10*84d9c625SLionel Sambuc #include <string.h>
11*84d9c625SLionel Sambuc 
12*84d9c625SLionel Sambuc #include <fcntl.h>
13*84d9c625SLionel Sambuc 
14*84d9c625SLionel Sambuc #include "../common/vi_db.h"
15*84d9c625SLionel Sambuc #include "../common/dbinternal.h"
16*84d9c625SLionel Sambuc 
17*84d9c625SLionel Sambuc /*
18*84d9c625SLionel Sambuc  * DB_ENV emulation
19*84d9c625SLionel Sambuc  */
20*84d9c625SLionel Sambuc 
21*84d9c625SLionel Sambuc static int db1_dbenv_close(DB_ENV *, u_int32_t);
22*84d9c625SLionel Sambuc static int db1_dbenv_open(DB_ENV *, char *, u_int32_t, int);
23*84d9c625SLionel Sambuc static int db1_dbenv_remove(DB_ENV *, char *, u_int32_t);
24*84d9c625SLionel Sambuc 
25*84d9c625SLionel Sambuc int
db_env_create(DB_ENV ** dbenvp,u_int32_t flags)26*84d9c625SLionel Sambuc db_env_create(DB_ENV **dbenvp, u_int32_t flags) {
27*84d9c625SLionel Sambuc 	DB_ENV *dbenv;
28*84d9c625SLionel Sambuc 
29*84d9c625SLionel Sambuc 	assert(flags == 0);
30*84d9c625SLionel Sambuc 
31*84d9c625SLionel Sambuc 	dbenv = malloc(sizeof *dbenv);
32*84d9c625SLionel Sambuc 	if (dbenv == NULL)
33*84d9c625SLionel Sambuc 		return -1;
34*84d9c625SLionel Sambuc 
35*84d9c625SLionel Sambuc 	dbenv->close = db1_dbenv_close;
36*84d9c625SLionel Sambuc 	dbenv->open = db1_dbenv_open;
37*84d9c625SLionel Sambuc 	dbenv->remove = db1_dbenv_remove;
38*84d9c625SLionel Sambuc 
39*84d9c625SLionel Sambuc 	dbenv->base_path = NULL;
40*84d9c625SLionel Sambuc 	dbenv->mode = 0;
41*84d9c625SLionel Sambuc 
42*84d9c625SLionel Sambuc 	*dbenvp = dbenv;
43*84d9c625SLionel Sambuc 	return 0;
44*84d9c625SLionel Sambuc }
45*84d9c625SLionel Sambuc 
46*84d9c625SLionel Sambuc static int
db1_dbenv_close(DB_ENV * dbenv,u_int32_t flags)47*84d9c625SLionel Sambuc db1_dbenv_close(DB_ENV *dbenv, u_int32_t flags) {
48*84d9c625SLionel Sambuc 	assert(flags == 0);
49*84d9c625SLionel Sambuc 
50*84d9c625SLionel Sambuc 	if (dbenv->base_path != NULL)
51*84d9c625SLionel Sambuc 		free(dbenv->base_path);
52*84d9c625SLionel Sambuc 
53*84d9c625SLionel Sambuc 	free(dbenv);
54*84d9c625SLionel Sambuc 	return 0;
55*84d9c625SLionel Sambuc }
56*84d9c625SLionel Sambuc 
57*84d9c625SLionel Sambuc static int
db1_dbenv_open(DB_ENV * dbenv,char * base_path,u_int32_t flags,int mode)58*84d9c625SLionel Sambuc db1_dbenv_open(DB_ENV *dbenv, char *base_path, u_int32_t flags, int mode) {
59*84d9c625SLionel Sambuc 
60*84d9c625SLionel Sambuc 	/* We ignore flags on purpose */
61*84d9c625SLionel Sambuc 
62*84d9c625SLionel Sambuc 	dbenv->base_path = strdup(base_path);
63*84d9c625SLionel Sambuc 	if (dbenv->base_path == NULL)
64*84d9c625SLionel Sambuc 		return ENOSPC;
65*84d9c625SLionel Sambuc 
66*84d9c625SLionel Sambuc 	dbenv->mode = mode != 0? mode : 0660;
67*84d9c625SLionel Sambuc 	return 0;
68*84d9c625SLionel Sambuc }
69*84d9c625SLionel Sambuc 
70*84d9c625SLionel Sambuc static int
db1_dbenv_remove(DB_ENV * dbenv_fake,char * base_path,u_int32_t flags)71*84d9c625SLionel Sambuc db1_dbenv_remove(DB_ENV *dbenv_fake, char *base_path, u_int32_t flags) {
72*84d9c625SLionel Sambuc 	/* dbenv_fake is not a useful environment */
73*84d9c625SLionel Sambuc 	/* XXX check if we have to remove files here */
74*84d9c625SLionel Sambuc 
75*84d9c625SLionel Sambuc 	return 0;
76*84d9c625SLionel Sambuc }
77*84d9c625SLionel Sambuc 
78*84d9c625SLionel Sambuc /*
79*84d9c625SLionel Sambuc  * DB emulation
80*84d9c625SLionel Sambuc  */
81*84d9c625SLionel Sambuc static int db1_db_close(DB *, u_int32_t);
82*84d9c625SLionel Sambuc static int db1_db_open(DB *, const char *, const char *, DBTYPE, u_int32_t, int);
83*84d9c625SLionel Sambuc static int db1_db_sync(DB *, u_int32_t);
84*84d9c625SLionel Sambuc static int db1_db_get(DB *, DB_TXN *, DBT *, DBT *, u_int32_t);
85*84d9c625SLionel Sambuc static int db1_db_put(DB *, DB_TXN *, DBT *, DBT *, u_int32_t);
86*84d9c625SLionel Sambuc static int db1_db_del(DB *, DB_TXN *, DBT *, u_int32_t);
87*84d9c625SLionel Sambuc static int db1_db_set_flags(DB *, u_int32_t);
88*84d9c625SLionel Sambuc static int db1_db_set_pagesize(DB *, u_int32_t);
89*84d9c625SLionel Sambuc static int db1_db_set_re_delim(DB *, int);
90*84d9c625SLionel Sambuc static int db1_db_set_re_source(DB *, const char *);
91*84d9c625SLionel Sambuc static int db1_db_cursor(DB *, DB_TXN *, DBC **, u_int32_t);
92*84d9c625SLionel Sambuc 
93*84d9c625SLionel Sambuc int
db_create(DB ** dbp,DB_ENV * dbenv,u_int32_t flags)94*84d9c625SLionel Sambuc db_create(DB **dbp, DB_ENV *dbenv, u_int32_t flags) {
95*84d9c625SLionel Sambuc 	assert(flags == 0);
96*84d9c625SLionel Sambuc 
97*84d9c625SLionel Sambuc 	*dbp = malloc(sizeof **dbp);
98*84d9c625SLionel Sambuc 	if (*dbp == NULL)
99*84d9c625SLionel Sambuc 		return -1;
100*84d9c625SLionel Sambuc 
101*84d9c625SLionel Sambuc 	(*dbp)->type = DB_UNKNOWN;
102*84d9c625SLionel Sambuc 	(*dbp)->actual_db = NULL;
103*84d9c625SLionel Sambuc 	(*dbp)->_pagesize = 0;
104*84d9c625SLionel Sambuc 	(*dbp)->_flags = 0;
105*84d9c625SLionel Sambuc 	memset(&(*dbp)->_recno_info, 0, sizeof (RECNOINFO));
106*84d9c625SLionel Sambuc 
107*84d9c625SLionel Sambuc 	(*dbp)->close = db1_db_close;
108*84d9c625SLionel Sambuc 	(*dbp)->open = db1_db_open;
109*84d9c625SLionel Sambuc 	(*dbp)->sync = db1_db_sync;
110*84d9c625SLionel Sambuc 	(*dbp)->get = db1_db_get;
111*84d9c625SLionel Sambuc 	(*dbp)->put = db1_db_put;
112*84d9c625SLionel Sambuc 	(*dbp)->del = db1_db_del;
113*84d9c625SLionel Sambuc 	(*dbp)->set_flags = db1_db_set_flags;
114*84d9c625SLionel Sambuc 	(*dbp)->set_pagesize = db1_db_set_pagesize;
115*84d9c625SLionel Sambuc 	(*dbp)->set_re_delim = db1_db_set_re_delim;
116*84d9c625SLionel Sambuc 	(*dbp)->set_re_source = db1_db_set_re_source;
117*84d9c625SLionel Sambuc 	(*dbp)->cursor = db1_db_cursor;
118*84d9c625SLionel Sambuc 
119*84d9c625SLionel Sambuc 	return 0;
120*84d9c625SLionel Sambuc }
121*84d9c625SLionel Sambuc 
122*84d9c625SLionel Sambuc const char *
db_strerror(int error)123*84d9c625SLionel Sambuc db_strerror(int error) {
124*84d9c625SLionel Sambuc 	return error > 0? strerror(error) : "record not found";
125*84d9c625SLionel Sambuc }
126*84d9c625SLionel Sambuc 
127*84d9c625SLionel Sambuc static int
db1_db_close(DB * db,u_int32_t flags)128*84d9c625SLionel Sambuc db1_db_close(DB *db, u_int32_t flags) {
129*84d9c625SLionel Sambuc 	if (flags & DB_NOSYNC) {
130*84d9c625SLionel Sambuc 		/* XXX warn user? */
131*84d9c625SLionel Sambuc 	}
132*84d9c625SLionel Sambuc 	db->actual_db->close(db->actual_db);
133*84d9c625SLionel Sambuc 
134*84d9c625SLionel Sambuc 	db->type = DB_UNKNOWN;
135*84d9c625SLionel Sambuc 	db->actual_db = NULL;
136*84d9c625SLionel Sambuc 	db->_pagesize = 0;
137*84d9c625SLionel Sambuc 	db->_flags = 0;
138*84d9c625SLionel Sambuc 	memset(&db->_recno_info, 0, sizeof (RECNOINFO));
139*84d9c625SLionel Sambuc 
140*84d9c625SLionel Sambuc 	return 0;
141*84d9c625SLionel Sambuc }
142*84d9c625SLionel Sambuc 
143*84d9c625SLionel Sambuc static int
db1_db_open(DB * db,const char * file,const char * database,DBTYPE type,u_int32_t flags,int mode)144*84d9c625SLionel Sambuc db1_db_open(DB *db, const char *file, const char *database, DBTYPE type,
145*84d9c625SLionel Sambuc 						u_int32_t flags, int mode) {
146*84d9c625SLionel Sambuc 	int oldflags = 0;
147*84d9c625SLionel Sambuc 
148*84d9c625SLionel Sambuc 	assert(database == NULL && !(flags & ~(DB_CREATE | DB_TRUNCATE)));
149*84d9c625SLionel Sambuc 
150*84d9c625SLionel Sambuc 	db->type = type;
151*84d9c625SLionel Sambuc 
152*84d9c625SLionel Sambuc 	if (flags & DB_CREATE)
153*84d9c625SLionel Sambuc 		oldflags |= O_CREAT;
154*84d9c625SLionel Sambuc 	if (flags & DB_TRUNCATE)
155*84d9c625SLionel Sambuc 		oldflags |= O_TRUNC;
156*84d9c625SLionel Sambuc 
157*84d9c625SLionel Sambuc 	if (type == DB_RECNO) {
158*84d9c625SLionel Sambuc 		const char *tmp = file;
159*84d9c625SLionel Sambuc 
160*84d9c625SLionel Sambuc 		/* The interface is reversed in DB3 */
161*84d9c625SLionel Sambuc 		file = db->_recno_info.bfname;
162*84d9c625SLionel Sambuc 		db->_recno_info.bfname = __UNCONST(tmp);
163*84d9c625SLionel Sambuc 
164*84d9c625SLionel Sambuc 		/* ... and so, we should avoid to truncate the main file! */
165*84d9c625SLionel Sambuc 		oldflags &= ~O_TRUNC;
166*84d9c625SLionel Sambuc 
167*84d9c625SLionel Sambuc 		db->_recno_info.flags =
168*84d9c625SLionel Sambuc 			db->_flags & DB_SNAPSHOT? R_SNAPSHOT : 0;
169*84d9c625SLionel Sambuc 		db->_recno_info.psize = db->_pagesize;
170*84d9c625SLionel Sambuc 	}
171*84d9c625SLionel Sambuc 
172*84d9c625SLionel Sambuc 	db->actual_db = dbopen(file, oldflags, mode, type,
173*84d9c625SLionel Sambuc 				type == DB_RECNO? &db->_recno_info : NULL);
174*84d9c625SLionel Sambuc 
175*84d9c625SLionel Sambuc 	return db->actual_db == NULL? errno : 0;
176*84d9c625SLionel Sambuc }
177*84d9c625SLionel Sambuc 
178*84d9c625SLionel Sambuc static int
db1_db_sync(DB * db,u_int32_t flags)179*84d9c625SLionel Sambuc db1_db_sync(DB *db, u_int32_t flags) {
180*84d9c625SLionel Sambuc 	assert(flags == 0);
181*84d9c625SLionel Sambuc 
182*84d9c625SLionel Sambuc 	return db->actual_db->sync(db->actual_db, db->type == DB_UNKNOWN?
183*84d9c625SLionel Sambuc 					R_RECNOSYNC : 0) == 0? 0 : errno;
184*84d9c625SLionel Sambuc }
185*84d9c625SLionel Sambuc 
186*84d9c625SLionel Sambuc static int
db1_db_get(DB * db,DB_TXN * txnid,DBT * key,DBT * data,u_int32_t flags)187*84d9c625SLionel Sambuc db1_db_get(DB *db, DB_TXN *txnid, DBT *key, DBT *data, u_int32_t flags) {
188*84d9c625SLionel Sambuc 	int err;
189*84d9c625SLionel Sambuc 	DBT_v1 data1;
190*84d9c625SLionel Sambuc 
191*84d9c625SLionel Sambuc 	assert(flags == 0 && txnid == NULL);
192*84d9c625SLionel Sambuc 
193*84d9c625SLionel Sambuc 	err = db->actual_db->get(db->actual_db, (DBT_v1 *) key, &data1, flags);
194*84d9c625SLionel Sambuc 	if (err == 1)
195*84d9c625SLionel Sambuc 		return DB_NOTFOUND;
196*84d9c625SLionel Sambuc 	else if (err == -1)
197*84d9c625SLionel Sambuc 		return errno;
198*84d9c625SLionel Sambuc 
199*84d9c625SLionel Sambuc 	if (data->flags & DB_DBT_USERMEM) {
200*84d9c625SLionel Sambuc 		data->size = data1.size;
201*84d9c625SLionel Sambuc 		if (data1.size > data->ulen)
202*84d9c625SLionel Sambuc 			return DB_BUFFER_SMALL;
203*84d9c625SLionel Sambuc 
204*84d9c625SLionel Sambuc 		memcpy(data->data, data1.data, data1.size);
205*84d9c625SLionel Sambuc 	}
206*84d9c625SLionel Sambuc 
207*84d9c625SLionel Sambuc 	return 0;
208*84d9c625SLionel Sambuc }
209*84d9c625SLionel Sambuc 
210*84d9c625SLionel Sambuc static int
db1_db_put(DB * db,DB_TXN * txnid,DBT * key,DBT * data,u_int32_t flags)211*84d9c625SLionel Sambuc db1_db_put(DB *db, DB_TXN *txnid, DBT *key, DBT *data, u_int32_t flags) {
212*84d9c625SLionel Sambuc 	int err;
213*84d9c625SLionel Sambuc 	DB_old *db_v1 = db->actual_db;
214*84d9c625SLionel Sambuc 	DBT data1;
215*84d9c625SLionel Sambuc 	DBT key1;
216*84d9c625SLionel Sambuc 	recno_t recno = 1;
217*84d9c625SLionel Sambuc 
218*84d9c625SLionel Sambuc 	assert((flags & ~DB_APPEND) == 0 && txnid == NULL);
219*84d9c625SLionel Sambuc 
220*84d9c625SLionel Sambuc 	key1 = *key;
221*84d9c625SLionel Sambuc 
222*84d9c625SLionel Sambuc 	if (flags & DB_APPEND) {
223*84d9c625SLionel Sambuc 		if (db_v1->seq(db_v1, (DBT_v1 *)(void *)key,
224*84d9c625SLionel Sambuc 		    (DBT_v1 *)(void *)&data1, R_LAST) == 1) {
225*84d9c625SLionel Sambuc 			key1.data = &recno;
226*84d9c625SLionel Sambuc 			key1.size = sizeof recno;
227*84d9c625SLionel Sambuc 		}
228*84d9c625SLionel Sambuc 	}
229*84d9c625SLionel Sambuc 	err = db_v1->put(db_v1, (DBT_v1 *)(void *)&key1, (DBT_v1 *)(void *)data,
230*84d9c625SLionel Sambuc 	    0);
231*84d9c625SLionel Sambuc 
232*84d9c625SLionel Sambuc 	return err == -1? errno : err;
233*84d9c625SLionel Sambuc }
234*84d9c625SLionel Sambuc 
235*84d9c625SLionel Sambuc static int
db1_db_del(DB * db,DB_TXN * txnid,DBT * key,u_int32_t flags)236*84d9c625SLionel Sambuc db1_db_del(DB *db, DB_TXN *txnid, DBT *key, u_int32_t flags) {
237*84d9c625SLionel Sambuc 	int err;
238*84d9c625SLionel Sambuc 	DB_old *db_v1 = db->actual_db;
239*84d9c625SLionel Sambuc 
240*84d9c625SLionel Sambuc 	assert(txnid == NULL && flags == 0);
241*84d9c625SLionel Sambuc 
242*84d9c625SLionel Sambuc 	err = db_v1->del(db_v1, (DBT_v1 *) key, 0);
243*84d9c625SLionel Sambuc 	return err == -1? errno : err;
244*84d9c625SLionel Sambuc }
245*84d9c625SLionel Sambuc 
246*84d9c625SLionel Sambuc static int
db1_db_set_flags(DB * db,u_int32_t flags)247*84d9c625SLionel Sambuc db1_db_set_flags(DB *db, u_int32_t flags) {
248*84d9c625SLionel Sambuc 	assert((flags & ~(DB_RENUMBER | DB_SNAPSHOT)) == 0);
249*84d9c625SLionel Sambuc 
250*84d9c625SLionel Sambuc 	/* Can't prevent renumbering from happening with DB1 */
251*84d9c625SLionel Sambuc 	assert((flags | db->_flags) & DB_RENUMBER);
252*84d9c625SLionel Sambuc 
253*84d9c625SLionel Sambuc 
254*84d9c625SLionel Sambuc 	db->_flags |= flags;
255*84d9c625SLionel Sambuc 
256*84d9c625SLionel Sambuc 	return 0;
257*84d9c625SLionel Sambuc }
258*84d9c625SLionel Sambuc 
259*84d9c625SLionel Sambuc static int
db1_db_set_pagesize(DB * db,u_int32_t pagesize)260*84d9c625SLionel Sambuc db1_db_set_pagesize(DB *db, u_int32_t pagesize) {
261*84d9c625SLionel Sambuc 	db->_pagesize = pagesize;
262*84d9c625SLionel Sambuc 
263*84d9c625SLionel Sambuc 	return 0;
264*84d9c625SLionel Sambuc }
265*84d9c625SLionel Sambuc 
266*84d9c625SLionel Sambuc static int
db1_db_set_re_delim(DB * db,int re_delim)267*84d9c625SLionel Sambuc db1_db_set_re_delim(DB *db, int re_delim) {
268*84d9c625SLionel Sambuc 	db->_recno_info.bval = re_delim;
269*84d9c625SLionel Sambuc 
270*84d9c625SLionel Sambuc 	return 0;
271*84d9c625SLionel Sambuc }
272*84d9c625SLionel Sambuc 
273*84d9c625SLionel Sambuc static int
db1_db_set_re_source(DB * db,const char * re_source)274*84d9c625SLionel Sambuc db1_db_set_re_source(DB *db, const char *re_source) {
275*84d9c625SLionel Sambuc 	db->_recno_info.bfname = __UNCONST(re_source);
276*84d9c625SLionel Sambuc 
277*84d9c625SLionel Sambuc 	return 0;
278*84d9c625SLionel Sambuc }
279*84d9c625SLionel Sambuc 
280*84d9c625SLionel Sambuc /* DBC emulation. Very basic, only one cursor at a time, enough for vi */
281*84d9c625SLionel Sambuc 
282*84d9c625SLionel Sambuc static int db1_dbc_close(DBC *);
283*84d9c625SLionel Sambuc static int db1_dbc_get(DBC *, DBT *, DBT *, u_int32_t);
284*84d9c625SLionel Sambuc static int db1_dbc_put(DBC *, DBT *, DBT *, u_int32_t);
285*84d9c625SLionel Sambuc 
286*84d9c625SLionel Sambuc static int
db1_db_cursor(DB * db,DB_TXN * txn,DBC ** cursorp,u_int32_t flags)287*84d9c625SLionel Sambuc db1_db_cursor(DB *db, DB_TXN *txn, DBC **cursorp, u_int32_t flags) {
288*84d9c625SLionel Sambuc 	DBC *cursor;
289*84d9c625SLionel Sambuc 
290*84d9c625SLionel Sambuc 	assert(txn == NULL && flags == 0);
291*84d9c625SLionel Sambuc 
292*84d9c625SLionel Sambuc 	cursor = malloc(sizeof *cursor);
293*84d9c625SLionel Sambuc 	if (cursor == NULL)
294*84d9c625SLionel Sambuc 		return -1;
295*84d9c625SLionel Sambuc 
296*84d9c625SLionel Sambuc 	cursor->db = db;
297*84d9c625SLionel Sambuc 	cursor->pos_key.data = &cursor->pos;
298*84d9c625SLionel Sambuc 	cursor->pos_key.size = sizeof cursor->pos;
299*84d9c625SLionel Sambuc 	cursor->c_close = db1_dbc_close;
300*84d9c625SLionel Sambuc 	cursor->c_get = db1_dbc_get;
301*84d9c625SLionel Sambuc 	cursor->c_put = db1_dbc_put;
302*84d9c625SLionel Sambuc 
303*84d9c625SLionel Sambuc 	*cursorp = cursor;
304*84d9c625SLionel Sambuc 
305*84d9c625SLionel Sambuc 	return 0;
306*84d9c625SLionel Sambuc }
307*84d9c625SLionel Sambuc 
308*84d9c625SLionel Sambuc static int
db1_dbc_close(DBC * cursor)309*84d9c625SLionel Sambuc db1_dbc_close(DBC *cursor) {
310*84d9c625SLionel Sambuc 	free(cursor);
311*84d9c625SLionel Sambuc 	return 0;
312*84d9c625SLionel Sambuc }
313*84d9c625SLionel Sambuc 
314*84d9c625SLionel Sambuc static int
db1_dbc_get(DBC * cursor,DBT * key,DBT * data,u_int32_t flags)315*84d9c625SLionel Sambuc db1_dbc_get(DBC *cursor, DBT *key, DBT *data, u_int32_t flags) {
316*84d9c625SLionel Sambuc 	DB *db = cursor->db;
317*84d9c625SLionel Sambuc 	DB_old *db_v1 = db->actual_db;
318*84d9c625SLionel Sambuc 	int ret = 0;
319*84d9c625SLionel Sambuc 
320*84d9c625SLionel Sambuc 
321*84d9c625SLionel Sambuc 	switch(flags) {
322*84d9c625SLionel Sambuc 	case DB_SET:
323*84d9c625SLionel Sambuc 		ret = db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) data,
324*84d9c625SLionel Sambuc 			R_CURSOR);
325*84d9c625SLionel Sambuc 		cursor->pos = * (db_recno_t *) key->data;
326*84d9c625SLionel Sambuc 		break;
327*84d9c625SLionel Sambuc 	case DB_FIRST:
328*84d9c625SLionel Sambuc 		ret = db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) data,
329*84d9c625SLionel Sambuc 			R_FIRST);
330*84d9c625SLionel Sambuc 		if (ret == 1)
331*84d9c625SLionel Sambuc 			ret = DB_NOTFOUND;
332*84d9c625SLionel Sambuc 		cursor->pos = * (db_recno_t *) key->data;
333*84d9c625SLionel Sambuc 		break;
334*84d9c625SLionel Sambuc 	case DB_LAST:
335*84d9c625SLionel Sambuc 		ret = db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) data,
336*84d9c625SLionel Sambuc 			R_LAST);
337*84d9c625SLionel Sambuc 		if (ret == 1)
338*84d9c625SLionel Sambuc 			ret = DB_NOTFOUND;
339*84d9c625SLionel Sambuc 		cursor->pos = * (db_recno_t *) key->data;
340*84d9c625SLionel Sambuc 		break;
341*84d9c625SLionel Sambuc 	default:
342*84d9c625SLionel Sambuc 		abort();
343*84d9c625SLionel Sambuc 	}
344*84d9c625SLionel Sambuc 
345*84d9c625SLionel Sambuc 	return ret;
346*84d9c625SLionel Sambuc }
347*84d9c625SLionel Sambuc 
348*84d9c625SLionel Sambuc static int
db1_dbc_put(DBC * cursor,DBT * key,DBT * data,u_int32_t flags)349*84d9c625SLionel Sambuc db1_dbc_put(DBC *cursor, DBT *key, DBT *data, u_int32_t flags) {
350*84d9c625SLionel Sambuc 	DB *db = cursor->db;
351*84d9c625SLionel Sambuc 	DB_old *db_v1 = db->actual_db;
352*84d9c625SLionel Sambuc 	int ret = 0;
353*84d9c625SLionel Sambuc 
354*84d9c625SLionel Sambuc 	assert((flags & ~(DB_BEFORE | DB_AFTER)) == 0);
355*84d9c625SLionel Sambuc 
356*84d9c625SLionel Sambuc 	ret = db_v1->put(db_v1, &cursor->pos_key, (DBT_v1 *) data,
357*84d9c625SLionel Sambuc 		flags == DB_BEFORE? R_IBEFORE : R_IAFTER);
358*84d9c625SLionel Sambuc 
359*84d9c625SLionel Sambuc 	return ret == -1? errno : ret;
360*84d9c625SLionel Sambuc }
361