$OpenBSD: patch-etc_afpd_ofork_c,v 1.1 2002/07/26 15:12:17 naddy Exp $
--- etc/afpd/ofork.c.orig	Fri Feb  8 10:57:27 2002
+++ etc/afpd/ofork.c	Wed Jul 24 15:22:42 2002
@@ -112,9 +112,13 @@ const char *oldpath, *newpath;
                 (strcmp(of->of_name, oldpath) == 0)) {
             of_unhash(of);
             strncpy( of->of_name, newpath, of->of_namelen);
-            of->of_d_prev->of_d_next = of->of_d_prev;
-            of->of_d_next->of_d_prev = of->of_d_next;
+            of->of_d_prev->of_d_next = of->of_d_next;
+            of->of_d_next->of_d_prev = of->of_d_prev;
             of->of_dir = newdir;
+		if (of->of_dir->d_ofork == of) {
+			of->of_dir->d_ofork = (of==of->of_d_next)?
+			NULL : of->of_d_next;
+			}
             if (!(d_ofork = newdir->d_ofork)) {
                 newdir->d_ofork = of;
                 of->of_d_next = of->of_d_prev = of;
@@ -238,7 +242,7 @@ struct adouble      *ad;
     }
     strncpy( of->of_name, path, of->of_namelen = MACFILELEN + 1);
     *ofrefnum = refnum;
-    of->of_refnum = of_refnum;
+    of->of_refnum = refnum;
     of_hash(of);
 
     if (eid == ADEID_DFORK)
@@ -287,7 +291,7 @@ struct ofork	*of;
         of->of_dir->d_ofork = (of == of->of_d_next) ? NULL : of->of_d_next;
     }
 
-    oforks[ of->of_refnum ] = NULL;
+    oforks[ of->of_refnum % nforks ] = NULL;
     free( of->of_name );
 
     /* decrease refcount */
