xref: /original-bsd/sys/sys/filedesc.h (revision 7c3db03c)
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.3 (Berkeley) 03/17/91
8  */
9 
10 #ifndef _FILEDESC_H_
11 #define _FILEDESC_H_
12 
13 /*
14  * This structure is used for the management of descriptors.
15  * It may be shared by multiple threads.
16  *
17  * A process is initially started out with NDFILE worth of
18  * descriptors, selected to be enough for typical applications
19  * based on the historic limit of 20 open files. Additional
20  * descriptors may be allocated up to a process' resource limit.
21  * The initial expansion is set to NOEXTENT; each time it runs out,
22  * it is doubled until the resource limit is reached. NOEXTENT should
23  * be selected to be the biggest multiple of OFILESIZE (see below)
24  * that will fit in a power-of-two sized piece of memory.
25  */
26 #define NOEXTENT	25		/* 125 bytes in 128-byte alloc. */
27 
28 struct filedesc {
29 	struct	file **fd_ofiles;	/* file structures for open files */
30 	char	*fd_ofileflags;		/* per-process open file flags */
31 	struct	vnode *fd_cdir;		/* current directory */
32 	struct	vnode *fd_rdir;		/* root directory */
33 	int	fd_nfiles;		/* number of open files allocated */
34 	int	fd_lastfile;		/* high-water mark of fd_ofiles */
35 	int	fd_freefile;		/* approx. next free file */
36 	u_short	fd_cmask;		/* mask for file creation */
37 	u_short	fd_refcnt;		/* reference count */
38 };
39 
40 /*
41  * Per-process open flags.
42  */
43 #define	UF_EXCLOSE 	0x01		/* auto-close on exec */
44 #define	UF_MAPPED 	0x02		/* mapped from device */
45 
46 /*
47  * Data structure access macros.
48  */
49 #define OFILE(fd, indx)	((fd)->fd_ofiles[indx])
50 #define OFILEFLAGS(fd, indx) ((fd)->fd_ofileflags[indx])
51 #define OFILESIZE (sizeof(struct file *) + sizeof(char))
52 
53 /*
54  * Kernel global variables and routines.
55  */
56 extern struct filedesc *fdcopy();
57 
58 #endif /* !_FILEDESC_H_ */
59