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.
23 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
29 #include <sys/types.h>
30 #include <libdevinfo.h>
31 #include <sys/devinfo_impl.h>
47 #define DEVFSADM_SUCCESS 0
48 #define DEVFSADM_FAILURE -1
49 #define DEVFSADM_MULTIPLE -2
50 #define DEVFSADM_TRUE 0
51 #define DEVFSADM_FALSE -1
67 #define DEVFSADM_CONTINUE 0
68 #define DEVFSADM_TERMINATE 1
76 #define RM_ALWAYS 0x08
77 #define RM_NOINTERPOSE 0x10
79 #define TYPE_EXACT 0x01
81 #define TYPE_PARTIAL 0x04
82 #define TYPE_MASK 0x07
83 #define DRV_EXACT 0x10
86 #define CREATE_DEFER 0x100
87 #define CREATE_MASK 0x100
89 /* command to start daemon */
90 #define DEVFSADMD_START_PATH "/usr/lib/devfsadm/devfsadmd"
91 #define DEVFSADMD_START "devfsadmd"
93 /* devfsadm event service door */
94 #define DEVFSADM_SERVICE_DOOR "/etc/sysevent/devfsadm_event_channel"
95 #define DEVNAME_LOOKUP_DOOR ".devname_lookup_door"
97 /* File of reserved devnames */
98 #define ENUMERATE_RESERVED "/etc/dev/reserved_devnames"
100 /* flags for devfsadm_mklink */
101 #define DEV_SYNC 0x02 /* synchronous mklink */
103 #define INFO_MID NULL /* always prints */
104 #define VERBOSE_MID "verbose" /* prints with -v */
105 #define CHATTY_MID "chatty" /* prints with -V chatty */
107 typedef struct devfsadm_create
{
108 char *device_class
; /* eg "disk", "tape", "display" */
109 char *node_type
; /* eg DDI_NT_TAPE, DDI_NT_BLOCK, etc */
110 char *drv_name
; /* eg sd, ssd */
111 int flags
; /* TYPE_{EXACT,RE,PARTIAL}, DRV_{EXACT,RE} */
112 int interpose_lvl
; /* eg ILEVEL_0.. ILEVEL_10 */
113 int (*callback_fcn
)(di_minor_t minor
, di_node_t node
);
116 typedef struct devfsadm_remove
{
117 char *device_class
; /* eg "disk", "tape", "display" */
118 char *dev_dirs_re
; /* dev dirs regex selector */
119 int flags
; /* eg POST, PRE, HOT, ALWAYS */
120 int interpose_lvl
; /* eg ILEVEL_0 .. ILEVEL_10 */
121 void (*callback_fcn
)(char *);
124 typedef struct devfsadm_remove_V1
{
125 char *device_class
; /* eg "disk", "tape", "display" */
126 char *dev_dirs_re
; /* dev dirs regex selector */
127 int flags
; /* eg POST, PRE, HOT, ALWAYS */
128 int interpose_lvl
; /* eg ILEVEL_0 .. ILEVEL_10 */
129 int (*callback_fcn
)(char *);
130 } devfsadm_remove_V1_t
;
132 typedef struct _devfsadm_create_reg
{
134 uint_t count
; /* number of node type registration */
136 devfsadm_create_t
*tblp
;
137 } _devfsadm_create_reg_t
;
139 typedef struct _devfsadm_remove_reg
{
141 uint_t count
; /* number of node type registration */
143 devfsadm_remove_t
*tblp
;
144 } _devfsadm_remove_reg_t
;
146 typedef struct _devfsadm_remove_reg_V1
{
148 uint_t count
; /* number of node type registration */
150 devfsadm_remove_V1_t
*tblp
;
151 } _devfsadm_remove_reg_V1_t
;
153 * "flags" in the devfs_enumerate structure can take the following values.
154 * These values specify the substring of devfs path to be used for
155 * enumeration. Components (see MATCH_ADDR/MATCH_MINOR) may be specified
156 * by using the "match_arg" member in the devfsadm_enumerate structure.
158 #define MATCH_ALL 0x001 /* Match entire devfs path */
159 #define MATCH_PARENT 0x002 /* Match upto last '/' in devfs path */
160 #define MATCH_ADDR 0x004 /* Match upto nth component of last address */
161 #define MATCH_MINOR 0x008 /* Match upto nth component of minor name */
162 #define MATCH_CALLBACK 0x010 /* Use callback to derive match string */
165 * The following flags are private to devfsadm and the disks module.
166 * NOT to be used by other modules.
168 #define MATCH_NODE 0x020
169 #define MATCH_MASK 0x03F
170 #define MATCH_UNCACHED 0x040 /* retry flags for disks module */
172 typedef struct devfsadm_enumerate
{
177 char *(*sel_fcn
)(const char *path
, void *cb_arg
);
179 } devfsadm_enumerate_t
;
181 #define DEVFSADM_CREATE_INIT_V0(tbl) \
182 _devfsadm_create_reg_t _devfsadm_create_reg = { \
184 (sizeof (tbl) / sizeof (devfsadm_create_t)), \
185 ((devfsadm_create_t *)(tbl)) }
187 #define DEVFSADM_REMOVE_INIT_V0(tbl)\
188 _devfsadm_remove_reg_t _devfsadm_remove_reg = {\
190 (sizeof (tbl) / sizeof (devfsadm_remove_t)), \
191 ((devfsadm_remove_t *)(tbl)) }
193 #define DEVFSADM_REMOVE_INIT_V1(tbl)\
194 _devfsadm_remove_reg_V1_t _devfsadm_remove_reg = {\
196 (sizeof (tbl) / sizeof (devfsadm_remove_V1_t)), \
197 ((devfsadm_remove_V1_t *)(tbl)) }
199 /* reserved devname support */
200 typedef struct devlink_re
{
204 regmatch_t
*d_pmatch
;
207 typedef struct enumerate_file
{
210 struct enumerate_file
*er_next
;
213 int devfsadm_noupdate(void);
214 const char *devfsadm_root_path(void);
215 int devfsadm_link_valid(di_node_t anynode
, char *link
);
216 int devfsadm_mklink(char *link
, di_node_t node
, di_minor_t minor
, int flags
);
217 int devfsadm_secondary_link(char *link
, char *primary_link
, int flags
);
218 void devfsadm_rm_link(char *file
);
219 void devfsadm_rm_all(char *file
);
220 void devfsadm_rm_stale_links(char *dir_re
, char *valid_link
, di_node_t node
,
222 void devfsadm_errprint(char *message
, ...);
223 void devfsadm_print(char *mid
, char *message
, ...);
224 int devfsadm_enumerate_int(char *devfs_path
, int index
, char **buf
,
225 devfsadm_enumerate_t rules
[], int nrules
);
226 int devfsadm_enumerate_char(char *devfs_path
, int index
, char **buf
,
227 devfsadm_enumerate_t rules
[], int nrules
);
228 char **devfsadm_lookup_dev_names(char *phys_path
, char *re
, int *lenp
);
229 void devfsadm_free_dev_names(char **dev_names
, int len
);
231 /* devlink cache related */
232 di_devlink_handle_t
devfsadm_devlink_cache(void);
235 * Private enumerate interface for controllers, disks, and sgen modules
237 int ctrl_enumerate_int(char *devfs_path
, int index
, char **buf
,
238 devfsadm_enumerate_t rules
[], int nrules
,
239 int multiple
, boolean_t scsi_vhci
);
241 * Private interfaces for ports module (port_link.c).
243 int devfsadm_enumerate_char_start(char *devfs_path
, int index
,
244 char **buf
, devfsadm_enumerate_t rules
[], int nrules
, char *start
);
245 int devfsadm_read_link(di_node_t node
, char *link
, char **devfs_path
);
246 char *s_strdup(const char *ptr
);
248 /* Private interface between reserve subsystm and disks link generator */
249 int devfsadm_have_reserved(void);
250 int devfsadm_is_reserved(devlink_re_t re_array
[], char *devlink
);
251 int devfsadm_reserve_id_cache(devlink_re_t re_array
[], enumerate_file_t
*head
);
257 #endif /* _DEVFSADM_H */