kern_descrip.c (137337) | kern_descrip.c (137355) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 35 */ 36 37#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/sys/kern/kern_descrip.c 137337 2004-11-07 15:34:45Z phk $"); | 38__FBSDID("$FreeBSD: head/sys/kern/kern_descrip.c 137355 2004-11-07 22:16:07Z phk $"); |
39 40#include "opt_compat.h" 41 42#include <sys/param.h> 43#include <sys/limits.h> 44#include <sys/systm.h> 45#include <sys/syscallsubr.h> 46#include <sys/sysproto.h> --- 47 unchanged lines hidden (view full) --- 94/* How to treat 'new' parameter when allocating a fd for do_dup(). */ 95enum dup_type { DUP_VARIABLE, DUP_FIXED }; 96 97static int do_dup(struct thread *td, enum dup_type type, int old, int new, 98 register_t *retval); 99static int fd_first_free(struct filedesc *, int, int); 100static int fd_last_used(struct filedesc *, int, int); 101static void fdgrowtable(struct filedesc *, int); | 39 40#include "opt_compat.h" 41 42#include <sys/param.h> 43#include <sys/limits.h> 44#include <sys/systm.h> 45#include <sys/syscallsubr.h> 46#include <sys/sysproto.h> --- 47 unchanged lines hidden (view full) --- 94/* How to treat 'new' parameter when allocating a fd for do_dup(). */ 95enum dup_type { DUP_VARIABLE, DUP_FIXED }; 96 97static int do_dup(struct thread *td, enum dup_type type, int old, int new, 98 register_t *retval); 99static int fd_first_free(struct filedesc *, int, int); 100static int fd_last_used(struct filedesc *, int, int); 101static void fdgrowtable(struct filedesc *, int); |
102static void fdunused(struct filedesc *fdp, int fd); |
|
102 103/* 104 * A process is initially started out with NDFILE descriptors stored within 105 * this structure, selected to be enough for typical applications based on 106 * the historical limit of 20 open files (and the usage of descriptors by 107 * shells). If these descriptors are exhausted, a larger descriptor table 108 * may be allocated, up to a process' resource limit; the internal arrays 109 * are then unused. --- 109 unchanged lines hidden (view full) --- 219 fdp->fd_lastfile = fd; 220 if (fd == fdp->fd_freefile) 221 fdp->fd_freefile = fd_first_free(fdp, fd, fdp->fd_nfiles); 222} 223 224/* 225 * Mark a file descriptor as unused. 226 */ | 103 104/* 105 * A process is initially started out with NDFILE descriptors stored within 106 * this structure, selected to be enough for typical applications based on 107 * the historical limit of 20 open files (and the usage of descriptors by 108 * shells). If these descriptors are exhausted, a larger descriptor table 109 * may be allocated, up to a process' resource limit; the internal arrays 110 * are then unused. --- 109 unchanged lines hidden (view full) --- 220 fdp->fd_lastfile = fd; 221 if (fd == fdp->fd_freefile) 222 fdp->fd_freefile = fd_first_free(fdp, fd, fdp->fd_nfiles); 223} 224 225/* 226 * Mark a file descriptor as unused. 227 */ |
227void | 228static void |
228fdunused(struct filedesc *fdp, int fd) 229{ 230 FILEDESC_LOCK_ASSERT(fdp, MA_OWNED); 231 KASSERT(fdisused(fdp, fd), 232 ("fd is already unused")); 233 KASSERT(fdp->fd_ofiles[fd] == NULL, 234 ("fd is still in use")); 235 fdp->fd_map[NDSLOT(fd)] &= ~NDBIT(fd); --- 1488 unchanged lines hidden (view full) --- 1724 FILEDESC_UNLOCK(fdp); 1725 (void) closef(fp, td); 1726 FILEDESC_LOCK(fdp); 1727 } 1728 } 1729 FILEDESC_UNLOCK(fdp); 1730} 1731 | 229fdunused(struct filedesc *fdp, int fd) 230{ 231 FILEDESC_LOCK_ASSERT(fdp, MA_OWNED); 232 KASSERT(fdisused(fdp, fd), 233 ("fd is already unused")); 234 KASSERT(fdp->fd_ofiles[fd] == NULL, 235 ("fd is still in use")); 236 fdp->fd_map[NDSLOT(fd)] &= ~NDBIT(fd); --- 1488 unchanged lines hidden (view full) --- 1725 FILEDESC_UNLOCK(fdp); 1726 (void) closef(fp, td); 1727 FILEDESC_LOCK(fdp); 1728 } 1729 } 1730 FILEDESC_UNLOCK(fdp); 1731} 1732 |
1733void 1734fdclose(struct filedesc *fdp, struct file *fp, int idx, struct thread *td) 1735{ 1736 1737 FILEDESC_LOCK(fdp); 1738 if (fdp->fd_ofiles[idx] == fp) { 1739 fdp->fd_ofiles[idx] = NULL; 1740 fdunused(fdp, idx); 1741 FILEDESC_UNLOCK(fdp); 1742 fdrop(fp, td); 1743 } else { 1744 FILEDESC_UNLOCK(fdp); 1745 } 1746} 1747 |
|
1732/* 1733 * Close any files on exec? 1734 */ 1735void 1736fdcloseexec(td) 1737 struct thread *td; 1738{ 1739 struct filedesc *fdp; --- 826 unchanged lines hidden --- | 1748/* 1749 * Close any files on exec? 1750 */ 1751void 1752fdcloseexec(td) 1753 struct thread *td; 1754{ 1755 struct filedesc *fdp; --- 826 unchanged lines hidden --- |