#ifdef CNID_BACKEND_CDB
+#include <atalk/volume.h>
#include <atalk/cnid_private.h>
#include "cnid_cdb_private.h"
static char *old_dbfiles[] = {"cnid.db", NULL};
-/* -----------------------
- * bandaid for LanTest performance pb. for now not used, cf. ifdef 0 below
-*/
-static int my_yield(void)
-{
- struct timeval t;
- int ret;
-
- t.tv_sec = 0;
- t.tv_usec = 1000;
- ret = select(0, NULL, NULL, NULL, &t);
- return 0;
-}
-
/* --------------- */
static int didname(DB *dbp _U_, const DBT *pkey _U_, const DBT *pdata, DBT *skey)
{
}
/* --------------- */
-static struct _cnid_db *cnid_cdb_new(const char *volpath)
+static struct _cnid_db *cnid_cdb_new(struct vol *vol)
{
struct _cnid_db *cdb;
int major, minor, patch;
if ((cdb = (struct _cnid_db *) calloc(1, sizeof(struct _cnid_db))) == NULL)
return NULL;
- if ((cdb->volpath = strdup(volpath)) == NULL) {
- free(cdb);
- return NULL;
- }
-
- cdb->flags = CNID_FLAG_PERSISTENT;
-
+ cdb->cnid_db_vol = vol;
+ cdb->cnid_db_flags = CNID_FLAG_PERSISTENT;
cdb->cnid_add = cnid_cdb_add;
cdb->cnid_delete = cnid_cdb_delete;
cdb->cnid_get = cnid_cdb_get;
cdb->cnid_close = cnid_cdb_close;
cdb->cnid_getstamp = cnid_cdb_getstamp;
cdb->cnid_rebuild_add = cnid_cdb_rebuild_add;
-
+ cdb->cnid_wipe = NULL;
return cdb;
}
int open_flag, len;
static int first = 0;
int rc;
-
- if (!args->dir || *args->dir == 0) {
- return NULL;
- }
+ struct vol *vol = args->cnid_args_vol;
/* this checks .AppleDB.
We need space for dir + '/' + DBHOMELEN + '/' + DBLEN */
- if ((len = strlen(args->dir)) > (MAXPATHLEN - DBHOMELEN - DBLEN - 2)) {
- LOG(log_error, logtype_default, "cnid_open: Pathname too large: %s", args->dir);
+ if ((len = strlen(vol->v_path)) > (MAXPATHLEN - DBHOMELEN - DBLEN - 2)) {
+ LOG(log_error, logtype_default, "cnid_open: Pathname too large: %s", vol->v_path);
return NULL;
}
- if ((cdb = cnid_cdb_new(args->dir)) == NULL) {
+ if ((cdb = cnid_cdb_new(vol)) == NULL) {
LOG(log_error, logtype_default, "cnid_open: Unable to allocate memory for database");
return NULL;
}
goto fail_cdb;
}
- cdb->_private = (void *) db;
- db->magic = CNID_DB_MAGIC;
+ cdb->cnid_db_private = (void *) db;
- strcpy(path, args->dir);
+ strcpy(path, vol->v_path);
if (path[len - 1] != '/') {
strcat(path, "/");
len++;
}
strcpy(path + len, DBHOME);
- if ((stat(path, &st) < 0) && (ad_mkdir(path, 0777 & ~args->mask) < 0)) {
+ if ((stat(path, &st) < 0) && (ad_mkdir(path, 0777 & ~vol->v_umask) < 0)) {
LOG(log_error, logtype_default, "cnid_open: DBHOME mkdir failed for %s", path);
goto fail_adouble;
}
}
/* Open the database environment. */
- if ((rc = db->dbenv->open(db->dbenv, path, DBOPTIONS, 0666 & ~args->mask)) != 0) {
+ if ((rc = db->dbenv->open(db->dbenv, path, DBOPTIONS, 0666 & ~vol->v_umask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: dbenv->open (rw) of %s failed: %s", path, db_strerror(rc));
/* FIXME: This should probably go. Even if it worked, any use for a read-only DB? Didier? */
if (rc == DB_RUNRECOVERY) {
/* We can't get a full transactional environment, so multi-access
* is out of the question. Let's assume a read-only environment,
* and try to at least get a shared memory pool. */
- if ((rc = db->dbenv->open(db->dbenv, path, DB_INIT_MPOOL, 0666 & ~args->mask)) != 0) {
+ if ((rc = db->dbenv->open(db->dbenv, path, DB_INIT_MPOOL, 0666 & ~vol->v_umask)) != 0) {
/* Nope, not a MPOOL, either. Last-ditch effort: we'll try to
* open the environment with no flags. */
- if ((rc = db->dbenv->open(db->dbenv, path, 0, 0666 & ~args->mask)) != 0) {
+ if ((rc = db->dbenv->open(db->dbenv, path, 0, 0666 & ~vol->v_umask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: dbenv->open of %s failed: %s", path, db_strerror(rc));
goto fail_lock;
}
goto fail_appinit;
}
- if ((rc = my_open(db->db_cnid, DBCNID, DBCNID, DB_BTREE, open_flag, 0666 & ~args->mask)) != 0) {
+ if ((rc = my_open(db->db_cnid, DBCNID, DBCNID, DB_BTREE, open_flag, 0666 & ~vol->v_umask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open dev/ino database: %s",
db_strerror(rc));
goto fail_appinit;
goto fail_appinit;
}
- if ((rc = my_open(db->db_didname, DBCNID, DBDIDNAME, DB_BTREE, open_flag, 0666 & ~args->mask))) {
+ if ((rc = my_open(db->db_didname, DBCNID, DBDIDNAME, DB_BTREE, open_flag, 0666 & ~vol->v_umask))) {
LOG(log_error, logtype_default, "cnid_open: Failed to open did/name database: %s",
db_strerror(rc));
goto fail_appinit;
goto fail_appinit;
}
- if ((rc = my_open(db->db_devino, DBCNID, DBDEVINO, DB_BTREE, open_flag, 0666 & ~args->mask)) != 0) {
+ if ((rc = my_open(db->db_devino, DBCNID, DBDEVINO, DB_BTREE, open_flag, 0666 & ~vol->v_umask)) != 0) {
LOG(log_error, logtype_default, "cnid_open: Failed to open devino database: %s",
db_strerror(rc));
goto fail_appinit;
}
}
- db_env_set_func_yield(my_yield);
return cdb;
fail_appinit:
free(db);
fail_cdb:
- if (cdb->volpath != NULL)
- free(cdb->volpath);
free(cdb);
return NULL;