Deleted Added
full compact
kern_descrip.c (156861) kern_descrip.c (156900)
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 156861 2006-03-18 23:27:21Z csjp $");
38__FBSDID("$FreeBSD: head/sys/kern/kern_descrip.c 156900 2006-03-20 00:13:47Z csjp $");
39
40#include "opt_compat.h"
41#include "opt_ddb.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45
46#include <sys/conf.h>

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

188 mask = ~(~(NDSLOTTYPE)0 << (size % NDENTRIES));
189 if ((mask &= map[off]) != 0)
190 return (off * NDENTRIES + flsl(mask) - 1);
191 --off;
192 }
193 for (minoff = NDSLOT(low); off >= minoff; --off)
194 if (map[off] != 0)
195 return (off * NDENTRIES + flsl(map[off]) - 1);
39
40#include "opt_compat.h"
41#include "opt_ddb.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45
46#include <sys/conf.h>

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

188 mask = ~(~(NDSLOTTYPE)0 << (size % NDENTRIES));
189 if ((mask &= map[off]) != 0)
190 return (off * NDENTRIES + flsl(mask) - 1);
191 --off;
192 }
193 for (minoff = NDSLOT(low); off >= minoff; --off)
194 if (map[off] != 0)
195 return (off * NDENTRIES + flsl(map[off]) - 1);
196 return (size - 1);
196 return (low - 1);
197}
198
199static int
200fdisused(struct filedesc *fdp, int fd)
201{
202 KASSERT(fd >= 0 && fd < fdp->fd_nfiles,
203 ("file descriptor %d out of range (0, %d)", fd, fdp->fd_nfiles));
204 return ((fdp->fd_map[NDSLOT(fd)] & NDBIT(fd)) != 0);

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

1252fdalloc(struct thread *td, int minfd, int *result)
1253{
1254 struct proc *p = td->td_proc;
1255 struct filedesc *fdp = p->p_fd;
1256 int fd = -1, maxfd;
1257
1258 FILEDESC_LOCK_ASSERT(fdp, MA_OWNED);
1259
197}
198
199static int
200fdisused(struct filedesc *fdp, int fd)
201{
202 KASSERT(fd >= 0 && fd < fdp->fd_nfiles,
203 ("file descriptor %d out of range (0, %d)", fd, fdp->fd_nfiles));
204 return ((fdp->fd_map[NDSLOT(fd)] & NDBIT(fd)) != 0);

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

1252fdalloc(struct thread *td, int minfd, int *result)
1253{
1254 struct proc *p = td->td_proc;
1255 struct filedesc *fdp = p->p_fd;
1256 int fd = -1, maxfd;
1257
1258 FILEDESC_LOCK_ASSERT(fdp, MA_OWNED);
1259
1260 if (fdp->fd_freefile > minfd)
1261 minfd = fdp->fd_freefile;
1262
1260 PROC_LOCK(p);
1261 maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
1262 PROC_UNLOCK(p);
1263
1264 /*
1265 * Search the bitmap for a free descriptor. If none is found, try
1266 * to grow the file table. Keep at it until we either get a file
1267 * descriptor or run into process or system limits; fdgrowtable()

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

1281 * used and return it to the caller.
1282 */
1283 KASSERT(!fdisused(fdp, fd),
1284 ("fd_first_free() returned non-free descriptor"));
1285 KASSERT(fdp->fd_ofiles[fd] == NULL,
1286 ("free descriptor isn't"));
1287 fdp->fd_ofileflags[fd] = 0; /* XXX needed? */
1288 fdused(fdp, fd);
1263 PROC_LOCK(p);
1264 maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
1265 PROC_UNLOCK(p);
1266
1267 /*
1268 * Search the bitmap for a free descriptor. If none is found, try
1269 * to grow the file table. Keep at it until we either get a file
1270 * descriptor or run into process or system limits; fdgrowtable()

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

1284 * used and return it to the caller.
1285 */
1286 KASSERT(!fdisused(fdp, fd),
1287 ("fd_first_free() returned non-free descriptor"));
1288 KASSERT(fdp->fd_ofiles[fd] == NULL,
1289 ("free descriptor isn't"));
1290 fdp->fd_ofileflags[fd] = 0; /* XXX needed? */
1291 fdused(fdp, fd);
1289 fdp->fd_freefile = fd_first_free(fdp, fd, fdp->fd_nfiles);
1290 *result = fd;
1291 return (0);
1292}
1293
1294/*
1295 * Check to see whether n user file descriptors
1296 * are available to the process p.
1297 */

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

1415 /* Create the file descriptor table. */
1416 newfdp->fd_fd.fd_refcnt = 1;
1417 newfdp->fd_fd.fd_holdcnt = 1;
1418 newfdp->fd_fd.fd_cmask = CMASK;
1419 newfdp->fd_fd.fd_ofiles = newfdp->fd_dfiles;
1420 newfdp->fd_fd.fd_ofileflags = newfdp->fd_dfileflags;
1421 newfdp->fd_fd.fd_nfiles = NDFILE;
1422 newfdp->fd_fd.fd_map = newfdp->fd_dmap;
1292 *result = fd;
1293 return (0);
1294}
1295
1296/*
1297 * Check to see whether n user file descriptors
1298 * are available to the process p.
1299 */

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

1417 /* Create the file descriptor table. */
1418 newfdp->fd_fd.fd_refcnt = 1;
1419 newfdp->fd_fd.fd_holdcnt = 1;
1420 newfdp->fd_fd.fd_cmask = CMASK;
1421 newfdp->fd_fd.fd_ofiles = newfdp->fd_dfiles;
1422 newfdp->fd_fd.fd_ofileflags = newfdp->fd_dfileflags;
1423 newfdp->fd_fd.fd_nfiles = NDFILE;
1424 newfdp->fd_fd.fd_map = newfdp->fd_dmap;
1425 newfdp->fd_fd.fd_lastfile = -1;
1423 return (&newfdp->fd_fd);
1424}
1425
1426static struct filedesc *
1427fdhold(struct proc *p)
1428{
1429 struct filedesc *fdp;
1430

--- 1256 unchanged lines hidden ---
1426 return (&newfdp->fd_fd);
1427}
1428
1429static struct filedesc *
1430fdhold(struct proc *p)
1431{
1432 struct filedesc *fdp;
1433

--- 1256 unchanged lines hidden ---