]> arthur.barton.de Git - netatalk.git/commitdiff
desktop.c:
authordidg <didg>
Sun, 16 Feb 2003 12:35:04 +0000 (12:35 +0000)
committerdidg <didg>
Sun, 16 Feb 2003 12:35:04 +0000 (12:35 +0000)
more if ((A = B) == C) to (C == (A = B))

directory.c:
deletecurdir() move cnid_delete inside opendir() closedir()

fork.c:
getmetada() use struct path in parameter

afp_openfork() we need to keep track if we (re)open the ressource fork.
it was a problem if:
- there's no ressource fork
- the data fork is open read write
- the ressource fork is open read write
- the data fork is closed.
With a Mac it was an issue with noadouble and no .AppleDouble folder,
otherwise the ressource fork is always created before opening the data fork.
(if it can't, because permission on .AppleDouble, then the RF can't be open
read write).

enumerate.c:
more if ((A = B) == C) to (C == (A = B))
adddir() free allocated memory

file.c:
use the new getmetada() format

copyfile() use ad_open, with the new ADFLAGS_NOHF attrib., rather than
open syscall.

deletefile() move cnid_delete inside open() close()

afp_creatfile() if there's an error in ressource fork creation then delete
the data fork if any. It's the reason for ADFLAGS_NOHF, we need to be sure
that the data fork was created by us, ie we have a file descriptor for it.

filedir.c:
remove cnid_delete(), now in deletefile()

adouble.h:
add a new attrib. ADFLAGS_NOHF mean don't return an error if there's
no ressource fork.
Helper for using ad_open in copyfile() and in afp_createfile()

cnid.h:
add CNID_ERR_CLOSE error, not used for now.

ad_lock.c:
ad_fcntl_lock() a previous fix a typo =/==, and now we have a
reference used after freed in realloc.

hf2off() df2off() change int to off_t

ad_open.c:
ad_open() ADFLAGS_NOHF attrib

etc/afpd/desktop.c
etc/afpd/directory.c
etc/afpd/enumerate.c
etc/afpd/file.c
etc/afpd/file.h
etc/afpd/filedir.c
etc/afpd/fork.c
include/atalk/adouble.h
include/atalk/cnid.h
libatalk/adouble/ad_lock.c
libatalk/adouble/ad_open.c

index 629da9d1affa776895fc5f2706fcb147109091d4..e91478c6e383e83986b598b22aed1d2c84a4a658 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: desktop.c,v 1.22 2003-01-24 07:08:42 didg Exp $
+ * $Id: desktop.c,v 1.23 2003-02-16 12:35:04 didg Exp $
  *
  * See COPYRIGHT.
  *
@@ -363,7 +363,7 @@ int         ibuflen, *rbuflen;
 
     memcpy( &vid, ibuf, sizeof( vid ));
     ibuf += sizeof( vid );
-    if (( vol = getvolbyvid( vid )) == NULL ) {
+    if (NULL == ( vol = getvolbyvid( vid )) ) {
         return( AFPERR_PARAM );
     }
 
@@ -440,7 +440,7 @@ int         ibuflen, *rbuflen;
 
     memcpy( &vid, ibuf, sizeof( vid ));
     ibuf += sizeof( vid );
-    if (( vol = getvolbyvid( vid )) == NULL ) {
+    if (NULL == ( vol = getvolbyvid( vid )) ) {
         return( AFPERR_PARAM );
     }
 
index e577f238ec286e243ae68e5a2c94a90fc0da4edf..aeab2c83ce62dc4c06fa7185c87e8a1884f232d8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: directory.c,v 1.61 2003-01-31 17:47:06 didg Exp $
+ * $Id: directory.c,v 1.62 2003-02-16 12:35:04 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -193,7 +193,7 @@ u_int32_t   did;
         if (ret != NULL) {
             break;
         }
-        if ((upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) == NULL) {
+        if (NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen))) {
             afp_errno = AFPERR_NOOBJ;
             return NULL;
         }
@@ -817,6 +817,14 @@ struct dir *dir;
 
 /* free everything down. we don't bother to recolor as this is only
  * called to free the entire tree */
+void dirfreename(struct dir *dir)
+{
+    if (dir->d_u_name != dir->d_m_name) {
+        free(dir->d_u_name);
+    }
+    free(dir->d_m_name);
+}
+
 void dirfree( dir )
 struct dir     *dir;
 {
@@ -831,10 +839,7 @@ struct dir *dir;
     }
 
     if (dir != SENTINEL) {
-        if (dir->d_u_name != dir->d_m_name) {
-            free(dir->d_u_name);
-        }
-        free(dir->d_m_name);
+        dirfreename(dir);
         free( dir );
     }
 }
@@ -1983,24 +1988,30 @@ int pathlen;
                return err;
             }
         }
-        closedir(dp);
     }
 
     if ( movecwd( vol, curdir->d_parent ) < 0 ) {
-        return afp_errno;
+        err = afp_errno;
+        goto delete_done;
     }
 
-    if ( (err = netatalk_rmdir(fdir->d_u_name))) {
-        return err;
-    }
-
-    dirchildremove(curdir, fdir);
+    if ( !(err = netatalk_rmdir(fdir->d_u_name))) {
+        dirchildremove(curdir, fdir);
 #ifdef CNID_DB
-    cnid_delete(vol->v_db, fdir->d_did);
+        cnid_delete(vol->v_db, fdir->d_did);
 #endif /* CNID_DB */
-    dir_remove( vol, fdir );
-
-    return( AFP_OK );
+        dir_remove( vol, fdir );
+        err = AFP_OK;
+    }
+delete_done:
+    if (dp) {
+        /* inode is used as key for cnid.
+         * Close the descriptor only after cnid_delete
+         * has been called. 
+        */
+        closedir(dp);
+    }
+    return err;
 }
 
 int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen )
index 1a7c437cd867f4336b2032f0e1b2c134f2011a59..8c161d8d9f28eab9bef26f25e3cb364875c3d2e1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: enumerate.c,v 1.33 2003-01-24 07:08:42 didg Exp $
+ * $Id: enumerate.c,v 1.34 2003-02-16 12:35:04 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -70,6 +70,8 @@ struct path     *path;
     /* Fail out if things go bad with CNID. */
     if (cdir->d_did == CNID_INVALID) {
         switch (errno) {
+        case CNID_ERR_CLOSE: /* the db is closed */
+            break;
         case CNID_ERR_PARAM:
             LOG(log_error, logtype_afpd, "adddir: Incorrect parameters passed to cnid_add");
             return NULL;
@@ -105,6 +107,7 @@ struct path     *path;
            - it's an ID reused as above
            - it's a hash duplicate and we are in big trouble
         */
+        dirfreename(edir);
         edir->d_m_name = cdir->d_m_name;
         edir->d_u_name = cdir->d_u_name;
         free(cdir);
@@ -449,8 +452,8 @@ int     ext;
             else {
                 s_path.m_name = NULL;
             }
-            if (( ret = getdirparams(vol, dbitmap, &s_path, dir,
-                                     data + header , &esz )) != AFP_OK ) {
+            if (AFP_OK != ( ret = getdirparams(vol, dbitmap, &s_path, dir,
+                                     data + header , &esz ))) {
                 return( ret );
             }
 
@@ -460,8 +463,8 @@ int     ext;
                 continue;
             }
             s_path.m_name = utompath(vol, s_path.u_name);
-            if (( ret = getfilparams(vol, fbitmap, &s_path, curdir, 
-                                     data + header , &esz )) != AFP_OK ) {
+            if (AFP_OK != ( ret = getfilparams(vol, fbitmap, &s_path, curdir, 
+                                     data + header , &esz )) ) {
                 return( ret );
             }
         }
index 64ffaaebc6e99e8268b41a7974039492b587e47d..bf93f9fc014d426e3dea0a28979c8a2cce41213a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: file.c,v 1.83 2003-02-04 18:26:20 didg Exp $
+ * $Id: file.c,v 1.84 2003-02-16 12:35:04 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -159,7 +159,7 @@ char *set_name(char *data, const char *name, u_int32_t utf8)
 /* -------------------------- */
 int getmetadata(struct vol *vol,
                  u_int16_t bitmap,
-                 char *path, struct dir *dir, struct stat *st,
+                 struct path *path, struct dir *dir, 
                  char *buf, int *buflen, struct adouble *adp, int attrbits )
 {
 #ifndef USE_LASTDID
@@ -172,12 +172,13 @@ int getmetadata(struct vol *vol,
     u_int16_t          ashort;
     u_char              achar, fdType[4];
     u_int32_t           utf8 = 0;
-
+    struct stat         *st;
 #ifdef DEBUG
     LOG(log_info, logtype_afpd, "begin getmetadata:");
 #endif /* DEBUG */
 
-    upath = mtoupath(vol, path);
+    upath = path->u_name;
+    st = &path->st;
 
     data = buf;
     while ( bitmap != 0 ) {
@@ -244,7 +245,7 @@ int getmetadata(struct vol *vol,
             break;
 
         case FILPBIT_FINFO :
-           get_finderinfo(path, adp, (char *)data);
+           get_finderinfo(path->m_name, adp, (char *)data);
             if (!adp) {
                 if (*upath == '.') { /* make it invisible */
                     ashort = htons(FINDERINFO_INVISIBLE);
@@ -437,12 +438,12 @@ int getmetadata(struct vol *vol,
     if ( l_nameoff ) {
         ashort = htons( data - buf );
         memcpy(l_nameoff, &ashort, sizeof( ashort ));
-        data = set_name(data, path, 0);
+        data = set_name(data, path->m_name, 0);
     }
     if ( utf_nameoff ) {
         ashort = htons( data - buf );
         memcpy(utf_nameoff, &ashort, sizeof( ashort ));
-        data = set_name(data, path, utf8);
+        data = set_name(data, path->m_name, utf8);
     }
     *buflen = data - buf;
     return (AFP_OK);
@@ -496,7 +497,7 @@ int getfilparams(struct vol *vol,
            }
        }
     }
-    rc = getmetadata(vol, bitmap, path->m_name, dir, &path->st, buf, buflen, adp, attrbits);
+    rc = getmetadata(vol, bitmap, path, dir, buf, buflen, adp, attrbits);
     if ( adp ) {
         ad_close( adp, ADFLAGS_HF );
     }
@@ -513,7 +514,6 @@ AFPObj      *obj;
 char   *ibuf, *rbuf;
 int            ibuflen, *rbuflen;
 {
-    struct stat         *st;
     struct adouble     ad, *adp;
     struct vol         *vol;
     struct dir         *dir;
@@ -583,23 +583,29 @@ int               ibuflen, *rbuflen;
         openf = O_RDWR|O_CREAT|O_EXCL;
     }
 
-    if ( ad_open( upath, vol_noadouble(vol)|ADFLAGS_DF|ADFLAGS_HF,
+    if ( ad_open( upath, vol_noadouble(vol)|ADFLAGS_DF|ADFLAGS_HF|ADFLAGS_NOHF,
                   openf, 0666, adp) < 0 ) {
         switch ( errno ) {
         case EEXIST :
             return( AFPERR_EXIST );
         case EACCES :
             return( AFPERR_ACCESS );
-        case ENOENT:
-            /* on noadouble volumes, just creating the data fork is ok */
-            st = &s_path->st;
-            if (vol_noadouble(vol) && (stat(upath, st) == 0))
-                goto createfile_done;
-            /* fallthrough */
         default :
             return( AFPERR_PARAM );
         }
     }
+    if ( ad_hfileno( adp ) == -1 ) {
+         /* on noadouble volumes, just creating the data fork is ok */
+         if (vol_noadouble(vol))
+             goto createfile_done;
+         /* FIXME with hard create on an existing file, we already
+          * corrupted the data file.
+          */
+         netatalk_unlink( upath );
+         ad_close( adp, ADFLAGS_DF );
+         return AFPERR_ACCESS;
+    }
+
     path = s_path->m_name;
     ad_setentrylen( adp, ADEID_NAME, strlen( path ));
     memcpy(ad_entry( adp, ADEID_NAME ), path,
@@ -903,11 +909,11 @@ struct adouble    *adp;
                /* FIXME  warning in syslog so admin'd know there's a conflict ?*/
                return AFPERR_OLOCK; /* little lie */
            }
-            if (( rc = copyfile(src, dst, newname, noadouble )) != AFP_OK ) {
-                deletefile( dst, 0 );
+            if (AFP_OK != ( rc = copyfile(src, dst, newname, noadouble )) ) {
+                /* on error copyfile delete dest */
                 return( rc );
             }
-            return deletefile( src, 0);
+            return deletefile(NULL, src, 0);
         default :
             return( AFPERR_PARAM );
         }
@@ -1169,96 +1175,75 @@ static __inline__ int copy_all(const int dfd, const void *buf,
     return AFP_OK;
 }
 
-/* XXX: this needs to use ad_open and ad_lock. so, we need to
- * pass in vol and path */
+/* -------------------------- */
+static int copy_fd(int dfd, int sfd)
+{
+    ssize_t cc;
+    int     err = AFP_OK;
+    char    filebuf[8192];
+
+#ifdef SENDFILE_FLAVOR_LINUX
+    struct stat         st;
+
+    if (fstat(sfd, &st) == 0) {
+        if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) {
+            switch (errno) {
+            case EINVAL:  /* there's no guarantee that all fs support sendfile */
+                break;
+            case EDQUOT:
+            case EFBIG:
+            case ENOSPC:
+                return AFPERR_DFULL;
+            case EROFS:
+                return AFPERR_VLOCK;
+            default:
+                return AFPERR_PARAM;
+            }
+        }
+        else {
+           return AFP_OK;
+        }
+    }
+#endif /* SENDFILE_FLAVOR_LINUX */
+
+    while (1) {
+        if ((cc = read(sfd, filebuf, sizeof(filebuf))) < 0) {
+            if (errno == EINTR)
+                continue;
+            err = AFPERR_PARAM;
+            break;
+        }
+
+        if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0))
+            break;
+    }
+    return err;
+}
+
+/* ----------------------------------
+ * if newname is NULL (from directory.c) we don't want to copy ressource fork.
+ * because we are doing it elsewhere.
+ */
 int copyfile(src, dst, newname, noadouble )
 char   *src, *dst, *newname;
 const int   noadouble;
 {
-    struct adouble     ad;
-#ifdef SENDFILE_FLAVOR_LINUX
-    struct stat         st;
-#endif
-    char               filebuf[8192];
-    int                        sfd, dfd, len, err = AFP_OK;
-    ssize_t             cc;
-    char                dpath[ MAXPATHLEN + 1];
-    int                 admode;
+    struct adouble     ads, add;
+    int                        len, err = AFP_OK;
+    int                 adflags;
+    
 #ifdef DEBUG
     LOG(log_info, logtype_afpd, "begin copyfile:");
 #endif /* DEBUG */
 
-    strcpy(dpath, ad_path( dst, ADFLAGS_HF ));
-    admode = ad_mode( dst, 0666 );
+    memset(&ads, 0, sizeof(ads));
+    memset(&add, 0, sizeof(add));
+    adflags = ADFLAGS_DF;
     if (newname) {
-        if ((sfd = open( ad_path( src, ADFLAGS_HF ), O_RDONLY, 0 )) < 0 ) {
-            switch ( errno ) {
-            case ENOENT :
-                break; /* just copy the data fork */
-            case EACCES :
-                return( AFPERR_ACCESS );
-            default :
-                return( AFPERR_PARAM );
-            }
-        } else {
-            if (( dfd = open( dpath, O_WRONLY|O_CREAT,ad_hf_mode(admode))) < 0 ) {
-                close( sfd );
-                switch ( errno ) {
-                case ENOENT :
-                    return( AFPERR_NOOBJ );
-                case EACCES :
-                    return( AFPERR_ACCESS );
-                case EROFS:
-                    return AFPERR_VLOCK;
-                default :
-                    return( AFPERR_PARAM );
-                }
-            }
-
-            /* copy the file */
-#ifdef SENDFILE_FLAVOR_LINUX
-            if (fstat(sfd, &st) == 0) {
-                if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) {
-                    switch (errno) {
-                    case EDQUOT:
-                    case EFBIG:
-                    case ENOSPC:
-                        err = AFPERR_DFULL;
-                        break;
-                    case EROFS:
-                        err = AFPERR_VLOCK;
-                        break;
-                    default:
-                        err = AFPERR_PARAM;
-                    }
-                }
-                goto copyheader_done;
-            }
-#endif /* SENDFILE_FLAVOR_LINUX */
-            while (1) {
-                if ((cc = read(sfd, filebuf, sizeof(filebuf))) < 0) {
-                    if (errno == EINTR)
-                        continue;
-                    err = AFPERR_PARAM;
-                    break;
-                }
-
-                if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0))
-                    break;
-            }
-
-copyheader_done:
-            close(sfd);
-            close(dfd);
-            if (err < 0) {
-                unlink(dpath);
-                return err;
-            }
-        }
+        adflags |= ADFLAGS_HF;
     }
 
-    /* data fork copying */
-    if (( sfd = open( src, O_RDONLY, 0 )) < 0 ) {
+    if (ad_open(src , adflags | ADFLAGS_NOHF, O_RDONLY, 0, &ads) < 0) {
         switch ( errno ) {
         case ENOENT :
             return( AFPERR_NOOBJ );
@@ -1268,10 +1253,14 @@ copyheader_done:
             return( AFPERR_PARAM );
         }
     }
-
-    if (( dfd = open( dst, O_WRONLY|O_CREAT, admode)) < 0 ) {
-        close( sfd );
-        switch ( errno ) {
+    if (ad_open(dst , adflags | noadouble, O_RDWR|O_CREAT|O_EXCL, 0666, &add) < 0) {
+        ad_close( &ads, adflags );
+        if (EEXIST != (err = errno)) {
+            deletefile(NULL, dst, 0);
+        }
+        switch ( err ) {
+        case EEXIST :
+            return AFPERR_EXIST;
         case ENOENT :
             return( AFPERR_NOOBJ );
         case EACCES :
@@ -1282,68 +1271,32 @@ copyheader_done:
             return( AFPERR_PARAM );
         }
     }
-
-#ifdef SENDFILE_FLAVOR_LINUX
-    if (fstat(sfd, &st) == 0) {
-        if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) {
-            switch (errno) {
-            case EDQUOT:
-            case EFBIG:
-            case ENOSPC:
-                err = AFPERR_DFULL;
-                break;
-            default:
-                err = AFPERR_PARAM;
-            }
-        }
-        goto copydata_done;
+    if (ad_hfileno(&ads) == -1 || AFP_OK == (err = copy_fd(ad_hfileno(&add), ad_hfileno(&ads)))){
+        /* copy the data fork */
+       err = copy_fd(ad_dfileno(&add), ad_dfileno(&ads));
     }
-#endif /* SENDFILE_FLAVOR_LINUX */
-
-    while (1) {
-        if ((cc = read( sfd, filebuf, sizeof( filebuf ))) < 0) {
-            if (errno == EINTR)
-                continue;
 
-            err = AFPERR_PARAM;
-            break;
-        }
-
-        if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0)) {
-            break;
-        }
+    if (newname) {
+        len = strlen( newname );
+        ad_setentrylen( &add, ADEID_NAME, len );
+        memcpy(ad_entry( &add, ADEID_NAME ), newname, len );
     }
 
-copydata_done:
-    close(sfd);
-    close(dfd);
-    if (err < 0) {
-        unlink(dpath);
-        unlink(dst);
-        return err;
+    ad_close( &ads, adflags );
+    ad_flush( &add, adflags );
+    if (ad_close( &add, adflags ) <0) {
+       err = errno;
     }
-
-    if (newname) {
-        memset(&ad, 0, sizeof(ad));
-        if ( ad_open( dst, noadouble | ADFLAGS_HF, O_RDWR|O_CREAT,
-                      0666, &ad) < 0 ) {
-            switch ( errno ) {
-            case ENOENT :
-                return noadouble ? AFP_OK : AFPERR_NOOBJ;
-            case EACCES :
-                return( AFPERR_ACCESS );
-            case EROFS:
-                return AFPERR_VLOCK;
-            default :
-                return( AFPERR_PARAM );
-            }
+    if (err != AFP_OK) {
+        deletefile(NULL, dst, 0);
+        switch ( err ) {
+        case ENOENT :
+            return( AFPERR_NOOBJ );
+        case EACCES :
+            return( AFPERR_ACCESS );
+        default :
+            return( AFPERR_PARAM );
         }
-
-        len = strlen( newname );
-        ad_setentrylen( &ad, ADEID_NAME, len );
-        memcpy(ad_entry( &ad, ADEID_NAME ), newname, len );
-        ad_flush( &ad, ADFLAGS_HF );
-        ad_close( &ad, ADFLAGS_HF );
     }
 
 #ifdef DEBUG
@@ -1355,8 +1308,8 @@ copydata_done:
 
 
 /* -----------------------------------
-   checkAttrib:   1 check kFPDeleteInhibitBit 
-   ie deletfile called by afp_delete
+   vol: not NULL delete cnid entry. then we are in curdir and file is a only filename
+   checkAttrib:   1 check kFPDeleteInhibitBit (deletfile called by afp_delete)
 
    when deletefile is called we don't have lock on it, file is closed (for us)
    untrue if called by renamefile
@@ -1364,7 +1317,8 @@ copydata_done:
    ad_open always try to open file RDWR first and ad_lock takes care of
    WRITE lock on read only file.
 */
-int deletefile( file, checkAttrib )
+int deletefile( vol, file, checkAttrib )
+struct vol      *vol;
 char           *file;
 int         checkAttrib;
 {
@@ -1431,8 +1385,16 @@ int         checkAttrib;
     if (ad_tmplock( &ad, ADEID_DFORK, ADLOCK_WR, 0, 0, 0 ) < 0) {
         err = AFPERR_BUSY;
     }
-    else if ( 0 == (err = netatalk_unlink( ad_path( file, ADFLAGS_HF )) )) {
-        err = netatalk_unlink( file );
+    else if (!(err = netatalk_unlink( ad_path( file, ADFLAGS_HF)) ) &&
+             !(err = netatalk_unlink( file )) ) {
+#ifdef CNID_DB /* get rid of entry */
+        cnid_t id;
+        if (vol && (id = cnid_get(vol->v_db, curdir->d_did, file, strlen(file)))) 
+        {
+            cnid_delete(vol->v_db, id);
+        }
+#endif /* CNID_DB */
+
     }
     ad_close( &ad, adflags );  /* ad_close removes locks if any */
 
@@ -1487,7 +1449,7 @@ int               ibuflen, *rbuflen;
         return( AFPERR_PARAM );
     }
 
-    if (( s_path = cname( vol, dir, &ibuf )) == NULL ) {
+    if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
         return afp_errno; /* was AFPERR_PARAM */
     }
 
@@ -1585,7 +1547,7 @@ int               ibuflen, *rbuflen;
         return AFPERR_NOID; /* was AFPERR_BADID, but help older Macs */
     }
 
-    if (( dir = dirlookup( vol, id )) == NULL ) {
+    if (NULL == ( dir = dirlookup( vol, id )) ) {
         return AFPERR_NOID; /* idem AFPERR_PARAM */
     }
     path.u_name = upath;
@@ -1607,8 +1569,8 @@ int               ibuflen, *rbuflen;
     memcpy(&bitmap, ibuf, sizeof(bitmap));
     bitmap = ntohs( bitmap );
     path.m_name = utompath(vol, upath);
-    if ((err = getfilparams(vol, bitmap, &path , curdir, 
-                            rbuf + sizeof(bitmap), &buflen)) != AFP_OK) {
+    if (AFP_OK != (err = getfilparams(vol, bitmap, &path , curdir, 
+                            rbuf + sizeof(bitmap), &buflen))) {
         return err;
     }
     *rbuflen = buflen + sizeof(bitmap);
@@ -1663,7 +1625,7 @@ int               ibuflen, *rbuflen;
         return AFPERR_NOID;
     }
 
-    if (( dir = dirlookup( vol, id )) == NULL ) {
+    if (NULL == ( dir = dirlookup( vol, id )) ) {
         return( AFPERR_PARAM );
     }
 
@@ -1681,9 +1643,7 @@ int               ibuflen, *rbuflen;
             return AFPERR_PARAM;
         }
     }
-
-    /* directories are bad */
-    if (S_ISDIR(st.st_mode))
+    else if (S_ISDIR(st.st_mode)) /* directories are bad */
         return AFPERR_BADTYPE;
 
     if (cnid_delete(vol->v_db, fileid)) {
index cc5b9835c49621794e45f2119f4cc01dcea3b06b..2c523b8e053bb126f8c1cd951ab6b56b10f37ebb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: file.h,v 1.14 2002-10-13 06:18:13 didg Exp $
+ * $Id: file.h,v 1.15 2003-02-16 12:35:04 didg Exp $
  *
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
@@ -85,7 +85,7 @@ extern int getfilparams __P((struct vol *, u_int16_t, struct path *,
 extern int setfilparams __P((struct vol *, struct path *, u_int16_t, char *));
 extern int renamefile   __P((char *, char *, char *, const int, struct adouble *));
 extern int copyfile     __P((char *, char *, char *, const int));
-extern int deletefile   __P((char *, int));
+extern int deletefile   __P((struct vol *, char *, int));
 
 extern void *get_finderinfo __P((const char *, struct adouble *, void *));
 extern int  copy_path_name __P((char *, char *i));
index 281887c54a3834a5dcc20bfd934958e621c0a68f..de03e292bc9f17835d22e02df1cd66472b785a6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: filedir.c,v 1.40 2003-01-24 07:08:43 didg Exp $
+ * $Id: filedir.c,v 1.41 2003-02-16 12:35:04 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -209,8 +209,8 @@ int         ibuflen, *rbuflen;
         /* this is a directory */
         *(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR;
     } else {
-        if (fbitmap && ret = getfilparams(vol, fbitmap, s_path, curdir, 
-                                            rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) {
+        if (fbitmap && AFP_OK != (ret = getfilparams(vol, fbitmap, s_path, curdir, 
+                                            rbuf + 3 * sizeof( u_int16_t ), &buflen )) ) {
             return( ret );
         }
         /* this is a file */
@@ -263,7 +263,7 @@ int         ibuflen, *rbuflen;
     memcpy( &did, ibuf, sizeof( did));
     ibuf += sizeof( did);
 
-    if (( dir = dirlookup( vol, did )) == NULL ) {
+    if (NULL == ( dir = dirlookup( vol, did )) ) {
        return afp_errno;    
     }
 
@@ -271,7 +271,7 @@ int         ibuflen, *rbuflen;
     bitmap = ntohs( bitmap );
     ibuf += sizeof( bitmap );
 
-    if (( path = cname( vol, dir, &ibuf )) == NULL ) {
+    if (NULL == ( path = cname( vol, dir, &ibuf ))) {
        return afp_errno;    
     }
 
@@ -484,7 +484,7 @@ int         ibuflen, *rbuflen;
     }
 
     /* source pathname */
-    if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
+    if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
        return afp_errno;    
     }
 
@@ -585,11 +585,8 @@ int                ibuflen, *rbuflen;
         }
     } else if (of_findname(s_path)) {
         rc = AFPERR_BUSY;
-    } else if (AFP_OK == (rc = deletefile( upath, 1))) {
-#ifdef CNID_DB /* get rid of entry */
-        cnid_t id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
-        cnid_delete(vol->v_db, id);
-#endif /* CNID_DB */
+    } else {
+        rc = deletefile(vol, upath, 1);
     }
     if ( rc == AFP_OK ) {
        curdir->offcnt--;
index e384fe43dd367d6fc0a2f4a14c43631cfae1459d..53779a023dc64ab7a1267ed079a5485e49d71fe4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: fork.c,v 1.48 2003-01-31 17:38:01 didg Exp $
+ * $Id: fork.c,v 1.49 2003-02-16 12:35:04 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -50,8 +50,8 @@
 struct ofork           *writtenfork;
 extern int getmetadata(struct vol *vol,
                  u_int16_t bitmap,
-                 char *path, struct dir *dir, struct stat *st,
-                 char *buf, int *buflen, struct adouble *adp, int attrbits );
+                 struct path *path, struct dir *dir, char *buf, 
+                 int *buflen, struct adouble *adp, int attrbits );
 
 static int getforkparams(ofork, bitmap, buf, buflen, attrbits )
 struct ofork   *ofork;
@@ -60,8 +60,8 @@ char          *buf;
 int                    *buflen;
 const u_int16_t     attrbits;
 {
-    struct stat                st;
-    char               *upath;
+    struct path         path;
+    struct stat                *st;
 
     struct adouble     *adp;
     struct dir         *dir;
@@ -86,22 +86,24 @@ const u_int16_t     attrbits;
     vol = ofork->of_vol;
     dir = ofork->of_dir;
 
+    path.u_name = mtoupath(vol, ofork->of_name);
+    path.m_name = ofork->of_name;
+    st = &path.st;
     if ( bitmap & ( (1<<FILPBIT_DFLEN) | (1<<FILPBIT_EXTDFLEN) | 
                     (1<<FILPBIT_FNUM) | (1 << FILPBIT_CDATE) | 
                     (1 << FILPBIT_MDATE) | (1 << FILPBIT_BDATE))) {
         if ( ad_dfileno( ofork->of_ad ) == -1 ) {
-            upath = mtoupath(vol, ofork->of_name);
             if (movecwd(vol, dir) < 0)
                 return( AFPERR_NOOBJ );
-            if ( stat( upath, &st ) < 0 )
+            if ( stat( path.u_name, st ) < 0 )
                 return( AFPERR_NOOBJ );
         } else {
-            if ( fstat( ad_dfileno( ofork->of_ad ), &st ) < 0 ) {
+            if ( fstat( ad_dfileno( ofork->of_ad ), st ) < 0 ) {
                 return( AFPERR_BITMAP );
             }
         }
     }
-    return getmetadata(vol, bitmap, ofork->of_name, dir, &st, buf, buflen, adp, attrbits );    
+    return getmetadata(vol, bitmap, &path, dir, buf, buflen, adp, attrbits );    
 }
 
 /* ---------------------------- */
@@ -177,8 +179,6 @@ static int setforkmode(struct adouble *adp, int eid, int ofrefnum, int what)
 
 /* -------------------------
 */
-extern int ad_testlock(struct adouble *adp, int eid, int off);
-
 static int getforkmode(struct adouble *adp, int eid, int what)
 {
     return ad_testlock(adp, eid,  what);
@@ -383,6 +383,7 @@ int         ibuflen, *rbuflen;
                     * fork if the user wants to open it for write acess. */
                     if (ad_open(upath, adflags, O_RDWR | O_CREAT, 0666, ofork->of_ad) < 0)
                         goto openfork_err;
+                    ofork->of_flags |= AFPFORK_OPEN;
                 }
                 break;
             case EMFILE :
@@ -401,8 +402,10 @@ int                ibuflen, *rbuflen;
                 break;
             }
         }
-        /* the fork is open */
-        ofork->of_flags |= AFPFORK_OPEN;
+        else {
+            /* the ressource fork is open too */
+            ofork->of_flags |= AFPFORK_OPEN;
+        }
     } else {
         /* try opening in read-only mode */
         ret = AFPERR_NOOBJ;
@@ -420,7 +423,6 @@ int         ibuflen, *rbuflen;
                         goto openfork_err;
                     }
                     adflags = ADFLAGS_DF;
-                    ofork->of_flags |= AFPFORK_OPEN;
                 }
                 /* else we don't set AFPFORK_OPEN because there's no ressource fork file 
                  * We need to check AFPFORK_OPEN in afp_closefork(). eg fork open read-only
@@ -443,7 +445,7 @@ int         ibuflen, *rbuflen;
             }
         }
         else {
-            /* the fork is open */
+            /* the ressource fork is open too */
             ofork->of_flags |= AFPFORK_OPEN;
         }
     }
@@ -503,7 +505,7 @@ int         ibuflen, *rbuflen;
                 break;
             default:
                 *rbuflen = 0;
-                LOG(log_error, logtype_afpd, "afp_openfork: ad_lock: %s", strerror(errno) );
+                LOG(log_error, logtype_afpd, "afp_openfork: ad_lock: %s", strerror(ret) );
                 return( AFPERR_PARAM );
             }
         }
@@ -775,7 +777,7 @@ struct ofork        *of;
     if ( ad_hfileno( of->of_ad ) == -1 ||
             memcmp( ufinderi, ad_entry( of->of_ad, ADEID_FINDERI ),
                     8) == 0 ) {
-        if (( em = getextmap( of->of_name )) == NULL ||
+        if (NULL == ( em = getextmap( of->of_name )) ||
                 memcmp( "TEXT", em->em_type, sizeof( em->em_type )) == 0 ) {
             return( 1 );
         } else {
@@ -1153,31 +1155,29 @@ int             ibuflen, *rbuflen;
     }
 
     adflags = 0;
-    if ((ofork->of_flags & AFPFORK_OPEN)) {
-        if ((ofork->of_flags & AFPFORK_DATA) && (ad_dfileno( ofork->of_ad ) != -1)) {
+    if ((ofork->of_flags & AFPFORK_DATA) && (ad_dfileno( ofork->of_ad ) != -1)) {
             adflags |= ADFLAGS_DF;
-        }
-        if ( ad_hfileno( ofork->of_ad ) != -1 ) {
-            adflags |= ADFLAGS_HF;
-            /*
-             * Only set the rfork's length if we're closing the rfork.
-             */
-            if ((ofork->of_flags & AFPFORK_RSRC)) {
-                ad_refresh( ofork->of_ad );
-                if ((ofork->of_flags & AFPFORK_DIRTY) && !gettimeofday(&tv, NULL)) {
-                    ad_setdate(ofork->of_ad, AD_DATE_MODIFY | AD_DATE_UNIX,tv.tv_sec);
-                   doflush++;
-                }
-                if ( doflush ) {
-                    ad_flush( ofork->of_ad, adflags );
-                }
+    }
+    if ( (ofork->of_flags & AFPFORK_OPEN) && ad_hfileno( ofork->of_ad ) != -1 ) {
+        adflags |= ADFLAGS_HF;
+        /*
+         * Only set the rfork's length if we're closing the rfork.
+         */
+        if ((ofork->of_flags & AFPFORK_RSRC)) {
+            ad_refresh( ofork->of_ad );
+            if ((ofork->of_flags & AFPFORK_DIRTY) && !gettimeofday(&tv, NULL)) {
+                ad_setdate(ofork->of_ad, AD_DATE_MODIFY | AD_DATE_UNIX,tv.tv_sec);
+               doflush++;
+            }
+            if ( doflush ) {
+                 ad_flush( ofork->of_ad, adflags );
             }
         }
+    }
 
-        if ( ad_close( ofork->of_ad, adflags ) < 0 ) {
-            LOG(log_error, logtype_afpd, "afp_closefork: ad_close: %s", strerror(errno) );
-            return( AFPERR_PARAM );
-        }
+    if ( ad_close( ofork->of_ad, adflags ) < 0 ) {
+        LOG(log_error, logtype_afpd, "afp_closefork: ad_close: %s", strerror(errno) );
+        return( AFPERR_PARAM );
     }
 
     of_dealloc( ofork );
index 1cf68a840c49b1d763dc1dd1b8519dc662a0bd54..23f5fd485d57593276bbb677dff6b40d3c9be07a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: adouble.h,v 1.19 2003-01-31 17:38:02 didg Exp $
+ * $Id: adouble.h,v 1.20 2003-02-16 12:35:05 didg Exp $
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
  *
@@ -248,6 +248,7 @@ struct adouble {
 #define ADFLAGS_DIR      (1<<2)
 #define ADFLAGS_NOADOUBLE (1<<3)
 #define ADFLAGS_V1COMPAT  (1<<4)
+#define ADFLAGS_NOHF      (1<<5)  /* not an error if no ressource fork */
 
 /* lock flags */
 #define ADLOCK_CLR      (0)
@@ -331,6 +332,7 @@ extern int ad_fcntl_tmplock __P((struct adouble *, const u_int32_t /*eid*/,
                                 const int /*type*/, const off_t /*offset*/,
                                 const off_t /*len*/, const int /*user*/));
 
+extern int ad_testlock      __P((struct adouble * /*adp*/, int /*eid*/, off_t /*off*/));
 extern int ad_excl_lock     __P((struct adouble * /*adp*/, const u_int32_t /*eid*/));
 
 #define ad_lock ad_fcntl_lock
index 1945583d4e692334f70690ceb7cfd0b80c2e9fda..57aa1c7de5979a3bb36c502aceca45ccc19f2a25 100644 (file)
@@ -18,7 +18,8 @@
 #define CNID_ERR_PARAM 0x80000001
 #define CNID_ERR_PATH  0x80000002
 #define CNID_ERR_DB    0x80000003
-#define CNID_ERR_MAX   0x80000004
+#define CNID_ERR_CLOSE 0x80000004   /* the db was not open */
+#define CNID_ERR_MAX   0x80000005
 
 typedef u_int32_t cnid_t;
 
@@ -52,4 +53,7 @@ extern cnid_t cnid_nextid __P((void *));
 extern int cnid_mangle_add __P((void *, char *, char *));
 extern char *cnid_mangle_get __P((void *, char *));
 
+extern int cnid_lock   __P((void *));
+extern int cnid_unlock __P((void *));
+
 #endif /* include/atalk/cnid.h */
index ebe202c58212d36b726d04ec78f074107743d160..8222500b0c46135cda15a7eacd22b7aa4ad78340 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * $Id: ad_lock.c,v 1.10 2003-01-31 11:26:36 didg Exp $
+ * $Id: ad_lock.c,v 1.11 2003-02-16 12:35:05 didg Exp $
  *
  * Copyright (c) 1998,1999 Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT for more information.
@@ -55,7 +55,6 @@ static int XLATE_FCNTL_LOCK(int type)
 }
 
 /* ----------------------- */
-
 static int OVERLAP(off_t a, off_t alen, off_t b, off_t blen) 
 {
  return (!alen && a <= b) || 
@@ -63,7 +62,6 @@ static int OVERLAP(off_t a, off_t alen, off_t b, off_t blen)
        ( (a + alen > b) && (b + blen > a) );
 }
 
-
 /* allocation for lock regions. we allocate aggressively and shrink
  * only in large chunks. */
 #define ARRAY_BLOCK_SIZE 10 
@@ -214,7 +212,7 @@ static __inline__  int adf_findxlock(struct ad_fd *ad,
        translate a data fork lock to an offset
 */
 
-static int df2off(int off)
+static off_t df2off(int off)
 {
 int start = off;
        if (off == AD_FILELOCK_OPEN_WR)
@@ -234,7 +232,7 @@ int start = off;
        translate a resource fork lock to an offset
 */
 
-static int hf2off(int off)
+static off_t hf2off(int off)
 {
 int start = off;
        if (off == AD_FILELOCK_OPEN_WR)
@@ -256,7 +254,8 @@ int ad_fcntl_lock(struct adouble *ad, const u_int32_t eid, const int locktype,
 {
   struct flock lock;
   struct ad_fd *adf;
-  adf_lock_t *adflock, *oldlock;
+  adf_lock_t *adflock;
+  int oldlock;
   int i;
   int type;  
 
@@ -340,10 +339,9 @@ int ad_fcntl_lock(struct adouble *ad, const u_int32_t eid, const int locktype,
   } 
 
   /* it wasn't an upgrade */
-  oldlock = NULL;
-  if ((lock.l_type == F_RDLCK) &&
-      ((i = adf_findxlock(adf, user, ADLOCK_RD, lock.l_start, lock.l_len)) > -1)) {
-    oldlock = adf->adf_lock + i;
+  oldlock = -1;
+  if (lock.l_type == F_RDLCK) {
+    oldlock = adf_findxlock(adf, user, ADLOCK_RD, lock.l_start, lock.l_len);
   } 
     
   /* no more space. this will also happen if lockmax == lockcount == 0 */
@@ -361,9 +359,9 @@ int ad_fcntl_lock(struct adouble *ad, const u_int32_t eid, const int locktype,
   /* fill in fields */
   memcpy(&adflock->lock, &lock, sizeof(lock));
   adflock->user = user;
-  if (oldlock)
-    adflock->refcount = oldlock->refcount;
-  else if ((adflock->refcount = calloc(1, sizeof(int))) == NULL) {
+  if (oldlock > -1) {
+    adflock->refcount = (adf->adf_lock + oldlock)->refcount;
+  else if ((adflock->refcount = calloc(1, sizeof(int))) == NULL) {
     goto fcntl_lock_err;
   }
   
index 5efa922a455614e02dcd6ffb035022ceac1bd1fa..28b072e3b10d542d44e5bbf2e2d9c66e9a359c54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ad_open.c,v 1.26 2003-01-24 06:58:25 didg Exp $
+ * $Id: ad_open.c,v 1.27 2003-02-16 12:35:05 didg Exp $
  *
  * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
@@ -646,6 +646,18 @@ struct stat stbuf;
     return ret;    
 }
 
+/* ----------------- */
+static int ad_error(struct adouble *ad, int adflags)
+{
+    if ((adflags & ADFLAGS_NOHF)) {
+        /* FIXME double check : set header offset ?*/
+        return 0;
+    }
+    if ((adflags & ADFLAGS_DF)) {
+       ad_close( ad, ADFLAGS_DF );
+    }
+    return -1 ;
+}
 
 static int new_rfork(const char *path, struct adouble *ad, int adflags);
 
@@ -769,14 +781,12 @@ int ad_open( path, adflags, oflags, mode, ad )
                 */
                if (errno == ENOENT && (adflags & ADFLAGS_NOADOUBLE) == 0) {
                    if (NULL == ( slash = strrchr( ad_p, '/' )) ) {
-                       ad_close( ad, open_df );
-                       return( -1 );
+                       return ad_error(ad, adflags);
                    }
                    *slash = '\0';
                    errno = 0;
                    if ( ad_mkdir( ad_p, 0777 ) < 0 ) {
-                       ad_close( ad, adflags );
-                       return( -1 );
+                       return ad_error(ad, adflags);
                    }
                    *slash = '/';
                    admode = mode;
@@ -784,12 +794,10 @@ int ad_open( path, adflags, oflags, mode, ad )
                    admode = ad_hf_mode(admode); 
                    ad->ad_hf.adf_fd = open( ad_p, oflags, admode);
                    if ( ad->ad_hf.adf_fd < 0 ) {
-                       ad_close( ad, open_df );
-                       return( -1 );
+                       return ad_error(ad, adflags);
                    }
                } else {
-                 ad_close( ad, open_df );
-                 return( -1 );
+                    return ad_error(ad, adflags);
                }
            }
            ad->ad_hf.adf_flags = oflags;
@@ -797,9 +805,9 @@ int ad_open( path, adflags, oflags, mode, ad )
            if (!st_invalid) {
                ad_chown(path, &st);
            }
-         } else {
-           ad_close( ad, open_df );
-           return( -1 );
+       }
+       else {
+           return ad_error(ad, adflags);
        }
     } else if (fstat(ad->ad_hf.adf_fd, &st) == 0 && st.st_size == 0) {
        /* for 0 length files, treat them as new. */
@@ -817,6 +825,7 @@ int ad_open( path, adflags, oflags, mode, ad )
          * instead of reading it.
         */
         if (new_rfork(path, ad, adflags) < 0) {
+            /* the file is already deleted, perm, whatever, so return an error*/
             ad_close(ad, adflags);
            return -1;
        }