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