From: Matthew Dillon Date: Wed, 22 Jun 2005 01:33:34 +0000 (+0000) Subject: File descriptor cleanup stage 2, remove the separate arrays for file X-Git-Tag: v2.0.1~6816 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/0679adc40618cfe16fe86b813133371fdcc0d4b7 File descriptor cleanup stage 2, remove the separate arrays for file pointers, fileflags, and allocation counts and replace the mess with a single structural array. Also revamp the code that checks whether the file descriptor array is built-in or allocated. Note that the removed malloc's were doing something weird, allocating 'nf * OFILESIZE + 1' bytes instead of 'nf * OFILESIZE' bytes. I could not find any reason at all why it was doing that. It's gone now anyway. --- diff --git a/sys/dev/misc/streams/streams.c b/sys/dev/misc/streams/streams.c index b0a1bb2ab8..c3bf470c4c 100644 --- a/sys/dev/misc/streams/streams.c +++ b/sys/dev/misc/streams/streams.c @@ -31,7 +31,7 @@ * in 3.0-980524-SNAP then hacked a bit (but probably not enough :-). * * $FreeBSD: src/sys/dev/streams/streams.c,v 1.16.2.1 2001/02/26 04:23:07 jlemon Exp $ - * $DragonFly: src/sys/dev/misc/streams/Attic/streams.c,v 1.15 2005/06/21 23:58:53 hsu Exp $ + * $DragonFly: src/sys/dev/misc/streams/Attic/streams.c,v 1.16 2005/06/22 01:33:24 dillon Exp $ */ #include @@ -242,7 +242,7 @@ streamsopen(dev_t dev, int oflags, int devtype, d_thread_t *td) return error; if ((error = socreate(family, &so, type, protocol, td)) != 0) { - if (p->p_fd->fd_ofiles[fd] == fp) { + if (p->p_fd->fd_files[fd].fp == fp) { funsetfd(p->p_fd, fd); fdrop(fp, td); } diff --git a/sys/emulation/ibcs2/i386/ibcs2_fcntl.c b/sys/emulation/ibcs2/i386/ibcs2_fcntl.c index 89096e3ca8..f9d65dcd7a 100644 --- a/sys/emulation/ibcs2/i386/ibcs2_fcntl.c +++ b/sys/emulation/ibcs2/i386/ibcs2_fcntl.c @@ -25,7 +25,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/ibcs2/ibcs2_fcntl.c,v 1.14 1999/09/19 17:00:14 green Exp $ - * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_fcntl.c,v 1.9 2003/08/27 06:30:03 rob Exp $ + * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_fcntl.c,v 1.10 2005/06/22 01:33:25 dillon Exp $ */ #include "opt_spx_hack.h" @@ -194,7 +194,7 @@ ibcs2_open(struct ibcs2_open_args *uap) #endif /* SPX_HACK */ if (!ret && !noctty && p && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) { struct filedesc *fdp = p->p_fd; - struct file *fp = fdp->fd_ofiles[uap->sysmsg_result]; + struct file *fp = fdp->fd_files[uap->sysmsg_result].fp; /* ignore any error, just give it a try */ if (fp->f_type == DTYPE_VNODE) diff --git a/sys/emulation/ibcs2/i386/ibcs2_ioctl.c b/sys/emulation/ibcs2/i386/ibcs2_ioctl.c index 62376f3952..a9f383530e 100644 --- a/sys/emulation/ibcs2/i386/ibcs2_ioctl.c +++ b/sys/emulation/ibcs2/i386/ibcs2_ioctl.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/ibcs2/ibcs2_ioctl.c,v 1.13.2.1 2001/07/31 20:14:21 jon Exp $ - * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_ioctl.c,v 1.8 2003/10/13 21:08:46 dillon Exp $ + * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_ioctl.c,v 1.9 2005/06/22 01:33:25 dillon Exp $ */ #include @@ -350,7 +350,7 @@ ibcs2_ioctl(struct ibcs2_ioctl_args *uap) fdp = p->p_fd; if (SCARG(uap, fd) < 0 || SCARG(uap, fd) >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) { + (fp = fdp->fd_files[SCARG(uap, fd)].fp) == NULL) { DPRINTF(("ibcs2_ioctl(td=%p): bad fd %d ", td, SCARG(uap, fd))); return EBADF; } diff --git a/sys/emulation/linux/linux_file.c b/sys/emulation/linux/linux_file.c index 1ac9e2da8f..88afd8199a 100644 --- a/sys/emulation/linux/linux_file.c +++ b/sys/emulation/linux/linux_file.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/compat/linux/linux_file.c,v 1.41.2.6 2003/01/06 09:19:43 fjoe Exp $ - * $DragonFly: src/sys/emulation/linux/linux_file.c,v 1.20 2005/04/22 02:09:15 swildner Exp $ + * $DragonFly: src/sys/emulation/linux/linux_file.c,v 1.21 2005/06/22 01:33:27 dillon Exp $ */ #include "opt_compat.h" @@ -141,7 +141,7 @@ linux_open(struct linux_open_args *args) if (error == 0 && !(flags & O_NOCTTY) && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) { struct filedesc *fdp = p->p_fd; - struct file *fp = fdp->fd_ofiles[args->sysmsg_result]; + struct file *fp = fdp->fd_files[args->sysmsg_result].fp; if (fp->f_type == DTYPE_VNODE) fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td); @@ -1040,7 +1040,7 @@ linux_fcntl_common(struct linux_fcntl64_args *args) */ fdp = p->p_fd; if ((u_int)args->fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[args->fd]) == NULL) + (fp = fdp->fd_files[args->fd].fp) == NULL) return (EBADF); if (fp->f_type == DTYPE_PIPE) return (EINVAL); diff --git a/sys/emulation/svr4/svr4_fcntl.c b/sys/emulation/svr4/svr4_fcntl.c index 4ff1640446..43f453a238 100644 --- a/sys/emulation/svr4/svr4_fcntl.c +++ b/sys/emulation/svr4/svr4_fcntl.c @@ -29,7 +29,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/svr4/svr4_fcntl.c,v 1.7 1999/12/12 10:27:04 newton Exp $ - * $DragonFly: src/sys/emulation/svr4/Attic/svr4_fcntl.c,v 1.15 2004/10/12 19:20:42 dillon Exp $ + * $DragonFly: src/sys/emulation/svr4/Attic/svr4_fcntl.c,v 1.16 2005/06/22 01:33:29 dillon Exp $ */ #include #include @@ -255,7 +255,7 @@ fd_revoke(struct thread *td, int fd) KKASSERT(p); fdp = p->p_fd; - if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) + if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_files[fd].fp) == NULL) return EBADF; if (fp->f_type != DTYPE_VNODE) @@ -304,7 +304,7 @@ fd_truncate(struct thread *td, int fd, struct flock *flp, int *retval) /* * We only support truncating the file. */ - if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) + if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_files[fd].fp) == NULL) return EBADF; vp = (struct vnode *)fp->f_data; @@ -375,7 +375,7 @@ svr4_sys_open(struct svr4_sys_open_args *uap) !(p->p_flag & P_CONTROLT)) { #if defined(NOTYET) struct filedesc *fdp = p->p_fd; - struct file *fp = fdp->fd_ofiles[retval]; + struct file *fp = fdp->fd_files[retval].fp; /* ignore any error, just give it a try */ if (fp->f_type == DTYPE_VNODE) diff --git a/sys/emulation/svr4/svr4_filio.c b/sys/emulation/svr4/svr4_filio.c index 5452e192e9..b63297d74e 100644 --- a/sys/emulation/svr4/svr4_filio.c +++ b/sys/emulation/svr4/svr4_filio.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/svr4/svr4_filio.c,v 1.8 2000/01/15 15:30:44 newton Exp $ - * $DragonFly: src/sys/emulation/svr4/Attic/svr4_filio.c,v 1.7 2003/08/07 21:17:19 dillon Exp $ + * $DragonFly: src/sys/emulation/svr4/Attic/svr4_filio.c,v 1.8 2005/06/22 01:33:29 dillon Exp $ */ #include @@ -106,7 +106,7 @@ svr4_sys_read(struct svr4_sys_read_args *uap) SCARG(&ra, buf) = SCARG(uap, buf); SCARG(&ra, nbyte) = SCARG(uap, nbyte); - if ((fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) { + if ((fp = fdp->fd_files[SCARG(uap, fd)].fp) == NULL) { DPRINTF(("Something fishy with the user-supplied file descriptor...\n")); return EBADF; } @@ -192,11 +192,11 @@ svr4_fil_ioctl(fp, td, retval, fd, cmd, data) switch (cmd) { case SVR4_FIOCLEX: - fdp->fd_ofileflags[fd] |= UF_EXCLOSE; + fdp->fd_files[fd].fileflags |= UF_EXCLOSE; return 0; case SVR4_FIONCLEX: - fdp->fd_ofileflags[fd] &= ~UF_EXCLOSE; + fdp->fd_files[fd].fileflags &= ~UF_EXCLOSE; return 0; case SVR4_FIOGETOWN: diff --git a/sys/emulation/svr4/svr4_ioctl.c b/sys/emulation/svr4/svr4_ioctl.c index 7d2d843e15..f8b79b7966 100644 --- a/sys/emulation/svr4/svr4_ioctl.c +++ b/sys/emulation/svr4/svr4_ioctl.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/svr4/svr4_ioctl.c,v 1.6 1999/12/08 12:00:48 newton Exp $ - * $DragonFly: src/sys/emulation/svr4/Attic/svr4_ioctl.c,v 1.11 2003/09/12 00:43:30 daver Exp $ + * $DragonFly: src/sys/emulation/svr4/Attic/svr4_ioctl.c,v 1.12 2005/06/22 01:33:29 dillon Exp $ */ #include @@ -110,7 +110,7 @@ svr4_sys_ioctl(struct svr4_sys_ioctl_args *uap) cmd = SCARG(uap, com); if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) + (fp = fdp->fd_files[SCARG(uap, fd)].fp) == NULL) return EBADF; if ((fp->f_flag & (FREAD | FWRITE)) == 0) diff --git a/sys/emulation/svr4/svr4_stream.c b/sys/emulation/svr4/svr4_stream.c index 174ce33f88..9d3b2fb105 100644 --- a/sys/emulation/svr4/svr4_stream.c +++ b/sys/emulation/svr4/svr4_stream.c @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/svr4/svr4_stream.c,v 1.12.2.2 2000/11/26 04:42:27 dillon Exp $ - * $DragonFly: src/sys/emulation/svr4/Attic/svr4_stream.c,v 1.13 2004/06/02 14:42:57 eirikn Exp $ + * $DragonFly: src/sys/emulation/svr4/Attic/svr4_stream.c,v 1.14 2005/06/22 01:33:29 dillon Exp $ */ /* @@ -1745,7 +1745,7 @@ svr4_sys_putmsg(struct svr4_sys_putmsg_args *uap) KKASSERT(p); fdp = p->p_fd; retval = &uap->sysmsg_result; - fp = fdp->fd_ofiles[SCARG(uap, fd)]; + fp = fdp->fd_files[SCARG(uap, fd)].fp; if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) { #ifdef DEBUG_SVR4 @@ -1942,7 +1942,7 @@ svr4_sys_getmsg(struct svr4_sys_getmsg_args *uap) KKASSERT(p); fdp = p->p_fd; retval = &uap->sysmsg_result; - fp = fdp->fd_ofiles[SCARG(uap, fd)]; + fp = fdp->fd_files[SCARG(uap, fd)].fp; if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) return EBADF; diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 888b6998f5..e4c2231275 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -27,7 +27,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/kern/imgact_elf.c,v 1.73.2.13 2002/12/28 19:49:41 dillon Exp $ - * $DragonFly: src/sys/kern/imgact_elf.c,v 1.29 2005/06/01 20:04:53 joerg Exp $ + * $DragonFly: src/sys/kern/imgact_elf.c,v 1.30 2005/06/22 01:33:21 dillon Exp $ */ #include @@ -1408,7 +1408,7 @@ elf_putfiles(struct proc *p, elf_buf_t target) * ignore STDIN/STDERR/STDOUT. */ for (i = 3; error == 0 && i < p->p_fd->fd_nfiles; i++) { - if ((fp = p->p_fd->fd_ofiles[i]) == NULL) + if ((fp = p->p_fd->fd_files[i].fp) == NULL) continue; /* * XXX Only checkpoint vnodes for now. diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index e4a298defc..89626ada5e 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -40,7 +40,7 @@ * * @(#)init_main.c 8.9 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/init_main.c,v 1.134.2.8 2003/06/06 20:21:32 tegge Exp $ - * $DragonFly: src/sys/kern/init_main.c,v 1.43 2005/06/21 23:58:53 hsu Exp $ + * $DragonFly: src/sys/kern/init_main.c,v 1.44 2005/06/22 01:33:21 dillon Exp $ */ #include "opt_init_path.h" @@ -81,7 +81,7 @@ void mi_startup(void); /* Should be elsewhere */ static struct session session0; static struct pgrp pgrp0; static struct procsig procsig0; -static struct filedesc0 filedesc0; +static struct filedesc filedesc0; static struct plimit limit0; static struct vmspace vmspace0; struct proc *initproc; @@ -272,8 +272,8 @@ SYSINIT(leavecrit, SI_SUB_LEAVE_CRIT, SI_ORDER_ANY, leavecrit, NULL) static void proc0_init(void *dummy __unused) { - struct proc *p; - struct filedesc0 *fdp; + struct filedesc *fdp; + struct proc *p; unsigned i; p = &proc0; @@ -338,14 +338,12 @@ proc0_init(void *dummy __unused) /* Create the file descriptor table. */ fdp = &filedesc0; - p->p_fd = &fdp->fd_fd; + p->p_fd = fdp; p->p_fdtol = NULL; - fdp->fd_fd.fd_refcnt = 1; - fdp->fd_fd.fd_cmask = cmask; - fdp->fd_fd.fd_ofiles = fdp->fd_dfiles; - fdp->fd_fd.fd_ofileflags = fdp->fd_dfileflags; - fdp->fd_fd.fd_oallocated = fdp->fd_dallocated; - fdp->fd_fd.fd_nfiles = NDFILE; + fdp->fd_refcnt = 1; + fdp->fd_cmask = cmask; + fdp->fd_files = fdp->fd_builtin_files; + fdp->fd_nfiles = NDFILE; /* Create the limits structures. */ p->p_limit = &limit0; diff --git a/sys/kern/kern_checkpoint.c b/sys/kern/kern_checkpoint.c index 1feb33304b..ba18a1de10 100644 --- a/sys/kern/kern_checkpoint.c +++ b/sys/kern/kern_checkpoint.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_checkpoint.c,v 1.2 2005/02/26 20:32:36 dillon Exp $ + * $DragonFly: src/sys/kern/kern_checkpoint.c,v 1.3 2005/06/22 01:33:21 dillon Exp $ */ #include @@ -637,7 +637,7 @@ elf_getfiles(struct proc *p, struct file *fp) * have not already closed. */ if (cfi->cfi_index < p->p_fd->fd_nfiles && - (ofp = p->p_fd->fd_ofiles[cfi->cfi_index]) != NULL) { + (ofp = p->p_fd->fd_files[cfi->cfi_index].fp) != NULL) { kern_close(cfi->cfi_index); } @@ -651,7 +651,7 @@ elf_getfiles(struct proc *p, struct file *fp) goto done; } KKASSERT(fd == cfi->cfi_index); - p->p_fd->fd_ofiles[cfi->cfi_index] = tempfp; + p->p_fd->fd_files[cfi->cfi_index].fp = tempfp; cfi++; PRINTF(("restoring %d\n", cfi->cfi_index)); } diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 688170e1cc..f1156516f0 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -37,7 +37,7 @@ * * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 * $FreeBSD: src/sys/kern/kern_descrip.c,v 1.81.2.19 2004/02/28 00:43:31 tegge Exp $ - * $DragonFly: src/sys/kern/kern_descrip.c,v 1.43 2005/06/21 23:58:53 hsu Exp $ + * $DragonFly: src/sys/kern/kern_descrip.c,v 1.44 2005/06/22 01:33:21 dillon Exp $ */ #include "opt_compat.h" @@ -175,9 +175,9 @@ kern_fcntl(int fd, int cmd, union fcntl_dat *dat) KKASSERT(p); if ((unsigned)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL) + (fp = fdp->fd_files[fd].fp) == NULL) return (EBADF); - pop = &fdp->fd_ofileflags[fd]; + pop = &fdp->fd_files[fd].fileflags; switch (cmd) { case F_DUPFD: @@ -280,7 +280,7 @@ kern_fcntl(int fd, int cmd, union fcntl_dat *dat) } /* Check for race with close */ if ((unsigned) fd >= fdp->fd_nfiles || - fp != fdp->fd_ofiles[fd]) { + fp != fdp->fd_files[fd].fp) { dat->fc_flock.l_whence = SEEK_SET; dat->fc_flock.l_start = 0; dat->fc_flock.l_len = 0; @@ -401,13 +401,13 @@ kern_dup(enum dup_type type, int old, int new, int *res) if (old < 0 || new < 0 || new > p->p_rlimit[RLIMIT_NOFILE].rlim_cur || new >= maxfilesperproc) return (EBADF); - if (old >= fdp->fd_nfiles || fdp->fd_ofiles[old] == NULL) + if (old >= fdp->fd_nfiles || fdp->fd_files[old].fp == NULL) return (EBADF); if (type == DUP_FIXED && old == new) { *res = new; return (0); } - fp = fdp->fd_ofiles[old]; + fp = fdp->fd_files[old].fp; fhold(fp); /* @@ -430,14 +430,14 @@ kern_dup(enum dup_type type, int old, int new, int *res) * bad file descriptor. Userland should do its own locking to * avoid this case. */ - if (fdp->fd_ofiles[old] != fp) { - if (fdp->fd_ofiles[new] == NULL) { + if (fdp->fd_files[old].fp != fp) { + if (fdp->fd_files[new].fp == NULL) { if (fdalloced) fdreserve(fdp, newfd, -1); if (new < fdp->fd_freefile) fdp->fd_freefile = new; while (fdp->fd_lastfile > 0 && - fdp->fd_ofiles[fdp->fd_lastfile] == NULL) + fdp->fd_files[fdp->fd_lastfile].fp == NULL) fdp->fd_lastfile--; } fdrop(fp, td); @@ -450,7 +450,7 @@ kern_dup(enum dup_type type, int old, int new, int *res) * to do the unmap now, but we cannot close it without * introducing an ownership race for the slot. */ - delfp = fdp->fd_ofiles[new]; + delfp = fdp->fd_files[new].fp; if (delfp != NULL && p->p_fdtol != NULL) { /* * Ask fdfree() to sleep to ensure that all relevant @@ -463,7 +463,7 @@ kern_dup(enum dup_type type, int old, int new, int *res) KASSERT(delfp == NULL || type == DUP_FIXED, ("dup() picked an open file")); #if 0 - if (delfp && (fdp->fd_ofileflags[new] & UF_MAPPED)) + if (delfp && (fdp->fd_files[new].fileflags & UF_MAPPED)) (void) munmapfd(p, new); #endif @@ -472,10 +472,11 @@ kern_dup(enum dup_type type, int old, int new, int *res) */ if (new > fdp->fd_lastfile) fdp->fd_lastfile = new; - if (!fdalloced && fdp->fd_ofiles[new] == NULL) + if (!fdalloced && fdp->fd_files[new].fp == NULL) fdreserve(fdp, new, 1); - fdp->fd_ofiles[new] = fp; - fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] &~ UF_EXCLOSE; + fdp->fd_files[new].fp = fp; + fdp->fd_files[new].fileflags = + fdp->fd_files[old].fileflags & ~UF_EXCLOSE; *res = new; /* @@ -669,10 +670,10 @@ kern_close(int fd) fdp = p->p_fd; if ((unsigned)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL) + (fp = fdp->fd_files[fd].fp) == NULL) return (EBADF); #if 0 - if (fdp->fd_ofileflags[fd] & UF_MAPPED) + if (fdp->fd_files[fd].fileflags & UF_MAPPED) (void) munmapfd(p, fd); #endif funsetfd(fdp, fd); @@ -690,7 +691,7 @@ kern_close(int fd) * we now hold the fp reference that used to be owned by the descriptor * array. */ - while (fdp->fd_lastfile > 0 && fdp->fd_ofiles[fdp->fd_lastfile] == NULL) + while (fdp->fd_lastfile > 0 && fdp->fd_files[fdp->fd_lastfile].fp == NULL) fdp->fd_lastfile--; if (fd < fdp->fd_knlistsize) knote_fdclose(p, fd); @@ -719,7 +720,7 @@ kern_fstat(int fd, struct stat *ub) fdp = p->p_fd; if ((unsigned)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL) + (fp = fdp->fd_files[fd].fp) == NULL) return (EBADF); fhold(fp); error = fo_stat(fp, ub, td); @@ -781,7 +782,7 @@ fpathconf(struct fpathconf_args *uap) KKASSERT(p); fdp = p->p_fd; if ((unsigned)uap->fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[uap->fd]) == NULL) + (fp = fdp->fd_files[uap->fd].fp) == NULL) return (EBADF); fhold(fp); @@ -815,9 +816,8 @@ SYSCTL_INT(_debug, OID_AUTO, fdexpand, CTLFLAG_RD, &fdexpand, 0, ""); static void fdgrow(struct filedesc *fdp, int want) { - struct file **newofile; - char *newofileflags; - int *newoallocated; + struct fdnode *newfiles; + struct fdnode *oldfiles; int nf, extra; nf = fdp->fd_nfiles; @@ -826,35 +826,30 @@ fdgrow(struct filedesc *fdp, int want) nf = 2 * nf + 1; } while (nf <= want); - newofile = malloc(nf * OFILESIZE + 1, M_FILEDESC, M_WAITOK); + newfiles = malloc(nf * sizeof(struct fdnode), M_FILEDESC, M_WAITOK); /* * deal with file-table extend race that might have occured * when malloc was blocked. */ if (fdp->fd_nfiles >= nf) { - free(newofile, M_FILEDESC); + free(newfiles, M_FILEDESC); return; } - newofileflags = (char *) &newofile[nf]; - newoallocated = (int *) &newofileflags[nf+1]; /* * Copy the existing ofile and ofileflags arrays * and zero the new portion of each array. */ extra = nf - fdp->fd_nfiles; - bcopy(fdp->fd_ofiles, newofile, fdp->fd_nfiles * sizeof(struct file *)); - bzero(&newofile[fdp->fd_nfiles], extra * sizeof(struct file *)); - bcopy(fdp->fd_ofileflags, newofileflags, fdp->fd_nfiles * sizeof(char)); - bzero(&newofileflags[fdp->fd_nfiles], extra * sizeof(char)); - bcopy(fdp->fd_oallocated, newoallocated, fdp->fd_nfiles * sizeof(int)); - bzero(&newoallocated[fdp->fd_nfiles], extra * sizeof(int)); - if (fdp->fd_nfiles > NDFILE) - free(fdp->fd_ofiles, M_FILEDESC); - fdp->fd_ofiles = newofile; - fdp->fd_ofileflags = newofileflags; - fdp->fd_oallocated = newoallocated; + bcopy(fdp->fd_files, newfiles, fdp->fd_nfiles * sizeof(struct fdnode)); + bzero(&newfiles[fdp->fd_nfiles], extra * sizeof(struct fdnode)); + + oldfiles = fdp->fd_files; + fdp->fd_files = newfiles; fdp->fd_nfiles = nf; + + if (oldfiles != fdp->fd_builtin_files) + free(oldfiles, M_FILEDESC); fdexpand++; } @@ -889,8 +884,8 @@ void fdreserve(struct filedesc *fdp, int fd, int incr) { while (fd >= 0) { - fdp->fd_oallocated[fd] += incr; - KKASSERT(fdp->fd_oallocated[fd] >= 0); + fdp->fd_files[fd].allocated += incr; + KKASSERT(fdp->fd_files[fd].allocated >= 0); fd = left_ancestor(fd); } } @@ -919,11 +914,11 @@ retry: /* move up the tree looking for a subtree with a free node */ for (fd = max(want, fdp->fd_freefile); fd < min(fdp->fd_nfiles, lim); fd = right_ancestor(fd)) { - if (fdp->fd_oallocated[fd] == 0) + if (fdp->fd_files[fd].allocated == 0) goto found; rsize = right_subtree_size(fd); - if (fdp->fd_oallocated[fd] == rsize) + if (fdp->fd_files[fd].allocated == rsize) continue; /* right subtree full */ /* @@ -935,10 +930,10 @@ retry: */ for (rsum = 0, rsize /= 2; rsize > 0; rsize /= 2) { node = fd + rsize; - rsum += fdp->fd_oallocated[node]; - if (fdp->fd_oallocated[fd] == rsum + rsize) { + rsum += fdp->fd_files[node].allocated; + if (fdp->fd_files[fd].allocated == rsum + rsize) { fd = node; /* move to the right */ - if (fdp->fd_oallocated[node] == 0) + if (fdp->fd_files[node].allocated == 0) goto found; rsum = 0; } @@ -956,13 +951,13 @@ retry: found: KKASSERT(fd < fdp->fd_nfiles); - fdp->fd_ofileflags[fd] = 0; + fdp->fd_files[fd].fileflags = 0; if (fd > fdp->fd_lastfile) fdp->fd_lastfile = fd; if (want <= fdp->fd_freefile) fdp->fd_freefile = fd; *result = fd; - KKASSERT(fdp->fd_ofiles[fd] == NULL); + KKASSERT(fdp->fd_files[fd].fp == NULL); fdreserve(fdp, fd, 1); return (0); } @@ -975,7 +970,7 @@ int fdavail(struct proc *p, int n) { struct filedesc *fdp = p->p_fd; - struct file **fpp; + struct fdnode *fdnode; int i, lim, last; lim = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfilesperproc); @@ -983,9 +978,9 @@ fdavail(struct proc *p, int n) return (1); last = min(fdp->fd_nfiles, lim); - fpp = &fdp->fd_ofiles[fdp->fd_freefile]; - for (i = last - fdp->fd_freefile; --i >= 0; fpp++) { - if (*fpp == NULL && --n <= 0) + fdnode = &fdp->fd_files[fdp->fd_freefile]; + for (i = last - fdp->fd_freefile; --i >= 0; ++fdnode) { + if (fdnode->fp == NULL && --n <= 0) return (1); } return (0); @@ -1000,7 +995,7 @@ fdavail(struct proc *p, int n) * separately be NULL indicating that you don't need the returned fd. * * A held file pointer is returned. If a descriptor has been allocated - * an additional hold on the fp will be made due to the fd_ofiles[] + * an additional hold on the fp will be made due to the fd_files[] * reference. */ int @@ -1054,7 +1049,7 @@ done: /* * Associate a file pointer with a file descriptor. On success the fp - * will have an additional ref representing the fd_ofiles[] association. + * will have an additional ref representing the fd_files[] association. */ int fsetfd(struct proc *p, struct file *fp, int *resultfd) @@ -1064,7 +1059,7 @@ fsetfd(struct proc *p, struct file *fp, int *resultfd) fd = -1; if ((error = fdalloc(p, 0, &fd)) == 0) { fhold(fp); - p->p_fd->fd_ofiles[fd] = fp; + p->p_fd->fd_files[fd].fp = fp; } *resultfd = fd; return (0); @@ -1073,8 +1068,8 @@ fsetfd(struct proc *p, struct file *fp, int *resultfd) void funsetfd(struct filedesc *fdp, int fd) { - fdp->fd_ofiles[fd] = NULL; - fdp->fd_ofileflags[fd] = 0; + fdp->fd_files[fd].fp = NULL; + fdp->fd_files[fd].fileflags = 0; fdreserve(fdp, fd, -1); if (fd < fdp->fd_freefile) fdp->fd_freefile = fd; @@ -1111,14 +1106,14 @@ ffree(struct file *fp) struct filedesc * fdinit(struct proc *p) { - struct filedesc0 *newfdp; + struct filedesc *newfdp; struct filedesc *fdp = p->p_fd; - newfdp = malloc(sizeof(struct filedesc0), M_FILEDESC, M_WAITOK|M_ZERO); + newfdp = malloc(sizeof(struct filedesc), M_FILEDESC, M_WAITOK|M_ZERO); if (fdp->fd_cdir) { - newfdp->fd_fd.fd_cdir = fdp->fd_cdir; - vref(newfdp->fd_fd.fd_cdir); - newfdp->fd_fd.fd_ncdir = cache_hold(fdp->fd_ncdir); + newfdp->fd_cdir = fdp->fd_cdir; + vref(newfdp->fd_cdir); + newfdp->fd_ncdir = cache_hold(fdp->fd_ncdir); } /* @@ -1126,26 +1121,24 @@ fdinit(struct proc *p) * proc0, but should unconditionally exist in other processes. */ if (fdp->fd_rdir) { - newfdp->fd_fd.fd_rdir = fdp->fd_rdir; - vref(newfdp->fd_fd.fd_rdir); - newfdp->fd_fd.fd_nrdir = cache_hold(fdp->fd_nrdir); + newfdp->fd_rdir = fdp->fd_rdir; + vref(newfdp->fd_rdir); + newfdp->fd_nrdir = cache_hold(fdp->fd_nrdir); } if (fdp->fd_jdir) { - newfdp->fd_fd.fd_jdir = fdp->fd_jdir; - vref(newfdp->fd_fd.fd_jdir); - newfdp->fd_fd.fd_njdir = cache_hold(fdp->fd_njdir); + newfdp->fd_jdir = fdp->fd_jdir; + vref(newfdp->fd_jdir); + newfdp->fd_njdir = cache_hold(fdp->fd_njdir); } /* Create the file descriptor table. */ - newfdp->fd_fd.fd_refcnt = 1; - newfdp->fd_fd.fd_cmask = cmask; - newfdp->fd_fd.fd_ofiles = newfdp->fd_dfiles; - newfdp->fd_fd.fd_ofileflags = newfdp->fd_dfileflags; - newfdp->fd_fd.fd_oallocated = newfdp->fd_dallocated; - newfdp->fd_fd.fd_nfiles = NDFILE; - newfdp->fd_fd.fd_knlistsize = -1; - - return (&newfdp->fd_fd); + newfdp->fd_refcnt = 1; + newfdp->fd_cmask = cmask; + newfdp->fd_files = newfdp->fd_builtin_files; + newfdp->fd_nfiles = NDFILE; + newfdp->fd_knlistsize = -1; + + return (newfdp); } /* @@ -1165,15 +1158,15 @@ struct filedesc * fdcopy(struct proc *p) { struct filedesc *newfdp, *fdp = p->p_fd; - struct file **fpp; + struct fdnode *fdnode; int i; /* Certain daemons might not have file descriptors. */ if (fdp == NULL) return (NULL); - newfdp = malloc(sizeof(struct filedesc0), M_FILEDESC, M_WAITOK); - bcopy(fdp, newfdp, sizeof(struct filedesc)); + newfdp = malloc(sizeof(struct filedesc), M_FILEDESC, M_WAITOK); + *newfdp = *fdp; if (newfdp->fd_cdir) { vref(newfdp->fd_cdir); newfdp->fd_ncdir = cache_hold(newfdp->fd_ncdir); @@ -1200,11 +1193,7 @@ fdcopy(struct proc *p) * in use. */ if (newfdp->fd_lastfile < NDFILE) { - struct filedesc0 *newfdp0 = (struct filedesc0 *)newfdp; - - newfdp->fd_ofiles = newfdp0->fd_dfiles; - newfdp->fd_ofileflags = newfdp0->fd_dfileflags; - newfdp->fd_oallocated = newfdp0->fd_dallocated; + newfdp->fd_files = newfdp->fd_builtin_files; i = NDFILE; } else { /* @@ -1215,25 +1204,27 @@ fdcopy(struct proc *p) i = newfdp->fd_nfiles; while ((i-1)/2 > newfdp->fd_lastfile && (i-1)/2 > NDFILE) i = (i-1)/2; - newfdp->fd_ofiles = malloc(i * OFILESIZE + 1, M_FILEDESC, - M_WAITOK); - newfdp->fd_ofileflags = (char *) &newfdp->fd_ofiles[i]; - newfdp->fd_oallocated = (int *) &newfdp->fd_ofileflags[i+1]; + newfdp->fd_files = malloc(i * sizeof(struct fdnode), + M_FILEDESC, M_WAITOK); } newfdp->fd_nfiles = i; - bcopy(fdp->fd_ofiles, newfdp->fd_ofiles, i * sizeof(struct file **)); - bcopy(fdp->fd_ofileflags, newfdp->fd_ofileflags, i * sizeof(char)); - bcopy(fdp->fd_oallocated, newfdp->fd_oallocated, i * sizeof(int)); + + if (fdp->fd_files != fdp->fd_builtin_files || + newfdp->fd_files != newfdp->fd_builtin_files + ) { + bcopy(fdp->fd_files, newfdp->fd_files, + i * sizeof(struct fdnode)); + } /* * kq descriptors cannot be copied. */ if (newfdp->fd_knlistsize != -1) { - fpp = &newfdp->fd_ofiles[newfdp->fd_lastfile]; - for (i = newfdp->fd_lastfile; i >= 0; i--, fpp--) { - if (*fpp != NULL && (*fpp)->f_type == DTYPE_KQUEUE) + fdnode = &newfdp->fd_files[newfdp->fd_lastfile]; + for (i = newfdp->fd_lastfile; i >= 0; i--, fdnode--) { + if (fdnode->fp != NULL && fdnode->fp->f_type == DTYPE_KQUEUE) funsetfd(newfdp, i); /* nulls out *fpp */ - if (*fpp == NULL && i == newfdp->fd_lastfile && i > 0) + if (fdnode->fp == NULL && i == newfdp->fd_lastfile && i > 0) newfdp->fd_lastfile--; } newfdp->fd_knlist = NULL; @@ -1242,10 +1233,10 @@ fdcopy(struct proc *p) newfdp->fd_knhashmask = 0; } - fpp = newfdp->fd_ofiles; - for (i = newfdp->fd_lastfile; i-- >= 0; fpp++) { - if (*fpp != NULL) - fhold(*fpp); + fdnode = newfdp->fd_files; + for (i = newfdp->fd_lastfile; i-- >= 0; fdnode++) { + if (fdnode->fp != NULL) + fhold(fdnode->fp); } return (newfdp); } @@ -1258,7 +1249,7 @@ fdfree(struct proc *p) { struct thread *td = p->p_thread; struct filedesc *fdp = p->p_fd; - struct file **fpp; + struct fdnode *fdnode; int i; struct filedesc_to_leader *fdtol; struct file *fp; @@ -1278,14 +1269,12 @@ fdfree(struct proc *p) if (fdtol->fdl_refcount == 1 && (p->p_leader->p_flag & P_ADVLOCK) != 0) { i = 0; - fpp = fdp->fd_ofiles; - for (i = 0, fpp = fdp->fd_ofiles; - i <= fdp->fd_lastfile; - i++, fpp++) { - if (*fpp == NULL || - (*fpp)->f_type != DTYPE_VNODE) + fdnode = fdp->fd_files; + for (i = 0; i <= fdp->fd_lastfile; i++, fdnode++) { + if (fdnode->fp == NULL || + fdnode->fp->f_type != DTYPE_VNODE) continue; - fp = *fpp; + fp = fdnode->fp; fhold(fp); lf.l_whence = SEEK_SET; lf.l_start = 0; @@ -1298,7 +1287,8 @@ fdfree(struct proc *p) &lf, F_POSIX); fdrop(fp, p->p_thread); - fpp = fdp->fd_ofiles + i; + /* reload due to possible reallocation */ + fdnode = &fdp->fd_files[i]; } } retry: @@ -1341,13 +1331,12 @@ fdfree(struct proc *p) * we are the last reference to the structure, we can * safely assume it will not change out from under us. */ - fpp = fdp->fd_ofiles; - for (i = fdp->fd_lastfile; i-- >= 0; fpp++) { - if (*fpp) - (void) closef(*fpp, td); + for (i = 0; i <= fdp->fd_lastfile; ++i) { + if (fdp->fd_files[i].fp) + closef(fdp->fd_files[i].fp, td); } - if (fdp->fd_nfiles > NDFILE) - free(fdp->fd_ofiles, M_FILEDESC); + if (fdp->fd_files != fdp->fd_builtin_files) + free(fdp->fd_files, M_FILEDESC); if (fdp->fd_cdir) { cache_drop(fdp->fd_ncdir); vrele(fdp->fd_cdir); @@ -1403,17 +1392,17 @@ setugidsafety(struct proc *p) return; /* - * note: fdp->fd_ofiles may be reallocated out from under us while + * note: fdp->fd_files may be reallocated out from under us while * we are blocked in a close. Be careful! */ for (i = 0; i <= fdp->fd_lastfile; i++) { if (i > 2) break; - if (fdp->fd_ofiles[i] && is_unsafe(fdp->fd_ofiles[i])) { + if (fdp->fd_files[i].fp && is_unsafe(fdp->fd_files[i].fp)) { struct file *fp; #if 0 - if ((fdp->fd_ofileflags[i] & UF_MAPPED) != 0) + if ((fdp->fd_files[i].fileflags & UF_MAPPED) != 0) (void) munmapfd(p, i); #endif if (i < fdp->fd_knlistsize) @@ -1422,12 +1411,12 @@ setugidsafety(struct proc *p) * NULL-out descriptor prior to close to avoid * a race while close blocks. */ - fp = fdp->fd_ofiles[i]; + fp = fdp->fd_files[i].fp; funsetfd(fdp, i); - (void) closef(fp, td); + closef(fp, td); } } - while (fdp->fd_lastfile > 0 && fdp->fd_ofiles[fdp->fd_lastfile] == NULL) + while (fdp->fd_lastfile > 0 && fdp->fd_files[fdp->fd_lastfile].fp == NULL) fdp->fd_lastfile--; } @@ -1446,16 +1435,16 @@ fdcloseexec(struct proc *p) return; /* - * We cannot cache fd_ofiles or fd_ofileflags since operations - * may block and rip them out from under us. + * We cannot cache fd_files since operations may block and rip + * them out from under us. */ for (i = 0; i <= fdp->fd_lastfile; i++) { - if (fdp->fd_ofiles[i] != NULL && - (fdp->fd_ofileflags[i] & UF_EXCLOSE)) { + if (fdp->fd_files[i].fp != NULL && + (fdp->fd_files[i].fileflags & UF_EXCLOSE)) { struct file *fp; #if 0 - if (fdp->fd_ofileflags[i] & UF_MAPPED) + if (fdp->fd_files[i].fileflags & UF_MAPPED) (void) munmapfd(p, i); #endif if (i < fdp->fd_knlistsize) @@ -1464,12 +1453,12 @@ fdcloseexec(struct proc *p) * NULL-out descriptor prior to close to avoid * a race while close blocks. */ - fp = fdp->fd_ofiles[i]; + fp = fdp->fd_files[i].fp; funsetfd(fdp, i); - (void) closef(fp, td); + closef(fp, td); } } - while (fdp->fd_lastfile > 0 && fdp->fd_ofiles[fdp->fd_lastfile] == NULL) + while (fdp->fd_lastfile > 0 && fdp->fd_files[fdp->fd_lastfile].fp == NULL) fdp->fd_lastfile--; } @@ -1496,7 +1485,7 @@ fdcheckstd(struct proc *p) devnull = -1; error = 0; for (i = 0; i < 3; i++) { - if (fdp->fd_ofiles[i] != NULL) + if (fdp->fd_files[i].fp != NULL) continue; if (devnull < 0) { if ((error = falloc(p, &fp, NULL)) != 0) @@ -1642,7 +1631,7 @@ flock(struct flock_args *uap) struct flock lf; if ((unsigned)uap->fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[uap->fd]) == NULL) + (fp = fdp->fd_files[uap->fd].fp) == NULL) return (EBADF); if (fp->f_type != DTYPE_VNODE) return (EOPNOTSUPP); @@ -1708,7 +1697,7 @@ dupfdopen(struct filedesc *fdp, int indx, int dfd, int mode, int error) * closed, then reject. */ if ((u_int)dfd >= fdp->fd_nfiles || - (wfp = fdp->fd_ofiles[dfd]) == NULL) { + (wfp = fdp->fd_files[dfd].fp) == NULL) { return (EBADF); } @@ -1732,13 +1721,13 @@ dupfdopen(struct filedesc *fdp, int indx, int dfd, int mode, int error) */ if (((mode & (FREAD|FWRITE)) | wfp->f_flag) != wfp->f_flag) return (EACCES); - fp = fdp->fd_ofiles[indx]; + fp = fdp->fd_files[indx].fp; #if 0 - if (fp && fdp->fd_ofileflags[indx] & UF_MAPPED) + if (fp && fdp->fd_files[indx].fileflags & UF_MAPPED) (void) munmapfd(p, indx); #endif - fdp->fd_ofiles[indx] = wfp; - fdp->fd_ofileflags[indx] = fdp->fd_ofileflags[dfd]; + fdp->fd_files[indx].fp = wfp; + fdp->fd_files[indx].fileflags = fdp->fd_files[dfd].fileflags; fhold(wfp); if (indx > fdp->fd_lastfile) fdp->fd_lastfile = indx; @@ -1754,17 +1743,17 @@ dupfdopen(struct filedesc *fdp, int indx, int dfd, int mode, int error) /* * Steal away the file pointer from dfd, and stuff it into indx. */ - fp = fdp->fd_ofiles[indx]; + fp = fdp->fd_files[indx].fp; #if 0 - if (fp && fdp->fd_ofileflags[indx] & UF_MAPPED) + if (fp && fdp->fd_files[indx].fileflags & UF_MAPPED) (void) munmapfd(p, indx); #endif - fdp->fd_ofiles[indx] = fdp->fd_ofiles[dfd]; - fdp->fd_ofileflags[indx] = fdp->fd_ofileflags[dfd]; + fdp->fd_files[indx].fp = fdp->fd_files[dfd].fp; + fdp->fd_files[indx].fileflags = fdp->fd_files[dfd].fileflags; funsetfd(fdp, dfd); /* - * we now own the reference to fp that the ofiles[] array + * we now own the reference to fp that the files[] array * used to own. Release it. */ if (fp) @@ -1777,7 +1766,7 @@ dupfdopen(struct filedesc *fdp, int indx, int dfd, int mode, int error) fdp->fd_lastfile = indx; } else { while (fdp->fd_lastfile > 0 && - fdp->fd_ofiles[fdp->fd_lastfile] == NULL) { + fdp->fd_files[fdp->fd_lastfile].fp == NULL) { fdp->fd_lastfile--; } } @@ -1850,7 +1839,7 @@ sysctl_kern_file(SYSCTL_HANDLER_ARGS) if ((fdp = p->p_fd) == NULL) continue; for (n = 0; n < fdp->fd_nfiles; ++n) { - if ((fp = fdp->fd_ofiles[n]) == NULL) + if ((fp = fdp->fd_files[n].fp) == NULL) continue; if (req->oldptr == NULL) { ++count; diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 0464def8f4..fd0f02fa55 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_event.c,v 1.2.2.10 2004/04/04 07:03:14 cperciva Exp $ - * $DragonFly: src/sys/kern/kern_event.c,v 1.14 2005/06/06 15:02:27 dillon Exp $ + * $DragonFly: src/sys/kern/kern_event.c,v 1.15 2005/06/22 01:33:21 dillon Exp $ */ #include @@ -401,7 +401,7 @@ kevent(struct kevent_args *uap) fdp = p->p_fd; if (((u_int)uap->fd) >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[uap->fd]) == NULL || + (fp = fdp->fd_files[uap->fd].fp) == NULL || (fp->f_type != DTYPE_KQUEUE)) return (EBADF); @@ -484,7 +484,7 @@ kqueue_register(struct kqueue *kq, struct kevent *kev, struct thread *td) if (fops->f_isfd) { /* validate descriptor */ if ((u_int)kev->ident >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[kev->ident]) == NULL) + (fp = fdp->fd_files[kev->ident].fp) == NULL) return (EBADF); fhold(fp); diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index f22d3db788..596b643e71 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -37,7 +37,7 @@ * * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/sys_generic.c,v 1.55.2.10 2001/03/17 10:39:32 peter Exp $ - * $DragonFly: src/sys/kern/sys_generic.c,v 1.21 2005/06/06 15:02:28 dillon Exp $ + * $DragonFly: src/sys/kern/sys_generic.c,v 1.22 2005/06/22 01:33:21 dillon Exp $ */ #include "opt_ktrace.h" @@ -89,7 +89,7 @@ holdfp(fdp, fd, flag) struct file* fp; if (((u_int)fd) >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL || + (fp = fdp->fd_files[fd].fp) == NULL || (fp->f_flag & flag) == 0) { return (NULL); } @@ -425,7 +425,7 @@ mapped_ioctl(int fd, u_long com, caddr_t uspc_data, struct ioctl_map *map) KKASSERT(p); fdp = p->p_fd; if ((u_int)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL) + (fp = fdp->fd_files[fd].fp) == NULL) return(EBADF); if ((fp->f_flag & (FREAD | FWRITE)) == 0) @@ -494,10 +494,10 @@ mapped_ioctl(int fd, u_long com, caddr_t uspc_data, struct ioctl_map *map) switch (com) { case FIONCLEX: - fdp->fd_ofileflags[fd] &= ~UF_EXCLOSE; + fdp->fd_files[fd].fileflags &= ~UF_EXCLOSE; return(0); case FIOCLEX: - fdp->fd_ofileflags[fd] |= UF_EXCLOSE; + fdp->fd_files[fd].fileflags |= UF_EXCLOSE; return(0); } @@ -776,7 +776,7 @@ selscan(struct proc *p, fd_mask **ibits, fd_mask **obits, int nfd, int *res) for (fd = i; bits && fd < nfd; fd++, bits >>= 1) { if (!(bits & 1)) continue; - fp = fdp->fd_ofiles[fd]; + fp = fdp->fd_files[fd].fp; if (fp == NULL) return (EBADF); if (fo_poll(fp, flag[msk], fp->f_cred, td)) { @@ -896,7 +896,7 @@ pollscan(struct proc *p, struct pollfd *fds, u_int nfd, int *res) } else if (fds->fd < 0) { fds->revents = 0; } else { - fp = fdp->fd_ofiles[fds->fd]; + fp = fdp->fd_files[fds->fd].fp; if (fp == NULL) { fds->revents = POLLNVAL; n++; diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index bca830683b..08ee98d789 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -17,7 +17,7 @@ * are met. * * $FreeBSD: src/sys/kern/sys_pipe.c,v 1.60.2.13 2002/08/05 15:05:15 des Exp $ - * $DragonFly: src/sys/kern/sys_pipe.c,v 1.28 2005/06/21 23:58:53 hsu Exp $ + * $DragonFly: src/sys/kern/sys_pipe.c,v 1.29 2005/06/22 01:33:21 dillon Exp $ */ /* @@ -265,7 +265,7 @@ pipe(struct pipe_args *uap) rf->f_ops = &pipeops; error = falloc(p, &wf, &fd2); if (error) { - if (fdp->fd_ofiles[fd1] == rf) { + if (fdp->fd_files[fd1].fp == rf) { funsetfd(fdp, fd1); fdrop(rf, td); } diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 9331f74a3c..22968b1bf8 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -35,7 +35,7 @@ * * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 * $FreeBSD: src/sys/kern/uipc_syscalls.c,v 1.65.2.17 2003/04/04 17:11:16 tegge Exp $ - * $DragonFly: src/sys/kern/uipc_syscalls.c,v 1.54 2005/06/21 23:58:53 hsu Exp $ + * $DragonFly: src/sys/kern/uipc_syscalls.c,v 1.55 2005/06/22 01:33:21 dillon Exp $ */ #include "opt_ktrace.h" @@ -111,7 +111,7 @@ kern_socket(int domain, int type, int protocol, int *res) return (error); error = socreate(domain, &so, type, protocol, td); if (error) { - if (fdp->fd_ofiles[fd] == fp) { + if (fdp->fd_files[fd].fp == fp) { funsetfd(fdp, fd); fdrop(fp, td); } @@ -344,7 +344,7 @@ done: */ if (error) { *res = -1; - if (fdp->fd_ofiles[fd] == nfp) { + if (fdp->fd_files[fd].fp == nfp) { funsetfd(fdp, fd); fdrop(nfp, td); } @@ -524,13 +524,13 @@ kern_socketpair(int domain, int type, int protocol, int *sv) fdrop(fp2, td); return (error); free4: - if (fdp->fd_ofiles[sv[1]] == fp2) { + if (fdp->fd_files[sv[1]].fp == fp2) { funsetfd(fdp, sv[1]); fdrop(fp2, td); } fdrop(fp2, td); free3: - if (fdp->fd_ofiles[sv[0]] == fp1) { + if (fdp->fd_files[sv[0]].fp == fp1) { funsetfd(fdp, sv[0]); fdrop(fp1, td); } @@ -1259,7 +1259,7 @@ holdsock(struct filedesc *fdp, int fdes, struct file **fpp) *fpp = NULL; if ((unsigned)fdes >= fdp->fd_nfiles) return EBADF; - if ((fp = fdp->fd_ofiles[fdes]) == NULL) + if ((fp = fdp->fd_files[fdes].fp) == NULL) return EBADF; if (fp->f_type != DTYPE_SOCKET) return ENOTSOCK; diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 6616409f12..0a06b29c72 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -32,7 +32,7 @@ * * From: @(#)uipc_usrreq.c 8.3 (Berkeley) 1/4/94 * $FreeBSD: src/sys/kern/uipc_usrreq.c,v 1.54.2.10 2003/03/04 17:28:09 nectar Exp $ - * $DragonFly: src/sys/kern/uipc_usrreq.c,v 1.21 2005/04/20 19:43:53 hsu Exp $ + * $DragonFly: src/sys/kern/uipc_usrreq.c,v 1.22 2005/06/22 01:33:21 dillon Exp $ */ #include @@ -936,7 +936,7 @@ unp_externalize(struct mbuf *rights) if (fdalloc(p, 0, &f)) panic("unp_externalize"); fp = *rp++; - p->p_fd->fd_ofiles[f] = fp; + p->p_fd->fd_files[f].fp = fp; fp->f_msgcount--; unp_rights--; *fdp++ = f; @@ -948,7 +948,7 @@ unp_externalize(struct mbuf *rights) if (fdalloc(p, 0, &f)) panic("unp_externalize"); fp = *rp--; - p->p_fd->fd_ofiles[f] = fp; + p->p_fd->fd_files[f].fp = fp; fp->f_msgcount--; unp_rights--; *fdp-- = f; @@ -1018,9 +1018,9 @@ unp_internalize(struct mbuf *control, struct thread *td) for (i = 0; i < oldfds; i++) { fd = *fdp++; if ((unsigned)fd >= fdescp->fd_nfiles || - fdescp->fd_ofiles[fd] == NULL) + fdescp->fd_files[fd].fp == NULL) return (EBADF); - if (fdescp->fd_ofiles[fd]->f_type == DTYPE_KQUEUE) + if (fdescp->fd_files[fd].fp->f_type == DTYPE_KQUEUE) return (EOPNOTSUPP); } /* @@ -1062,7 +1062,7 @@ unp_internalize(struct mbuf *control, struct thread *td) fdp = (int *)(cm + 1) + oldfds - 1; rp = (struct file **)CMSG_DATA(cm) + oldfds - 1; for (i = 0; i < oldfds; i++) { - fp = fdescp->fd_ofiles[*fdp--]; + fp = fdescp->fd_files[*fdp--].fp; *rp-- = fp; fp->f_count++; fp->f_msgcount++; @@ -1072,7 +1072,7 @@ unp_internalize(struct mbuf *control, struct thread *td) fdp = (int *)(cm + 1); rp = (struct file **)CMSG_DATA(cm); for (i = 0; i < oldfds; i++) { - fp = fdescp->fd_ofiles[*fdp++]; + fp = fdescp->fd_files[*fdp++].fp; *rp++ = fp; fp->f_count++; fp->f_msgcount++; diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index b6237f4f31..4e7492a69e 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -14,7 +14,7 @@ * of the author. This software is distributed AS-IS. * * $FreeBSD: src/sys/kern/vfs_aio.c,v 1.70.2.28 2003/05/29 06:15:35 alc Exp $ - * $DragonFly: src/sys/kern/vfs_aio.c,v 1.16 2005/06/09 20:47:37 swildner Exp $ + * $DragonFly: src/sys/kern/vfs_aio.c,v 1.17 2005/06/22 01:33:21 dillon Exp $ */ /* @@ -1191,7 +1191,7 @@ _aio_aqueue(struct aiocb *job, struct aio_liojob *lj, int type) return EBADF; } - fp = aiocbe->fd_file = fdp->fd_ofiles[fd]; + fp = aiocbe->fd_file = fdp->fd_files[fd].fp; if ((fp == NULL) || ((opcode == LIO_WRITE) && ((fp->f_flag & FWRITE) == 0))) { TAILQ_INSERT_HEAD(&aio_freejobs, aiocbe, list); @@ -1254,7 +1254,7 @@ _aio_aqueue(struct aiocb *job, struct aio_liojob *lj, int type) goto aqueue_fail; } if ((u_int)kev.ident >= fdp->fd_nfiles || - (kq_fp = fdp->fd_ofiles[kev.ident]) == NULL || + (kq_fp = fdp->fd_files[kev.ident].fp) == NULL || (kq_fp->f_type != DTYPE_KQUEUE)) { error = EBADF; goto aqueue_fail; @@ -1596,7 +1596,7 @@ aio_cancel(struct aio_cancel_args *uap) fdp = p->p_fd; if ((u_int)uap->fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[uap->fd]) == NULL) + (fp = fdp->fd_files[uap->fd].fp) == NULL) return (EBADF); if (fp->f_type == DTYPE_VNODE) { diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 78974b3d2e..88e047cd89 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -37,7 +37,7 @@ * * @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94 * $FreeBSD: src/sys/kern/vfs_syscalls.c,v 1.151.2.18 2003/04/04 20:35:58 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_syscalls.c,v 1.63 2005/06/21 23:58:53 hsu Exp $ + * $DragonFly: src/sys/kern/vfs_syscalls.c,v 1.64 2005/06/22 01:33:21 dillon Exp $ */ #include @@ -747,7 +747,7 @@ mountctl(struct mountctl_args *uap) if (uap->fd == -1) { fp = NULL; } else if ((u_int)uap->fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[uap->fd]) == NULL) { + (fp = fdp->fd_files[uap->fd].fp) == NULL) { error = EBADF; goto done; } @@ -1311,7 +1311,7 @@ kern_open(struct nlookupdata *nd, int oflags, int mode, int *res) * if it succeeds. * * Note that if fsetfd() succeeds it will add a ref to fp - * which represents the fd_ofiles[] assignment. We must still + * which represents the fd_files[] assignment. We must still * drop our reference. */ if ((error == ENODEV || error == ENXIO) && p->p_dupfd >= 0) { @@ -1322,9 +1322,9 @@ kern_open(struct nlookupdata *nd, int oflags, int mode, int *res) fdrop(fp, td); /* our ref */ return (0); } - if (fdp->fd_ofiles[indx] == fp) { + if (fdp->fd_files[indx].fp == fp) { funsetfd(fdp, indx); - fdrop(fp, td); /* fd_ofiles[] ref */ + fdrop(fp, td); /* fd_files[] ref */ } } } @@ -1362,7 +1362,7 @@ kern_open(struct nlookupdata *nd, int oflags, int mode, int *res) * like opening the file succeeded but it was immediately closed. */ if (fp->f_count == 1) { - KASSERT(fdp->fd_ofiles[indx] != fp, + KASSERT(fdp->fd_files[indx].fp != fp, ("Open file descriptor lost all refs")); vrele(vp); fo_close(fp, td); @@ -1391,7 +1391,7 @@ kern_open(struct nlookupdata *nd, int oflags, int mode, int *res) * owned by the descriptor array, the other by us. */ vrele(vp); - if (fdp->fd_ofiles[indx] == fp) { + if (fdp->fd_files[indx].fp == fp) { funsetfd(fdp, indx); fdrop(fp, td); } @@ -1759,7 +1759,7 @@ kern_lseek(int fd, off_t offset, int whence, off_t *res) int error; if ((u_int)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL) + (fp = fdp->fd_files[fd].fp) == NULL) return (EBADF); if (fp->f_type != DTYPE_VNODE) return (ESPIPE); @@ -3056,7 +3056,7 @@ getvnode(struct filedesc *fdp, int fd, struct file **fpp) struct file *fp; if ((u_int)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL) + (fp = fdp->fd_files[fd].fp) == NULL) return (EBADF); if (fp->f_type != DTYPE_VNODE && fp->f_type != DTYPE_FIFO) return (EINVAL); @@ -3272,7 +3272,7 @@ fhopen(struct fhopen_args *uap) * but handle the case where someone might have dup()d * or close()d it when we weren't looking. */ - if (fdp->fd_ofiles[indx] == fp) { + if (fdp->fd_files[indx].fp == fp) { funsetfd(fdp, indx); fdrop(fp, td); } diff --git a/sys/netgraph/socket/ng_socket.c b/sys/netgraph/socket/ng_socket.c index 389e05b3ca..28343aa4a0 100644 --- a/sys/netgraph/socket/ng_socket.c +++ b/sys/netgraph/socket/ng_socket.c @@ -37,7 +37,7 @@ * Author: Julian Elischer * * $FreeBSD: src/sys/netgraph/ng_socket.c,v 1.11.2.6 2002/07/02 22:17:18 archie Exp $ - * $DragonFly: src/sys/netgraph/socket/ng_socket.c,v 1.10 2005/06/02 22:11:46 swildner Exp $ + * $DragonFly: src/sys/netgraph/socket/ng_socket.c,v 1.11 2005/06/22 01:33:30 dillon Exp $ * $Whistle: ng_socket.c,v 1.28 1999/11/01 09:24:52 julian Exp $ */ @@ -568,7 +568,7 @@ ng_internalize(struct mbuf *control, struct thread *td) * struct file. */ fd = *(int *) (cm + 1); if ((unsigned) fd >= fdp->fd_nfiles - || (fp = fdp->fd_ofiles[fd]) == NULL) { + || (fp = fdp->fd_files[fd].fp) == NULL) { return (EBADF); } diff --git a/sys/netproto/smb/smb_dev.c b/sys/netproto/smb/smb_dev.c index 9af6774766..916b49d1d8 100644 --- a/sys/netproto/smb/smb_dev.c +++ b/sys/netproto/smb/smb_dev.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netsmb/smb_dev.c,v 1.2.2.1 2001/05/22 08:32:33 bp Exp $ - * $DragonFly: src/sys/netproto/smb/smb_dev.c,v 1.10 2005/06/10 22:44:02 dillon Exp $ + * $DragonFly: src/sys/netproto/smb/smb_dev.c,v 1.11 2005/06/22 01:33:31 dillon Exp $ */ #include #include @@ -383,7 +383,7 @@ nsmb_getfp(struct filedesc* fdp, int fd, int flag) struct file* fp; if (((u_int)fd) >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL || + (fp = fdp->fd_files[fd].fp) == NULL || (fp->f_flag & flag) == 0) return (NULL); return (fp); diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 9b422db8c7..851ec7d6d3 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -32,7 +32,7 @@ * * @(#)filedesc.h 8.1 (Berkeley) 6/2/93 * $FreeBSD: src/sys/sys/filedesc.h,v 1.19.2.5 2003/06/06 20:21:32 tegge Exp $ - * $DragonFly: src/sys/sys/filedesc.h,v 1.10 2005/06/21 23:58:53 hsu Exp $ + * $DragonFly: src/sys/sys/filedesc.h,v 1.11 2005/06/22 01:33:22 dillon Exp $ */ #ifndef _SYS_FILEDESC_H_ @@ -55,13 +55,21 @@ */ #define NDFILE 15 /* must be of the form 2^n - 1 */ +struct file; struct klist; struct namecache; +struct fdnode { + struct file *fp; + char fileflags; + char unused01; + char unused02; + char unused03; + int allocated; +}; + struct filedesc { - struct file **fd_ofiles; /* file structures for open files */ - char *fd_ofileflags; /* per-process open file flags */ - int *fd_oallocated; /* subtree allocation count */ + struct fdnode *fd_files; /* file structures for open files */ struct vnode *fd_cdir; /* current directory (phaseout) */ struct vnode *fd_rdir; /* root directory (phaseout) */ struct vnode *fd_jdir; /* jail root directory (phaseout) */ @@ -69,7 +77,7 @@ struct filedesc { struct namecache *fd_nrdir; /* root directory */ struct namecache *fd_njdir; /* jail directory */ int fd_nfiles; /* number of open files allocated */ - int fd_lastfile; /* high-water mark of fd_ofiles */ + int fd_lastfile; /* high-water mark of fd_files */ int fd_freefile; /* approx. next free file */ int fd_cmask; /* mask for file creation */ int fd_refcnt; /* reference count */ @@ -80,25 +88,9 @@ struct filedesc { struct klist *fd_knhash; /* hash table for attached knotes */ int fd_holdleaderscount; /* block fdfree() for shared close() */ int fd_holdleaderswakeup; /* fdfree() needs wakeup */ + struct fdnode fd_builtin_files[NDFILE]; }; -/* - * Basic allocation of descriptors: - * one of the above, plus arrays for NDFILE descriptors. - */ -struct filedesc0 { - struct filedesc fd_fd; - /* - * These arrays are used when the number of open files is - * <= NDFILE, and are then pointed to by the pointers above. - */ - struct file *fd_dfiles[NDFILE]; - char fd_dfileflags[NDFILE]; - int fd_dallocated[NDFILE]; -}; - - - /* * Structure to keep track of (process leader, struct fildedesc) tuples. * Each process has a pointer to such a structure when detailed tracking @@ -124,11 +116,6 @@ struct filedesc_to_leader { #define UF_MAPPED 0x02 /* mapped from device */ #endif -/* - * Storage required per open file descriptor. - */ -#define OFILESIZE (sizeof(struct file *) + sizeof(char) + sizeof(int)) - /* * This structure that holds the information needed to send a SIGIO or * a SIGURG signal to a process or process group when new data arrives diff --git a/sys/vfs/fdesc/fdesc_vfsops.c b/sys/vfs/fdesc/fdesc_vfsops.c index ab0957db81..468647546a 100644 --- a/sys/vfs/fdesc/fdesc_vfsops.c +++ b/sys/vfs/fdesc/fdesc_vfsops.c @@ -36,7 +36,7 @@ * @(#)fdesc_vfsops.c 8.4 (Berkeley) 1/21/94 * * $FreeBSD: src/sys/miscfs/fdesc/fdesc_vfsops.c,v 1.22.2.3 2002/08/23 17:42:39 njl Exp $ - * $DragonFly: src/sys/vfs/fdesc/fdesc_vfsops.c,v 1.13 2005/02/11 22:07:32 joerg Exp $ + * $DragonFly: src/sys/vfs/fdesc/fdesc_vfsops.c,v 1.14 2005/06/22 01:33:32 dillon Exp $ */ /* @@ -177,7 +177,7 @@ fdesc_statfs(struct mount *mp, struct statfs *sbp, struct thread *td) last = min(fdp->fd_nfiles, lim); freefd = 0; for (i = fdp->fd_freefile; i < last; i++) - if (fdp->fd_ofiles[i] == NULL) + if (fdp->fd_files[i].fp == NULL) freefd++; /* diff --git a/sys/vfs/fdesc/fdesc_vnops.c b/sys/vfs/fdesc/fdesc_vnops.c index 84461dd5ae..72c750060f 100644 --- a/sys/vfs/fdesc/fdesc_vnops.c +++ b/sys/vfs/fdesc/fdesc_vnops.c @@ -36,7 +36,7 @@ * @(#)fdesc_vnops.c 8.9 (Berkeley) 1/21/94 * * $FreeBSD: src/sys/miscfs/fdesc/fdesc_vnops.c,v 1.47.2.1 2001/10/22 22:49:26 chris Exp $ - * $DragonFly: src/sys/vfs/fdesc/fdesc_vnops.c,v 1.17 2005/02/15 08:32:18 joerg Exp $ + * $DragonFly: src/sys/vfs/fdesc/fdesc_vnops.c,v 1.18 2005/06/22 01:33:32 dillon Exp $ */ /* @@ -210,7 +210,7 @@ fdesc_lookup(struct vop_lookup_args *ap) fd = 10 * fd + *pname++ - '0'; } - if (fd >= nfiles || p->p_fd->fd_ofiles[fd] == NULL) { + if (fd >= nfiles || p->p_fd->fd_files[fd].fp == NULL) { error = EBADF; goto bad; } @@ -299,7 +299,7 @@ fdesc_getattr(struct vop_getattr_args *ap) case Fdesc: fd = VTOFDESC(vp)->fd_fd; - if (fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) + if (fd >= fdp->fd_nfiles || (fp = fdp->fd_files[fd].fp) == NULL) return (EBADF); bzero(&stb, sizeof(stb)); @@ -446,7 +446,7 @@ fdesc_readdir(struct vop_readdir_args *ap) dp->d_type = DT_DIR; break; default: - if (fdp->fd_ofiles[fcnt] == NULL) + if (fdp->fd_files[fcnt].fp == NULL) goto done; bzero((caddr_t) dp, UIO_MX); diff --git a/sys/vfs/portal/portal_vnops.c b/sys/vfs/portal/portal_vnops.c index 7c568aa360..98a4e359ce 100644 --- a/sys/vfs/portal/portal_vnops.c +++ b/sys/vfs/portal/portal_vnops.c @@ -36,7 +36,7 @@ * @(#)portal_vnops.c 8.14 (Berkeley) 5/21/95 * * $FreeBSD: src/sys/miscfs/portal/portal_vnops.c,v 1.38 1999/12/21 06:29:00 chris Exp $ - * $DragonFly: src/sys/vfs/portal/portal_vnops.c,v 1.21 2005/06/06 15:09:38 drhodus Exp $ + * $DragonFly: src/sys/vfs/portal/portal_vnops.c,v 1.22 2005/06/22 01:33:33 dillon Exp $ */ /* @@ -401,7 +401,7 @@ portal_open(struct vop_open_args *ap) * of the mode of the existing descriptor. */ KKASSERT(td->td_proc); - fp = td->td_proc->p_fd->fd_ofiles[fd]; + fp = td->td_proc->p_fd->fd_files[fd].fp; if (((ap->a_mode & (FREAD|FWRITE)) | fp->f_flag) != fp->f_flag) { portal_closefd(td, fd); error = EACCES; diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index 78e3933952..0361339456 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -39,7 +39,7 @@ * * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94 * $FreeBSD: src/sys/vm/vm_mmap.c,v 1.108.2.6 2002/07/02 20:06:19 dillon Exp $ - * $DragonFly: src/sys/vm/vm_mmap.c,v 1.21 2004/10/12 19:29:34 dillon Exp $ + * $DragonFly: src/sys/vm/vm_mmap.c,v 1.22 2005/06/22 01:33:34 dillon Exp $ */ /* @@ -243,7 +243,7 @@ kern_mmap(caddr_t uaddr, size_t ulen, int uprot, int uflags, int fd, * sure it is of appropriate type. */ if (((unsigned) fd) >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL) + (fp = fdp->fd_files[fd].fp) == NULL) return (EBADF); if (fp->f_type != DTYPE_VNODE) return (EINVAL); @@ -510,7 +510,7 @@ munmapfd(p, fd) /* * XXX should unmap any regions mapped to this file */ - p->p_fd->fd_ofileflags[fd] &= ~UF_MAPPED; + p->p_fd->fd_files[fd].fileflags &= ~UF_MAPPED; } #endif