+#ifdef HAVE_EAFD
+ if (ad_meta_fileno(ad) < 0)
+ EC_FAIL;
+ if ((ad_reso_fileno(ad) = sys_getxattrfd(ad_meta_fileno(ad), AD_EA_RESO, oflags)) == -1) {
+ if (!(adflags & ADFLAGS_CREATE)) {
+ switch (errno) {
+ case EACCES:
+ case EPERM:
+ case EROFS:
+ if (!(adflags & ADFLAGS_RDONLY)) {
+ LOG(log_error, logtype_ad, "ad_open_rf_ea(\"%s\"): \"%s\"", fullpathname(path), strerror(errno));
+ EC_FAIL;
+ }
+ oflags &= ~O_RDWR;
+ oflags |= O_RDONLY;
+ if ((ad_reso_fileno(ad) = sys_getxattrfd(ad_meta_fileno(ad), AD_EA_RESO, oflags)) == -1) {
+ LOG(log_error, logtype_ad, "ad_open_rf_ea(\"%s\"): \"%s\"", fullpathname(path), strerror(errno));
+ EC_FAIL;
+ }
+ break;
+ case ENOENT:
+ EC_EXIT_STATUS(0);
+ default:
+ LOG(log_error, logtype_ad, "ad_open_rf_ea(\"%s\"): \"%s\"", fullpathname(path), strerror(errno));
+ EC_FAIL;
+ }
+ } else {
+ oflags |= O_CREAT;
+ EC_NEG1_LOG( ad_reso_fileno(ad) = sys_getxattrfd(ad_meta_fileno(ad),
+ AD_EA_RESO, oflags, 0666) );
+ }
+ }
+#else
+ EC_NULL_LOG( rfpath = ad->ad_ops->ad_path(path, adflags) );
+ if ((ad_reso_fileno(ad) = open(rfpath, oflags)) == -1) {
+ if (!(adflags & ADFLAGS_CREATE)) {
+ switch (errno) {
+ case EACCES:
+ case EPERM:
+ case EROFS:
+ if (!(adflags & ADFLAGS_RDONLY)) {
+ LOG(log_error, logtype_ad, "ad_open_rf_ea(\"%s\"): \"%s\"", fullpathname(rfpath), strerror(errno));
+ EC_FAIL;
+ }
+ oflags &= ~O_RDWR;
+ oflags |= O_RDONLY;
+ if ((ad_reso_fileno(ad) = open(rfpath, oflags)) == -1) {
+ LOG(log_error, logtype_ad, "ad_open_rf_ea(\"%s\"): \"%s\"", fullpathname(rfpath), strerror(errno));
+ EC_FAIL;
+ }
+ break;
+ case ENOENT:
+ EC_EXIT_STATUS(0);
+ default:
+ LOG(log_error, logtype_ad, "ad_open_rf_ea(\"%s\"): \"%s\"", fullpathname(rfpath), strerror(errno));
+ EC_FAIL;
+ }
+ } else {
+ oflags |= O_CREAT;
+ EC_NEG1_LOG( ad_reso_fileno(ad) = open(rfpath, oflags, mode) );
+ LOG(log_debug, logtype_ad, "ad_open_rf(\"%s\"): created adouble rfork: \"%s\"",
+ path, rfpath);
+ }
+ }
+#endif
+ 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 (ad->ad_rfp->adf_flags & O_CREAT) {
+ /* This is a new adouble header file, create it */
+ LOG(log_debug, logtype_ad, "ad_open_rf(\"%s\"): created adouble rfork, initializing: \"%s\"",
+ path, rfpath);
+ EC_NEG1_LOG( new_ad_header(ad, path, NULL, adflags) );
+ LOG(log_debug, logtype_ad, "ad_open_rf(\"%s\"): created adouble rfork, flushing: \"%s\"",
+ path, rfpath);
+ ad_flush(ad);
+ } else {
+ /* Read the adouble header */
+ LOG(log_debug, logtype_ad, "ad_open_rf(\"%s\"): reading adouble rfork: \"%s\"",
+ path, rfpath);
+ EC_NEG1_LOG( ad_header_read_osx(NULL, ad, &st) );
+ }
+#endif