~ubuntu-branches/debian/wheezy/netatalk/wheezy

« back to all changes in this revision

Viewing changes to etc/cnid_dbd/cmd_dbd_scanvol.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2011-06-05 21:04:21 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110605210421-19gag2srevj0ocxh
Tags: 2.2~beta4-1
* New upstream release.
  + Fixes "Internal Error" after ad_open on sparc.
    Closes: bug#606005. Thanks to Alfredo Sola.
* Adjust references to unofficial packages in README.Debian.
* Use dversionmangle (not uversionmangle) in watch file. Fix add
  leading dash (-) to upstream version in mangling.
* Update patches:
  + Drop patches 107 and 294 (Zeroconf support): Implemented
    (differently) upstream now.
  + Drop patches 109 and 112 (avoid broken XFS linkage) obsolete.
  + Drop patch 200 (hostname resolving): adopted upstream.
  + Refresh patch 205.
* Rewrite copyright file using draft 174 of DEP-5 format.
* Build-depend on and recommend unversioned (i.e. default) BerkeleyDB
  packages.
  Closes: bug#621413. Thanks to Ondřej Surý.
  Simplify suggestions on older versioned BerkeleyDB packages.
* Stop installing some documentation dropped upstream, and let CDBS
  automagically handle some of the remains.
* Update control file:
  + Bump policy compliance to standards-version 3.9.2.
  + Shorten Vcs-* URLs.
* Add patches 115 and (for automade file) 214 to avoid installing
  unneeded /default dir.
  Closes: bug#628119. Thanks to Russell Muetzelfeldt and Luk Claes.
* Don't ship .la files. Closes: bug#621849. Thanks to Andreas Metzler
  and Luk Claes.
* Stop renaming afile and achfile, dropped upstream.
* Explicitly enable DDP (AppleTalk), now disabled by default.
* Enable Zeroconf, should be stable now.
* Simplify package relations:
  + Drop (build-)dependency fallback unneeded even for oldstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <atalk/volume.h>
34
34
#include <atalk/ea.h>
35
35
#include <atalk/util.h>
 
36
#include <atalk/acl.h>
36
37
 
37
38
#include "cmd_dbd.h"
38
39
#include "dbif.h"
43
44
#define ADDIR_OK (addir_ok == 0)
44
45
#define ADFILE_OK (adfile_ok == 0)
45
46
 
46
 
/* These must be accessible for cmd_dbd_* funcs */
47
 
struct volinfo        *volinfo;
48
 
char                  cwdbuf[MAXPATHLEN+1];
49
47
 
50
 
/* Some static vars */
 
48
static struct volinfo *myvolinfo;
 
49
static char           cwdbuf[MAXPATHLEN+1];
51
50
static DBD            *dbd;
52
51
static DBD            *dbd_rebuild;
53
52
static dbd_flags_t    dbd_flags;
84
83
    u = upath;
85
84
    outlen = strlen(upath);
86
85
 
87
 
    if ((volinfo->v_casefold & AFPVOL_UTOMUPPER))
 
86
    if ((myvolinfo->v_casefold & AFPVOL_UTOMUPPER))
88
87
        flags |= CONV_TOUPPER;
89
 
    else if ((volinfo->v_casefold & AFPVOL_UTOMLOWER))
 
88
    else if ((myvolinfo->v_casefold & AFPVOL_UTOMLOWER))
90
89
        flags |= CONV_TOLOWER;
91
90
 
92
 
    if ((volinfo->v_flags & AFPVOL_EILSEQ)) {
 
91
    if ((myvolinfo->v_flags & AFPVOL_EILSEQ)) {
93
92
        flags |= CONV__EILSEQ;
94
93
    }
95
94
 
96
95
    /* convert charsets */
97
 
    if ((size_t)-1 == ( outlen = convert_charset(volinfo->v_volcharset,
 
96
    if ((size_t)-1 == ( outlen = convert_charset(myvolinfo->v_volcharset,
98
97
                                                 CH_UTF8_MAC,
99
 
                                                 volinfo->v_maccharset,
 
98
                                                 myvolinfo->v_maccharset,
100
99
                                                 u, outlen, mpath, MAXPATHLEN, &flags)) ) {
101
100
        dbd_log( LOGSTD, "Conversion from %s to %s for %s failed.",
102
 
                 volinfo->v_volcodepage, volinfo->v_maccodepage, u);
 
101
                 myvolinfo->v_volcodepage, myvolinfo->v_maccodepage, u);
103
102
        return NULL;
104
103
    }
105
104
 
125
124
    }
126
125
 
127
126
    /* set conversion flags */
128
 
    if (!(volinfo->v_flags & AFPVOL_NOHEX))
 
127
    if (!(myvolinfo->v_flags & AFPVOL_NOHEX))
129
128
        flags |= CONV_ESCAPEHEX;
130
 
    if (!(volinfo->v_flags & AFPVOL_USEDOTS))
 
129
    if (!(myvolinfo->v_flags & AFPVOL_USEDOTS))
131
130
        flags |= CONV_ESCAPEDOTS;
132
131
 
133
 
    if ((volinfo->v_casefold & AFPVOL_MTOUUPPER))
 
132
    if ((myvolinfo->v_casefold & AFPVOL_MTOUUPPER))
134
133
        flags |= CONV_TOUPPER;
135
 
    else if ((volinfo->v_casefold & AFPVOL_MTOULOWER))
 
134
    else if ((myvolinfo->v_casefold & AFPVOL_MTOULOWER))
136
135
        flags |= CONV_TOLOWER;
137
136
 
138
 
    if ((volinfo->v_flags & AFPVOL_EILSEQ)) {
 
137
    if ((myvolinfo->v_flags & AFPVOL_EILSEQ)) {
139
138
        flags |= CONV__EILSEQ;
140
139
    }
141
140
 
146
145
    outlen = MAXPATHLEN;
147
146
 
148
147
    if ((size_t)-1 == (outlen = convert_charset(CH_UTF8_MAC,
149
 
                                                volinfo->v_volcharset,
150
 
                                                volinfo->v_maccharset,
 
148
                                                myvolinfo->v_volcharset,
 
149
                                                myvolinfo->v_maccharset,
151
150
                                                m, inplen, u, outlen, &flags)) ) {
152
151
        dbd_log( LOGSTD, "conversion from UTF8-MAC to %s for %s failed.",
153
 
                 volinfo->v_volcodepage, mpath);
 
152
                 myvolinfo->v_volcodepage, mpath);
154
153
        return NULL;
155
154
    }
156
155
 
223
222
      and can compare it with the currents volume path
224
223
    */
225
224
    int i = 0;
226
 
    while (volinfo->v_path[i]) {
227
 
        if ((pathbuf[i] == 0) || (volinfo->v_path[i] != pathbuf[i])) {
 
225
    while (myvolinfo->v_path[i]) {
 
226
        if ((pathbuf[i] == 0) || (myvolinfo->v_path[i] != pathbuf[i])) {
228
227
            dbd_log( LOGDEBUG, "extra-share symlink '%s/%s', following", cwdbuf, name);
229
228
            return 1;
230
229
        }
305
304
    else
306
305
        adflags = ADFLAGS_DIR;
307
306
 
308
 
    adname = volinfo->ad_path(fname, adflags);
 
307
    adname = myvolinfo->ad_path(fname, adflags);
309
308
 
310
309
    if ((ret = access( adname, F_OK)) != 0) {
311
310
        if (errno != ENOENT) {
321
320
            return -1;
322
321
 
323
322
        /* Create ad file */
324
 
        ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
 
323
        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
325
324
 
326
325
        if ((ret = ad_open_metadata( fname, adflags, O_CREAT, &ad)) != 0) {
327
326
            dbd_log( LOGSTD, "Error creating AppleDouble file '%s/%s': %s",
341
340
        chmod(adname, st->st_mode);
342
341
#endif
343
342
    } else {
344
 
        ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
 
343
        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
345
344
        if (ad_open_metadata( fname, adflags, O_RDONLY, &ad) != 0) {
346
345
            dbd_log( LOGSTD, "Error opening AppleDouble file for '%s/%s'", cwdbuf, fname);
347
346
            return -1;
471
470
    }
472
471
 
473
472
    /* Check for ".Parent" */
474
 
    if ( (adpar_ok = access(volinfo->ad_path(".", ADFLAGS_DIR), F_OK)) != 0) {
 
473
    if ( (adpar_ok = access(myvolinfo->ad_path(".", ADFLAGS_DIR), F_OK)) != 0) {
475
474
        if (errno != ENOENT) {
476
475
            dbd_log(LOGSTD, "Access error on '%s/%s': %s",
477
 
                    cwdbuf, volinfo->ad_path(".", ADFLAGS_DIR), strerror(errno));
 
476
                    cwdbuf, myvolinfo->ad_path(".", ADFLAGS_DIR), strerror(errno));
478
477
            return -1;
479
478
        }
480
479
        dbd_log(LOGSTD, "Missing .AppleDouble/.Parent for '%s'", cwdbuf);
493
492
        }
494
493
 
495
494
        /* Create ad dir and set name */
496
 
        ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
 
495
        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
497
496
 
498
497
        if (ad_open_metadata( ".", ADFLAGS_DIR, O_CREAT, &ad) != 0) {
499
498
            dbd_log( LOGSTD, "Error creating AppleDouble dir in %s: %s", cwdbuf, strerror(errno));
514
513
            return -1;
515
514
        }
516
515
        chown(ADv2_DIRNAME, st.st_uid, st.st_gid);
517
 
        chown(volinfo->ad_path(".", ADFLAGS_DIR), st.st_uid, st.st_gid);
 
516
        chown(myvolinfo->ad_path(".", ADFLAGS_DIR), st.st_uid, st.st_gid);
518
517
    }
519
518
 
520
519
    return 0;
533
532
    char *namep, *namedup = NULL;
534
533
 
535
534
    /* Check if this is an AFPVOL_EA_AD vol */
536
 
    if (volinfo->v_vfs_ea == AFPVOL_EA_AD) {
 
535
    if (myvolinfo->v_vfs_ea == AFPVOL_EA_AD) {
537
536
        /* Does the filename contain "::EA" ? */
538
537
        namedup = strdup(name);
539
538
        if ((namep = strstr(namedup, "::EA")) == NULL) {
676
675
 
677
676
    /* Get CNID from ad-file if volume is using AFPVOL_CACHE */
678
677
    ad_cnid = 0;
679
 
    if ( (volinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
680
 
        ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
 
678
    if ( (myvolinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
 
679
        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
681
680
        if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
682
681
            
683
682
            if (dbd_flags & DBD_FLAGS_CLEANUP)
711
710
    memset(&rply, 0, sizeof(struct cnid_dbd_rply));
712
711
    rqst.did = did;
713
712
    rqst.cnid = ad_cnid;
714
 
    if ( ! (volinfo->v_flags & AFPVOL_NODEV))
 
713
    if ( ! (myvolinfo->v_flags & AFPVOL_NODEV))
715
714
        rqst.dev = st->st_dev;
716
715
    rqst.ino = st->st_ino;
717
716
    rqst.type = S_ISDIR(st->st_mode)?1:0;
768
767
                db_cnid = rply.cnid;
769
768
                dbd_log(LOGSTD, "New CNID for '%s/%s': %u", cwdbuf, name, ntohl(db_cnid));
770
769
 
771
 
                if ((volinfo->v_flags & AFPVOL_CACHE)
 
770
                if ((myvolinfo->v_flags & AFPVOL_CACHE)
772
771
                    && ADFILE_OK
773
772
                    && ( ! (dbd_flags & DBD_FLAGS_SCAN))) {
774
773
                    dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file",
775
774
                            cwdbuf, name, ntohl(db_cnid));
776
 
                    ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
 
775
                    ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
777
776
                    if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
778
777
                        dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
779
778
                                cwdbuf, name, strerror(errno));
807
806
 
808
807
    if ((ad_cnid == 0) && db_cnid) {
809
808
        /* in db but zeroID in ad-file, write it to ad-file if AFPVOL_CACHE */
810
 
        if ((volinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
 
809
        if ((myvolinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
811
810
            if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
812
811
                dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file",
813
812
                        cwdbuf, name, ntohl(db_cnid));
814
 
                ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
 
813
                ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
815
814
                if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
816
815
                    dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
817
816
                            cwdbuf, name, strerror(errno));
955
954
        }
956
955
 
957
956
        /* Check EA files */
958
 
        if (volinfo->v_vfs_ea == AFPVOL_EA_AD)
 
957
        if (myvolinfo->v_vfs_ea == AFPVOL_EA_AD)
959
958
            check_eafiles(ep->d_name);
960
959
 
961
960
        /**************************************************************************
1002
1001
    }
1003
1002
 
1004
1003
    /* Make this stuff accessible from all funcs easily */
1005
 
    volinfo = vi;
 
1004
    myvolinfo = vi;
1006
1005
    dbd_flags = flags;
1007
1006
 
1008
1007
    /* Init a fake struct vol with just enough so we can call ea_open and friends */
1009
1008
    volume.v_adouble = AD_VERSION2;
1010
 
    volume.v_vfs_ea = volinfo->v_vfs_ea;
 
1009
    volume.v_vfs_ea = myvolinfo->v_vfs_ea;
1011
1010
    initvol_vfs(&volume);
1012
1011
 
1013
1012
    /* Run with umask 0 */
1014
1013
    umask(0);
1015
1014
 
1016
1015
    /* Remove trailing slash from volume, chdir to vol */
1017
 
    if (volinfo->v_path[strlen(volinfo->v_path) - 1] == '/')
1018
 
        volinfo->v_path[strlen(volinfo->v_path) - 1] = 0;
1019
 
    strcpy(cwdbuf, volinfo->v_path);
1020
 
    chdir(volinfo->v_path);
 
1016
    if (myvolinfo->v_path[strlen(myvolinfo->v_path) - 1] == '/')
 
1017
        myvolinfo->v_path[strlen(myvolinfo->v_path) - 1] = 0;
 
1018
    strcpy(cwdbuf, myvolinfo->v_path);
 
1019
    chdir(myvolinfo->v_path);
1021
1020
 
1022
1021
    /* Start recursion */
1023
1022
    if (dbd_readdir(1, htonl(2)) < 0)  /* 2 = volumeroot CNID */
1072
1071
                    dbd_log(LOGSTD, "Orphaned CNID in database: %u", dbd_cnid);
1073
1072
                    if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
1074
1073
                        rqst.cnid = htonl(dbd_cnid);
1075
 
                        ret = dbd_delete(dbd, &rqst, &rply, DBIF_CNID);
 
1074
                        if ((ret = dbd_delete(dbd, &rqst, &rply, DBIF_CNID)) == -1) {
 
1075
                            dbd_log(LOGSTD, "Error deleting CNID %u", dbd_cnid);
 
1076
                            (void)dbif_txn_abort(dbd);
 
1077
                            goto cleanup;
 
1078
                        }
 
1079
                        
1076
1080
                        dbif_txn_close(dbd, ret);
1077
1081
                        deleted++;
1078
1082
                    }
1088
1092
 
1089
1093
        if (dbd_cnid < rebuild_cnid) {
1090
1094
            /* CNID is orphaned -> delete */
1091
 
            dbd_log(LOGSTD, "Orphaned CNID in database: %u.", dbd_cnid);
 
1095
            dbd_log(LOGSTD, "One orphaned CNID in database: %u.", dbd_cnid);
1092
1096
            if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
1093
1097
                rqst.cnid = htonl(dbd_cnid);
1094
 
                ret = dbd_delete(dbd, &rqst, &rply, DBIF_CNID);
 
1098
                if ((ret = dbd_delete(dbd, &rqst, &rply, DBIF_CNID)) == -1) {
 
1099
                    dbd_log(LOGSTD, "Error deleting CNID %u", dbd_cnid);
 
1100
                    (void)dbif_txn_abort(dbd);
 
1101
                    goto cleanup;
 
1102
                }
1095
1103
                dbif_txn_close(dbd, ret);
1096
1104
                deleted++;
1097
1105
            }
1107
1115
            dbif_idwalk(dbd_rebuild, NULL, 1); /* Close cursor */
1108
1116
            goto cleanup;
1109
1117
        }
1110
 
    }
 
1118
    } /* while ((dbif_idwalk(dbd, &dbd_cnid, 0)) == 1) */
1111
1119
 
1112
1120
cleanup:
1113
1121
    dbif_idwalk(dbd, NULL, 1); /* Close cursor */
1118
1126
/*
1119
1127
  Main func called from cmd_dbd.c
1120
1128
*/
1121
 
int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
 
1129
int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *vi, dbd_flags_t flags)
1122
1130
{
1123
1131
    int ret = 0;
1124
1132
    struct db_param db_param = { 0 };
1125
1133
 
1126
1134
    /* Set cachesize for in-memory rebuild db */
1127
 
    db_param.cachesize = 128 * 1024 * 1024; /* 128 MB */
 
1135
    db_param.cachesize = 256 * 1024 * 1024; /* 128 MB */
1128
1136
 
1129
1137
    /* Make it accessible for all funcs */
1130
1138
    dbd = dbd_ref;
1131
1139
 
1132
1140
    /* We only support unicode volumes ! */
1133
 
    if ( volinfo->v_volcharset != CH_UTF8) {
1134
 
        dbd_log( LOGSTD, "Not a Unicode volume: %s, %u != %u", volinfo->v_volcodepage, volinfo->v_volcharset, CH_UTF8);
 
1141
    if ( vi->v_volcharset != CH_UTF8) {
 
1142
        dbd_log( LOGSTD, "Not a Unicode volume: %s, %u != %u", vi->v_volcodepage, vi->v_volcharset, CH_UTF8);
1135
1143
        return -1;
1136
1144
    }
1137
1145
 
1155
1163
        goto exit_cleanup;      /* Got signal, jump from dbd_readdir */
1156
1164
 
1157
1165
    /* scanvol */
1158
 
    if ( (scanvol(volinfo, flags)) != 0)
 
1166
    if ( (scanvol(vi, flags)) != 0)
1159
1167
        return -1;
1160
1168
 
1161
1169
    if (! nocniddb) {