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