X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fcnid_dbd%2Fcmd_dbd.c;h=ad0e22b4189acba3c2343baef0e8b11a8cc1ad8f;hb=260c314546ffcfdbef47f2c7de82d5310b26df0a;hp=e07741564136026d719db8505bb04df8f3101c0c;hpb=631499485e36f463ee795f7173c57e5f23de9d20;p=netatalk.git diff --git a/etc/cnid_dbd/cmd_dbd.c b/etc/cnid_dbd/cmd_dbd.c index e0774156..ad0e22b4 100644 --- a/etc/cnid_dbd/cmd_dbd.c +++ b/etc/cnid_dbd/cmd_dbd.c @@ -12,49 +12,6 @@ GNU General Public License for more details. */ -/* - dbd specs and implementation progress - ===================================== - - St := Status - - Force option - ------------ - - St Spec - -- ---- - OK If -f is requested, ensure -e is too. - Check if volumes is using AFPVOL_CACHE, then wipe db from disk. Rebuild from ad-files. - - 1st pass: Scan volume - -------------------- - - St Type Check - -- ---- ----- - OK F/D Make sure ad file exists - OK D Make sure .AppleDouble dir exist, create if missing. Error creating - it is fatal as that shouldn't happen as root. - OK F/D Delete orphaned ad-files, log dirs in ad-dir - OK F/D Check name encoding by roundtripping, log on error - OK F/D try: read CNID from ad file (if cnid caching is on) - try: fetch CNID from database - -> on mismatch: use CNID from file, update database (deleting both found CNIDs first) - -> if no CNID in ad file: write CNID from database to ad file - -> if no CNID in database: add CNID from ad file to database - -> on no CNID at all: create one and store in both places - OK F/D Add found CNID, DID, filename, dev/inode, stamp to rebuild database - OK F/D Check/update stamp (implicitly done while checking CNIDs) - - - 2nd pass: Delete unused CNIDs - ----------------------------- - - St Spec - -- ---- - OK Step through dbd (the one on disk) and rebuild-db from pass 1 and delete any CNID from - dbd not in rebuild db. This in only done in exclusive mode. -*/ - #ifdef HAVE_CONFIG_H #include "config.h" #endif /* HAVE_CONFIG_H */ @@ -170,7 +127,8 @@ static void set_signal(void) static void usage (void) { - printf("Usage: dbd [-e|-t|-v|-x] -d [-i] | -s [-c|-n]| -r [-c|-f] | -u \n" + printf("dbd (Netatalk %s)\n" + "Usage: dbd [-e|-t|-v|-x] -d [-i] | -s [-c|-n]| -r [-c|-f] | -u \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" @@ -186,7 +144,7 @@ static void usage (void) " 7. Check for orphaned CNIDs in database (requires -e)\n" " 8. Open and close adouble files\n" " Options: -c Don't check .AppleDouble stuff, only ckeck orphaned.\n" - " -n Don't open CNID database, skip CNID checks\n\n" + " -n Don't open CNID database, skip CNID checks.\n\n" " -r Rebuild volume:\n" " 1. Sync CNIDSs in database with volume\n" " 2. Make sure .AppleDouble dir exist, create if missing\n" @@ -197,18 +155,21 @@ static void usage (void) " 7. Check for orphaned CNIDs in database (requires -e)\n" " 8. Open and close adouble files\n" " Options: -c Don't create .AppleDouble stuff, only cleanup orphaned.\n" - " -f wipe database and rebuild from IDs stored in AppleDouble files,\n" - " only available for volumes without 'nocnidcache' option. Implies -e.\n\n" + " -f wipe database and rebuild from IDs stored in AppleDouble\n" + " files, only available for volumes without 'nocnidcache'\n" + " option. Implies -e.\n\n" " -u Upgrade:\n" - " Opens the database which triggers any necessary upgrades, then closes and exits.\n\n" + " Opens the database which triggers any necessary upgrades,\n" + " then closes and exits.\n\n" "General options:\n" " -e only work on inactive volumes and lock them (exclusive)\n" " -x rebuild indexes (just for completeness, mostly useless!)\n" " -t show statistics while running\n" " -v verbose\n\n" "WARNING:\n" - "For -r -f restore of the CNID database from the adouble files, the CNID must of course\n" - "be synched to them files first with a plain -r rebuild !\n" + "For -r -f restore of the CNID database from the adouble files,\n" + "the CNID must of course be synched to them files first with a plain -r rebuild!\n" + , VERSION ); } @@ -301,9 +262,9 @@ int main(int argc, char **argv) /* Setup logging. Should be portable among *NIXes */ if (!verbose) - setuplog("default log_info /dev/tty"); + setuplog("default:info", "/dev/tty"); else - setuplog("default log_debug /dev/tty"); + setuplog("default:debug", "/dev/tty"); /* Load .volinfo file */ if (loadvolinfo(volpath, &volinfo) == -1) { @@ -315,6 +276,15 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } + if (volinfo.v_adouble == AD_VERSION_EA) + dbd_log( LOGDEBUG, "adouble:ea volume"); + else if (volinfo.v_adouble == AD_VERSION2) + dbd_log( LOGDEBUG, "adouble:v2 volume"); + else { + dbd_log( LOGSTD, "unknown adouble volume"); + exit(EXIT_FAILURE); + } + /* Sanity checks to ensure we can touch this volume */ if (volinfo.v_vfs_ea != AFPVOL_EA_AD && volinfo.v_vfs_ea != AFPVOL_EA_SYS) { dbd_log( LOGSTD, "Unknown Extended Attributes option: %u", volinfo.v_vfs_ea); @@ -360,22 +330,22 @@ int main(int argc, char **argv) /* Get db lock */ if ((db_locked = get_lock(LOCK_EXCL, dbpath)) == -1) - goto exit_failure; + goto exit_noenv; if (db_locked != LOCK_EXCL) { /* Couldn't get exclusive lock, try shared lock if -e wasn't requested */ if (exclusive) { dbd_log(LOGSTD, "Database is in use and exlusive was requested"); - goto exit_failure; + goto exit_noenv; } if ((db_locked = get_lock(LOCK_SHRD, NULL)) != LOCK_SHRD) - goto exit_failure; + goto exit_noenv; } /* Check if -f is requested and wipe db if yes */ - if ((flags & DBD_FLAGS_FORCE) && rebuild && (volinfo.v_flags & AFPVOL_CACHE)) { + if ((flags & DBD_FLAGS_FORCE) && rebuild) { char cmd[8 + MAXPATHLEN]; if ((db_locked = get_lock(LOCK_FREE, NULL)) != 0) - goto exit_failure; + goto exit_noenv; snprintf(cmd, 8 + MAXPATHLEN, "rm -rf \"%s\"", dbpath); dbd_log( LOGDEBUG, "Removing old database of volume: '%s'", volpath); @@ -386,7 +356,7 @@ int main(int argc, char **argv) } dbd_log( LOGDEBUG, "Removed old database."); if ((db_locked = get_lock(LOCK_EXCL, dbpath)) == -1) - goto exit_failure; + goto exit_noenv; } /* @@ -394,13 +364,13 @@ int main(int argc, char **argv) */ if ( ! nocniddb) { if ((dbd = dbif_init(dbpath, "cnid2.db")) == NULL) - goto exit_failure; + goto exit_noenv; if (dbif_env_open(dbd, &db_param, (db_locked == LOCK_EXCL) ? (DBOPTIONS | DB_RECOVER) : DBOPTIONS) < 0) { dbd_log( LOGSTD, "error opening database!"); - goto exit_failure; + goto exit_noenv; } if (db_locked == LOCK_EXCL) @@ -451,8 +421,13 @@ exit_success: ret = 0; exit_failure: + if (dbif_env_remove(dbpath) < 0) { + dbd_log( LOGSTD, "Error removing BerkeleyDB database environment"); + ret++; + } get_lock(0, NULL); - + +exit_noenv: if ((fchdir(cdir)) < 0) dbd_log(LOGSTD, "fchdir: %s", strerror(errno));