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