CPU: Wrong CPU Load %.
[tomato.git] / release / src / router / ppp / pppd / tdb.h
blob56ae0ac2a0b1bfcc5640f5eeb34121da110e1005
1 #define STANDALONE 1
2 /*
3 * Database functions
4 * Copyright (C) Andrew Tridgell 1999
5 *
6 * Redistribution and use in source and binary forms are permitted
7 * provided that the above copyright notice and this paragraph are
8 * duplicated in all such forms AND provided that this software or
9 * any derived work is only used as part of the PPP daemon (pppd)
10 * and related utilities.
11 * The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 * Note: this software is also available under the Gnu Public License
18 * version 2 or later.
21 typedef unsigned tdb_len;
22 typedef unsigned tdb_off;
24 #define TDB_MAGIC_FOOD "TDB file\n"
26 /* this is stored at the front of every database */
27 struct tdb_header {
28 char magic_food[32]; /* for /etc/magic */
29 unsigned version; /* version of the code */
30 unsigned hash_size; /* number of hash entries */
33 typedef struct {
34 char *dptr;
35 size_t dsize;
36 } TDB_DATA;
38 /* this is the context structure that is returned from a db open */
39 typedef struct {
40 char *name; /* the name of the database */
41 void *map_ptr; /* where it is currently mapped */
42 int fd; /* open file descriptor for the database */
43 tdb_len map_size; /* how much space has been mapped */
44 int read_only; /* opened read-only */
45 int *locked; /* set if we have a chain locked */
46 int ecode; /* error code for last tdb error */
47 struct tdb_header header; /* a cached copy of the header */
48 } TDB_CONTEXT;
50 /* flags to tdb_store() */
51 #define TDB_REPLACE 1
52 #define TDB_INSERT 2
54 /* flags for tdb_open() */
55 #define TDB_CLEAR_IF_FIRST 1
57 /* error codes */
58 enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK,
59 TDB_ERR_OOM, TDB_ERR_EXISTS};
61 #if STANDALONE
62 TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags,
63 int open_flags, mode_t mode);
64 char *tdb_error(TDB_CONTEXT *tdb);
65 int tdb_writelock(TDB_CONTEXT *tdb);
66 int tdb_writeunlock(TDB_CONTEXT *tdb);
67 TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
68 int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
69 int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
70 int tdb_close(TDB_CONTEXT *tdb);
71 TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
72 TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
73 int tdb_traverse(TDB_CONTEXT *tdb,
74 int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state),
75 void *state);
76 int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
77 #endif