X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=etc%2Fcnid_dbd%2Fcmd_dbd_scanvol.c;h=7cf72871de3990e87b4e3c5f8e1b98b9c183d3d6;hp=576df49fb570bd26009014e9ac8226d75eda5f6d;hb=2fdd522410f80afcd055d7333f491ee6c0b4b9fa;hpb=154c130f7a3a407e686eda99a6658773e137b05f diff --git a/etc/cnid_dbd/cmd_dbd_scanvol.c b/etc/cnid_dbd/cmd_dbd_scanvol.c index 576df49f..7cf72871 100644 --- a/etc/cnid_dbd/cmd_dbd_scanvol.c +++ b/etc/cnid_dbd/cmd_dbd_scanvol.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "cmd_dbd.h" #include "dbif.h" @@ -292,17 +293,16 @@ static const char *check_special_dirs(const char *name) */ static int check_adfile(const char *fname, const struct stat *st) { - int ret, adflags; + int ret; + int adflags = ADFLAGS_HF; struct adouble ad; - char *adname; + const char *adname; if (dbd_flags & DBD_FLAGS_CLEANUP) return 0; if (S_ISREG(st->st_mode)) - adflags = 0; - else - adflags = ADFLAGS_DIR; + adflags |= ADFLAGS_DIR; adname = myvolinfo->ad_path(fname, adflags); @@ -322,7 +322,7 @@ static int check_adfile(const char *fname, const struct stat *st) /* Create ad file */ ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options); - if ((ret = ad_open_metadata( fname, adflags, O_CREAT, &ad)) != 0) { + if ((ret = ad_open(&ad, fname, adflags, O_CREAT | O_RDWR, 0666)) != 0) { dbd_log( LOGSTD, "Error creating AppleDouble file '%s/%s': %s", cwdbuf, adname, strerror(errno)); @@ -341,7 +341,7 @@ static int check_adfile(const char *fname, const struct stat *st) #endif } else { ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options); - if (ad_open_metadata( fname, adflags, O_RDONLY, &ad) != 0) { + if (ad_open(&ad, fname, adflags, O_RDONLY) != 0) { dbd_log( LOGSTD, "Error opening AppleDouble file for '%s/%s'", cwdbuf, fname); return -1; } @@ -494,7 +494,7 @@ static int check_addir(int volroot) /* Create ad dir and set name */ ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options); - if (ad_open_metadata( ".", ADFLAGS_DIR, O_CREAT, &ad) != 0) { + if (ad_open(&ad, ".", ADFLAGS_HF | ADFLAGS_DIR, O_CREAT | O_RDWR, 0777) != 0) { dbd_log( LOGSTD, "Error creating AppleDouble dir in %s: %s", cwdbuf, strerror(errno)); return -1; } @@ -690,7 +690,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi ad_cnid = 0; 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 (ad_open(&ad, name, adflags, O_RDWR) != 0) { if (dbd_flags & DBD_FLAGS_CLEANUP) return CNID_INVALID; @@ -706,7 +706,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi ad_flush(&ad); } else - ad_cnid = ad_getid(&ad, st->st_dev, st->st_ino, did, stamp); + ad_cnid = ad_getid(&ad, st->st_dev, st->st_ino, 0, stamp); if (ad_cnid == 0) dbd_log( LOGSTD, "Bad CNID in adouble file of '%s/%s'", cwdbuf, name); @@ -791,7 +791,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file", cwdbuf, name, ntohl(db_cnid)); ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options); - if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) { + if (ad_open(&ad, name, adflags, O_RDWR) != 0) { dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s", cwdbuf, name, strerror(errno)); return CNID_INVALID; @@ -831,7 +831,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file", cwdbuf, name, ntohl(db_cnid)); ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options); - if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) { + if (ad_open(&ad, name, adflags, O_RDWR) != 0) { dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s", cwdbuf, name, strerror(errno)); return CNID_INVALID; @@ -1082,8 +1082,6 @@ static void delete_orphaned_cnids(DBD *dbd, DBD *dbd_rebuild, dbd_flags_t flags) struct cnid_dbd_rqst rqst; struct cnid_dbd_rply rply; - dbd->db_param.txn_frequency = 0; - /* jump over rootinfo key */ if ( dbif_idwalk(dbd, &dbd_cnid, 0) != 1) return; @@ -1198,7 +1196,6 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *vi, dbd_flags_t flags) db_param.cachesize = 64 * 1024; /* 64 MB */ db_param.maxlocks = DEFAULT_MAXLOCKS; db_param.maxlockobjs = DEFAULT_MAXLOCKOBJS; - db_param.txn_frequency = 1000; /* close txn every 1000 objects */ db_param.logfile_autoremove = 1; /* Make it accessible for all funcs */ @@ -1210,15 +1207,16 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *vi, dbd_flags_t flags) return -1; } - /* temporary rebuild db, used with -re rebuild to delete unused CNIDs, not used with -f */ - if (! nocniddb && !(flags & DBD_FLAGS_FORCE)) { - /* Get volume stamp */ - dbd_getstamp(dbd, &rqst, &rply); - if (rply.result != CNID_DBD_RES_OK) - goto exit; - memcpy(stamp, rply.name, CNID_DEV_LEN); + /* Get volume stamp */ + dbd_getstamp(dbd, &rqst, &rply); + if (rply.result != CNID_DBD_RES_OK) { + ret = -1; + goto exit; + } + memcpy(stamp, rply.name, CNID_DEV_LEN); - /* open/create rebuild dbd, copy rootinfo key */ + /* temporary rebuild db, used with -re rebuild to delete unused CNIDs, not used with -f */ + if (! nocniddb && (flags & DBD_FLAGS_EXCL) && !(flags & DBD_FLAGS_FORCE)) { tmpdb_path = get_tmpdb_path(); if (NULL == (dbd_rebuild = dbif_init(tmpdb_path, "cnid2.db"))) { ret = -1; @@ -1256,10 +1254,10 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *vi, dbd_flags_t flags) exit: if (! nocniddb) { - if (dbif_txn_close(dbd, 2) != 0) + if (dbif_txn_close(dbd, ret == 0 ? 1 : 0) != 0) ret = -1; if (dbd_rebuild) - if (dbif_txn_close(dbd_rebuild, 2) != 0) + if (dbif_txn_close(dbd_rebuild, ret == 0 ? 1 : 0) != 0) ret = -1; if ((ret == 0) && dbd_rebuild && (flags & DBD_FLAGS_EXCL) && !(flags & DBD_FLAGS_FORCE)) /* We can only do this in exclusive mode, otherwise we might delete CNIDs added from