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.
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.
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]
22 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
28 #include <sys/types.h>
29 #include <libdevinfo.h>
30 #include <sys/devinfo_impl.h>
46 #define DEVFSADM_SUCCESS 0
47 #define DEVFSADM_FAILURE -1
48 #define DEVFSADM_MULTIPLE -2
49 #define DEVFSADM_TRUE 0
50 #define DEVFSADM_FALSE -1
66 #define DEVFSADM_CONTINUE 0
67 #define DEVFSADM_TERMINATE 1
75 #define RM_ALWAYS 0x08
76 #define RM_NOINTERPOSE 0x10
78 #define TYPE_EXACT 0x01
80 #define TYPE_PARTIAL 0x04
81 #define TYPE_MASK 0x07
82 #define DRV_EXACT 0x10
85 #define CREATE_DEFER 0x100
86 #define CREATE_MASK 0x100
88 /* command to start daemon */
89 #define DEVFSADMD_START_PATH "/usr/lib/devfsadm/devfsadmd"
90 #define DEVFSADMD_START "devfsadmd"
92 /* devfsadm event service door */
93 #define DEVFSADM_SERVICE_DOOR "/etc/sysevent/devfsadm_event_channel"
94 #define DEVNAME_LOOKUP_DOOR ".devname_lookup_door"
96 /* File of reserved devnames */
97 #define ENUMERATE_RESERVED "/etc/dev/reserved_devnames"
99 /* flags for devfsadm_mklink */
100 #define DEV_SYNC 0x02 /* synchronous mklink */
102 #define INFO_MID NULL /* always prints */
103 #define VERBOSE_MID "verbose" /* prints with -v */
104 #define CHATTY_MID "chatty" /* prints with -V chatty */
106 typedef struct devfsadm_create
{
107 char *device_class
; /* eg "disk", "tape", "display" */
108 char *node_type
; /* eg DDI_NT_TAPE, DDI_NT_BLOCK, etc */
109 char *drv_name
; /* eg sd, ssd */
110 int flags
; /* TYPE_{EXACT,RE,PARTIAL}, DRV_{EXACT,RE} */
111 int interpose_lvl
; /* eg ILEVEL_0.. ILEVEL_10 */
112 int (*callback_fcn
)(di_minor_t minor
, di_node_t node
);
115 typedef struct devfsadm_remove
{
116 char *device_class
; /* eg "disk", "tape", "display" */
117 char *dev_dirs_re
; /* dev dirs regex selector */
118 int flags
; /* eg POST, PRE, HOT, ALWAYS */
119 int interpose_lvl
; /* eg ILEVEL_0 .. ILEVEL_10 */
120 void (*callback_fcn
)(char *);
123 typedef struct devfsadm_remove_V1
{
124 char *device_class
; /* eg "disk", "tape", "display" */
125 char *dev_dirs_re
; /* dev dirs regex selector */
126 int flags
; /* eg POST, PRE, HOT, ALWAYS */
127 int interpose_lvl
; /* eg ILEVEL_0 .. ILEVEL_10 */
128 int (*callback_fcn
)(char *);
129 } devfsadm_remove_V1_t
;
131 typedef struct _devfsadm_create_reg
{
133 uint_t count
; /* number of node type registration */
135 devfsadm_create_t
*tblp
;
136 } _devfsadm_create_reg_t
;
138 typedef struct _devfsadm_remove_reg
{
140 uint_t count
; /* number of node type registration */
142 devfsadm_remove_t
*tblp
;
143 } _devfsadm_remove_reg_t
;
145 typedef struct _devfsadm_remove_reg_V1
{
147 uint_t count
; /* number of node type registration */
149 devfsadm_remove_V1_t
*tblp
;
150 } _devfsadm_remove_reg_V1_t
;
152 * "flags" in the devfs_enumerate structure can take the following values.
153 * These values specify the substring of devfs path to be used for
154 * enumeration. Components (see MATCH_ADDR/MATCH_MINOR) may be specified
155 * by using the "match_arg" member in the devfsadm_enumerate structure.
157 #define MATCH_ALL 0x001 /* Match entire devfs path */
158 #define MATCH_PARENT 0x002 /* Match upto last '/' in devfs path */
159 #define MATCH_ADDR 0x004 /* Match upto nth component of last address */
160 #define MATCH_MINOR 0x008 /* Match upto nth component of minor name */
161 #define MATCH_CALLBACK 0x010 /* Use callback to derive match string */
164 * The following flags are private to devfsadm and the disks module.
165 * NOT to be used by other modules.
167 #define MATCH_NODE 0x020
168 #define MATCH_MASK 0x03F
169 #define MATCH_UNCACHED 0x040 /* retry flags for disks module */
171 typedef struct devfsadm_enumerate
{
176 char *(*sel_fcn
)(const char *path
, void *cb_arg
);
178 } devfsadm_enumerate_t
;
180 #define DEVFSADM_CREATE_INIT_V0(tbl) \
181 _devfsadm_create_reg_t _devfsadm_create_reg = { \
183 (sizeof (tbl) / sizeof (devfsadm_create_t)), \
184 ((devfsadm_create_t *)(tbl)) }
186 #define DEVFSADM_REMOVE_INIT_V0(tbl)\
187 _devfsadm_remove_reg_t _devfsadm_remove_reg = {\
189 (sizeof (tbl) / sizeof (devfsadm_remove_t)), \
190 ((devfsadm_remove_t *)(tbl)) }
192 #define DEVFSADM_REMOVE_INIT_V1(tbl)\
193 _devfsadm_remove_reg_V1_t _devfsadm_remove_reg = {\
195 (sizeof (tbl) / sizeof (devfsadm_remove_V1_t)), \
196 ((devfsadm_remove_V1_t *)(tbl)) }
198 /* reserved devname support */
199 typedef struct devlink_re
{
203 regmatch_t
*d_pmatch
;
206 typedef struct enumerate_file
{
209 struct enumerate_file
*er_next
;
212 int devfsadm_noupdate(void);
213 const char *devfsadm_root_path(void);
214 int devfsadm_link_valid(di_node_t anynode
, char *link
);
215 int devfsadm_mklink(char *link
, di_node_t node
, di_minor_t minor
, int flags
);
216 int devfsadm_secondary_link(char *link
, char *primary_link
, int flags
);
217 void devfsadm_rm_link(char *file
);
218 void devfsadm_rm_all(char *file
);
219 void devfsadm_rm_stale_links(char *dir_re
, char *valid_link
, di_node_t node
,
221 void devfsadm_errprint(char *message
, ...);
222 void devfsadm_print(char *mid
, char *message
, ...);
223 int devfsadm_enumerate_int(char *devfs_path
, int index
, char **buf
,
224 devfsadm_enumerate_t rules
[], int nrules
);
225 int devfsadm_enumerate_char(char *devfs_path
, int index
, char **buf
,
226 devfsadm_enumerate_t rules
[], int nrules
);
227 char **devfsadm_lookup_dev_names(char *phys_path
, char *re
, int *lenp
);
228 void devfsadm_free_dev_names(char **dev_names
, int len
);
230 /* devlink cache related */
231 di_devlink_handle_t
devfsadm_devlink_cache(void);
234 * Private enumerate interface for disks and sgen modules
236 int disk_enumerate_int(char *devfs_path
, int index
, char **buf
,
237 devfsadm_enumerate_t rules
[], int nrules
);
239 * Private interfaces for ports module (port_link.c).
241 int devfsadm_enumerate_char_start(char *devfs_path
, int index
,
242 char **buf
, devfsadm_enumerate_t rules
[], int nrules
, char *start
);
243 int devfsadm_read_link(di_node_t node
, char *link
, char **devfs_path
);
244 char *s_strdup(const char *ptr
);
246 /* Private interface between reserve subsystm and disks link generator */
247 int devfsadm_have_reserved(void);
248 int devfsadm_is_reserved(devlink_re_t re_array
[], char *devlink
);
249 int devfsadm_reserve_id_cache(devlink_re_t re_array
[], enumerate_file_t
*head
);
255 #endif /* _DEVFSADM_H */