]> arthur.barton.de Git - netatalk.git/commitdiff
Creating a ressource fork clobbered the metadata EA
authorFrank Lahm <franklahm@googlemail.com>
Mon, 12 Mar 2012 12:01:19 +0000 (13:01 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 12 Mar 2012 12:01:19 +0000 (13:01 +0100)
include/atalk/adouble.h
libatalk/adouble/ad_flush.c
libatalk/adouble/ad_open.c

index 72106aef6719a401591f20aa15a91d422f762fe4..cfc4302be4d3d5d122ef733ce56492bf66741dca 100644 (file)
@@ -369,7 +369,8 @@ struct adouble {
 #define ad_unref(ad) --((ad)->ad_refcount)
 
 /* ad_flush.c */
-extern int ad_rebuild_adouble_header (struct adouble *);
+extern int ad_rebuild_adouble_header_v2(struct adouble *);
+extern int ad_rebuild_adouble_header_ea(struct adouble *);
 extern int ad_copy_header (struct adouble *, struct adouble *);
 extern int ad_flush (struct adouble *);
 extern int ad_close (struct adouble *, int);
index 3d5060d1c25b5d25a2dba1dfad11fb160d229f9e..8ea385e792eb89ae281d8e5273a6d0782a272caf 100644 (file)
@@ -53,7 +53,7 @@ static const uint32_t set_eid[] = {
 /*
  * Prepare ad->ad_data buffer from struct adouble for writing on disk
  */
-int ad_rebuild_adouble_header(struct adouble *ad)
+int ad_rebuild_adouble_header_v2(struct adouble *ad)
 {
     uint32_t       eid;
     uint32_t       temp;
@@ -61,7 +61,7 @@ int ad_rebuild_adouble_header(struct adouble *ad)
     char        *buf, *nentp;
     int             len;
 
-    LOG(log_debug, logtype_default, "ad_rebuild_adouble_header");
+    LOG(log_debug, logtype_default, "ad_rebuild_adouble_header_v2");
 
     buf = ad->ad_data;
 
@@ -78,9 +78,8 @@ int ad_rebuild_adouble_header(struct adouble *ad)
     nentp = buf;
     buf += sizeof( nent );
     for ( eid = 0, nent = 0; eid < ADEID_MAX; eid++ ) {
-        if ( ad->ad_eid[ eid ].ade_off == 0 ) {
+        if (ad->ad_eid[ eid ].ade_off == 0)
             continue;
-        }
         temp = htonl( EID_DISK(eid) );
         memcpy(buf, &temp, sizeof( temp ));
         buf += sizeof( temp );
@@ -97,20 +96,53 @@ int ad_rebuild_adouble_header(struct adouble *ad)
     nent = htons( nent );
     memcpy(nentp, &nent, sizeof( nent ));
 
-    switch (ad->ad_vers) {
-    case AD_VERSION2:
-        len = ad_getentryoff(ad, ADEID_RFORK);
-        break;
-    case AD_VERSION_EA:
-        len = AD_DATASZ_EA;
-        break;
-    default:
-        LOG(log_error, logtype_afpd, "Unexpected adouble version");
-        len = 0;
-        break;
+    return ad_getentryoff(ad, ADEID_RFORK);
+}
+
+int ad_rebuild_adouble_header_ea(struct adouble *ad)
+{
+    uint32_t       eid;
+    uint32_t       temp;
+    uint16_t       nent;
+    char        *buf, *nentp;
+    int             len;
+
+    LOG(log_debug, logtype_default, "ad_rebuild_adouble_header_ea");
+
+    buf = ad->ad_data;
+
+    temp = htonl( ad->ad_magic );
+    memcpy(buf, &temp, sizeof( temp ));
+    buf += sizeof( temp );
+
+    temp = htonl( ad->ad_version );
+    memcpy(buf, &temp, sizeof( temp ));
+    buf += sizeof( temp );
+
+    buf += sizeof( ad->ad_filler );
+
+    nentp = buf;
+    buf += sizeof( nent );
+    for ( eid = 0, nent = 0; eid < ADEID_MAX; eid++ ) {
+        if ((ad->ad_eid[ eid ].ade_off == 0) || (eid == ADEID_RFORK))
+            continue;
+        temp = htonl( EID_DISK(eid) );
+        memcpy(buf, &temp, sizeof( temp ));
+        buf += sizeof( temp );
+
+        temp = htonl( ad->ad_eid[ eid ].ade_off );
+        memcpy(buf, &temp, sizeof( temp ));
+        buf += sizeof( temp );
+
+        temp = htonl( ad->ad_eid[ eid ].ade_len );
+        memcpy(buf, &temp, sizeof( temp ));
+        buf += sizeof( temp );
+        nent++;
     }
+    nent = htons( nent );
+    memcpy(nentp, &nent, sizeof( nent ));
 
-    return len;
+    return AD_DATASZ_EA;
 }
 
 /*!
index ff2a980238b98cc53dbe2de0bec532cb86fb8434..196053ee31ab288601b4c365f56da42600c00263 100644 (file)
@@ -118,7 +118,7 @@ static int ad_mkrf_osx(const char *path);
 static struct adouble_fops ad_adouble = {
     &ad_path,
     &ad_mkrf,
-    &ad_rebuild_adouble_header,
+    &ad_rebuild_adouble_header_v2,
     &ad_header_read,
     &ad_header_upgrade,
 };
@@ -131,19 +131,11 @@ static struct adouble_fops ad_adouble_ea = {
     &ad_path_osx,
     &ad_mkrf_osx,
 #endif
-    &ad_rebuild_adouble_header,
+    &ad_rebuild_adouble_header_ea,
     &ad_header_read_ea,
     &ad_header_upgrade_ea,
 };
 
-static struct adouble_fops ad_osx = {
-    &ad_path_osx,
-    &ad_mkrf_osx,
-    &ad_rebuild_adouble_header,
-    &ad_header_read,
-    &ad_header_upgrade,
-};
-
 static const struct entry entry_order2[ADEID_NUM_V2 + 1] = {
     {ADEID_NAME,        ADEDOFF_NAME_V2,     ADEDLEN_INIT},
     {ADEID_COMMENT,     ADEDOFF_COMMENT_V2,  ADEDLEN_INIT},