Remove confusing and incorrect comment inherited from patchkit days.
[unix-history] / sys / kern / kern_descrip.c
index de89694..de80981 100644 (file)
@@ -30,9 +30,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     @(#)kern_descrip.c      7.28 (Berkeley) 6/25/91
+ *     from: @(#)kern_descrip.c        7.28 (Berkeley) 6/25/91
+ *     $Id: kern_descrip.c,v 1.5 1993/11/25 01:32:54 wollman Exp $
  */
  */
-static char rcsid[] = "$Header: /usr/bill/working/sys/kern/RCS/kern_descrip.c,v 1.2 92/01/21 21:29:09 william Exp $";
 
 #include "param.h"
 #include "systm.h"
 
 #include "param.h"
 #include "systm.h"
@@ -50,16 +50,20 @@ static char rcsid[] = "$Header: /usr/bill/working/sys/kern/RCS/kern_descrip.c,v
 #include "syslog.h"
 #include "resourcevar.h"
 
 #include "syslog.h"
 #include "resourcevar.h"
 
+#include "vm/vm_user.h"
+
 /*
  * Descriptor management.
  */
 struct file *filehead; /* head of list of open files */
 int nfiles;            /* actual number of open files */
 /*
  * Descriptor management.
  */
 struct file *filehead; /* head of list of open files */
 int nfiles;            /* actual number of open files */
+extern int maxfdescs;  /* maximum number of file descriptors to a process */
 
 /*
  * System calls on descriptors.
  */
 /* ARGSUSED */
 
 /*
  * System calls on descriptors.
  */
 /* ARGSUSED */
+int
 getdtablesize(p, uap, retval)
        struct proc *p;
        struct args *uap;
 getdtablesize(p, uap, retval)
        struct proc *p;
        struct args *uap;
@@ -73,12 +77,16 @@ getdtablesize(p, uap, retval)
 /*
  * Duplicate a file descriptor.
  */
 /*
  * Duplicate a file descriptor.
  */
+
+struct dup_args {
+       int     i;
+};
+
 /* ARGSUSED */
 /* ARGSUSED */
+int
 dup(p, uap, retval)
        struct proc *p;
 dup(p, uap, retval)
        struct proc *p;
-       struct args {
-               int     i;
-       } *uap;
+       struct dup_args *uap;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
@@ -107,13 +115,17 @@ dup(p, uap, retval)
 /*
  * Duplicate a file descriptor to a particular value.
  */
 /*
  * Duplicate a file descriptor to a particular value.
  */
+
+struct dup2_args {
+       u_int   from;
+       u_int   to;
+};
+
 /* ARGSUSED */
 /* ARGSUSED */
+int
 dup2(p, uap, retval)
        struct proc *p;
 dup2(p, uap, retval)
        struct proc *p;
-       struct args {
-               u_int   from;
-               u_int   to;
-       } *uap;
+       struct dup2_args *uap;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
@@ -123,7 +135,8 @@ dup2(p, uap, retval)
 
        if (old >= fdp->fd_nfiles ||
            (fp = fdp->fd_ofiles[old]) == NULL ||
 
        if (old >= fdp->fd_nfiles ||
            (fp = fdp->fd_ofiles[old]) == NULL ||
-           new >= p->p_rlimit[RLIMIT_OFILE].rlim_cur)
+           new >= p->p_rlimit[RLIMIT_OFILE].rlim_cur ||
+           new >= maxfdescs)
                return (EBADF);
        *retval = new;
        if (old == new)
                return (EBADF);
        *retval = new;
        if (old == new)
@@ -152,14 +165,18 @@ dup2(p, uap, retval)
 /*
  * The file control system call.
  */
 /*
  * The file control system call.
  */
+
+struct fcntl_args {
+       int     fd;
+       int     cmd;
+       int     arg;
+};
+
 /* ARGSUSED */
 /* ARGSUSED */
+int
 fcntl(p, uap, retval)
        struct proc *p;
 fcntl(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     fd;
-               int     cmd;
-               int     arg;
-       } *uap;
+       register struct fcntl_args *uap;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
@@ -175,7 +192,8 @@ fcntl(p, uap, retval)
        pop = &fdp->fd_ofileflags[uap->fd];
        switch(uap->cmd) {
        case F_DUPFD:
        pop = &fdp->fd_ofileflags[uap->fd];
        switch(uap->cmd) {
        case F_DUPFD:
-               if ((unsigned)uap->arg >= p->p_rlimit[RLIMIT_OFILE].rlim_cur)
+               if ((unsigned)uap->arg >= p->p_rlimit[RLIMIT_OFILE].rlim_cur ||
+                   ((unsigned)uap->arg >= maxfdescs))
                        return (EINVAL);
                if (error = fdalloc(p, uap->arg, &i))
                        return (error);
                        return (EINVAL);
                if (error = fdalloc(p, uap->arg, &i))
                        return (error);
@@ -301,11 +319,14 @@ fcntl(p, uap, retval)
  * Close a file descriptor.
  */
 /* ARGSUSED */
  * Close a file descriptor.
  */
 /* ARGSUSED */
+struct close_args {
+       int     fd;
+};
+
+int
 close(p, uap, retval)
        struct proc *p;
 close(p, uap, retval)
        struct proc *p;
-       struct args {
-               int     fd;
-       } *uap;
+       struct close_args *uap;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
@@ -331,13 +352,17 @@ close(p, uap, retval)
 /*
  * Return status information about a file descriptor.
  */
 /*
  * Return status information about a file descriptor.
  */
+
+struct fstat_args {
+       int     fd;
+       struct  stat *sb;
+};
+
 /* ARGSUSED */
 /* ARGSUSED */
+int
 fstat(p, uap, retval)
        struct proc *p;
 fstat(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     fd;
-               struct  stat *sb;
-       } *uap;
+       register struct fstat_args *uap;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
@@ -372,6 +397,7 @@ fstat(p, uap, retval)
  */
 int fdexpand;
 
  */
 int fdexpand;
 
+int
 fdalloc(p, want, result)
        struct proc *p;
        int want;
 fdalloc(p, want, result)
        struct proc *p;
        int want;
@@ -440,6 +466,7 @@ fdalloc(p, want, result)
  * Check to see whether n user file descriptors
  * are available to the process p.
  */
  * Check to see whether n user file descriptors
  * are available to the process p.
  */
+int
 fdavail(p, n)
        struct proc *p;
        register int n;
 fdavail(p, n)
        struct proc *p;
        register int n;
@@ -462,6 +489,7 @@ fdavail(p, n)
  * Create a new open file structure and allocate
  * a file decriptor for the process that refers to it.
  */
  * Create a new open file structure and allocate
  * a file decriptor for the process that refers to it.
  */
+int
 falloc(p, resultfp, resultfd)
        register struct proc *p;
        struct file **resultfp;
 falloc(p, resultfp, resultfd)
        register struct proc *p;
        struct file **resultfp;
@@ -509,6 +537,7 @@ falloc(p, resultfp, resultfd)
 /*
  * Free a file descriptor.
  */
 /*
  * Free a file descriptor.
  */
+void
 ffree(fp)
        register struct file *fp;
 {
 ffree(fp)
        register struct file *fp;
 {
@@ -642,6 +671,7 @@ fdcloseexec(p)
  * Internal form of close.
  * Decrement reference count on file structure.
  */
  * Internal form of close.
  * Decrement reference count on file structure.
  */
+int
 closef(fp, p)
        register struct file *fp;
        register struct proc *p;
 closef(fp, p)
        register struct file *fp;
        register struct proc *p;
@@ -690,13 +720,16 @@ closef(fp, p)
  * the entire file (l_whence = SEEK_SET, l_start = 0, l_len = 0).
  */
 
  * the entire file (l_whence = SEEK_SET, l_start = 0, l_len = 0).
  */
 
+struct flock_args {
+       int     fd;
+       int     how;
+};
+
 /* ARGSUSED */
 /* ARGSUSED */
+int
 flock(p, uap, retval)
        struct proc *p;
 flock(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     fd;
-               int     how;
-       } *uap;
+       register struct flock_args *uap;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
@@ -740,6 +773,7 @@ flock(p, uap, retval)
  * references to this file will be direct to the other driver.
  */
 /* ARGSUSED */
  * references to this file will be direct to the other driver.
  */
 /* ARGSUSED */
+int
 fdopen(dev, mode, type)
        dev_t dev;
        int mode, type;
 fdopen(dev, mode, type)
        dev_t dev;
        int mode, type;
@@ -760,6 +794,7 @@ fdopen(dev, mode, type)
 /*
  * Duplicate the specified descriptor to a free descriptor.
  */
 /*
  * Duplicate the specified descriptor to a free descriptor.
  */
+int
 dupfdopen(fdp, indx, dfd, mode)
        register struct filedesc *fdp;
        register int indx, dfd;
 dupfdopen(fdp, indx, dfd, mode)
        register struct filedesc *fdp;
        register int indx, dfd;