dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / devfsadm / devfsadm.h
blob3d801f66dbf018a4e11c496eb59219b12697ac6d
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
25 #ifndef _DEVFSADM_H
26 #define _DEVFSADM_H
28 #include <sys/types.h>
29 #include <libdevinfo.h>
30 #include <sys/devinfo_impl.h>
31 #include <regex.h>
33 #undef DEBUG
34 #ifndef DEBUG
35 #define NDEBUG 1
36 #else
37 #undef NDEBUG
38 #endif
40 #include <assert.h>
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
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
52 #define ILEVEL_0 0
53 #define ILEVEL_1 1
54 #define ILEVEL_2 2
55 #define ILEVEL_3 3
56 #define ILEVEL_4 4
57 #define ILEVEL_5 5
58 #define ILEVEL_6 6
59 #define ILEVEL_7 7
60 #define ILEVEL_8 8
61 #define ILEVEL_9 9
63 #define DEVFSADM_V0 0
64 #define DEVFSADM_V1 1
66 #define DEVFSADM_CONTINUE 0
67 #define DEVFSADM_TERMINATE 1
69 #define INTEGER 0
70 #define CHARACTER 1
72 #define RM_HOT 0x01
73 #define RM_PRE 0x02
74 #define RM_POST 0x04
75 #define RM_ALWAYS 0x08
76 #define RM_NOINTERPOSE 0x10
78 #define TYPE_EXACT 0x01
79 #define TYPE_RE 0x02
80 #define TYPE_PARTIAL 0x04
81 #define TYPE_MASK 0x07
82 #define DRV_EXACT 0x10
83 #define DRV_RE 0x20
84 #define DRV_MASK 0x30
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);
113 } devfsadm_create_t;
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 *);
121 } devfsadm_remove_t;
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 {
132 uint_t version;
133 uint_t count; /* number of node type registration */
134 /* structures */
135 devfsadm_create_t *tblp;
136 } _devfsadm_create_reg_t;
138 typedef struct _devfsadm_remove_reg {
139 uint_t version;
140 uint_t count; /* number of node type registration */
141 /* structures */
142 devfsadm_remove_t *tblp;
143 } _devfsadm_remove_reg_t;
145 typedef struct _devfsadm_remove_reg_V1 {
146 uint_t version;
147 uint_t count; /* number of node type registration */
148 /* structures */
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 {
172 char *re;
173 int subexp;
174 uint_t flags;
175 char *match_arg;
176 char *(*sel_fcn)(const char *path, void *cb_arg);
177 void *cb_arg;
178 } devfsadm_enumerate_t;
180 #define DEVFSADM_CREATE_INIT_V0(tbl) \
181 _devfsadm_create_reg_t _devfsadm_create_reg = { \
182 DEVFSADM_V0, \
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 = {\
188 DEVFSADM_V0, \
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 = {\
194 DEVFSADM_V1, \
195 (sizeof (tbl) / sizeof (devfsadm_remove_V1_t)), \
196 ((devfsadm_remove_V1_t *)(tbl)) }
198 /* reserved devname support */
199 typedef struct devlink_re {
200 char *d_re;
201 int d_subexp;
202 regex_t d_rcomp;
203 regmatch_t *d_pmatch;
204 } devlink_re_t;
206 typedef struct enumerate_file {
207 char *er_file;
208 char *er_id;
209 struct enumerate_file *er_next;
210 } enumerate_file_t;
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,
220 di_minor_t minor);
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);
251 #ifdef __cplusplus
253 #endif
255 #endif /* _DEVFSADM_H */