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