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 92654 2002-03-19 09:11:49Z jeff $
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#include <vm/vm_zone.h>
71
72static MALLOC_DEFINE(M_FILEDESC, "file desc", "Open file descriptor table");
73static MALLOC_DEFINE(M_SIGIO, "sigio", "sigio structures");
74
75uma_zone_t file_zone;
76
77static d_open_t fdopen;
78#define NUMFDESC 64
79
80#define CDEV_MAJOR 22
81static struct cdevsw fildesc_cdevsw = {
82 /* open */ fdopen,
83 /* close */ noclose,
84 /* read */ noread,

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

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

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

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

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

2109static void filelistinit __P((void *));
2110SYSINIT(select, SI_SUB_LOCK, SI_ORDER_FIRST, filelistinit, NULL)
2111
2112/* ARGSUSED*/
2113static void
2114filelistinit(dummy)
2115 void *dummy;
2116{
2117 file_zone = uma_zcreate("Files", sizeof(struct file), NULL, NULL,
2118 NULL, NULL, UMA_ALIGN_PTR, 0);
2119
2120 sx_init(&filelist_lock, "filelist lock");
2121}