include ../h/mx.h for lint's sake
[unix-history] / usr / src / sys / kern / vfs_vnops.c
index be70be5..c30e1ef 100644 (file)
@@ -1,4 +1,4 @@
-/*     vfs_vnops.c     3.1     %H%     */
+/*     vfs_vnops.c     4.1     %G%     */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -93,7 +93,8 @@ register struct file *fp;
                goto call;
 
        for(fp=file; fp < &file[NFILE]; fp++)
                goto call;
 
        for(fp=file; fp < &file[NFILE]; fp++)
-               if (fp->f_count && fp->f_inode==ip)
+               if (fp->f_count && (ip=fp->f_inode)->i_un.i_rdev==dev &&
+                   (ip->i_mode&IFMT) == (mode&IFMT))
                        return;
 
 call:
                        return;
 
 call:
@@ -235,6 +236,7 @@ ufalloc()
        return(-1);
 }
 
        return(-1);
 }
 
+struct file *lastf = &file[0];
 /*
  * Allocate a user file descriptor
  * and a file structure.
 /*
  * Allocate a user file descriptor
  * and a file structure.
@@ -253,14 +255,19 @@ falloc()
        i = ufalloc();
        if(i < 0)
                return(NULL);
        i = ufalloc();
        if(i < 0)
                return(NULL);
-       for(fp = &file[0]; fp < &file[NFILE]; fp++)
-               if(fp->f_count == 0) {
-                       u.u_ofile[i] = fp;
-                       fp->f_count++;
-                       fp->f_un.f_offset = 0;
-                       return(fp);
-               }
+       for(fp = lastf; fp < &file[NFILE]; fp++)
+               if(fp->f_count == 0)
+                       goto slot;
+       for(fp = &file[0]; fp < lastf; fp++)
+               if(fp->f_count == 0)
+                       goto slot;
        printf("no file\n");
        u.u_error = ENFILE;
        return(NULL);
        printf("no file\n");
        u.u_error = ENFILE;
        return(NULL);
+slot:
+       u.u_ofile[i] = fp;
+       fp->f_count++;
+       fp->f_un.f_offset = 0;
+       lastf = fp + 1;
+       return(fp);
 }
 }