int nocniddb = 0; /* Dont open CNID database, only scan filesystem */
volatile sig_atomic_t alarmed;
-struct volinfo volinfo;
+struct volinfo volinfo; /* needed by pack.c:idxname() */
static DBD *dbd;
static int verbose; /* Logging flag */
extern int nocniddb; /* Dont open CNID database, only scan filesystem */
extern volatile sig_atomic_t alarmed;
-// extern struct volinfo *volinfo;
-extern char cwdbuf[MAXPATHLEN+1];
extern void dbd_log(enum logtype lt, char *fmt, ...);
extern int cmd_dbd_scanvol(DBD *dbd, struct volinfo *volinfo, dbd_flags_t flags);
#define ADDIR_OK (addir_ok == 0)
#define ADFILE_OK (adfile_ok == 0)
-/* These must be accessible for cmd_dbd_* funcs */
-struct volinfo *volinfo;
-char cwdbuf[MAXPATHLEN+1];
-/* Some static vars */
+static struct volinfo *myvolinfo;
+static char cwdbuf[MAXPATHLEN+1];
static DBD *dbd;
static DBD *dbd_rebuild;
static dbd_flags_t dbd_flags;
u = upath;
outlen = strlen(upath);
- if ((volinfo->v_casefold & AFPVOL_UTOMUPPER))
+ if ((myvolinfo->v_casefold & AFPVOL_UTOMUPPER))
flags |= CONV_TOUPPER;
- else if ((volinfo->v_casefold & AFPVOL_UTOMLOWER))
+ else if ((myvolinfo->v_casefold & AFPVOL_UTOMLOWER))
flags |= CONV_TOLOWER;
- if ((volinfo->v_flags & AFPVOL_EILSEQ)) {
+ if ((myvolinfo->v_flags & AFPVOL_EILSEQ)) {
flags |= CONV__EILSEQ;
}
/* convert charsets */
- if ((size_t)-1 == ( outlen = convert_charset(volinfo->v_volcharset,
+ if ((size_t)-1 == ( outlen = convert_charset(myvolinfo->v_volcharset,
CH_UTF8_MAC,
- volinfo->v_maccharset,
+ myvolinfo->v_maccharset,
u, outlen, mpath, MAXPATHLEN, &flags)) ) {
dbd_log( LOGSTD, "Conversion from %s to %s for %s failed.",
- volinfo->v_volcodepage, volinfo->v_maccodepage, u);
+ myvolinfo->v_volcodepage, myvolinfo->v_maccodepage, u);
return NULL;
}
}
/* set conversion flags */
- if (!(volinfo->v_flags & AFPVOL_NOHEX))
+ if (!(myvolinfo->v_flags & AFPVOL_NOHEX))
flags |= CONV_ESCAPEHEX;
- if (!(volinfo->v_flags & AFPVOL_USEDOTS))
+ if (!(myvolinfo->v_flags & AFPVOL_USEDOTS))
flags |= CONV_ESCAPEDOTS;
- if ((volinfo->v_casefold & AFPVOL_MTOUUPPER))
+ if ((myvolinfo->v_casefold & AFPVOL_MTOUUPPER))
flags |= CONV_TOUPPER;
- else if ((volinfo->v_casefold & AFPVOL_MTOULOWER))
+ else if ((myvolinfo->v_casefold & AFPVOL_MTOULOWER))
flags |= CONV_TOLOWER;
- if ((volinfo->v_flags & AFPVOL_EILSEQ)) {
+ if ((myvolinfo->v_flags & AFPVOL_EILSEQ)) {
flags |= CONV__EILSEQ;
}
outlen = MAXPATHLEN;
if ((size_t)-1 == (outlen = convert_charset(CH_UTF8_MAC,
- volinfo->v_volcharset,
- volinfo->v_maccharset,
+ myvolinfo->v_volcharset,
+ myvolinfo->v_maccharset,
m, inplen, u, outlen, &flags)) ) {
dbd_log( LOGSTD, "conversion from UTF8-MAC to %s for %s failed.",
- volinfo->v_volcodepage, mpath);
+ myvolinfo->v_volcodepage, mpath);
return NULL;
}
and can compare it with the currents volume path
*/
int i = 0;
- while (volinfo->v_path[i]) {
- if ((pathbuf[i] == 0) || (volinfo->v_path[i] != pathbuf[i])) {
+ while (myvolinfo->v_path[i]) {
+ if ((pathbuf[i] == 0) || (myvolinfo->v_path[i] != pathbuf[i])) {
dbd_log( LOGDEBUG, "extra-share symlink '%s/%s', following", cwdbuf, name);
return 1;
}
else
adflags = ADFLAGS_DIR;
- adname = volinfo->ad_path(fname, adflags);
+ adname = myvolinfo->ad_path(fname, adflags);
if ((ret = access( adname, F_OK)) != 0) {
if (errno != ENOENT) {
return -1;
/* Create ad file */
- ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+ ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
if ((ret = ad_open_metadata( fname, adflags, O_CREAT, &ad)) != 0) {
dbd_log( LOGSTD, "Error creating AppleDouble file '%s/%s': %s",
chmod(adname, st->st_mode);
#endif
} else {
- ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+ ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
if (ad_open_metadata( fname, adflags, O_RDONLY, &ad) != 0) {
dbd_log( LOGSTD, "Error opening AppleDouble file for '%s/%s'", cwdbuf, fname);
return -1;
}
/* Check for ".Parent" */
- if ( (adpar_ok = access(volinfo->ad_path(".", ADFLAGS_DIR), F_OK)) != 0) {
+ if ( (adpar_ok = access(myvolinfo->ad_path(".", ADFLAGS_DIR), F_OK)) != 0) {
if (errno != ENOENT) {
dbd_log(LOGSTD, "Access error on '%s/%s': %s",
- cwdbuf, volinfo->ad_path(".", ADFLAGS_DIR), strerror(errno));
+ cwdbuf, myvolinfo->ad_path(".", ADFLAGS_DIR), strerror(errno));
return -1;
}
dbd_log(LOGSTD, "Missing .AppleDouble/.Parent for '%s'", cwdbuf);
}
/* Create ad dir and set name */
- ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+ ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
if (ad_open_metadata( ".", ADFLAGS_DIR, O_CREAT, &ad) != 0) {
dbd_log( LOGSTD, "Error creating AppleDouble dir in %s: %s", cwdbuf, strerror(errno));
return -1;
}
chown(ADv2_DIRNAME, st.st_uid, st.st_gid);
- chown(volinfo->ad_path(".", ADFLAGS_DIR), st.st_uid, st.st_gid);
+ chown(myvolinfo->ad_path(".", ADFLAGS_DIR), st.st_uid, st.st_gid);
}
return 0;
char *namep, *namedup = NULL;
/* Check if this is an AFPVOL_EA_AD vol */
- if (volinfo->v_vfs_ea == AFPVOL_EA_AD) {
+ if (myvolinfo->v_vfs_ea == AFPVOL_EA_AD) {
/* Does the filename contain "::EA" ? */
namedup = strdup(name);
if ((namep = strstr(namedup, "::EA")) == NULL) {
/* Get CNID from ad-file if volume is using AFPVOL_CACHE */
ad_cnid = 0;
- if ( (volinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
- ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+ if ( (myvolinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
+ ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
if (dbd_flags & DBD_FLAGS_CLEANUP)
memset(&rply, 0, sizeof(struct cnid_dbd_rply));
rqst.did = did;
rqst.cnid = ad_cnid;
- if ( ! (volinfo->v_flags & AFPVOL_NODEV))
+ if ( ! (myvolinfo->v_flags & AFPVOL_NODEV))
rqst.dev = st->st_dev;
rqst.ino = st->st_ino;
rqst.type = S_ISDIR(st->st_mode)?1:0;
db_cnid = rply.cnid;
dbd_log(LOGSTD, "New CNID for '%s/%s': %u", cwdbuf, name, ntohl(db_cnid));
- if ((volinfo->v_flags & AFPVOL_CACHE)
+ if ((myvolinfo->v_flags & AFPVOL_CACHE)
&& ADFILE_OK
&& ( ! (dbd_flags & DBD_FLAGS_SCAN))) {
dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file",
cwdbuf, name, ntohl(db_cnid));
- ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+ ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
cwdbuf, name, strerror(errno));
if ((ad_cnid == 0) && db_cnid) {
/* in db but zeroID in ad-file, write it to ad-file if AFPVOL_CACHE */
- if ((volinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
+ if ((myvolinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file",
cwdbuf, name, ntohl(db_cnid));
- ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+ ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
cwdbuf, name, strerror(errno));
}
/* Check EA files */
- if (volinfo->v_vfs_ea == AFPVOL_EA_AD)
+ if (myvolinfo->v_vfs_ea == AFPVOL_EA_AD)
check_eafiles(ep->d_name);
/**************************************************************************
}
/* Make this stuff accessible from all funcs easily */
- volinfo = vi;
+ myvolinfo = vi;
dbd_flags = flags;
/* Init a fake struct vol with just enough so we can call ea_open and friends */
volume.v_adouble = AD_VERSION2;
- volume.v_vfs_ea = volinfo->v_vfs_ea;
+ volume.v_vfs_ea = myvolinfo->v_vfs_ea;
initvol_vfs(&volume);
/* Run with umask 0 */
umask(0);
/* Remove trailing slash from volume, chdir to vol */
- if (volinfo->v_path[strlen(volinfo->v_path) - 1] == '/')
- volinfo->v_path[strlen(volinfo->v_path) - 1] = 0;
- strcpy(cwdbuf, volinfo->v_path);
- chdir(volinfo->v_path);
+ if (myvolinfo->v_path[strlen(myvolinfo->v_path) - 1] == '/')
+ myvolinfo->v_path[strlen(myvolinfo->v_path) - 1] = 0;
+ strcpy(cwdbuf, myvolinfo->v_path);
+ chdir(myvolinfo->v_path);
/* Start recursion */
if (dbd_readdir(1, htonl(2)) < 0) /* 2 = volumeroot CNID */
/*
Main func called from cmd_dbd.c
*/
-int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
+int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *vi, dbd_flags_t flags)
{
int ret = 0;
struct db_param db_param = { 0 };
dbd = dbd_ref;
/* We only support unicode volumes ! */
- if ( volinfo->v_volcharset != CH_UTF8) {
- dbd_log( LOGSTD, "Not a Unicode volume: %s, %u != %u", volinfo->v_volcodepage, volinfo->v_volcharset, CH_UTF8);
+ if ( vi->v_volcharset != CH_UTF8) {
+ dbd_log( LOGSTD, "Not a Unicode volume: %s, %u != %u", vi->v_volcodepage, vi->v_volcharset, CH_UTF8);
return -1;
}
goto exit_cleanup; /* Got signal, jump from dbd_readdir */
/* scanvol */
- if ( (scanvol(volinfo, flags)) != 0)
+ if ( (scanvol(vi, flags)) != 0)
return -1;
if (! nocniddb) {
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/cdefs.h>
#include <unistd.h>
-#include <atalk/logger.h>
+
#include <db.h>
+
+#include <atalk/logger.h>
+#include <atalk/util.h>
+
#include "db_param.h"
#include "dbif.h"
#include "pack.h"
#define DB_ERRLOGFILE "db_errlog"
-static char *old_dbfiles[] = {"cnid.db", NULL};
-
-/* --------------- */
-static int upgrade_required(const DBD *dbd)
+/*!
+ * Get the db stamp which is the st_ctime of the file "cnid2.db" and store it in buffer
+ */
+static int dbif_stamp(DBD *dbd, void *buffer, int size)
{
- int i;
- int cwd = -1;
- int ret = 0;
- int found = 0;
struct stat st;
+ int rc,cwd;
- if ( ! dbd->db_filename)
- /* in memory db */
- return 0;
+ if (size < 8)
+ return -1;
/* Remember cwd */
if ((cwd = open(".", O_RDONLY)) < 0) {
/* chdir to db_envhome */
if ((chdir(dbd->db_envhome)) != 0) {
LOG(log_error, logtype_cnid, "error chdiring to db_env '%s': %s", dbd->db_envhome, strerror(errno));
- ret = -1;
- goto exit;
+ return -1;
}
- for (i = 0; old_dbfiles[i] != NULL; i++) {
- if ( !(stat(old_dbfiles[i], &st) < 0) ) {
- found++;
- continue;
- }
- if (errno != ENOENT) {
- LOG(log_error, logtype_cnid, "cnid_open: Checking %s gave %s", old_dbfiles[i], strerror(errno));
- found++;
- }
+ if ((rc = stat(dbd->db_table[DBIF_CNID].name, &st)) < 0) {
+ LOG(log_error, logtype_cnid, "error stating database %s: %s", dbd->db_table[DBIF_CNID].name, db_strerror(errno));
+ return -1;
}
-exit:
- if (cwd != -1) {
- if ((fchdir(cwd)) != 0) {
- LOG(log_error, logtype_cnid, "error chdiring back: %s", strerror(errno));
- ret = -1;
- }
- close(cwd);
+ LOG(log_maxdebug, logtype_cnid,"stamp: %s", asctime(localtime(&st.st_ctime)));
+
+ memset(buffer, 0, size);
+ memcpy(buffer, &st.st_ctime, sizeof(st.st_ctime));
+
+ if ((fchdir(cwd)) != 0) {
+ LOG(log_error, logtype_cnid, "error chdiring back: %s", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+/*!
+ * Inititialize rootinfo key (which has CNID 0 as key)
+ *
+ * This also "stamps" the database, which means storing st.st_ctime of the
+ * "cnid2.db" file in the rootinfo data at the DEV offset
+ *
+ * @param dbd (rw) database handle
+ * @param version (r) database version number
+ *
+ * @returns -1 on error, 0 on success
+ */
+static int dbif_init_rootinfo(DBD *dbd, int version)
+{
+ DBT key, data;
+ uint32_t v;
+ char buf[ROOTINFO_DATALEN];
+
+ LOG(log_debug, logtype_cnid, "Setting CNID database version to %u", version);
+
+ v = version;
+ v = htonl(v);
+
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+ key.data = ROOTINFO_KEY;
+ key.size = ROOTINFO_KEYLEN;
+ data.data = buf;
+ data.size = ROOTINFO_DATALEN;
+
+ memcpy(buf, ROOTINFO_DATA, ROOTINFO_DATALEN);
+ memcpy(buf + CNID_DID_OFS, &v, sizeof(v));
+ if (dbif_stamp(dbd, buf + CNID_DEV_OFS, CNID_DEV_LEN) < 0)
+ return -1;
+
+ if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0)
+ return -1;
+
+ return 0;
+}
+
+/*!
+ * Return CNID database version number
+ *
+ * Returns version in *version
+ *
+ * @returns -1 on error, 0 if theres no rootinfo key yet, 1 if *version is returned
+ */
+static int dbif_getversion(DBD *dbd, uint32_t *version)
+{
+ DBT key, data;
+ int ret;
+
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+ key.data = ROOTINFO_KEY;
+ key.size = ROOTINFO_KEYLEN;
+
+ switch (dbif_get(dbd, DBIF_CNID, &key, &data, 0)) {
+ case 1: /* found */
+ memcpy(version, (char *)data.data + CNID_DID_OFS, sizeof(uint32_t));
+ *version = ntohl(*version);
+ LOG(log_debug, logtype_cnid, "CNID database version %u", *version);
+ ret = 1;
+ break;
+ case 0: /* not found */
+ ret = 0;
+ break;
+ default:
+ ret = -1;
+ break;
}
- return (ret < 0 ? ret : found);
+
+ return ret;
+}
+
+/*!
+ * Set CNID database version number
+ *
+ * Initializes rootinfo key as neccessary, as does dbif_getversion
+ * @returns -1 on error, 0 on success
+ */
+static int dbif_setversion(DBD *dbd, uint32_t version)
+{
+ int ret;
+ DBT key, data;
+ uint32_t v;
+
+ LOG(log_debug, logtype_cnid, "Setting CNID database version to %u", version);
+
+ v = version;
+ v = htonl(v);
+
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+ key.data = ROOTINFO_KEY;
+ key.size = ROOTINFO_KEYLEN;
+
+ if ((ret = dbif_get(dbd, DBIF_CNID, &key, &data, 0)) == -1)
+ return -1;
+ if (ret == 0) {
+ /* No rootinfo key yet, init it */
+ if (dbif_init_rootinfo(dbd, CNID_VERSION) != 0)
+ return -1;
+ /* Now try again */
+ if (dbif_get(dbd, DBIF_CNID, &key, &data, 0) == -1)
+ return -1;
+ }
+ memcpy((char *)data.data + CNID_DID_OFS, &v, sizeof(v));
+ data.size = ROOTINFO_DATALEN;
+ if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0)
+ return -1;
+
+ return 0;
}
/*!
*/
static int dbif_upgrade(DBD *dbd)
{
- int version;
+ uint32_t version;
- if ((version = dbif_getversion(dbd)) == -1)
+ if (dbif_getversion(dbd, &version) == -1)
return -1;
/*
return ret;
}
-#include <atalk/util.h>
-
-/* --------------- */
-int dbif_stamp(DBD *dbd, void *buffer, int size)
-{
- struct stat st;
- int rc,cwd;
-
- if (size < 8)
- return -1;
-
- /* Remember cwd */
- if ((cwd = open(".", O_RDONLY)) < 0) {
- LOG(log_error, logtype_cnid, "error opening cwd: %s", strerror(errno));
- return -1;
- }
-
- /* chdir to db_envhome */
- if ((chdir(dbd->db_envhome)) != 0) {
- LOG(log_error, logtype_cnid, "error chdiring to db_env '%s': %s", dbd->db_envhome, strerror(errno));
- return -1;
- }
-
- if ((rc = stat(dbd->db_table[DBIF_CNID].name, &st)) < 0) {
- LOG(log_error, logtype_cnid, "error stating database %s: %s", dbd->db_table[DBIF_CNID].name, db_strerror(errno));
- return -1;
- }
-
- LOG(log_maxdebug, logtype_cnid,"stamp: %s", asctime(localtime(&st.st_ctime)));
-
- memset(buffer, 0, size);
- memcpy(buffer, &st.st_ctime, sizeof(st.st_ctime));
-
- if ((fchdir(cwd)) != 0) {
- LOG(log_error, logtype_cnid, "error chdiring back: %s", strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
/* --------------- */
DBD *dbif_init(const char *envhome, const char *filename)
{
/*
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 upgrade_required() and the DB_ERRLOGFILE
+ 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.
*/
{
int ret;
- /* Refuse to do anything if this is an old version of the CNID database */
- if (upgrade_required(dbd)) {
- LOG(log_error, logtype_cnid, "Found version 1 of the CNID database. Please upgrade to version 2");
- return -1;
- }
-
if ((ret = db_env_create(&dbd->db_env, 0))) {
LOG(log_error, logtype_cnid, "error creating DB environment: %s",
db_strerror(ret));
if (reindex)
LOG(log_info, logtype_cnid, "Reindexing name index...");
- int version = CNID_VERSION;
- if (dbd->db_envhome) {
- if ((version = dbif_getversion(dbd)) == -1)
+ uint32_t version = CNID_VERSION;
+ if (dbd->db_envhome && !reindex) {
+ if (dbif_getversion(dbd, &version) == -1)
return -1;
}
return 1;
}
-/*!
- * Inititialize rootinfo key (which has CNID 0 as key)
- *
- * This also "stamps" the database, which means storing st.st_ctime of the
- * "cnid2.db" file in the rootinfo data at the DEV offset
- *
- * @param dbd (rw) database handle
- * @param version (r) database version number
- *
- * @returns -1 on error, 0 on success
- */
-static int dbif_init_rootinfo(DBD *dbd, int version)
-{
- DBT key, data;
- uint32_t v;
- char buf[ROOTINFO_DATALEN];
-
- LOG(log_debug, logtype_cnid, "Setting CNID database version to %u", version);
-
- v = version;
- v = htonl(v);
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = ROOTINFO_KEY;
- key.size = ROOTINFO_KEYLEN;
- data.data = buf;
- data.size = ROOTINFO_DATALEN;
-
- memcpy(buf, ROOTINFO_DATA, ROOTINFO_DATALEN);
- memcpy(buf + CNID_DID_OFS, &v, sizeof(v));
- if (dbif_stamp(dbd, buf + CNID_DEV_OFS, CNID_DEV_LEN) < 0)
- return -1;
-
- if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0)
- return -1;
-
- return 0;
-}
-
-/*!
- * Initialize or return CNID database version number
- *
- * Calls dbif_init_rootinfo if the rootinfo key does not exist yet
- *
- * @returns -1 on error, version number otherwise
- */
-int dbif_getversion(DBD *dbd)
-{
- DBT key, data;
- uint32_t version;
- int ret;
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = ROOTINFO_KEY;
- key.size = ROOTINFO_KEYLEN;
-
- switch (dbif_get(dbd, DBIF_CNID, &key, &data, 0)) {
- case 1: /* found */
- memcpy(&version, (char *)data.data + CNID_DID_OFS, sizeof(version));
- version = ntohl(version);
- LOG(log_debug, logtype_cnid, "CNID database version %u", version);
- ret = version;
- break;
- case 0: /* not found */
- if (dbif_init_rootinfo(dbd, CNID_VERSION) != 0)
- return -1;
- ret = CNID_VERSION;
- break;
- default:
- return -1;
- }
- return ret;
-}
-
-/*!
- * Set CNID database version number
- *
- * Initializes rootinfo key as neccessary, as does dbif_getversion
- * @returns -1 on error, version number otherwise
- */
-int dbif_setversion(DBD *dbd, int version)
-{
- int ret;
- DBT key, data;
- uint32_t v;
-
- LOG(log_debug, logtype_cnid, "Setting CNID database version to %u", version);
-
- v = version;
- v = htonl(v);
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = ROOTINFO_KEY;
- key.size = ROOTINFO_KEYLEN;
-
- if ((ret = dbif_get(dbd, DBIF_CNID, &key, &data, 0)) == -1)
- return -1;
- if (ret == 0) {
- /* No rootinfo key yet, init it */
- if (dbif_init_rootinfo(dbd, CNID_VERSION) != 0)
- return -1;
- /* Now try again */
- if (dbif_get(dbd, DBIF_CNID, &key, &data, 0) == -1)
- return -1;
- }
- memcpy((char *)data.data + CNID_DID_OFS, &v, sizeof(v));
- data.size = ROOTINFO_DATALEN;
- if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0)
- return -1;
-
- return 0;
-}
-
/*!
* Search the database by name
*
extern int dbif_open(DBD *dbd, struct db_param *dbp, int reindex);
extern int dbif_close(DBD *dbd);
extern int dbif_env_remove(const char *path);
-extern int dbif_getversion(DBD *dbd);
-extern int dbif_setversion(DBD *dbd, int);
extern int dbif_get(DBD *, const int, DBT *, DBT *, u_int32_t);
extern int dbif_pget(DBD *, const int, DBT *, DBT *, DBT *, u_int32_t);
extern int dbif_put(DBD *, const int, DBT *, DBT *, u_int32_t);
extern int dbif_del(DBD *, const int, DBT *, u_int32_t);
extern int dbif_count(DBD *, const int, u_int32_t *);
-extern int dbif_stamp(DBD *, void *, int);
extern int dbif_search(DBD *dbd, DBT *key, char *resbuf);
extern int dbif_copy_rootinfokey(DBD *srcdbd, DBD *destdbd);
extern int dbif_txn_begin(DBD *);
*/
#define DBOPTIONS (DB_CREATE | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | DB_RECOVER)
-/* Global */
+/* Global, needed by pack.c:idxname() */
struct volinfo volinfo;
static DBD *dbd;
/* --------------- */
int idxname(DB *dbp _U_, const DBT *pkey _U_, const DBT *pdata, DBT *skey)
{
- char buffer[MAXPATHLEN +2];
+ static char buffer[MAXPATHLEN +2];
uint16_t flags = CONV_TOLOWER;
memset(skey, 0, sizeof(DBT));
- skey->data = (char *)pdata->data + CNID_NAME_OFS;
if (convert_charset(volinfo.v_volcharset,
volinfo.v_volcharset,