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