netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
dbif.c File Reference
`#include <arpa/inet.h>`
`#include <errno.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/stat.h>`
`#include <sys/types.h>`
`#include <unistd.h>`
`#include <db.h>`
`#include <atalk/cnid.h>`
`#include <atalk/errchk.h>`
`#include <atalk/logger.h>`
`#include <atalk/util.h>`
`#include "db_param.h"`
`#include "dbif.h"`
`#include "pack.h"`

## Macros
#define | DB_ERRLOGFILE "db_errlog"
#define | UNINTIALIZED_DB UINT32_MAX
| Upgrade CNID database versions, initialize rootinfo key as as necessary in dbif_setversion().

## Functions
static int | dbif_stamp (DBD *dbd, void *buffer, int size)
| Get the db stamp which is the st_ctime of the file "cnid2.db" and store it in buffer.
static int | dbif_init_rootinfo (DBD *dbd, int version)
| Inititialize rootinfo key (which has CNID 0 as key).
static int | dbif_getversion (DBD *dbd, uint32_t *version)
| Return CNID database version number.
static int | dbif_setversion (DBD *dbd, uint32_t version)
| Set CNID database version number.
static int | dbif_upgrade (DBD *dbd)
static int | dbif_openlog (DBD *dbd)
static int | dbif_logautorem (DBD *dbd)
DBD * | dbif_init (const char *envhome, const char *filename)
int | dbif_env_open (DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags)
int | dbif_open (DBD *dbd, struct db_param *dbp, int reindex)
static int | dbif_closedb (DBD *dbd)
int | dbif_close (DBD *dbd)
int | dbif_env_remove (const char *path)
int | dbif_get (DBD *dbd, const int dbi, DBT *key, DBT *val, uint32_t flags)
int | dbif_put (DBD *dbd, const int dbi, DBT *key, DBT *val, uint32_t flags)
int | dbif_del (DBD *dbd, const int dbi, DBT *key, uint32_t flags)
static bool | dbif_name_contains (const void *name, size_t namelen, const void *term, size_t termlen)
int | dbif_search (DBD *dbd, DBT *key, char *resbuf, uint32_t offset, bool *more)
| Paginated substring cursor scan over the name index.
int | dbif_txn_begin (DBD *dbd)
int | dbif_txn_commit (DBD *dbd)
int | dbif_txn_abort (DBD *dbd)
int | dbif_txn_close (DBD *dbd, int ret)
| Close a transaction based on ret code.
int | dbif_txn_checkpoint (DBD *dbd, uint32_t kbyte, uint32_t min, uint32_t flags)
int | dbif_count (DBD *dbd, const int dbi, uint32_t *count)
int | dbif_copy_rootinfokey (DBD *srcdbd, DBD *destdbd)
int | dbif_dump (DBD *dbd, int dumpindexes)
int | dbif_idwalk (DBD *dbd, cnid_t *cnid, int close)
| Iterates over dbd, returning cnids.

## Macro Definition Documentation

## ◆ DB_ERRLOGFILE

#define DB_ERRLOGFILE "db_errlog"

## ◆ UNINTIALIZED_DB

#define UNINTIALIZED_DB UINT32_MAX

Upgrade CNID database versions, initialize rootinfo key as as necessary in dbif_setversion().

For now this does nothing, as upgrading from ver. 0 to 1 is done in dbif_open

## Function Documentation

## ◆ dbif_close()

int dbif_close | ( | DBD * | dbd | ) |

## ◆ dbif_closedb()

int dbif_closedb | ( | DBD * | dbd | ) |
| static

## ◆ dbif_copy_rootinfokey()

int dbif_copy_rootinfokey | ( | DBD * | srcdbd,
|  | DBD * | destdbd )

## ◆ dbif_count()

int dbif_count | ( | DBD * | dbd,
|  | const int | dbi,
|  | uint32_t * | count )

## ◆ dbif_del()

int dbif_del | ( | DBD * | dbd,
|  | const int | dbi,
|  | DBT * | key,
|  | uint32_t | flags )

## ◆ dbif_dump()

int dbif_dump | ( | DBD * | dbd,
|  | int | dumpindexes )

## ◆ dbif_env_open()

int dbif_env_open | ( | DBD * | dbd,
|  | struct db_param * | dbp,
|  | uint32_t | dbenv_oflags )

We must open the db_env with an absolute pathname, as 'dbd' keeps chdir'ing, which breaks e.g. bdb logfile-rotation with relative pathnames. But still we use relative paths with DB_ERRLOGFILE in order to avoid creating absolute paths by copying. Both have no problem with a relative path.

## ◆ dbif_env_remove()

int dbif_env_remove | ( | const char * | path | ) |

## ◆ dbif_get()

int dbif_get | ( | DBD * | dbd,
|  | const int | dbi,
|  | DBT * | key,
|  | DBT * | val,
|  | uint32_t | flags )

## ◆ dbif_getversion()

int dbif_getversion | ( | DBD * | dbd,
|  | uint32_t * | version )
| static

Return CNID database version number.

Returns version in *version

Returns
  -1 on error, 0 if there's no rootinfo key yet, 1 if *version is returned

## ◆ dbif_idwalk()

int dbif_idwalk | ( | DBD * | dbd,
|  | cnid_t * | cnid,
|  | int | close )

Iterates over dbd, returning cnids.

Uses in-value of cnid to seek to that cnid, then gets next and return that in cnid. If close=1, close cursor.

Returns
  -1 on error, 0 on EOD (end-of-database), 1 if returning cnid.

## ◆ dbif_init()

DBD * dbif_init | ( | const char * | envhome,
|  | const char * | filename )

## ◆ dbif_init_rootinfo()

int dbif_init_rootinfo | ( | DBD * | dbd,
|  | int | version )
| static

Inititialize rootinfo key (which has CNID 0 as key).

Note
  This also "stamps" the database, which means storing st.st_ctime of the "cnid2.db" file in the rootinfo data at the DEV offset

Parameters

  [in,out] | dbd | database handle
  [in] | version | database version number

Returns
  -1 on error, 0 on success

## ◆ dbif_logautorem()

int dbif_logautorem | ( | DBD * | dbd | ) |
| static

## ◆ dbif_name_contains()

bool dbif_name_contains | ( | const void * | name,
|  | size_t | namelen,
|  | const void * | term,
|  | size_t | termlen )
| static

## ◆ dbif_open()

int dbif_open | ( | DBD * | dbd,
|  | struct db_param * | dbp,
|  | int | reindex )

## ◆ dbif_openlog()

int dbif_openlog | ( | DBD * | dbd | ) |
| static

## ◆ dbif_put()

int dbif_put | ( | DBD * | dbd,
|  | const int | dbi,
|  | DBT * | key,
|  | DBT * | val,
|  | uint32_t | flags )

## ◆ dbif_search()

int dbif_search | ( | DBD * | dbd,
|  | DBT * | key,
|  | char * | resbuf,
|  | uint32_t | offset,
|  | bool * | more )

Paginated substring cursor scan over the name index.

Skips `offset` matching entries before emitting up to DBD_MAX_SRCH_RSLTS results into `resbuf`. After the buffer fills, continues until the next matching entry to decide whether further matches exist; reports the result via `more`.

The caller MUST keep a separate backup of the original name bytes because BDB takes ownership of key->data after each pget() call.

Parameters

  [in] | dbd | database handle
  [in] | key | initialised with the search name (key->data, key->size)
  [out] | resbuf | buffer for matching CNIDs in network byte order, must have capacity for DBD_MAX_SRCH_RSLTS * sizeof(cnid_t) bytes
  [in] | offset | number of leading matches to skip, range 0..DBD_SEARCH_MAX_OFFSET
  [out] | more | set to true iff a (offset + DBD_MAX_SRCH_RSLTS + 1)-th matching entry exists in the index, false otherwise. MUST be non-NULL.

Returns
  -1 on BDB engine error, else the number of matches written to `resbuf` (0..DBD_MAX_SRCH_RSLTS)

## ◆ dbif_setversion()

int dbif_setversion | ( | DBD * | dbd,
|  | uint32_t | version )
| static

Set CNID database version number.

Initializes rootinfo key as neccessary

Returns
  -1 on error, 0 on success

## ◆ dbif_stamp()

int dbif_stamp | ( | DBD * | dbd,
|  | void * | buffer,
|  | int | size )
| static

Get the db stamp which is the st_ctime of the file "cnid2.db" and store it in buffer.

## ◆ dbif_txn_abort()

int dbif_txn_abort | ( | DBD * | dbd | ) |

## ◆ dbif_txn_begin()

int dbif_txn_begin | ( | DBD * | dbd | ) |

## ◆ dbif_txn_checkpoint()

int dbif_txn_checkpoint | ( | DBD * | dbd,
|  | uint32_t | kbyte,
|  | uint32_t | min,
|  | uint32_t | flags )

## ◆ dbif_txn_close()

int dbif_txn_close | ( | DBD * | dbd,
|  | int | ret )

Close a transaction based on ret code.

Note
  ret = 1 -> commit txn if db_param.txn_frequency
  ret = 0 -> abort txn db_param.txn_frequency -> exit!
  anything else -> exit!

Returns
  0 on success (abort or commit), -1 on error

Switch between commit+abort

## ◆ dbif_txn_commit()

int dbif_txn_commit | ( | DBD * | dbd | ) |

## ◆ dbif_upgrade()

int dbif_upgrade | ( | DBD * | dbd | ) |
| static