]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/fork.c
Various fixes for adouble:v2
[netatalk.git] / etc / afpd / fork.c
index 560f766b5e41e29cc21611b08c3b9db13bc37ae4..7bd2128b350fe8624189cb04e191ea3024f7672a 100644 (file)
@@ -54,7 +54,7 @@ static int getforkparams(struct ofork *ofork, uint16_t bitmap, char *buf, size_t
         return( AFPERR_BITMAP );
     }
 
-    if ( ad_reso_fileno( ofork->of_ad ) == -1 ) { /* META ? */
+    if (! AD_META_OPEN(ofork->of_ad)) {
         adp = NULL;
     } else {
         adp = ofork->of_ad;
@@ -266,9 +266,6 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         return  AFPERR_BADTYPE;
     }
 
-    LOG(log_debug, logtype_afpd, "afp_openfork(\"%s\", %s)",
-        fullpathname(s_path->u_name), (fork & OPENFORK_RSCS) ? "RSRC" : "DATA");
-
     /* stat() data fork st is set because it's not a dir */
     switch ( s_path->st_errno ) {
     case 0:
@@ -311,6 +308,8 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     } else {
         eid = ADEID_RFORK;
         adflags = ADFLAGS_RF | ADFLAGS_HF;
+        if (!(access & OPENACC_WR))
+            adflags |= ADFLAGS_NORF;
     }
 
     path = s_path->m_name;
@@ -319,6 +318,11 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         return( AFPERR_NFILE );
     }
 
+    LOG(log_debug, logtype_afpd, "afp_openfork(\"%s\", %s, %s)",
+        fullpathname(s_path->u_name),
+        (fork & OPENFORK_RSCS) ? "data" : "reso",
+        !(access & OPENACC_WR) ? "O_RDONLY" : "O_RDWR");
+
     ret = AFPERR_NOOBJ;
     if (access & OPENACC_WR) {
         /* try opening in read-write mode */
@@ -366,7 +370,6 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     } else {
         /* try opening in read-only mode */
         ret = AFPERR_NOOBJ;
-        /* we need w access for setting deny mode fcntl excl lock */
         if (ad_open(ofork->of_ad, upath, adflags | ADFLAGS_RDONLY | ADFLAGS_SETSHRMD) < 0) {
             switch ( errno ) {
             case EROFS:
@@ -415,7 +418,7 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     }
 
     if ((ret = getforkparams(ofork, bitmap, rbuf + 2 * sizeof(int16_t), &buflen)) != AFP_OK) {
-        ad_close( ofork->of_ad, adflags );
+        ad_close( ofork->of_ad, adflags | ADFLAGS_SETSHRMD);
         goto openfork_err;
     }
 
@@ -430,7 +433,7 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     if (ad_meta_fileno(ofork->of_ad) != -1) {   /* META */
         ad_getattr(ofork->of_ad, &bshort);
         if ((bshort & htons(ATTRBIT_NOWRITE)) && (access & OPENACC_WR)) {
-            ad_close( ofork->of_ad, adflags );
+            ad_close( ofork->of_ad, adflags | ADFLAGS_SETSHRMD);
             of_dealloc( ofork );
             ofrefnum = 0;
             memcpy(rbuf, &ofrefnum, sizeof(ofrefnum));
@@ -444,14 +447,14 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
 
     /* don't try to lock non-existent rforks. */
     if ((eid == ADEID_DFORK)
-        || (ad_meta_fileno(ofork->of_ad) != -1)
-        || (vol->v_adouble & AD_VERSION_EA)) { /* META */
-
+        || (ad_reso_fileno(ofork->of_ad) != -1)
+        || (ofork->of_ad->ad_vers == AD_VERSION_EA)) {
         ret = fork_setmode(ofork->of_ad, eid, access, ofrefnum);
         /* can we access the fork? */
         if (ret < 0) {
+            ofork->of_flags |= AFPFORK_ERROR;
             ret = errno;
-            ad_close( ofork->of_ad, adflags );
+            ad_close( ofork->of_ad, adflags | ADFLAGS_SETSHRMD);
             of_dealloc( ofork );
             switch (ret) {
             case EAGAIN: /* return data anyway */
@@ -561,7 +564,7 @@ int afp_setforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen, char *rbuf _U
         if (err < 0)
             goto afp_setfork_err;
     } else if (bitmap == (1<<FILPBIT_RFLEN) || bitmap == (1<<FILPBIT_EXTRFLEN)) {
-        ad_refresh( ofork->of_ad );
+        ad_refresh(NULL, ofork->of_ad );
 
         st_size = ad_size(ofork->of_ad, eid);
         err = -2;
@@ -640,7 +643,7 @@ static int byte_lock(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf
     ibuf += sizeof(ofrefnum);
 
     if (NULL == ( ofork = of_find( ofrefnum )) ) {
-        LOG(log_error, logtype_afpd, "afp_bytelock: of_find(%d) could not locate fork", ofrefnum );
+        LOG(log_error, logtype_afpd, "byte_lock: of_find(%d) could not locate fork", ofrefnum );
         return( AFPERR_PARAM );
     }
 
@@ -654,7 +657,6 @@ static int byte_lock(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf
     offset = get_off_t(&ibuf, is64);
     length = get_off_t(&ibuf, is64);
 
-    /* FIXME AD_FILELOCK test is surely wrong */
     if (length == -1)
         length = BYTELOCK_MAX;
     else if (!length || is_neg(is64, length)) {
@@ -1067,7 +1069,7 @@ int flushfork(struct ofork *ofork)
          (ofork->of_flags & AFPFORK_RSRC)) {
 
         /* read in the rfork length */
-        ad_refresh(ofork->of_ad);
+        ad_refresh(NULL, ofork->of_ad);
 
         /* set the date if we're dirty */
         if ((ofork->of_flags & AFPFORK_DIRTY) && !gettimeofday(&tv, NULL)) {
@@ -1137,6 +1139,9 @@ static ssize_t write_file(struct ofork *ofork, int eid,
         }
     }
 
+    LOG(log_debug, logtype_afpd, "write_file(off: %ju, size: %zu)",
+        (uintmax_t)offset, rbuflen);
+
     if (( cc = ad_write(ofork->of_ad, eid, offset, 0,
                         rbuf, rbuflen)) < 0 ) {
         switch ( errno ) {
@@ -1242,15 +1247,16 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
     case AFPPROTO_DSI:
     {
         DSI *dsi = obj->handle;
-
         /* find out what we have already and write it out. */
         cc = dsi_writeinit(dsi, rbuf, *rbuflen);
+
         if (!cc || (cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) {
             dsi_writeflush(dsi);
             *rbuflen = 0;
             ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount, ofork->of_refnum);
             return cc;
         }
+
         offset += cc;
 
 #if 0 /*def HAVE_SENDFILE_WRITE*/
@@ -1353,15 +1359,14 @@ int afp_getforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbu
         return( AFPERR_PARAM );
     }
 
-    if ( ad_meta_fileno( ofork->of_ad ) != -1 ) { /* META */
-        if ( ad_refresh( ofork->of_ad ) < 0 ) {
+    if (AD_META_OPEN(ofork->of_ad)) {
+        if ( ad_refresh(NULL, ofork->of_ad ) < 0 ) {
             LOG(log_error, logtype_afpd, "getforkparams(%s): ad_refresh: %s", of_name(ofork), strerror(errno) );
             return( AFPERR_PARAM );
         }
     }
 
-    if (AFP_OK != ( ret = getforkparams( ofork, bitmap,
-                                         rbuf + sizeof( u_short ), &buflen ))) {
+    if (AFP_OK != (ret = getforkparams(ofork, bitmap, rbuf + sizeof( u_short ), &buflen ))) {
         return( ret );
     }