summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/devpolicy.h
blob: d6b76e551a6ed82ba768206926ab93ec666a36f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_SYS_DEVPOLICY_H
#define	_SYS_DEVPOLICY_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/types.h>
#include <sys/priv.h>
#include <sys/param.h>
#include <sys/vnode.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Device policy system call interface data structure.
 *
 * Inside the kernel we only make the structure definition available when the
 * privilege set definition is complete, i.e., something included
 * <sys/priv_const.h> before including this file.
 */

typedef struct devplcysys devplcysys_t;

#if defined(__PRIV_CONST_IMPL) || !defined(_KERNEL)

struct devplcysys {
	major_t		dps_maj;	/* major number */
	minor_t		dps_lomin;	/* low minor number, if known */
	minor_t		dps_himin;	/* high minor number, if known */
	char		dps_minornm[MAXNAMELEN]; /* minor name/pattern */
	boolean_t	dps_isblock;	/* expanded device is a block dev */
#ifdef _KERNEL
	priv_set_t	dps_rdp;	/* privileges required for reading */
	priv_set_t	dps_wrp;	/* privileges required for writing */
#else
	priv_chunk_t	dps_sets[1];	/* read/write privilege sets */
#endif
};

#ifdef _KERNEL
/*
 * The actual device policy structure.  This is returned on table
 * lookups.
 */
struct devplcy {
	uint32_t	dp_ref;		/* Reference count */
	uint32_t	dp_gen;		/* Generation count */
	priv_set_t	dp_rdp;		/* Privileges required for reading */
	priv_set_t	dp_wrp;		/* Privileges required for writing */
};
#endif /* _KERNEL */

#endif /* __PRIV_CONST_IMPL || !_KERNEL */

#ifdef _KERNEL

typedef struct devplcy devplcy_t;

extern devplcy_t *nullpolicy;		/* The null policy */

extern volatile uint32_t devplcy_gen;	/* The current generation count */

extern devplcy_t *dpget(void);
extern void dphold(devplcy_t *);
extern void dpfree(devplcy_t *);
extern devplcy_t *devpolicy_find(vnode_t *);

extern void devpolicy_init(void);
extern int devpolicy_load(int, size_t, devplcysys_t *);
extern int devpolicy_get(int *, size_t, devplcysys_t *);
extern int devpolicy_getbyname(size_t, devplcysys_t *, char *);

extern devplcy_t *devpolicy_priv_by_name(const char *, const char *);

#else /* _KERNEL */
#define	DEVPLCYSYS_SZ(ip)	(sizeof (devplcysys_t) + \
				((ip)->priv_setsize * 2 - 1) * \
				sizeof (priv_chunk_t))
#define	DEVPLCYSYS_RDP(dp, ip)	((priv_set_t *)(&(dp)->dps_sets[0]))
#define	DEVPLCYSYS_WRP(dp, ip)	\
			((priv_set_t *)(&(dp)->dps_sets[(ip)->priv_setsize]))

#define	DEVPLCY_TKN_RDP		"read_priv_set"
#define	DEVPLCY_TKN_WRP		"write_priv_set"

#endif /* _KERNEL */

#define	MAXDEVPOLICY		1000
#define	DEVPOLICY_DFLT_MAJ	((major_t)~0)

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_DEVPOLICY_H */