int err = 0;
char filebuf[8192];
int sfd, dfd;
- off_t soff, doff;
if (eid == ADEID_DFORK) {
sfd = ad_data_fileno(ads);
dfd = ad_reso_fileno(add);
}
- soff = doff = ad_getentryoff(ads, eid);
-
- if ((off_t)-1 == lseek(sfd, soff, SEEK_SET))
+ if ((off_t)-1 == lseek(sfd, ad_getentryoff(ads, eid), SEEK_SET))
return -1;
- if ((off_t)-1 == lseek(dfd, doff, SEEK_SET))
+ if ((off_t)-1 == lseek(dfd, ad_getentryoff(add, eid), SEEK_SET))
return -1;
#if 0 /* ifdef SENDFILE_FLAVOR_LINUX */
adflags = ADFLAGS_DF | ADFLAGS_RF | ADFLAGS_NORF;
- if (ad_openat(adp, sfd, src, adflags | ADFLAGS_NOHF | ADFLAGS_RDONLY) < 0) {
+ if (ad_openat(adp, sfd, src, adflags | ADFLAGS_RDONLY) < 0) {
ret_err = errno;
goto done;
}
return AFPERR_EXIST;
}
-#if 0
- if (AD_RSRC_OPEN(adp))
- err = copy_fork(ADEID_RFORK, &add, adp);
-#endif
-
- if (err == 0)
- err = copy_fork(ADEID_DFORK, &add, adp);
+ if ((err = copy_fork(ADEID_DFORK, &add, adp)) != 0)
+ LOG(log_error, logtype_afpd, "copyfile('%s'): %s", src, strerror(errno));
if (err == 0)
- err = d_vol->vfs->vfs_copyfile(d_vol, sfd, src, dst);
+ if ((err = d_vol->vfs->vfs_copyfile(d_vol, sfd, src, dst)) != 0)
+ LOG(log_error, logtype_afpd, "copyfile('%s'): %s", src, strerror(errno));
if (err < 0)
ret_err = errno;
return buf;
}
+#define OPENFLAGS2LOGSTRBUFSIZ 128
+const char *openflags2logstr(int oflags)
+{
+ int first = 1;
+ static char buf[OPENFLAGS2LOGSTRBUFSIZ];
+
+ buf[0] = 0;
+
+ if ((oflags & O_RDONLY) || (oflags == O_RDONLY)) {
+ strlcat(buf, "O_RDONLY", OPENFLAGS2LOGSTRBUFSIZ);
+ first = 0;
+ }
+ if (oflags & O_RDWR) {
+ if (!first)
+ strlcat(buf, "|", OPENFLAGS2LOGSTRBUFSIZ);
+ strlcat(buf, "O_RDWR", OPENFLAGS2LOGSTRBUFSIZ);
+ first = 0;
+ }
+ if (oflags & O_CREAT) {
+ if (!first)
+ strlcat(buf, "|", OPENFLAGS2LOGSTRBUFSIZ);
+ strlcat(buf, "O_CREAT", OPENFLAGS2LOGSTRBUFSIZ);
+ first = 0;
+ }
+ if (oflags & O_TRUNC) {
+ if (!first)
+ strlcat(buf, "|", OPENFLAGS2LOGSTRBUFSIZ);
+ strlcat(buf, "O_TRUNC", OPENFLAGS2LOGSTRBUFSIZ);
+ first = 0;
+ }
+ if (oflags & O_EXCL) {
+ if (!first)
+ strlcat(buf, "|", OPENFLAGS2LOGSTRBUFSIZ);
+ strlcat(buf, "O_EXCL", OPENFLAGS2LOGSTRBUFSIZ);
+ first = 0;
+ }
+ return buf;
+}
+
static uint32_t get_eid(uint32_t eid)
{
if (eid <= 15)
* @param adflags (r) flags from ad_open(..., adflags, ...)
* @returns mapped flags suitable for calling open()
*/
-static int ad2openflags(int adfile, int adflags)
+static int ad2openflags(const struct adouble *ad, int adfile, int adflags)
{
int oflags = 0;
if (adflags & ADFLAGS_RDWR)
oflags |= O_RDWR;
if (adflags & ADFLAGS_RDONLY) {
- if ((adfile & ADFLAGS_DF) && (adflags & ADFLAGS_SETSHRMD))
+ if (((adfile & ADFLAGS_DF) && (adflags & ADFLAGS_SETSHRMD))
+ /* need rw access for locks */
+ || ((ad->ad_vers == AD_VERSION2) && (adflags & ADFLAGS_HF)))
+ /* need rw access for adouble file for the case:
+ 1) openfork(data:O_RDONLY), 2) openfork(reso:O_RDWR) */
oflags |= O_RDWR;
else
oflags |= O_RDONLY;
goto EC_CLEANUP;
}
- oflags = O_NOFOLLOW | ad2openflags(ADFLAGS_DF, adflags);
+ oflags = O_NOFOLLOW | ad2openflags(ad, ADFLAGS_DF, adflags);
admode = mode;
if ((adflags & ADFLAGS_CREATE)) {
}
ad_p = ad->ad_ops->ad_path(path, adflags);
- oflags = O_NOFOLLOW | ad2openflags(ADFLAGS_HF, adflags);
+ oflags = O_NOFOLLOW | ad2openflags(ad, ADFLAGS_HF, adflags);
+ LOG(log_debug, logtype_default,"ad_open_hf_v2(\"%s\"): open flags: %s",
+ fullpathname(path), openflags2logstr(oflags));
nocreatflags = oflags & ~(O_CREAT | O_EXCL);
ad_meta_fileno(ad) = open(ad_p, nocreatflags);
}
/* retry with O_CREAT */
- EC_NEG1_LOG( ad_meta_fileno(ad) = open(ad_p, oflags, admode) );
+ EC_NEG1( ad_meta_fileno(ad) = open(ad_p, oflags, admode) );
ad->ad_mdp->adf_flags = oflags;
/* just created, set owner if admin owner (root) */
if (!st_invalid)
ad_meta_fileno(ad), ad->ad_mdp->adf_refcount,
ad_reso_fileno(ad), ad->ad_rfp->adf_refcount);
- oflags = O_NOFOLLOW | (ad2openflags(ADFLAGS_DF, adflags) & ~(O_CREAT | O_TRUNC));
+ oflags = O_NOFOLLOW | (ad2openflags(ad, ADFLAGS_DF, adflags) & ~(O_CREAT | O_TRUNC));
if (ad_meta_fileno(ad) == -2)
/* symlink */
LOG(log_debug, logtype_default, "ad_open_rf(\"%s\"): BEGIN", fullpathname(path));
- oflags = O_NOFOLLOW | (ad2openflags(ADFLAGS_HF, adflags) & ~O_CREAT);
+ oflags = O_NOFOLLOW | (ad2openflags(ad, ADFLAGS_HF, adflags) & ~O_CREAT);
if (ad_reso_fileno(ad) != -1) {
/* the file is already open, but we want write access: */
off_t ad_getentryoff(const struct adouble *ad, int eid)
{
if (ad->ad_vers == AD_VERSION2)
- return ad->ad_eid[ADEID_RFORK].ade_off;
+ return ad->ad_eid[eid].ade_off;
- if (eid == ADEID_DFORK) {
+ switch (eid) {
+ case ADEID_DFORK:
return 0;
- } else if (eid == ADEID_RFORK) {
+ case ADEID_RFORK:
#ifdef HAVE_EAFD
return 0;
#else
return ADEDOFF_RFORK_OSX;
#endif
- } else {
+ default:
return ad->ad_eid[eid].ade_off;
}
+ /* deadc0de */
+ AFP_PANIC("What am I doing here?");
}
const char *ad_path_ea( const char *path, int adflags _U_)
/* Checking for open forks requires sharemode lock support (ie RDWR instead of RDONLY) */
adflags |= ADFLAGS_SETSHRMD;
- if ((ad->ad_vers == AD_VERSION2) && (adflags & ADFLAGS_SETSHRMD)) {
- /* sharemode locks are stored in the data fork, adouble:v2 needs this extra handling */
- adflags |= ADFLAGS_DF;
- }
-
- if ((ad->ad_vers == AD_VERSION2) && (adflags & ADFLAGS_RF)) {
- adflags |= ADFLAGS_HF;
+ if (ad->ad_vers == AD_VERSION2) {
+ if (adflags & ADFLAGS_SETSHRMD)
+ /* sharemode locks are stored in the data fork, adouble:v2 needs this extra handling here */
+ adflags |= ADFLAGS_DF;
+ if (adflags & ADFLAGS_RF)
+ adflags |= ADFLAGS_HF;
if (adflags & ADFLAGS_NORF)
adflags |= ADFLAGS_NOHF;
}