xref: /original-bsd/sys/sys/filedesc.h (revision 6d57652c)
1 /*
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)filedesc.h	7.1 (Berkeley) 01/10/91
8  */
9 
10 #ifndef _FILEDESC_
11 /*
12  * This structure is used for the management of descriptors.
13  * It may be shared by multiple threads.
14  *
15  * A process is initially started out with NDFILE worth of
16  * descriptors, selected to be enough for typical applications
17  * based on the historic limit of 20 open files. Additional
18  * descriptors may be allocated up to a system defined limit
19  * defined by the global variable nofile; the initial value
20  * of nofile is set to NOFILE. The initial expansion is set to
21  * NDEXTENT; each time it runs out it is doubled until nofile
22  * is reached. NDEXTENT should be selected to be the biggest
23  * multiple of OFILESIZE (see below) that will fit in a
24  * power-of-two sized piece of memory.
25  */
26 #define NDFILE		20
27 #define NDEXTENT	25
28 
29 struct filedesc {
30 	struct	vnode *fd_cdir;		/* current directory */
31 	struct	vnode *fd_rdir;		/* root directory */
32 	u_short	fd_cmask;		/* mask for file creation */
33 	u_short	fd_refcnt;		/* reference count */
34 	short	fd_lastfile;		/* high-water mark of fd_ofile */
35 	short	fd_maxfiles;		/* maximum number of open files */
36 	struct	file *fd_ofile[NDFILE];	/* file structures for open files */
37 	struct	file **fd_moreofiles;	/* the rest of the open files */
38 	char	fd_ofileflags[NDFILE];	/* per-process open file flags */
39 	char	*fd_moreofileflags;	/* the rest of the open file flags */
40 	long	fd_spare;		/* unused to round up to power of two */
41 };
42 
43 /*
44  * Per-process open flags.
45  */
46 #define	UF_EXCLOSE 	0x01		/* auto-close on exec */
47 #define	UF_MAPPED 	0x02		/* mapped from device */
48 
49 /*
50  * Data structure access macros.
51  */
52 #if !defined(vax) && !defined(tahoe)
53 #define OFILE(fd, indx) ((indx) < NDFILE ? \
54 	(fd)->fd_ofile[indx] : \
55 	(fd)->fd_moreofiles[(indx) - NDFILE])
56 #define OFILEFLAGS(fd, indx) ((indx) < NDFILE ? \
57 	(fd)->fd_ofileflags[indx] : \
58 	(fd)->fd_moreofileflags[(indx) - NDFILE])
59 #define OFILESIZE (sizeof(struct file *) + sizeof(char))
60 #else
61 /* PCC cannot handle above as lvalues */
62 struct file **ofilefunc();
63 char *ofileflagsfunc();
64 #define OFILE(fd, indx) *ofilefunc(fd, indx)
65 #define OFILEFLAGS(fd, indx) *ofileflagsfunc(fd, indx)
66 #define OFILESIZE (sizeof(struct file *) + sizeof(char))
67 #endif
68 
69 /*
70  * Kernel global variables and routines.
71  */
72 extern struct filedesc *fddup();
73 extern int nofile;
74 #endif _FILEDESC_
75