xref: /illumos-gate/usr/src/uts/common/sys/devpolicy.h (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
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 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_DEVPOLICY_H
28 #define	_SYS_DEVPOLICY_H
29 
30 #include <sys/types.h>
31 #include <sys/priv.h>
32 #include <sys/param.h>
33 #include <sys/vnode.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Device policy system call interface data structure.
41  *
42  * Inside the kernel we only make the structure definition available when the
43  * privilege set definition is complete, i.e., something included
44  * <sys/priv_const.h> before including this file.
45  */
46 
47 typedef struct devplcysys devplcysys_t;
48 
49 #if defined(__PRIV_CONST_IMPL) || !defined(_KERNEL)
50 
51 struct devplcysys {
52 	major_t		dps_maj;	/* major number */
53 	minor_t		dps_lomin;	/* low minor number, if known */
54 	minor_t		dps_himin;	/* high minor number, if known */
55 	char		dps_minornm[MAXNAMELEN]; /* minor name/pattern */
56 	boolean_t	dps_isblock;	/* expanded device is a block dev */
57 #ifdef _KERNEL
58 	priv_set_t	dps_rdp;	/* privileges required for reading */
59 	priv_set_t	dps_wrp;	/* privileges required for writing */
60 #else
61 	priv_chunk_t	dps_sets[1];	/* read/write privilege sets */
62 #endif
63 };
64 
65 #ifdef _KERNEL
66 /*
67  * The actual device policy structure.  This is returned on table
68  * lookups.
69  */
70 struct devplcy {
71 	uint32_t	dp_ref;		/* Reference count */
72 	uint32_t	dp_gen;		/* Generation count */
73 	priv_set_t	dp_rdp;		/* Privileges required for reading */
74 	priv_set_t	dp_wrp;		/* Privileges required for writing */
75 };
76 #endif /* _KERNEL */
77 
78 #endif /* __PRIV_CONST_IMPL || !_KERNEL */
79 
80 #ifdef _KERNEL
81 
82 typedef struct devplcy devplcy_t;
83 
84 extern devplcy_t *nullpolicy;		/* The null policy */
85 
86 extern volatile uint32_t devplcy_gen;	/* The current generation count */
87 
88 extern devplcy_t *dpget(void);
89 extern void dphold(devplcy_t *);
90 extern void dpfree(devplcy_t *);
91 extern devplcy_t *devpolicy_find(vnode_t *);
92 
93 extern void devpolicy_init(void);
94 extern int devpolicy_load(int, size_t, devplcysys_t *);
95 extern int devpolicy_get(int *, size_t, devplcysys_t *);
96 extern int devpolicy_getbyname(size_t, devplcysys_t *, char *);
97 
98 extern devplcy_t *devpolicy_priv_by_name(const char *, const char *);
99 
100 #else /* _KERNEL */
101 #define	DEVPLCYSYS_SZ(ip)	(sizeof (devplcysys_t) + \
102 				((ip)->priv_setsize * 2 - 1) * \
103 				sizeof (priv_chunk_t))
104 #define	DEVPLCYSYS_RDP(dp, ip)	((priv_set_t *)(&(dp)->dps_sets[0]))
105 #define	DEVPLCYSYS_WRP(dp, ip)	\
106 			((priv_set_t *)(&(dp)->dps_sets[(ip)->priv_setsize]))
107 
108 #define	DEVPLCY_TKN_RDP		"read_priv_set"
109 #define	DEVPLCY_TKN_WRP		"write_priv_set"
110 
111 #endif /* _KERNEL */
112 
113 #define	MAXDEVPOLICY		1000
114 #define	DEVPOLICY_DFLT_MAJ	((major_t)~0)
115 
116 #ifdef	__cplusplus
117 }
118 #endif
119 
120 #endif	/* _SYS_DEVPOLICY_H */
121