]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/fork.c
removed unneeded cnid_lookups; fixed a bug in afp_createid.
[netatalk.git] / etc / afpd / fork.c
index bd9d0a4ef002170a2d4781c71f9942e0de1db79d..f0bab5ec96f58348bc879b985881636b345cdff4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: fork.c,v 1.5 2001-06-20 18:33:04 rufustfirefly Exp $
+ * $Id: fork.c,v 1.8 2001-08-27 15:26:16 uhees Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -36,7 +36,9 @@
 #include <atalk/afp.h>
 #include <atalk/adouble.h>
 #include <atalk/util.h>
+#ifdef CNID_DB
 #include <atalk/cnid.h>
+#endif
 
 #include "fork.h"
 #include "file.h"
@@ -68,7 +70,7 @@ static int getforkparams(ofork, bitmap, buf, buflen, attrbits )
     } else {
        aint = ad_getentrylen( ofork->of_ad, ADEID_RFORK );
        if ( ad_refresh( ofork->of_ad ) < 0 ) {
-           syslog( LOG_ERR, "getforkparams: ad_refresh: %m");
+           syslog( LOG_ERR, "getforkparams: ad_refresh: %s", strerror(errno) );
            return( AFPERR_PARAM );
        }
        /* See afp_closefork() for why this is bad */
@@ -155,7 +157,7 @@ static int getforkparams(ofork, bitmap, buf, buflen, attrbits )
                memcpy(data, ufinderi, 8 );
                if (( em = getextmap( ofork->of_name )) != NULL ) {
                    memcpy(data, em->em_type, sizeof( em->em_type ));
-                   memcpy(data + 4, em->em_creator, 
+                   memcpy(data + 4, em->em_creator,
                            sizeof( em->em_creator ));
                }
            }
@@ -173,29 +175,28 @@ static int getforkparams(ofork, bitmap, buf, buflen, attrbits )
            break;
 
        case FILPBIT_FNUM :
-           /*
-            * See file.c getfilparams() for why this is done this
-            * way.
-            */
+               aint = 0;
 #if AD_VERSION > AD_VERSION1
-           if (isad) 
-             memcpy(&aint, ad_entry(ofork->of_ad, ADEID_DID), sizeof(aint));
-           else
-             aint = 0;
-           
-           if (!(aint = cnid_add(ofork->of_vol->v_db, &st, 
-                                 ofork->of_dir->d_did, 
-                                 upath, strlen(upath), aint))) {
+        /* look in AD v2 header */
+        if (isad)
+               memcpy(&aint, ad_entry(ofork->of_ad, ADEID_DID), sizeof(aint));
 #endif /* AD_VERSION > AD_VERSION1 */
+
+#ifdef CNID_DB
+        aint = cnid_add(ofork->of_vol->v_db, &st,
+                                 ofork->of_dir->d_did,
+                                 upath, strlen(upath), aint);
+#endif /* CNID_DB */
+
+               if (aint == 0) {
 #ifdef AFS
              aint = st.st_ino;
 #else /* AFS */
              aint = ( st.st_dev << 16 ) | ( st.st_ino & 0x0000ffff );
 #endif /* AFS */
-#if AD_VERSION > AD_VERSION1
            }
-#endif /* AD_VERSION > AD_VERSION1 */
-           memcpy(data, &aint, sizeof( aint ));
+
+               memcpy(data, &aint, sizeof( aint ));
            data += sizeof( aint );
            break;
 
@@ -362,7 +363,7 @@ int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen )
         goto openfork_err;
         break;
        default:
-        syslog( LOG_ERR, "afp_openfork: ad_open: %m" );
+        syslog( LOG_ERR, "afp_openfork: ad_open: %s", strerror(errno) );
         ret = AFPERR_PARAM;
         goto openfork_err;
         break;
@@ -414,7 +415,7 @@ int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen )
       if (!ret && (access & OPENACC_RD)) {
        ofork->of_flags |= AFPFORK_ACCRD;
        ret = ad_lock(ofork->of_ad, eid, ADLOCK_RD | ADLOCK_FILELOCK, 
-                     AD_FILELOCK_RD, 1, ofrefnum); 
+                     AD_FILELOCK_RD, 1, ofrefnum);
       }
     
       /* can we access the fork? */
@@ -457,7 +458,7 @@ int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen )
          break;
        default:
          *rbuflen = 0;
-         syslog( LOG_ERR, "afp_openfork: ad_lock: %m" );
+         syslog( LOG_ERR, "afp_openfork: ad_lock: %s", strerror(errno) );
          return( AFPERR_PARAM );
        }
       }
@@ -494,7 +495,7 @@ int afp_setforkparams(obj, ibuf, ibuflen, rbuf, rbuflen )
 
     *rbuflen = 0;
     if (( ofork = of_find( ofrefnum )) == NULL ) {
-       syslog( LOG_ERR, "afp_setforkparams: of_find: %m" );
+       syslog( LOG_ERR, "afp_setforkparams: of_find: %s", strerror(errno) );
        return( AFPERR_PARAM );
     }
 
@@ -519,7 +520,8 @@ int afp_setforkparams(obj, ibuf, ibuflen, rbuf, rbuflen )
          goto afp_setfork_err;
        
        if (ad_flush( ofork->of_ad, ADFLAGS_HF ) < 0) {
-           syslog( LOG_ERR, "afp_setforkparams: ad_flush: %m" );
+           syslog( LOG_ERR, "afp_setforkparams: ad_flush: %s",
+                   strerror(errno) );
            return( AFPERR_PARAM );
        }
     } else
@@ -582,7 +584,7 @@ int afp_bytelock(obj, ibuf, ibuflen, rbuf, rbuflen )
     ibuf += sizeof(ofrefnum);
 
     if (( ofork = of_find( ofrefnum )) == NULL ) {
-       syslog( LOG_ERR, "afp_bytelock: of_find: %m" );
+       syslog( LOG_ERR, "afp_bytelock: of_find: %s", strerror(errno) );
        return( AFPERR_PARAM );
     }
 
@@ -682,7 +684,7 @@ static __inline__ ssize_t read_file(struct ofork *ofork, int eid,
 
     cc = ad_read(ofork->of_ad, eid, offset, rbuf, *rbuflen);
     if ( cc < 0 ) {
-       syslog( LOG_ERR, "afp_read: ad_read: %m" );
+       syslog( LOG_ERR, "afp_read: ad_read: %s", strerror(errno) );
        *rbuflen = 0;
        return( AFPERR_PARAM );
     }
@@ -743,7 +745,7 @@ int afp_read(obj, ibuf, ibuflen, rbuf, rbuflen)
     ibuf += sizeof( u_short );
 
     if (( ofork = of_find( ofrefnum )) == NULL ) {
-       syslog( LOG_ERR, "afp_read: of_find: %m" );
+       syslog( LOG_ERR, "afp_read: of_find: %s", strerror(errno) );
        err = AFPERR_PARAM;
        goto afp_read_err;
     }
@@ -841,7 +843,7 @@ int afp_read(obj, ibuf, ibuflen, rbuf, rbuflen)
          if (errno == EINVAL)
            goto afp_read_loop;
          else {
-           syslog(LOG_ERR, "afp_read: ad_readfile: %m");
+           syslog(LOG_ERR, "afp_read: ad_readfile: %s", strerror(errno));
            goto afp_read_exit;
          }
        }
@@ -876,7 +878,7 @@ afp_read_loop:
       goto afp_read_done;
 
 afp_read_exit:
-      syslog(LOG_ERR, "afp_read: %m");
+      syslog(LOG_ERR, "afp_read: %s", strerror(errno));
       dsi_readdone(dsi);
       ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount);
       obj->exit(1);
@@ -924,12 +926,12 @@ int afp_flushfork(obj, ibuf, ibuflen, rbuf, rbuflen )
     memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
 
     if (( ofork = of_find( ofrefnum )) == NULL ) {
-       syslog( LOG_ERR, "afp_flushfork: of_find: %m" );
+       syslog( LOG_ERR, "afp_flushfork: of_find: %s", strerror(errno) );
        return( AFPERR_PARAM );
     }
 
     if ( flushfork( ofork ) < 0 ) {
-       syslog( LOG_ERR, "afp_flushfork: %m" );
+       syslog( LOG_ERR, "afp_flushfork: %s", strerror(errno) );
     }
 
     return( AFP_OK );
@@ -944,8 +946,8 @@ int flushfork( ofork )
 
     if ( ad_dfileno( ofork->of_ad ) != -1 &&
            fsync( ad_dfileno( ofork->of_ad )) < 0 ) {
-       syslog( LOG_ERR, "flushfork: dfile(%d) %m", 
-               ad_dfileno(ofork->of_ad) );
+       syslog( LOG_ERR, "flushfork: dfile(%d) %s", 
+               ad_dfileno(ofork->of_ad), strerror(errno) );
        err = -1;
     }