/*
- $Id: cmd_dbd.c,v 1.7 2009-09-14 01:24:40 didg Exp $
+ $Id: cmd_dbd.c,v 1.8 2009-10-12 11:30:52 franklahm Exp $
Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
#define LOCKFILENAME "lock"
#define DBOPTIONS (DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN)
-static DBD *dbd;
-
+int nocniddb = 0; /* Dont open CNID database, only scan filesystem */
volatile sig_atomic_t alarmed;
+
+static DBD *dbd;
static int verbose; /* Logging flag */
static int exclusive; /* Exclusive volume access */
static struct db_param db_param = {
static void usage ()
{
- printf("Usage: dbd [-e|-v|-x|-u] -d [-i] | -s | -r [-f] <path to netatalk volume>\n"
+ printf("Usage: dbd [-e|-v|-x|-u] -d [-i] | -s [-n]| -r [-f] <path to netatalk volume>\n"
"dbd can dump, scan, reindex and rebuild Netatalk dbd CNID databases.\n"
"dbd must be run with appropiate permissions i.e. as root.\n\n"
"Main commands are:\n"
" 5. Check for directories inside AppleDouble directories\n"
" 6. Check name encoding by roundtripping, log on error\n"
" 7. Check for orphaned CNIDs in database (requires -e)\n"
+ " 8. Open and close adouble files\n"
+ " Option: -n Don't open CNID database, skip CNID checks\n"
" -r Rebuild volume:\n"
" 1. Sync CNIDSs in database with volume\n"
" 2. Make sure .AppleDouble dir exist, create if missing\n"
" 5. Check for directories inside AppleDouble directories\n"
" 6. Check name encoding by roundtripping, log on error\n"
" 7. Check for orphaned CNIDs in database (requires -e)\n"
+ " 8. Open and close adouble files\n"
" Option: -f wipe database and rebuild from IDs stored in AppleDouble files,\n"
" only available for volumes with 'cachecnid' option. Implies -e.\n"
" -u Prepare upgrade:\n"
exit(EXIT_FAILURE);
}
- while ((c = getopt(argc, argv, ":dsruvxife")) != -1) {
+ while ((c = getopt(argc, argv, ":dsnruvxife")) != -1) {
switch(c) {
case 'd':
dump = 1;
scan = 1;
flags |= DBD_FLAGS_SCAN;
break;
+ case 'n':
+ nocniddb = 1;
+ break;
case 'r':
rebuild = 1;
break;
/*
Lets start with the BerkeleyDB stuff
*/
- if ((dbd = dbif_init(dbpath, "cnid2.db")) == NULL)
- goto exit_failure;
-
- if (dbif_env_open(dbd, &db_param, exclusive ? (DBOPTIONS | DB_RECOVER) : DBOPTIONS) < 0) {
- dbd_log( LOGSTD, "error opening database!");
- goto exit_failure;
- }
+ if ( ! nocniddb) {
+ if ((dbd = dbif_init(dbpath, "cnid2.db")) == NULL)
+ goto exit_failure;
+
+ if (dbif_env_open(dbd, &db_param, exclusive ? (DBOPTIONS | DB_RECOVER) : DBOPTIONS) < 0) {
+ dbd_log( LOGSTD, "error opening database!");
+ goto exit_failure;
+ }
- if (exclusive)
- dbd_log( LOGDEBUG, "Finished recovery.");
+ if (exclusive)
+ dbd_log( LOGDEBUG, "Finished recovery.");
- if (dbif_open(dbd, &db_param, rebuildindexes) < 0) {
- dbif_close(dbd);
- goto exit_failure;
- }
+ if (dbif_open(dbd, &db_param, rebuildindexes) < 0) {
+ dbif_close(dbd);
+ goto exit_failure;
+ }
- if (dbd_stamp(dbd) < 0) {
- dbif_close(dbd);
- goto exit_failure;
+ if (dbd_stamp(dbd) < 0) {
+ dbif_close(dbd);
+ goto exit_failure;
+ }
}
- if (dump) {
+ /* Now execute given command scan|rebuild|dump */
+ if (dump && ! nocniddb) {
if (dbif_dump(dbd, dumpindexes) < 0) {
dbd_log( LOGSTD, "Error dumping database");
}
- } else if (rebuild || scan) {
+ } else if ((rebuild && ! nocniddb) || (scan && nocniddb)) {
if (cmd_dbd_scanvol(dbd, &volinfo, flags) < 0) {
dbd_log( LOGSTD, "Error repairing database.");
}
}
- if (dbif_close(dbd) < 0) {
+ /* Cleanup */
+ if (! nocniddb && dbif_close(dbd) < 0) {
dbd_log( LOGSTD, "Error closing database");
goto exit_failure;
}
/*
- $Id: cmd_dbd_scanvol.c,v 1.8 2009-09-14 02:56:19 didg Exp $
+ $Id: cmd_dbd_scanvol.c,v 1.9 2009-10-12 11:30:52 franklahm Exp $
Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
return -1;
}
/* Missing. Log and create it */
- dbd_log(LOGSTD, "Missing AppleDoube file '%s/%s'", cwdbuf, adname);
+ dbd_log(LOGSTD, "Missing AppleDouble file '%s/%s'", cwdbuf, adname);
if (dbd_flags & DBD_FLAGS_SCAN)
/* Scan only requested, dont change anything */
if ((ret = ad_open_metadata( fname, adflags, O_CREAT, &ad)) != 0) {
dbd_log( LOGSTD, "Error creating AppleDouble file '%s/%s': %s",
cwdbuf, adname, strerror(errno));
+
return -1;
}
#if 0
chmod(adname, st->st_mode);
#endif
+ } else {
+ ad_init(&ad, volinfo->v_adouble, volinfo->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;
+ }
+ ad_close_metadata(&ad);
}
return 0;
}
if (ADDIR_OK)
adfile_ok = check_adfile(ep->d_name, &st);
- /* Check CNIDs */
- cnid = check_cnid(ep->d_name, did, &st, adfile_ok, adflags);
-
- /* Now add this object to our rebuild dbd */
- if (cnid) {
- rqst.cnid = rply.cnid;
- dbd_rebuild_add(dbd_rebuild, &rqst, &rply);
- if (rply.result != CNID_DBD_RES_OK) {
- dbd_log( LOGDEBUG, "Fatal error adding CNID: %u for '%s/%s' to in-memory rebuild-db",
- cnid, cwdbuf, ep->d_name);
- exit(EXIT_FAILURE);
+ if ( ! nocniddb) {
+ /* Check CNIDs */
+ cnid = check_cnid(ep->d_name, did, &st, adfile_ok, adflags);
+
+ /* Now add this object to our rebuild dbd */
+ if (cnid) {
+ rqst.cnid = rply.cnid;
+ dbd_rebuild_add(dbd_rebuild, &rqst, &rply);
+ if (rply.result != CNID_DBD_RES_OK) {
+ dbd_log( LOGDEBUG, "Fatal error adding CNID: %u for '%s/%s' to in-memory rebuild-db",
+ cnid, cwdbuf, ep->d_name);
+ exit(EXIT_FAILURE);
+ }
}
}
/**************************************************************************
Recursion
**************************************************************************/
- if (S_ISDIR(st.st_mode) && cnid) { /* If we have no cnid for it we cant recur */
+ if (S_ISDIR(st.st_mode) && (cnid || nocniddb)) { /* If we have no cnid for it we cant recur */
strcat(cwdbuf, "/");
strcat(cwdbuf, ep->d_name);
dbd_log( LOGDEBUG, "Entering directory: %s", cwdbuf);
return -1;
}
- /* Get volume stamp */
- dbd_getstamp(dbd, &rqst, &rply);
- if (rply.result != CNID_DBD_RES_OK)
- goto exit_cleanup;
- memcpy(stamp, rply.name, CNID_DEV_LEN);
+ if (! nocniddb) {
+ /* Get volume stamp */
+ dbd_getstamp(dbd, &rqst, &rply);
+ if (rply.result != CNID_DBD_RES_OK)
+ goto exit_cleanup;
+ memcpy(stamp, rply.name, CNID_DEV_LEN);
- /* open/create rebuild dbd, copy rootinfo key */
- if (NULL == (dbd_rebuild = dbif_init(NULL, NULL)))
- return -1;
- if (0 != (dbif_open(dbd_rebuild, NULL, 0)))
- return -1;
- if (0 != (dbif_copy_rootinfokey(dbd, dbd_rebuild)))
- goto exit_cleanup;
+ /* open/create rebuild dbd, copy rootinfo key */
+ if (NULL == (dbd_rebuild = dbif_init(NULL, NULL)))
+ return -1;
+ if (0 != (dbif_open(dbd_rebuild, NULL, 0)))
+ return -1;
+ if (0 != (dbif_copy_rootinfokey(dbd, dbd_rebuild)))
+ goto exit_cleanup;
+ }
if (setjmp(jmp) != 0)
goto exit_cleanup; /* Got signal, jump from dbd_readdir */
if ( (scanvol(volinfo, flags)) != 0)
return -1;
+ if (! nocniddb) {
/* We can only do this in exclusive mode, otherwise we might delete CNIDs added from
other clients in between our pass 1 and 2 */
- if (flags & DBD_FLAGS_EXCL)
- delete_orphaned_cnids(dbd, dbd_rebuild, flags);
+ if (flags & DBD_FLAGS_EXCL)
+ delete_orphaned_cnids(dbd, dbd_rebuild, flags);
+ }
exit_cleanup:
- dbif_close(dbd_rebuild);
+ if (! nocniddb)
+ dbif_close(dbd_rebuild);
return ret;
}