xref: /titanic_44/usr/src/cmd/devfsadm/devfsadm.h (revision 03831d35f7499c87d51205817c93e9a8d42c4bae)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _DEVFSADM_H
28 #define	_DEVFSADM_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <libdevinfo.h>
34 #include <sys/devinfo_impl.h>
35 #include <regex.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #define	DEVFSADM_SUCCESS 0
42 #define	DEVFSADM_FAILURE -1
43 #define	DEVFSADM_MULTIPLE -2
44 #define	DEVFSADM_TRUE 0
45 #define	DEVFSADM_FALSE -1
46 
47 #define	ILEVEL_0 0
48 #define	ILEVEL_1 1
49 #define	ILEVEL_2 2
50 #define	ILEVEL_3 3
51 #define	ILEVEL_4 4
52 #define	ILEVEL_5 5
53 #define	ILEVEL_6 6
54 #define	ILEVEL_7 7
55 #define	ILEVEL_8 8
56 #define	ILEVEL_9 9
57 
58 #define	DEVFSADM_V0 0
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 
71 #define	TYPE_EXACT 0x01
72 #define	TYPE_RE 0x02
73 #define	TYPE_PARTIAL 0x04
74 #define	TYPE_MASK 0x07
75 #define	DRV_EXACT 0x10
76 #define	DRV_RE 0x20
77 #define	DRV_MASK 0x30
78 #define	CREATE_DEFER 0x100
79 #define	CREATE_MASK 0x100
80 
81 /* command to start daemon */
82 #define	DEVFSADMD_START_PATH	"/usr/lib/devfsadm/devfsadmd"
83 #define	DEVFSADMD_START		"devfsadmd"
84 
85 /* devfsadm event service door */
86 #define	DEVFSADM_SERVICE_DOOR	"/etc/sysevent/devfsadm_event_channel"
87 
88 /* flags for devfsadm_mklink */
89 #define	DEV_SYNC 0x02	/* synchronous mklink */
90 
91 #define	INFO_MID		NULL		/* always prints */
92 #define	VERBOSE_MID		"verbose"	/* prints with -v */
93 #define	CHATTY_MID		"chatty" 	/* prints with -V chatty */
94 
95 typedef struct devfsadm_create {
96 	char	*device_class;	/* eg "disk", "tape", "display" */
97 	char	*node_type;	/* eg DDI_NT_TAPE, DDI_NT_BLOCK, etc */
98 	char	*drv_name;	/* eg sd, ssd */
99 	int	flags;		/* TYPE_{EXACT,RE,PARTIAL}, DRV_{EXACT,RE} */
100 	int interpose_lvl;	/* eg ILEVEL_0.. ILEVEL_10 */
101 	int (*callback_fcn)(di_minor_t minor, di_node_t node);
102 } devfsadm_create_t;
103 
104 typedef struct devfsadm_remove {
105 	char 	*device_class;	/* eg "disk", "tape", "display" */
106 	char    *dev_dirs_re;   /* dev dirs regex selector */
107 	int	flags;		/* eg POST, PRE, HOT, ALWAYS */
108 	int	interpose_lvl;	/* eg ILEVEL_0 .. ILEVEL_10 */
109 	void (*callback_fcn)(char *logical_link);
110 } devfsadm_remove_t;
111 
112 typedef struct _devfsadm_create_reg {
113 	uint_t version;
114 	uint_t count;	/* number of node type registration */
115 			/* structures */
116 	devfsadm_create_t *tblp;
117 } _devfsadm_create_reg_t;
118 
119 typedef struct _devfsadm_remove_reg {
120 	uint_t version;
121 	uint_t count;   /* number of node type registration */
122 			/* structures */
123 	devfsadm_remove_t *tblp;
124 } _devfsadm_remove_reg_t;
125 
126 
127 /*
128  * "flags" in the devfs_enumerate structure can take the following values.
129  * These values specify the substring of devfs path to be used for
130  * enumeration. Components (see MATCH_ADDR/MATCH_MINOR) may be specified
131  * by using the "match_arg" member in the devfsadm_enumerate structure.
132  */
133 #define	MATCH_ALL	0x001	/* Match entire devfs path */
134 #define	MATCH_PARENT	0x002	/* Match upto last '/' in devfs path */
135 #define	MATCH_ADDR	0x004	/* Match upto nth component of last address */
136 #define	MATCH_MINOR	0x008	/* Match upto nth component of minor name */
137 #define	MATCH_CALLBACK	0x010	/* Use callback to derive match string */
138 
139 /*
140  * The following flags are private to devfsadm and the disks module.
141  * NOT to be used by other modules.
142  */
143 #define	MATCH_NODE	0x020
144 #define	MATCH_MASK	0x03F
145 #define	MATCH_UNCACHED	0x040 /* retry flags for disks module */
146 
147 typedef struct devfsadm_enumerate {
148 	char *re;
149 	int subexp;
150 	uint_t flags;
151 	char *match_arg;
152 	char *(*sel_fcn)(const char *path, void *cb_arg);
153 	void *cb_arg;
154 } devfsadm_enumerate_t;
155 
156 #define	DEVFSADM_CREATE_INIT_V0(tbl) \
157 	_devfsadm_create_reg_t _devfsadm_create_reg = { \
158 	DEVFSADM_V0, \
159 	(sizeof (tbl) / sizeof (devfsadm_create_t)), \
160 	((devfsadm_create_t *)(tbl)) }
161 
162 #define	DEVFSADM_REMOVE_INIT_V0(tbl)\
163 	_devfsadm_remove_reg_t _devfsadm_remove_reg = {\
164 	DEVFSADM_V0, \
165 	(sizeof (tbl) / sizeof (devfsadm_remove_t)), \
166 	((devfsadm_remove_t *)(tbl)) }
167 
168 int devfsadm_noupdate(void);
169 const char *devfsadm_root_path(void);
170 int devfsadm_link_valid(char *link);
171 int devfsadm_mklink(char *link, di_node_t node, di_minor_t minor, int flags);
172 int devfsadm_secondary_link(char *link, char *primary_link, int flags);
173 void devfsadm_rm_link(char *file);
174 void devfsadm_rm_all(char *file);
175 void devfsadm_rm_stale_links(char *dir_re, char *valid_link, di_node_t node,
176 		di_minor_t minor);
177 void devfsadm_errprint(char *message, ...);
178 void devfsadm_print(char *mid, char *message, ...);
179 int devfsadm_enumerate_int(char *devfs_path, int index, char **buf,
180 			    devfsadm_enumerate_t rules[], int nrules);
181 int devfsadm_enumerate_char(char *devfs_path, int index, char **buf,
182 			    devfsadm_enumerate_t rules[], int nrules);
183 /*
184  * Private enumerate interface for disks and sgen modules
185  */
186 int disk_enumerate_int(char *devfs_path, int index, char **buf,
187 			    devfsadm_enumerate_t rules[], int nrules);
188 /*
189  * Private interfaces for ports module (port_link.c).
190  */
191 int devfsadm_enumerate_char_start(char *devfs_path, int index,
192     char **buf, devfsadm_enumerate_t rules[], int nrules, char *start);
193 int devfsadm_read_link(char *link, char **devfs_path);
194 char *s_strdup(const char *ptr);
195 
196 #ifdef	__cplusplus
197 }
198 #endif
199 
200 #endif	/* _DEVFSADM_H */
201