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