/*
* 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;
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;
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 );
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;
}
/*!
memcpy(buf, &temp, sizeof( temp ));
buf += sizeof( temp );
+ memset(buf, 0, sizeof(ad->ad_filler));
buf += sizeof( ad->ad_filler );
nent = htons(ADEID_NUM_OSX);
{
int ret = 0;
- if (ad_data_fileno(ad) == -2) {
+ if (ad_data_fileno(ad) == AD_SYMLINK) {
free(ad->ad_data_fork.adf_syml);
ad->ad_data_fork.adf_syml = NULL;
} else {
adflags |= ADFLAGS_HF;
if ((adflags & ADFLAGS_DF)
- && (ad_data_fileno(ad) >= 0 || ad_data_fileno(ad) == -2) /* -2 means symlink */
+ && (ad_data_fileno(ad) >= 0 || ad_data_fileno(ad) == AD_SYMLINK)
&& --ad->ad_data_fork.adf_refcount == 0) {
if (ad_data_closefd(ad) < 0)
err = -1;