]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/ofork.c
Merge branch-2-1
[netatalk.git] / etc / afpd / ofork.c
index 687809e3e5ad7262c5d615d519adcead56dc2be2..a6359ad29329373e5db2fdb7b673cfbf3fee6241 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ofork.c,v 1.30.4.4 2010-02-09 14:56:30 franklahm Exp $
+ * $Id: ofork.c,v 1.32 2010/03/12 15:16:49 franklahm Exp $
  *
  * Copyright (c) 1996 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -103,11 +103,10 @@ int of_flush(const struct vol *vol)
     return( 0 );
 }
 
-int of_rename(
-    const struct vol *vol,
-    struct ofork *s_of,
-    struct dir *olddir, const char *oldpath _U_,
-    struct dir *newdir, const char *newpath)
+int of_rename(const struct vol *vol,
+              struct ofork *s_of,
+              struct dir *olddir, const char *oldpath _U_,
+              struct dir *newdir, const char *newpath)
 {
     struct ofork *of, *next, *d_ofork;
     int done = 0;
@@ -288,15 +287,33 @@ int of_stat(struct path *path)
 
     path->st_errno = 0;
     path->st_valid = 1;
-    if ((ret = stat(path->u_name, &path->st)) < 0) {
-        LOG(log_debug, logtype_afpd, "of_stat: {'%s/%s': %s}",
+
+    if ((ret = lstat(path->u_name, &path->st)) < 0) {
+        LOG(log_debug, logtype_afpd, "of_stat('%s/%s': %s)",
             cfrombstring(curdir->d_fullpath), path->u_name, strerror(errno));
-        path->st_errno = errno;
+       path->st_errno = errno;
     }
+
     return ret;
 }
 
-/* --------------------------
+
+#ifdef HAVE_RENAMEAT
+int of_fstatat(int dirfd, struct path *path)
+{
+    int ret;
+
+    path->st_errno = 0;
+    path->st_valid = 1;
+
+    if ((ret = fstatat(dirfd, path->u_name, &path->st, AT_SYMLINK_NOFOLLOW)) < 0)
+       path->st_errno = errno;
+
+   return ret;
+}
+#endif /* HAVE_RENAMEAT */
+
+/* -------------------------- 
    stat the current directory.
    stat(".") works even if "." is deleted thus
    we have to stat ../name because we want to know if it's there
@@ -322,18 +339,19 @@ int of_statdir(struct vol *vol, struct path *path)
 
     LOG(log_debug, logtype_afpd, "of_statdir: stating: '%s'", pathname);
 
-    if (!(ret = stat(pathname, &path->st)))
+    if (!(ret = lstat(pathname, &path->st)))
         return 0;
 
     path->st_errno = errno;
 
     /* hmm, can't stat curdir anymore */
     if (errno == EACCES && (dir = dirlookup(vol, curdir->d_pdid))) {
-        if (movecwd(vol, dir))
-            return -1;
-        path->st_errno = 0;
-        if ((ret = stat(cfrombstring(path->d_dir->d_u_name), &path->st)) < 0)
-            path->st_errno = errno;
+       if (movecwd(vol, dir)) 
+           return -1;
+       path->st_errno = 0;
+
+       if ((ret = lstat(cfrombstring(path->d_dir->d_u_name), &path->st)) < 0) 
+           path->st_errno = errno;
     }
 
     return ret;
@@ -364,6 +382,41 @@ struct ofork *of_findname(struct path *path)
     return NULL;
 }
 
+/*!
+ * @brief Search for open fork by dirfd/name
+ *
+ * Function call of_fstatat with dirfd and path and uses dev and ino
+ * to search the open fork table.
+ *
+ * @param dirfd     (r) directory fd
+ * @param path      (rw) pointer to struct path
+ */
+#ifdef HAVE_RENAMEAT
+struct ofork *of_findnameat(int dirfd, struct path *path)
+{
+    struct ofork *of;
+    struct file_key key;
+    
+    if ( ! path->st_valid) {
+        of_fstatat(dirfd, path);
+    }
+       
+    if (path->st_errno)
+        return NULL;
+
+    key.dev = path->st.st_dev;
+    key.inode = path->st.st_ino;
+
+    for (of = ofork_table[hashfn(&key)]; of; of = of->next) {
+        if (key.dev == of->key.dev && key.inode == of->key.inode ) {
+            return of;
+        }
+    }
+
+    return NULL;
+}
+#endif
+
 void of_dealloc( struct ofork *of)
 {
     if (!oforks)