xref: /illumos-gate/usr/src/uts/common/sys/open.h (revision 2a613b5974ae49c8b068a3998ff554f8c6f0f593)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved	*/
24 
25 
26 #ifndef _SYS_OPEN_H
27 #define	_SYS_OPEN_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * Some drivers need to be able to keep accurate records of open/close
35  * calls to determine whether a device is still in use.  To allow this
36  * open/close calls have been typed and the type is passed as a third
37  * argument in open/close calls, as in:
38  *	(*cdevsw[getmajor(dev)].d_open)(getminor(dev), flag, OTYP_CHR);
39  * or
40  *	(*cdevsw[getmajor(dev)].d_close)(getminor(dev), flag, OTYP_CHR);
41  * Five types of open/close calls have been defined:
42  * OTYP_BLK:	open/close of a block special file
43  * OTYP_MNT:	open/close for mounting/unmounting a file system
44  * OTYP_CHR:	open/close of a character special file
45  * OTYP_SWP:	open/close of a swapping device.
46  * OTYP_LYR:	open/close calls from a driver to another driver,
47  *		without a file being open for the dev of the lower driver.
48  *
49  * The first four types of open/close calls obey the protocol rule
50  * that many more opens may occur for a given minor(dev) for that type of open,
51  * but a close call happens only on the last close of that dev.
52  * This protocol allows a flag to be used (set by opens, cleared by closes)
53  * to keep track of the state for a given minor device value.
54  *
55  * Calls of the fifth type (OTYP_LYR) must obey the protocol rule
56  * that open and close call calls are always paired.  This protocol
57  * permits several drivers to be layers above the same device driver.
58  * A counter can be used for this protocol.
59  *
60  * The value OTYPCNT is defined for the purpose of declaring arrays
61  * in drivers and for performing range checks (0 <= otyp < OTYPCNT)
62  * on values passed.
63  */
64 
65 #define	OTYPCNT		5
66 #define	OTYP_BLK	0
67 #define	OTYP_MNT	1
68 #define	OTYP_CHR	2
69 #define	OTYP_SWP	3
70 #define	OTYP_LYR	4
71 
72 #ifdef	__cplusplus
73 }
74 #endif
75 
76 #endif	/* _SYS_OPEN_H */
77