From: franklahm Date: Wed, 6 Jan 2010 14:05:15 +0000 (+0000) Subject: Only update adouble file with CNID on mismatch. X-Git-Tag: branch-dircache-rewrite-start~26 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=6f3a5b930085e56f39b415f20db02df98dbecfff Only update adouble file with CNID on mismatch. ad_setid: compared sizeof(dev_t) with the wrong adouble entrylen. ad_metadata: alos check if really ADVOL_CACHE for adouble file creation. --- diff --git a/etc/afpd/file.c b/etc/afpd/file.c index 098d6d47..1e45f191 100644 --- a/etc/afpd/file.c +++ b/etc/afpd/file.c @@ -1,5 +1,5 @@ /* - * $Id: file.c,v 1.129 2010-01-06 11:08:53 franklahm Exp $ + * $Id: file.c,v 1.130 2010-01-06 14:05:15 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -194,16 +194,17 @@ char *set_name(const struct vol *vol, char *data, cnid_t pid, char *name, cnid_t u_int32_t get_id(struct vol *vol, struct adouble *adp, const struct stat *st, const cnid_t did, char *upath, const int len) { - u_int32_t aint = 0; + u_int32_t adcnid; + u_int32_t dbcnid = CNID_INVALID; if (vol->v_cdb != NULL) { /* prime aint with what we think is the cnid, set did to zero for catching moved files */ - aint = ad_getid(adp, st->st_dev, st->st_ino, 0, vol->v_stamp); + adcnid = ad_getid(adp, st->st_dev, st->st_ino, 0, vol->v_stamp); - aint = cnid_add(vol->v_cdb, st, did, upath, len, aint); + dbcnid = cnid_add(vol->v_cdb, st, did, upath, len, adcnid); /* Throw errors if cnid_add fails. */ - if (aint == CNID_INVALID) { + if (dbcnid == CNID_INVALID) { switch (errno) { case CNID_ERR_CLOSE: /* the db is closed */ break; @@ -219,16 +220,15 @@ u_int32_t get_id(struct vol *vol, struct adouble *adp, const struct stat *st, return CNID_INVALID; } } - else if (adp ) { - /* update the ressource fork - * for a folder adp is always null - */ - if (ad_setid(adp, st->st_dev, st->st_ino, aint, did, vol->v_stamp)) { + else if (adp && (adcnid != dbcnid)) { + /* Update the ressource fork. For a folder adp is always null */ + LOG(log_debug, logtype_afpd, "get_id: calling ad_setid. adcnid: %u, dbcnid: %u", htonl(adcnid), htonl(dbcnid)); + if (ad_setid(adp, st->st_dev, st->st_ino, dbcnid, did, vol->v_stamp)) { ad_flush(adp); } } } - return aint; + return dbcnid; } /* -------------------------- */ @@ -264,7 +264,7 @@ int getmetadata(struct vol *vol, id = get_id(vol, adp, st, dir->d_did, upath, strlen(upath)); else id = path->id; - if (id == 0) + if (id == CNID_INVALID) return afp_errno; if (!path->m_name) { path->m_name = utompath(vol, upath, id, utf8_encoding()); diff --git a/libatalk/adouble/ad_attr.c b/libatalk/adouble/ad_attr.c index 8d026fe9..e90b6b8e 100644 --- a/libatalk/adouble/ad_attr.c +++ b/libatalk/adouble/ad_attr.c @@ -1,5 +1,5 @@ /* - * $Id: ad_attr.c,v 1.13 2009-12-23 07:21:08 franklahm Exp $ + * $Id: ad_attr.c,v 1.14 2010-01-06 14:05:15 franklahm Exp $ */ #ifdef HAVE_CONFIG_H @@ -154,9 +154,9 @@ u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino * only use the ID if adouble is writable for us. */ if (adp - && ( adp->ad_options & ADVOL_CACHE) + && (adp->ad_options & ADVOL_CACHE) && (adp->ad_md->adf_flags & O_RDWR ) - && (sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVID)) /* One check to ensure ALL values are there */ + && (sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)) /* One check to ensure ALL values are there */ ) { memcpy(&dev, ad_entry(adp, ADEID_PRIVDEV), sizeof(dev_t)); memcpy(&ino, ad_entry(adp, ADEID_PRIVINO), sizeof(ino_t)); diff --git a/libatalk/adouble/ad_open.c b/libatalk/adouble/ad_open.c index 76f2442c..b0eb4235 100644 --- a/libatalk/adouble/ad_open.c +++ b/libatalk/adouble/ad_open.c @@ -1,5 +1,5 @@ /* - * $Id: ad_open.c,v 1.67 2010-01-06 12:59:10 franklahm Exp $ + * $Id: ad_open.c,v 1.68 2010-01-06 14:05:15 franklahm Exp $ * * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu) * Copyright (c) 1990,1991 Regents of The University of Michigan. @@ -1515,7 +1515,8 @@ sfm: * ADFLAGS_CREATE: force creation of header file, but only as use, not as root * @param adp pointer to struct adouble * - * @note caller MUST pass ADFLAGS_DIR for directories + * @note caller MUST pass ADFLAGS_DIR for directories. Whether ADFLAGS_CREATE really creates + * a adouble file depends on various other volume options, eg. ADVOL_CACHE */ int ad_metadata(const char *name, int flags, struct adouble *adp) { @@ -1526,7 +1527,9 @@ int ad_metadata(const char *name, int flags, struct adouble *adp) dir = flags & ADFLAGS_DIR; /* Check if we shall call ad_open with O_CREAT */ - if ( ! (adp->ad_options & ADVOL_NOADOUBLE) && (flags & ADFLAGS_CREATE) ) + if ( (adp->ad_options & ADVOL_CACHE) + && ! (adp->ad_options & ADVOL_NOADOUBLE) + && (flags & ADFLAGS_CREATE) ) create = O_CREAT; if ((ret = ad_open(name, ADFLAGS_HF | dir, O_RDWR | create, 0666, adp)) < 0 && errno == EACCES) {