static int ad_header_read(const char *path, struct adouble *ad, const struct stat *hst);
static int ad_header_upgrade(struct adouble *ad, const char *name);
+#ifdef HAVE_EAFD
static int ad_mkrf_ea(const char *path);
+#endif
static int ad_header_read_ea(const char *path, struct adouble *ad, const struct stat *hst);
static int ad_header_upgrade_ea(struct adouble *ad, const char *name);
static int ad_reso_size(const char *path, int adflags, struct adouble *ad);
adosx.ad_version = ntohl(adosx.ad_version);
if ((adosx.ad_magic != AD_MAGIC) || (adosx.ad_version != AD_VERSION2)) {
- LOG(log_warning, logtype_ad, "ad_valid_header_osx: not an adouble:osx file");
+ LOG(log_warning, logtype_ad, "ad_valid_header_osx(\"%s\"): not an adouble:osx file", fullpathname(path));
EC_FAIL;
}
}
if (header_len < AD_HEADER_LEN) {
- LOG(log_error, logtype_ad, "ad_header_read_ea: bogus AppleDouble header.");
+ LOG(log_error, logtype_ad, "ad_header_read_ea(\"%s\"): bogus AppleDouble header.", fullpathname(path));
errno = EIO;
return -1;
}
ad->ad_version = ntohl( ad->ad_version );
if ((ad->ad_magic != AD_MAGIC) || (ad->ad_version != AD_VERSION2)) {
- LOG(log_error, logtype_ad, "ad_header_read_ea: wrong magic or version");
+ LOG(log_error, logtype_ad, "ad_header_read_ea(\"%s\"): wrong magic or version", fullpathname(path));
errno = EIO;
return -1;
}
if (len + AD_HEADER_LEN > sizeof(ad->ad_data))
len = sizeof(ad->ad_data) - AD_HEADER_LEN;
if (len > header_len - AD_HEADER_LEN) {
- LOG(log_error, logtype_ad, "ad_header_read_ea: can't read entry info.");
+ LOG(log_error, logtype_ad, "ad_header_read_ea(\"%s\"): can't read entry info.", fullpathname(path));
errno = EIO;
return -1;
}
return 0;
}
+#ifdef HAVE_EAFD
static int ad_mkrf_ea(const char *path _U_)
{
AFP_PANIC("ad_mkrf_ea: dont use");
return 0;
}
+#endif
static int ad_mkrf_osx(const char *path _U_)
{
if (adflags & ADFLAGS_TRUNC)
oflags |= O_TRUNC;
+ if (!(ad->ad_options & ADVOL_FOLLO_SYML))
+ oflags |= O_NOFOLLOW;
+
return oflags;
}
goto EC_CLEANUP;
}
- oflags = O_NOFOLLOW | ad2openflags(ad, ADFLAGS_DF, adflags);
+ oflags = ad2openflags(ad, ADFLAGS_DF, adflags);
admode = mode;
if ((adflags & ADFLAGS_CREATE)) {
}
ad_p = ad->ad_ops->ad_path(path, adflags);
- oflags = O_NOFOLLOW | ad2openflags(ad, ADFLAGS_HF, adflags);
+ oflags = ad2openflags(ad, ADFLAGS_HF, adflags);
LOG(log_debug, logtype_ad,"ad_open_hf_v2(\"%s\"): open flags: %s",
fullpathname(path), openflags2logstr(oflags));
nocreatflags = oflags & ~(O_CREAT | O_EXCL);
static int ad_open_hf_ea(const char *path, int adflags, int mode, struct adouble *ad)
{
EC_INIT;
- ssize_t rforklen;
int oflags;
int opened = 0;
ad_meta_fileno(ad), ad->ad_mdp->adf_refcount,
ad_reso_fileno(ad), ad->ad_rfp->adf_refcount);
- oflags = O_NOFOLLOW | (ad2openflags(ad, ADFLAGS_DF, adflags) & ~(O_CREAT | O_TRUNC));
+ oflags = ad2openflags(ad, ADFLAGS_DF, adflags) & ~(O_CREAT | O_TRUNC);
if (ad_meta_fileno(ad) == AD_SYMLINK)
goto EC_CLEANUP;
break;
}
- if (ret != 0)
+ if (ret == 0)
+ ad->ad_meta_refcount++;
+ else
ret = ad_error(ad, adflags);
return ret;
static int ad_open_rf_v2(const char *path, int adflags, int mode, struct adouble *ad)
{
+ EC_INIT;
+
/*
* ad_open_hf_v2() does the work, but if it failed and adflags are ADFLAGS_NOHF | ADFLAGS_RF
* ad_open_hf_v2() didn't give an error, but we're supposed to return a reso fork fd
*/
- if (!AD_RSRC_OPEN(ad) && !(adflags & ADFLAGS_NORF))
- return -1;
- return 0;
+
+ LOG(log_debug, logtype_ad, "ad_open_rf_v2(\"%s\"): BEGIN", fullpathname(path));
+
+ if (!AD_META_OPEN(ad) && !(adflags & ADFLAGS_NORF))
+ EC_FAIL;
+ if (AD_META_OPEN(ad))
+ ad->ad_reso_refcount++;
+
+EC_CLEANUP:
+ LOG(log_debug, logtype_ad, "ad_open_rf_v2(\"%s\"): END: %d", fullpathname(path), ret);
+ EC_EXIT;
}
static int ad_open_rf_ea(const char *path, int adflags, int mode, struct adouble *ad)
int oflags;
int opened = 0;
int closeflags = adflags & (ADFLAGS_DF | ADFLAGS_HF);
- ssize_t rlen;
#ifndef HAVE_EAFD
const char *rfpath;
struct stat st;
LOG(log_debug, logtype_ad, "ad_open_rf(\"%s\"): BEGIN", fullpathname(path));
- oflags = O_NOFOLLOW | (ad2openflags(ad, ADFLAGS_RF, adflags) & ~O_CREAT);
+ oflags = ad2openflags(ad, ADFLAGS_RF, adflags) & ~O_CREAT;
if (ad_reso_fileno(ad) != -1) {
/* the file is already open, but we want write access: */
opened = 1;
ad->ad_rfp->adf_refcount = 1;
ad->ad_rfp->adf_flags = oflags;
+ ad->ad_reso_refcount++;
#ifndef HAVE_EAFD
EC_ZERO_LOG( fstat(ad_reso_fileno(ad), &st) );
if (opened && (ad_reso_fileno(ad) != -1)) {
close(ad_reso_fileno(ad));
ad_reso_fileno(ad) = -1;
+ ad->ad_reso_refcount--;
ad->ad_rfp->adf_refcount = 0;
}
if (adflags & ADFLAGS_NORF) {
p = ad_dir(path);
if (!p)
return -1;
- return lstat( p, stbuf );
+ return stat( p, stbuf );
}
/* ----------------
}
if (adflags & ADFLAGS_HF) {
- ad->ad_meta_refcount++;
if (ad_open_hf(path, adflags, mode, ad) != 0) {
- ad->ad_meta_refcount--;
EC_FAIL;
}
}
if (adflags & ADFLAGS_RF) {
- ad->ad_reso_refcount++;
if (ad_open_rf(path, adflags, mode, ad) != 0) {
- ad->ad_reso_refcount--;
EC_FAIL;
}
}
EC_INIT;
int cwdfd = -1;
va_list args;
- mode_t mode;
+ mode_t mode = 0;
if (dirfd != -1) {
if ((cwdfd = open(".", O_RDONLY) == -1) || (fchdir(dirfd) != 0))
+ if (cwdfd > 0)
+ close(cwdfd);
EC_FAIL;
}