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