]> arthur.barton.de Git - netatalk.git/commitdiff
Various fixes for adouble:v2
authorFrank Lahm <franklahm@googlemail.com>
Thu, 2 Feb 2012 10:34:57 +0000 (11:34 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Thu, 2 Feb 2012 10:34:57 +0000 (11:34 +0100)
etc/afpd/file.c
libatalk/adouble/ad_open.c
libatalk/adouble/ad_write.c

index 6d253d1ecc43941a8e62b12697be86061c35524c..14906d294f124d800a43493450901299f606d0dc 100644 (file)
@@ -1375,7 +1375,6 @@ static int copy_fork(int eid, struct adouble *add, struct adouble *ads)
     int     err = 0;
     char    filebuf[8192];
     int     sfd, dfd;
-    off_t   soff, doff;
 
     if (eid == ADEID_DFORK) {
         sfd = ad_data_fileno(ads);
@@ -1386,12 +1385,10 @@ static int copy_fork(int eid, struct adouble *add, struct adouble *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 */
@@ -1468,7 +1465,7 @@ int copyfile(const struct vol *s_vol,
 
     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;
     }
@@ -1495,16 +1492,12 @@ int copyfile(const struct vol *s_vol,
         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;
index 4e6941c76555f8adf8a0b625d153b3f3383b8245..d179e1114cbd2cfe7c8d0b7b62dfd47ab646780d 100644 (file)
@@ -262,6 +262,45 @@ const char *adflags2logstr(int adflags)
     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)
@@ -707,14 +746,18 @@ static int ad_error(struct adouble *ad, int adflags)
  * @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;
@@ -759,7 +802,7 @@ static int ad_open_df(const char *path, int adflags, mode_t mode, struct adouble
         goto EC_CLEANUP;
     }
 
-    oflags = O_NOFOLLOW | ad2openflags(ADFLAGS_DF, adflags);
+    oflags = O_NOFOLLOW | ad2openflags(ad, ADFLAGS_DF, adflags);
 
     admode = mode;
     if ((adflags & ADFLAGS_CREATE)) {
@@ -847,7 +890,9 @@ static int ad_open_hf_v2(const char *path, int adflags, mode_t mode, struct adou
     }
 
     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);
@@ -891,7 +936,7 @@ static int ad_open_hf_v2(const char *path, int adflags, mode_t mode, struct adou
             }
 
             /* 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)
@@ -957,7 +1002,7 @@ static int ad_open_hf_ea(const char *path, int adflags, int mode, struct adouble
         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 */
@@ -1119,7 +1164,7 @@ static int ad_open_rf(const char *path, int adflags, int mode, struct adouble *a
 
     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: */
@@ -1209,19 +1254,22 @@ EC_CLEANUP:
 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_)
@@ -1506,13 +1554,12 @@ int ad_open(struct adouble *ad, const char *path, int adflags, ...)
         /* 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;
     }
index d7bef2fd7f666301f731f9420df3f9c0a6f586c8..1ca938900a168afee36db9fd6bb2e7f112b4c47b 100644 (file)
@@ -162,8 +162,10 @@ char            c = 0;
 /* ------------------------ */
 int ad_rtruncate( struct adouble *ad, const off_t size)
 {
-    if (sys_ftruncate(ad_reso_fileno(ad), size + ad->ad_eid[ ADEID_RFORK ].ade_off ) < 0 )
+    if (sys_ftruncate(ad_reso_fileno(ad), size + ad->ad_eid[ ADEID_RFORK ].ade_off ) < 0 ) {
+        LOG(log_error, logtype_default, "sys_ftruncate: %s", strerror(errno));
         return -1;
+    }
 
     ad->ad_rlen = size;    
 
@@ -172,8 +174,11 @@ int ad_rtruncate( struct adouble *ad, const off_t size)
 
 int ad_dtruncate(struct adouble *ad, const off_t size)
 {
-    if (sys_ftruncate(ad_data_fileno(ad), size) < 0)
+    if (sys_ftruncate(ad_data_fileno(ad), size) < 0) {
+        LOG(log_error, logtype_default, "sys_ftruncate(fd: %d): %s",
+            ad_data_fileno(ad), strerror(errno));
         return -1;
+    }
 
     return 0;
 }