]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/adouble/ad_attr.c
Only update adouble file with CNID on mismatch.
[netatalk.git] / libatalk / adouble / ad_attr.c
index a5727d52d40a31a2d48939057e95ceed983b0cfc..e90b6b8e0268c9ff41dc7c23e14ae5198fe49f87 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ad_attr.c,v 1.10 2009-07-21 13:41:16 didg Exp $
+ * $Id: ad_attr.c,v 1.14 2010-01-06 14:05:15 franklahm Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -114,24 +114,22 @@ int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
 #if AD_VERSION == AD_VERSION2
 int ad_setid (struct adouble *adp, const dev_t dev, const ino_t ino , const u_int32_t id, const cnid_t did, const void *stamp)
 {
-    if (adp->ad_flags == AD_VERSION2  && ( adp->ad_options & ADVOL_CACHE) &&
-        ad_getentryoff(adp, ADEID_PRIVDEV) &&
-        sizeof(dev_t) == ADEDLEN_PRIVDEV && sizeof(ino_t) == ADEDLEN_PRIVINO)
-    {
+    if ((adp->ad_flags == AD_VERSION2) && (adp->ad_options & ADVOL_CACHE)) {
+
+        /* ad_getid depends on this to detect presence of ALL entries */
+        ad_setentrylen( adp, ADEID_PRIVID, sizeof(id));
+        memcpy(ad_entry( adp, ADEID_PRIVID ), &id, sizeof(id));
+
         ad_setentrylen( adp, ADEID_PRIVDEV, sizeof(dev_t));
         if ((adp->ad_options & ADVOL_NODEV)) {
             memset(ad_entry( adp, ADEID_PRIVDEV ), 0, sizeof(dev_t));
-        }
-        else {
+        } else {
             memcpy(ad_entry( adp, ADEID_PRIVDEV ), &dev, sizeof(dev_t));
         }
 
         ad_setentrylen( adp, ADEID_PRIVINO, sizeof(ino_t));
         memcpy(ad_entry( adp, ADEID_PRIVINO ), &ino, sizeof(ino_t));
 
-        ad_setentrylen( adp, ADEID_PRIVID, sizeof(id));
-        memcpy(ad_entry( adp, ADEID_PRIVID ), &id, sizeof(id));
-
         ad_setentrylen( adp, ADEID_DID, sizeof(did));
         memcpy(ad_entry( adp, ADEID_DID ), &did, sizeof(did));
 
@@ -155,21 +153,20 @@ u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino
      * note inode and device are opaques and not in network order
      * only use the ID if adouble is writable for us.
      */
-    if (adp && ( adp->ad_options & ADVOL_CACHE) && ( adp->ad_md->adf_flags & O_RDWR )
-        && sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)
-        && sizeof(ino_t) == ad_getentrylen(adp,ADEID_PRIVINO)
-        && sizeof(temp) == ad_getentrylen(adp,ADEID_PRIVSYN)
-        && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_DID)
-        && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_PRIVID)
+    if (adp
+        && (adp->ad_options & ADVOL_CACHE)
+        && (adp->ad_md->adf_flags & O_RDWR )
+        && (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));
         memcpy(temp, ad_entry(adp, ADEID_PRIVSYN), sizeof(temp));
         memcpy(&a_did, ad_entry(adp, ADEID_DID), sizeof(cnid_t));
 
-        if (  ((adp->ad_options & ADVOL_NODEV) || dev == st_dev)
-              && ino == st_ino && a_did == did
-              && !memcmp(stamp, temp, sizeof(temp))) {
+        if ( ((adp->ad_options & ADVOL_NODEV) || dev == st_dev)
+             && ino == st_ino
+             && (!did || a_did == did)
+             && (memcmp(stamp, temp, sizeof(temp)) == 0) ) {
             memcpy(&aint, ad_entry(adp, ADEID_PRIVID), sizeof(aint));
             return aint;
         }
@@ -182,12 +179,7 @@ u_int32_t ad_forcegetid (struct adouble *adp)
 {
     u_int32_t aint = 0;
 
-    if (adp && ( adp->ad_options & ADVOL_CACHE)
-        && sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)
-        && sizeof(ino_t) == ad_getentrylen(adp,ADEID_PRIVINO)
-        && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_DID)
-        && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_PRIVID)
-        ) {
+    if (adp && (adp->ad_options & ADVOL_CACHE)) {
         memcpy(&aint, ad_entry(adp, ADEID_PRIVID), sizeof(aint));
         return aint;
     }