Deleted Added
sdiff udiff text old ( 92641 ) new ( 92654 )
full compact
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.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
39 * $FreeBSD: head/sys/kern/kern_descrip.c 92641 2002-03-19 04:30:04Z alfred $
40 */
41
42#include "opt_compat.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/lock.h>
47#include <sys/malloc.h>

--- 14 unchanged lines hidden (view full) ---

62#include <sys/event.h>
63#include <sys/sx.h>
64#include <sys/socketvar.h>
65
66#include <machine/limits.h>
67
68#include <vm/vm.h>
69#include <vm/vm_extern.h>
70
71static MALLOC_DEFINE(M_FILEDESC, "file desc", "Open file descriptor table");
72MALLOC_DEFINE(M_FILE, "file", "Open file structure");
73static MALLOC_DEFINE(M_SIGIO, "sigio", "sigio structures");
74
75static d_open_t fdopen;
76#define NUMFDESC 64
77
78#define CDEV_MAJOR 22
79static struct cdevsw fildesc_cdevsw = {
80 /* open */ fdopen,
81 /* close */ noclose,
82 /* read */ noread,

--- 1007 unchanged lines hidden (view full) ---

1090 nfiles++;
1091 sx_xunlock(&filelist_lock);
1092 /*
1093 * Allocate a new file descriptor.
1094 * If the process has file descriptor zero open, add to the list
1095 * of open files at that point, otherwise put it at the front of
1096 * the list of open files.
1097 */
1098 MALLOC(fp, struct file *, sizeof(struct file), M_FILE, M_WAITOK | M_ZERO);
1099
1100 /*
1101 * wait until after malloc (which may have blocked) returns before
1102 * allocating the slot, else a race might have shrunk it if we had
1103 * allocated it before the malloc.
1104 */
1105 FILEDESC_LOCK(p->p_fd);
1106 if ((error = fdalloc(td, 0, &i))) {
1107 FILEDESC_UNLOCK(p->p_fd);
1108 sx_xlock(&filelist_lock);
1109 nfiles--;
1110 sx_xunlock(&filelist_lock);
1111 FREE(fp, M_FILE);
1112 return (error);
1113 }
1114 fp->f_mtxp = mtx_pool_alloc();
1115 fp->f_gcflag = 0;
1116 fp->f_count = 1;
1117 fp->f_cred = crhold(td->td_ucred);
1118 fp->f_ops = &badfileops;
1119 fp->f_seqcount = 1;

--- 24 unchanged lines hidden (view full) ---

1144{
1145
1146 KASSERT((fp->f_count == 0), ("ffree: fp_fcount not 0!"));
1147 sx_xlock(&filelist_lock);
1148 LIST_REMOVE(fp, f_list);
1149 nfiles--;
1150 sx_xunlock(&filelist_lock);
1151 crfree(fp->f_cred);
1152 FREE(fp, M_FILE);
1153}
1154
1155/*
1156 * Build a new filedesc structure.
1157 */
1158struct filedesc *
1159fdinit(td)
1160 struct thread *td;

--- 945 unchanged lines hidden (view full) ---

2106static void filelistinit __P((void *));
2107SYSINIT(select, SI_SUB_LOCK, SI_ORDER_FIRST, filelistinit, NULL)
2108
2109/* ARGSUSED*/
2110static void
2111filelistinit(dummy)
2112 void *dummy;
2113{
2114 sx_init(&filelist_lock, "filelist lock");
2115}