]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/ofork.c
Convert afp_moveandrename and all called funcs to XXXat semantics if available
[netatalk.git] / etc / afpd / ofork.c
index 9bb6966770effcd6f627ff91746e7990d3f96224..49c014ccef9befec7be7f15068e5c7039e757139 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ofork.c,v 1.30 2009-11-13 00:27:36 didg 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.
@@ -101,11 +101,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;
@@ -285,11 +284,26 @@ int of_stat  (struct path *path)
 int ret;
     path->st_errno = 0;
     path->st_valid = 1;
-    if ((ret = stat(path->u_name, &path->st)) < 0)
+    if ((ret = lstat(path->u_name, &path->st)) < 0)
        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
@@ -309,7 +323,7 @@ int ret;
     /* FIXME, what about: we don't have r-x perm anymore ? */
     strlcpy(pathname +3, path->d_dir->d_u_name, sizeof (pathname) -3);
 
-    if (!(ret = stat(pathname, &path->st)))
+    if (!(ret = lstat(pathname, &path->st)))
         return 0;
         
     path->st_errno = errno;
@@ -318,15 +332,14 @@ int ret;
        if (movecwd(vol, curdir->d_parent)) 
            return -1;
        path->st_errno = 0;
-       if ((ret = stat(path->d_dir->d_u_name, &path->st)) < 0) 
+       if ((ret = lstat(path->d_dir->d_u_name, &path->st)) < 0) 
            path->st_errno = errno;
     }
     return ret;
 }
 
 /* -------------------------- */
-struct ofork *
-            of_findname(struct path *path)
+struct ofork *of_findname(struct path *path)
 {
     struct ofork *of;
     struct file_key key;
@@ -350,6 +363,41 @@ struct ofork *
     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)