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