]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_descrip.c
xnu-201.19.tar.gz
[apple/xnu.git] / bsd / kern / kern_descrip.c
index 7ede17b05fefee92e80d9e6d0c8eda8590117759..c592c4140223d59469fd273bfec5f06002ac4112 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
  * SUCH DAMAGE.
  *
  *     @(#)kern_descrip.c      8.8 (Berkeley) 2/14/95
- *
- *     History:
- *             CHW     8/5/98    Added F_SETSIZE command to truncate without
- *                                     zero filling space 
- *             CHW     7/6/98    Updated Preallocate command to take a structure
- *                               and return output.
- *             CHW     6/25/98   Fixed a bug in the lock call in fcntl 
- *                               Preallocate command
  */
 
 #include <sys/param.h>
@@ -103,7 +95,6 @@ getdtablesize(p, uap, retval)
        void *uap;
        register_t *retval;
 {
-
        *retval = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfiles);
        return (0);
 }
@@ -115,7 +106,6 @@ ogetdtablesize(p, uap, retval)
        void *uap;
        register_t *retval;
 {
-
        *retval = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, NOFILE);
        return (0);
 }
@@ -200,8 +190,7 @@ dup2(p, uap, retval)
                        _fdrelse(fdp, i);
                        goto closeit;
                }
-       }
-       else {
+       } else {
                struct file **fpp;
                char flags;
 closeit:
@@ -214,7 +203,8 @@ closeit:
                if (*(fpp = &fdp->fd_ofiles[new])) {
                        struct file *fp = *fpp;
 
-                       *fpp = NULL; (void) closef(fp, p);
+                       *fpp = NULL;
+                       (void) closef(fp, p);
                }
        }
        return (finishdup(fdp, old, new, retval));
@@ -972,9 +962,9 @@ ffree(fp)
                fp->f_cred = NOCRED;
                crfree(cred);
        }
-#if 1 || DIAGNOSTIC
+
        fp->f_count = 0;
-#endif
+
        nfiles--;
        FREE_ZONE(fp, sizeof *fp, M_FILE);
 }
@@ -1062,8 +1052,7 @@ fdcopy(p)
                                *fpp = NULL;
                                *flags = 0;
                        }
-       }
-       else
+       } else
                (void) memset(newfdp->fd_ofiles, 0, i * OFILESIZE);
 
        return (newfdp);
@@ -1076,9 +1065,10 @@ void
 fdfree(p)
        struct proc *p;
 {
-       register struct filedesc *fdp;
-       register struct file **fpp;
-       register int i;
+       struct filedesc *fdp;
+       struct file **fpp;
+       int i;
+       struct vnode *tvp;
 
        if ((fdp = p->p_fd) == NULL)
                return;
@@ -1093,9 +1083,14 @@ fdfree(p)
                FREE_ZONE(fdp->fd_ofiles,
                                fdp->fd_nfiles * OFILESIZE, M_OFILETABL);
        }
-       vrele(fdp->fd_cdir);
-       if (fdp->fd_rdir)
-               vrele(fdp->fd_rdir);
+       tvp = fdp->fd_cdir;
+       fdp->fd_cdir = NULL;
+       vrele(tvp);
+       if (fdp->fd_rdir) {
+               tvp = fdp->fd_rdir;
+               fdp->fd_rdir = NULL;
+               vrele(tvp);
+       }
        FREE_ZONE(fdp, sizeof *fdp, M_FILEDESC);
 }