From 7ff88627be9a15a9da5d58279767d953ebf9e124 Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Mon, 12 Mar 2012 13:01:19 +0100 Subject: [PATCH] Creating a ressource fork clobbered the metadata EA --- include/atalk/adouble.h | 3 +- libatalk/adouble/ad_flush.c | 64 +++++++++++++++++++++++++++---------- libatalk/adouble/ad_open.c | 12 ++----- 3 files changed, 52 insertions(+), 27 deletions(-) diff --git a/include/atalk/adouble.h b/include/atalk/adouble.h index 72106aef..cfc4302b 100644 --- a/include/atalk/adouble.h +++ b/include/atalk/adouble.h @@ -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); diff --git a/libatalk/adouble/ad_flush.c b/libatalk/adouble/ad_flush.c index 3d5060d1..8ea385e7 100644 --- a/libatalk/adouble/ad_flush.c +++ b/libatalk/adouble/ad_flush.c @@ -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; } /*! diff --git a/libatalk/adouble/ad_open.c b/libatalk/adouble/ad_open.c index ff2a9802..196053ee 100644 --- a/libatalk/adouble/ad_open.c +++ b/libatalk/adouble/ad_open.c @@ -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}, -- 2.39.2