xref: /titanic_51/usr/src/cmd/devfsadm/devfsadm.h (revision a776e90690d98f629ab57f6493ff5949af9d65bd)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _DEVFSADM_H
27 #define	_DEVFSADM_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <libdevinfo.h>
33 #include <sys/devinfo_impl.h>
34 #include <regex.h>
35 
36 #undef	DEBUG
37 #ifndef DEBUG
38 #define	NDEBUG 1
39 #else
40 #undef	NDEBUG
41 #endif
42 
43 #include <assert.h>
44 
45 #ifdef	__cplusplus
46 extern "C" {
47 #endif
48 
49 #define	DEVFSADM_SUCCESS 0
50 #define	DEVFSADM_FAILURE -1
51 #define	DEVFSADM_MULTIPLE -2
52 #define	DEVFSADM_TRUE 0
53 #define	DEVFSADM_FALSE -1
54 
55 #define	ILEVEL_0 0
56 #define	ILEVEL_1 1
57 #define	ILEVEL_2 2
58 #define	ILEVEL_3 3
59 #define	ILEVEL_4 4
60 #define	ILEVEL_5 5
61 #define	ILEVEL_6 6
62 #define	ILEVEL_7 7
63 #define	ILEVEL_8 8
64 #define	ILEVEL_9 9
65 
66 #define	DEVFSADM_V0 0
67 #define	DEVFSADM_V1 1
68 
69 #define	DEVFSADM_CONTINUE 0
70 #define	DEVFSADM_TERMINATE 1
71 
72 #define	INTEGER 0
73 #define	CHARACTER 1
74 
75 #define	RM_HOT 0x01
76 #define	RM_PRE 0x02
77 #define	RM_POST 0x04
78 #define	RM_ALWAYS 0x08
79 #define	RM_NOINTERPOSE 0x10
80 
81 #define	TYPE_EXACT 0x01
82 #define	TYPE_RE 0x02
83 #define	TYPE_PARTIAL 0x04
84 #define	TYPE_MASK 0x07
85 #define	DRV_EXACT 0x10
86 #define	DRV_RE 0x20
87 #define	DRV_MASK 0x30
88 #define	CREATE_DEFER 0x100
89 #define	CREATE_MASK 0x100
90 
91 /* command to start daemon */
92 #define	DEVFSADMD_START_PATH	"/usr/lib/devfsadm/devfsadmd"
93 #define	DEVFSADMD_START		"devfsadmd"
94 
95 /* devfsadm event service door */
96 #define	DEVFSADM_SERVICE_DOOR	"/etc/sysevent/devfsadm_event_channel"
97 #define	DEVNAME_LOOKUP_DOOR	".devname_lookup_door"
98 
99 /* /dev device name binding rule locations */
100 #define	DEVNAME_MASTER_MAP	"/etc/dev/devname_master"
101 
102 /* File of reserved devnames */
103 #define	ENUMERATE_RESERVED "/etc/dev/reserved_devnames"
104 
105 /* flags for devfsadm_mklink */
106 #define	DEV_SYNC 0x02	/* synchronous mklink */
107 
108 #define	INFO_MID		NULL		/* always prints */
109 #define	VERBOSE_MID		"verbose"	/* prints with -v */
110 #define	CHATTY_MID		"chatty" 	/* prints with -V chatty */
111 
112 typedef struct devfsadm_create {
113 	char	*device_class;	/* eg "disk", "tape", "display" */
114 	char	*node_type;	/* eg DDI_NT_TAPE, DDI_NT_BLOCK, etc */
115 	char	*drv_name;	/* eg sd, ssd */
116 	int	flags;		/* TYPE_{EXACT,RE,PARTIAL}, DRV_{EXACT,RE} */
117 	int interpose_lvl;	/* eg ILEVEL_0.. ILEVEL_10 */
118 	int (*callback_fcn)(di_minor_t minor, di_node_t node);
119 } devfsadm_create_t;
120 
121 typedef struct devfsadm_remove {
122 	char 	*device_class;	/* eg "disk", "tape", "display" */
123 	char    *dev_dirs_re;   /* dev dirs regex selector */
124 	int	flags;		/* eg POST, PRE, HOT, ALWAYS */
125 	int	interpose_lvl;	/* eg ILEVEL_0 .. ILEVEL_10 */
126 	void	(*callback_fcn)(char *);
127 } devfsadm_remove_t;
128 
129 typedef struct devfsadm_remove_V1 {
130 	char 	*device_class;	/* eg "disk", "tape", "display" */
131 	char    *dev_dirs_re;   /* dev dirs regex selector */
132 	int	flags;		/* eg POST, PRE, HOT, ALWAYS */
133 	int	interpose_lvl;	/* eg ILEVEL_0 .. ILEVEL_10 */
134 	int	(*callback_fcn)(char *);
135 } devfsadm_remove_V1_t;
136 
137 typedef struct _devfsadm_create_reg {
138 	uint_t version;
139 	uint_t count;	/* number of node type registration */
140 			/* structures */
141 	devfsadm_create_t *tblp;
142 } _devfsadm_create_reg_t;
143 
144 typedef struct _devfsadm_remove_reg {
145 	uint_t version;
146 	uint_t count;   /* number of node type registration */
147 			/* structures */
148 	devfsadm_remove_t *tblp;
149 } _devfsadm_remove_reg_t;
150 
151 typedef struct _devfsadm_remove_reg_V1 {
152 	uint_t version;
153 	uint_t count;   /* number of node type registration */
154 			/* structures */
155 	devfsadm_remove_V1_t *tblp;
156 } _devfsadm_remove_reg_V1_t;
157 /*
158  * "flags" in the devfs_enumerate structure can take the following values.
159  * These values specify the substring of devfs path to be used for
160  * enumeration. Components (see MATCH_ADDR/MATCH_MINOR) may be specified
161  * by using the "match_arg" member in the devfsadm_enumerate structure.
162  */
163 #define	MATCH_ALL	0x001	/* Match entire devfs path */
164 #define	MATCH_PARENT	0x002	/* Match upto last '/' in devfs path */
165 #define	MATCH_ADDR	0x004	/* Match upto nth component of last address */
166 #define	MATCH_MINOR	0x008	/* Match upto nth component of minor name */
167 #define	MATCH_CALLBACK	0x010	/* Use callback to derive match string */
168 
169 /*
170  * The following flags are private to devfsadm and the disks module.
171  * NOT to be used by other modules.
172  */
173 #define	MATCH_NODE	0x020
174 #define	MATCH_MASK	0x03F
175 #define	MATCH_UNCACHED	0x040 /* retry flags for disks module */
176 
177 typedef struct devfsadm_enumerate {
178 	char *re;
179 	int subexp;
180 	uint_t flags;
181 	char *match_arg;
182 	char *(*sel_fcn)(const char *path, void *cb_arg);
183 	void *cb_arg;
184 } devfsadm_enumerate_t;
185 
186 #define	DEVFSADM_CREATE_INIT_V0(tbl) \
187 	_devfsadm_create_reg_t _devfsadm_create_reg = { \
188 	DEVFSADM_V0, \
189 	(sizeof (tbl) / sizeof (devfsadm_create_t)), \
190 	((devfsadm_create_t *)(tbl)) }
191 
192 #define	DEVFSADM_REMOVE_INIT_V0(tbl)\
193 	_devfsadm_remove_reg_t _devfsadm_remove_reg = {\
194 	DEVFSADM_V0, \
195 	(sizeof (tbl) / sizeof (devfsadm_remove_t)), \
196 	((devfsadm_remove_t *)(tbl)) }
197 
198 #define	DEVFSADM_REMOVE_INIT_V1(tbl)\
199 	_devfsadm_remove_reg_V1_t _devfsadm_remove_reg = {\
200 	DEVFSADM_V1, \
201 	(sizeof (tbl) / sizeof (devfsadm_remove_V1_t)), \
202 	((devfsadm_remove_V1_t *)(tbl)) }
203 
204 /* reserved devname support */
205 typedef struct devlink_re {
206 	char *d_re;
207 	int d_subexp;
208 	regex_t d_rcomp;
209 	regmatch_t *d_pmatch;
210 } devlink_re_t;
211 
212 typedef struct enumerate_file {
213 	char *er_file;
214 	char *er_id;
215 	struct enumerate_file *er_next;
216 } enumerate_file_t;
217 
218 int devfsadm_noupdate(void);
219 const char *devfsadm_root_path(void);
220 int devfsadm_link_valid(char *link);
221 int devfsadm_mklink(char *link, di_node_t node, di_minor_t minor, int flags);
222 int devfsadm_secondary_link(char *link, char *primary_link, int flags);
223 void devfsadm_rm_link(char *file);
224 void devfsadm_rm_all(char *file);
225 void devfsadm_rm_stale_links(char *dir_re, char *valid_link, di_node_t node,
226 		di_minor_t minor);
227 void devfsadm_errprint(char *message, ...);
228 void devfsadm_print(char *mid, char *message, ...);
229 int devfsadm_enumerate_int(char *devfs_path, int index, char **buf,
230 			    devfsadm_enumerate_t rules[], int nrules);
231 int devfsadm_enumerate_char(char *devfs_path, int index, char **buf,
232 			    devfsadm_enumerate_t rules[], int nrules);
233 char **devfsadm_lookup_dev_names(char *phys_path, char *re, int *lenp);
234 void devfsadm_free_dev_names(char **dev_names, int len);
235 
236 /* devlink cache related */
237 di_devlink_handle_t devfsadm_devlink_cache(void);
238 
239 /*
240  * Private enumerate interface for disks and sgen modules
241  */
242 int disk_enumerate_int(char *devfs_path, int index, char **buf,
243 			    devfsadm_enumerate_t rules[], int nrules);
244 /*
245  * Private interfaces for ports module (port_link.c).
246  */
247 int devfsadm_enumerate_char_start(char *devfs_path, int index,
248     char **buf, devfsadm_enumerate_t rules[], int nrules, char *start);
249 int devfsadm_read_link(char *link, char **devfs_path);
250 char *s_strdup(const char *ptr);
251 
252 /* Private interface between reserve subsystm and disks link generator */
253 int devfsadm_have_reserved(void);
254 int devfsadm_is_reserved(devlink_re_t re_array[], char *devlink);
255 int devfsadm_reserve_id_cache(devlink_re_t re_array[], enumerate_file_t *head);
256 
257 #ifdef	__cplusplus
258 }
259 #endif
260 
261 #endif	/* _DEVFSADM_H */
262