]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/file.c
remove a debug quota log output
[netatalk.git] / etc / afpd / file.c
index 96970807805b98ff327650f1ca6ea218d4611f43..d41e1252f45d2bb32d43923ffa88d50b3055bb49 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: file.c,v 1.96 2005-04-28 20:49:41 bfernhomberg Exp $
+ * $Id: file.c,v 1.100 2006-09-15 00:02:56 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -575,7 +575,7 @@ int getfilparams(struct vol *vol,
     }
     rc = getmetadata(vol, bitmap, path, dir, buf, buflen, adp, attrbits);
     if ( adp ) {
-        ad_close( adp, ADFLAGS_HF );
+        ad_close_metadata( adp);
     }
 #ifdef DEBUG
     LOG(log_info, logtype_afpd, "end getfilparams:");
@@ -910,8 +910,7 @@ int setfilparams(struct vol *vol,
 
     /* second try with adouble open 
     */
-    if ( ad_open( upath, vol_noadouble(vol) | ADFLAGS_HF,
-                 O_RDWR|O_CREAT, 0666, adp) < 0) {
+    if ( ad_open_metadata( upath, vol_noadouble(vol), O_CREAT, adp) < 0) {
         /* for some things, we don't need an adouble header */
         if (f_bitmap & ~(1<<FILPBIT_MDATE)) {
             return vol_noadouble(vol) ? AFP_OK : AFPERR_ACCESS;
@@ -996,8 +995,8 @@ setfilparam_done:
     }
 
     if (isad) {
-        ad_flush( adp, ADFLAGS_HF );
-        ad_close( adp, ADFLAGS_HF );
+        ad_flush_metadata( adp);
+        ad_close_metadata( adp);
 
     }
 
@@ -1378,6 +1377,7 @@ static int copy_fd(int dfd, int sfd)
 /* ----------------------------------
  * if newname is NULL (from directory.c) we don't want to copy ressource fork.
  * because we are doing it elsewhere.
+ * currently if newname is NULL then adp is NULL. 
  */
 int copyfile(s_vol, d_vol, src, dst, newname, adp )
 const struct vol *s_vol, *d_vol;
@@ -1389,6 +1389,7 @@ struct adouble *adp;
     int                 ret_err = 0;
     int                 adflags;
     int                 noadouble = vol_noadouble(d_vol);
+    int                 stat_result;
     struct stat         st;
     
 #ifdef DEBUG
@@ -1415,7 +1416,14 @@ struct adouble *adp;
         adflags &= ~ADFLAGS_HF;
     }
 
-    if (ad_open(dst , adflags | noadouble, O_RDWR|O_CREAT|O_EXCL, 0666, &add) < 0) {
+    stat_result = fstat(ad_dfileno(adp), &st); /* saving stat exit code, thus saving us on one more stat later on */
+
+    if (stat_result < 0) {           
+      /* unlikely but if fstat fails, the default file mode will be 0666. */
+      st.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+    }
+
+    if (ad_open(dst , adflags | noadouble, O_RDWR|O_CREAT|O_EXCL, st.st_mode, &add) < 0) {
         ret_err = errno;
         ad_close( adp, adflags );
         if (EEXIST != ret_err) {
@@ -1424,6 +1432,8 @@ struct adouble *adp;
         }
         return AFPERR_EXIST;
     }
+    /* XXX if the source and the dest don't use the same resource type it's broken
+    */
     if (ad_hfileno(adp) == -1 || 0 == (err = copy_fd(ad_hfileno(&add), ad_hfileno(adp)))){
         /* copy the data fork */
        err = copy_fd(ad_dfileno(&add), ad_dfileno(adp));
@@ -1436,33 +1446,35 @@ struct adouble *adp;
     ad_close( adp, adflags );
 
     if (ad_close( &add, adflags ) <0) {
+        if (!ret_err) {
+            ret_err = errno;
+        }
         deletefile(d_vol, dst, 0);
-        ret_err = errno;
         goto done;
     } 
-    else {
+
+    if (!ret_err && newname && (adflags & ADFLAGS_HF)) {
+        /* set the new name in the resource fork */
        ad_init(&add, d_vol->v_adouble, d_vol->v_ad_options);
-       if (ad_open(dst , adflags | noadouble, O_RDWR, 0666, &add) < 0) {
+       if (ad_open_metadata(dst , noadouble, 0, &add) < 0) {
            ret_err = errno;
        }
+       else {
+            ad_setname(&add, newname);
+            ad_flush_metadata( &add);
+            if (ad_close_metadata( &add)) {
+                ret_err = errno;
+            }
+        }
     }
 
-    if (!ret_err && newname) {
-        ad_setname(&add, newname);
-    }
-
-    ad_flush( &add, adflags );
-    if (ad_close( &add, adflags ) <0) {
-       ret_err = errno;
-    }
     if (ret_err) {
         deletefile(d_vol, dst, 0);
     }
-    else if (!stat(src, &st)) {
+    else if (stat_result == 0) {
         /* set dest modification date to src date */
         struct utimbuf ut;
 
-        /* ADS here ? */
        ut.actime = ut.modtime = st.st_mtime;
        utime(dst, &ut);
        /* FIXME netatalk doesn't use resource fork file date
@@ -1531,7 +1543,7 @@ int         checkAttrib;
                 continue;
 
             case EACCES:
-                adp = NULL; /* maybe it's a file we no rw mode for us */
+                adp = NULL; /* maybe it's a file with no write mode for us */
                 break;      /* was return AFPERR_ACCESS;*/
             case EROFS:
                 return AFPERR_VLOCK;
@@ -1547,23 +1559,11 @@ int         checkAttrib;
     if (checkAttrib) {
         u_int16_t   bshort;
         
-        if (adp && (adflags & ADFLAGS_HF)) {
-
+        if ( ad_metadata( file , 0, &ad) == 0 ) {
             ad_getattr(&ad, &bshort);
+            ad_close_metadata( &ad);
             if ((bshort & htons(ATTRBIT_NODELETE))) {
-                ad_close( &ad, adflags );
-                return(AFPERR_OLOCK);
-            }
-        }
-        else if (!adp) {
-            /* was EACCESS error try to get only metadata */
-            ad_init(&ad, vol->v_adouble, vol->v_ad_options);  /* OK */
-            if ( ad_metadata( file , 0, &ad) == 0 ) {
-                ad_getattr(&ad, &bshort);
-                ad_close( &ad, ADFLAGS_HF );
-                if ((bshort & htons(ATTRBIT_NODELETE))) {
-                    return  AFPERR_OLOCK;
-                }
+                return  AFPERR_OLOCK;
             }
         }
     }
@@ -1720,13 +1720,13 @@ static int reenumerate_loop(struct dirent *de, char *mname _U_, void *data)
             
         adp = of_ad(vol, &path, &ad);
             
-        if ( ad_open( de->d_name, ADFLAGS_HF, O_RDWR, 0, adp ) < 0 ) {
+        if ( ad_open_metadata( de->d_name, 0, 0, adp ) < 0 ) {
             return 0;
         }
         if (ad_setid(adp, path.st.st_dev, path.st.st_ino, aint, did, vol->v_stamp)) {
-            ad_flush(adp, ADFLAGS_HF);
+            ad_flush_metadata(adp);
         }
-        ad_close(adp, ADFLAGS_HF);
+        ad_close_metadata(adp);
     }
 #endif /* AD_VERSION > AD_VERSION1 */