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 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 23*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #ifndef _DEVFSADM_IMPL_H 27*7c478bd9Sstevel@tonic-gate #define _DEVFSADM_IMPL_H 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 32*7c478bd9Sstevel@tonic-gate extern "C" { 33*7c478bd9Sstevel@tonic-gate #endif 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include <dlfcn.h> 36*7c478bd9Sstevel@tonic-gate #include <stdarg.h> 37*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/file.h> 39*7c478bd9Sstevel@tonic-gate #include <locale.h> 40*7c478bd9Sstevel@tonic-gate #include <libintl.h> 41*7c478bd9Sstevel@tonic-gate #include <ctype.h> 42*7c478bd9Sstevel@tonic-gate #include <signal.h> 43*7c478bd9Sstevel@tonic-gate #include <deflt.h> 44*7c478bd9Sstevel@tonic-gate #include <ftw.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/instance.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 47*7c478bd9Sstevel@tonic-gate #include <dirent.h> 48*7c478bd9Sstevel@tonic-gate #include <pwd.h> 49*7c478bd9Sstevel@tonic-gate #include <grp.h> 50*7c478bd9Sstevel@tonic-gate #include <stdio.h> 51*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 52*7c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 53*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 54*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 55*7c478bd9Sstevel@tonic-gate #include <errno.h> 56*7c478bd9Sstevel@tonic-gate #include <unistd.h> 57*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 58*7c478bd9Sstevel@tonic-gate #include <sys/int_types.h> 59*7c478bd9Sstevel@tonic-gate #include <limits.h> 60*7c478bd9Sstevel@tonic-gate #include <strings.h> 61*7c478bd9Sstevel@tonic-gate #include <devfsadm.h> 62*7c478bd9Sstevel@tonic-gate #include <libdevinfo.h> 63*7c478bd9Sstevel@tonic-gate #include <sys/devinfo_impl.h> 64*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 65*7c478bd9Sstevel@tonic-gate #include <libgen.h> 66*7c478bd9Sstevel@tonic-gate #include <sys/hwconf.h> 67*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 68*7c478bd9Sstevel@tonic-gate #include <door.h> 69*7c478bd9Sstevel@tonic-gate #include <syslog.h> 70*7c478bd9Sstevel@tonic-gate #include <libsysevent.h> 71*7c478bd9Sstevel@tonic-gate #include <thread.h> 72*7c478bd9Sstevel@tonic-gate #include <message.h> 73*7c478bd9Sstevel@tonic-gate #include <sys/cladm.h> 74*7c478bd9Sstevel@tonic-gate #include <librcm.h> 75*7c478bd9Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 76*7c478bd9Sstevel@tonic-gate #include <sys/sysevent/dev.h> 77*7c478bd9Sstevel@tonic-gate #include <libzonecfg.h> 78*7c478bd9Sstevel@tonic-gate #include <device_info.h> 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate #undef DEBUG 81*7c478bd9Sstevel@tonic-gate #ifndef DEBUG 82*7c478bd9Sstevel@tonic-gate #define NDEBUG 1 83*7c478bd9Sstevel@tonic-gate #else 84*7c478bd9Sstevel@tonic-gate #undef NDEBUG 85*7c478bd9Sstevel@tonic-gate #endif 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate #include <assert.h> 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate #define DEV_LOCK_FILE ".devfsadm_dev.lock" 91*7c478bd9Sstevel@tonic-gate #define DAEMON_LOCK_FILE ".devfsadm_daemon.lock" 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate #define DEV "/dev" 94*7c478bd9Sstevel@tonic-gate #define DEV_LEN 4 95*7c478bd9Sstevel@tonic-gate #define DEVICES "/devices" 96*7c478bd9Sstevel@tonic-gate #define DEVICES_LEN 8 97*7c478bd9Sstevel@tonic-gate #define MODULE_DIRS "/usr/lib/devfsadm/linkmod" 98*7c478bd9Sstevel@tonic-gate #define ALIASFILE "/etc/driver_aliases" 99*7c478bd9Sstevel@tonic-gate #define NAME_TO_MAJOR "/etc/name_to_major" 100*7c478bd9Sstevel@tonic-gate #define RECONFIG_BOOT "_INIT_RECONFIG" 101*7c478bd9Sstevel@tonic-gate #define PID_STR_LEN 10 102*7c478bd9Sstevel@tonic-gate #define EXTRA_PRIVS "/etc/security/extra_privs" 103*7c478bd9Sstevel@tonic-gate #define DEV_POLICY "/etc/security/device_policy" 104*7c478bd9Sstevel@tonic-gate #define LDEV_FILE "/etc/logindevperm" 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate #define DEVFSADM_DEFAULT_FILE "/etc/default/devfsadm" 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate #define MINOR_FINI_TIMEOUT_DEFAULT 2 109*7c478bd9Sstevel@tonic-gate #define FORCE_CALL_MINOR_FINI 10 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate #define SYNCH_DOOR_PERMS (S_IRUSR | S_IWUSR) 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate #define ZONE_DOOR_PERMS (S_IRUSR | S_IWUSR) 115*7c478bd9Sstevel@tonic-gate #define ZONE_REG_DOOR ".zone_reg_door" 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate enum zreg_op { 118*7c478bd9Sstevel@tonic-gate ZONE_REG = 1, 119*7c478bd9Sstevel@tonic-gate ZONE_UNREG = 2 120*7c478bd9Sstevel@tonic-gate }; 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate enum zreg_err { 123*7c478bd9Sstevel@tonic-gate ZONE_SUCCESS = 0, 124*7c478bd9Sstevel@tonic-gate ZONE_ERR_NOZONE = 1, 125*7c478bd9Sstevel@tonic-gate ZONE_ERR_DOOR = 2, 126*7c478bd9Sstevel@tonic-gate ZONE_ERR_REPOSITORY = 3, 127*7c478bd9Sstevel@tonic-gate ZONE_ERR_NOLIB = 4 128*7c478bd9Sstevel@tonic-gate }; 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate struct zreg { 131*7c478bd9Sstevel@tonic-gate char zreg_zonename[ZONENAME_MAX]; 132*7c478bd9Sstevel@tonic-gate enum zreg_op zreg_op; 133*7c478bd9Sstevel@tonic-gate enum zreg_err zreg_error; 134*7c478bd9Sstevel@tonic-gate int zreg_errno; 135*7c478bd9Sstevel@tonic-gate }; 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate #define DRVCONFIG "drvconfig" 138*7c478bd9Sstevel@tonic-gate #define DEVFSADM "devfsadm" 139*7c478bd9Sstevel@tonic-gate #define DEVFSADMD "devfsadmd" 140*7c478bd9Sstevel@tonic-gate #define DEVLINKS "devlinks" 141*7c478bd9Sstevel@tonic-gate #define TAPES "tapes" 142*7c478bd9Sstevel@tonic-gate #define AUDLINKS "audlinks" 143*7c478bd9Sstevel@tonic-gate #define PORTS "ports" 144*7c478bd9Sstevel@tonic-gate #define DISKS "disks" 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate #define MAX_IDLE_DELAY 5 147*7c478bd9Sstevel@tonic-gate #define MAX_DELAY 30 148*7c478bd9Sstevel@tonic-gate #define NAME 0x01 149*7c478bd9Sstevel@tonic-gate #define ADDR 0x03 150*7c478bd9Sstevel@tonic-gate #define MINOR 0x04 151*7c478bd9Sstevel@tonic-gate #define COUNTER 0x05 152*7c478bd9Sstevel@tonic-gate #define CONSTANT 0x06 153*7c478bd9Sstevel@tonic-gate #define TYPE 0x07 154*7c478bd9Sstevel@tonic-gate #define TYPE_S "type" 155*7c478bd9Sstevel@tonic-gate #define ADDR_S "addr" 156*7c478bd9Sstevel@tonic-gate #define ADDR_S_LEN 4 157*7c478bd9Sstevel@tonic-gate #define MINOR_S "minor" 158*7c478bd9Sstevel@tonic-gate #define MINOR_S_LEN 5 159*7c478bd9Sstevel@tonic-gate #define NAME_S "name" 160*7c478bd9Sstevel@tonic-gate #define TAB '\t' 161*7c478bd9Sstevel@tonic-gate #define NEWLINE '\n' 162*7c478bd9Sstevel@tonic-gate #define MAX_DEVLINK_LINE 4028 163*7c478bd9Sstevel@tonic-gate #define INTEGER 0 164*7c478bd9Sstevel@tonic-gate #define LETTER 1 165*7c478bd9Sstevel@tonic-gate #define MAX_PERM_LINE 256 166*7c478bd9Sstevel@tonic-gate #define MAX_LDEV_LINE 256 167*7c478bd9Sstevel@tonic-gate #define LDEV_DELIMS " \t\n" 168*7c478bd9Sstevel@tonic-gate #define LDEV_DRVLIST_DELIMS "=" 169*7c478bd9Sstevel@tonic-gate #define LDEV_DRV_DELIMS ", \t\n" 170*7c478bd9Sstevel@tonic-gate #define LDEV_DEV_DELIM ":" 171*7c478bd9Sstevel@tonic-gate #define LDEV_DRVLIST_NAME "driver" 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate #define TYPE_LINK 0x00 174*7c478bd9Sstevel@tonic-gate #define TYPE_DEVICES 0x01 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate #define CREATE_LINK 0x01 177*7c478bd9Sstevel@tonic-gate #define READ_LINK 0x02 178*7c478bd9Sstevel@tonic-gate #define CREATE_NODE 0x01 179*7c478bd9Sstevel@tonic-gate #define READ_NODE 0x02 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate #define DCA_CREATE_LINK 0x01 182*7c478bd9Sstevel@tonic-gate #define DCA_FREE_LIST 0x02 183*7c478bd9Sstevel@tonic-gate #define DCA_LOAD_DRV 0x04 184*7c478bd9Sstevel@tonic-gate #define DCA_CHECK_TYPE 0x10 185*7c478bd9Sstevel@tonic-gate #define DCA_NOTIFY_RCM 0x20 186*7c478bd9Sstevel@tonic-gate #define DCA_FLUSH_PATHINST 0x40 187*7c478bd9Sstevel@tonic-gate #define DCA_HOT_PLUG 0x80 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate #define CACHE_STATE 0x0 190*7c478bd9Sstevel@tonic-gate #define SYNC_STATE 0x1 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate #define MODULE_ACTIVE 0x01 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate #define MAX_SLEEP 120 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate #define DEVLINKTAB_FILE "/etc/devlink.tab" 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate #define MODULE_SUFFIX ".so" 199*7c478bd9Sstevel@tonic-gate #define MINOR_INIT "minor_init" 200*7c478bd9Sstevel@tonic-gate #define MINOR_FINI "minor_fini" 201*7c478bd9Sstevel@tonic-gate #define _DEVFSADM_CREATE_REG "_devfsadm_create_reg" 202*7c478bd9Sstevel@tonic-gate #define _DEVFSADM_REMOVE_REG "_devfsadm_remove_reg" 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate #define NUM_EV_STR 4 205*7c478bd9Sstevel@tonic-gate #define EV_TYPE 0 206*7c478bd9Sstevel@tonic-gate #define EV_CLASS 1 207*7c478bd9Sstevel@tonic-gate #define EV_PATH_NAME 2 208*7c478bd9Sstevel@tonic-gate #define EV_MINOR_NAME 3 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate /* add new debug level and meanings here */ 211*7c478bd9Sstevel@tonic-gate #define DEVLINK_MID "devfsadm:devlink" 212*7c478bd9Sstevel@tonic-gate #define MODLOAD_MID "devfsadm:modload" 213*7c478bd9Sstevel@tonic-gate #define INITFINI_MID "devfsadm:initfini" 214*7c478bd9Sstevel@tonic-gate #define EVENT_MID "devfsadm:event" 215*7c478bd9Sstevel@tonic-gate #define REMOVE_MID "devfsadm:remove" 216*7c478bd9Sstevel@tonic-gate #define LOCK_MID "devfsadm:lock" 217*7c478bd9Sstevel@tonic-gate #define PATH2INST_MID "devfsadm:path2inst" 218*7c478bd9Sstevel@tonic-gate #define CACHE_MID "devfsadm:cache" 219*7c478bd9Sstevel@tonic-gate #define BUILDCACHE_MID "devfsadm:buildcache" 220*7c478bd9Sstevel@tonic-gate #define RECURSEDEV_MID "devfsadm:recursedev" 221*7c478bd9Sstevel@tonic-gate #define INSTSYNC_MID "devfsadm:instsync" 222*7c478bd9Sstevel@tonic-gate #define FILES_MID "devfsadm:files" 223*7c478bd9Sstevel@tonic-gate #define ENUM_MID "devfsadm:enum" 224*7c478bd9Sstevel@tonic-gate #define LINKCACHE_MID "devfsadm:linkcache" 225*7c478bd9Sstevel@tonic-gate #define ADDREMCACHE_MID "devfsadm:addremcache" 226*7c478bd9Sstevel@tonic-gate #define MALLOC_MID "devfsadm:malloc" 227*7c478bd9Sstevel@tonic-gate #define ZONE_MID "devfsadm:zone" 228*7c478bd9Sstevel@tonic-gate #define ALL_MID "all" 229*7c478bd9Sstevel@tonic-gate 230*7c478bd9Sstevel@tonic-gate #define DEVFSADM_DEBUG_ON (verbose == NULL) ? FALSE : TRUE 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate typedef struct recurse_dev { 233*7c478bd9Sstevel@tonic-gate void (*fcn)(char *, void *); 234*7c478bd9Sstevel@tonic-gate void *data; 235*7c478bd9Sstevel@tonic-gate } recurse_dev_t; 236*7c478bd9Sstevel@tonic-gate 237*7c478bd9Sstevel@tonic-gate typedef struct link { 238*7c478bd9Sstevel@tonic-gate char *devlink; /* without ".../dev/" prefix */ 239*7c478bd9Sstevel@tonic-gate char *contents; /* without "../devices" prefix */ 240*7c478bd9Sstevel@tonic-gate struct link *next; 241*7c478bd9Sstevel@tonic-gate } link_t; 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate typedef struct linkhead { 244*7c478bd9Sstevel@tonic-gate regex_t dir_re_compiled; 245*7c478bd9Sstevel@tonic-gate char *dir_re; 246*7c478bd9Sstevel@tonic-gate link_t *link; 247*7c478bd9Sstevel@tonic-gate link_t *nextlink; 248*7c478bd9Sstevel@tonic-gate struct linkhead *nexthead; 249*7c478bd9Sstevel@tonic-gate } linkhead_t; 250*7c478bd9Sstevel@tonic-gate 251*7c478bd9Sstevel@tonic-gate typedef struct link_list { 252*7c478bd9Sstevel@tonic-gate int type; 253*7c478bd9Sstevel@tonic-gate char *constant; 254*7c478bd9Sstevel@tonic-gate int arg; 255*7c478bd9Sstevel@tonic-gate struct link_list *next; 256*7c478bd9Sstevel@tonic-gate } link_list_t; 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate typedef struct selector_list { 259*7c478bd9Sstevel@tonic-gate int key; 260*7c478bd9Sstevel@tonic-gate char *val; 261*7c478bd9Sstevel@tonic-gate int arg; 262*7c478bd9Sstevel@tonic-gate struct selector_list *next; 263*7c478bd9Sstevel@tonic-gate } selector_list_t; 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate typedef struct devlinktab_list { 266*7c478bd9Sstevel@tonic-gate int line_number; 267*7c478bd9Sstevel@tonic-gate char *selector_pattern; 268*7c478bd9Sstevel@tonic-gate char *p_link_pattern; 269*7c478bd9Sstevel@tonic-gate char *s_link_pattern; 270*7c478bd9Sstevel@tonic-gate selector_list_t *selector; 271*7c478bd9Sstevel@tonic-gate link_list_t *p_link; 272*7c478bd9Sstevel@tonic-gate link_list_t *s_link; 273*7c478bd9Sstevel@tonic-gate struct devlinktab_list *next; 274*7c478bd9Sstevel@tonic-gate } devlinktab_list_t; 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate typedef struct module { 277*7c478bd9Sstevel@tonic-gate char *name; 278*7c478bd9Sstevel@tonic-gate void *dlhandle; 279*7c478bd9Sstevel@tonic-gate int (*minor_init)(); 280*7c478bd9Sstevel@tonic-gate int (*minor_fini)(); 281*7c478bd9Sstevel@tonic-gate int flags; 282*7c478bd9Sstevel@tonic-gate struct module *next; 283*7c478bd9Sstevel@tonic-gate } module_t; 284*7c478bd9Sstevel@tonic-gate 285*7c478bd9Sstevel@tonic-gate typedef struct create_list { 286*7c478bd9Sstevel@tonic-gate devfsadm_create_t *create; 287*7c478bd9Sstevel@tonic-gate module_t *modptr; 288*7c478bd9Sstevel@tonic-gate regex_t node_type_comp; 289*7c478bd9Sstevel@tonic-gate regex_t drv_name_comp; 290*7c478bd9Sstevel@tonic-gate struct create_list *next; 291*7c478bd9Sstevel@tonic-gate } create_list_t; 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate struct minor { 294*7c478bd9Sstevel@tonic-gate di_node_t node; 295*7c478bd9Sstevel@tonic-gate di_minor_t minor; 296*7c478bd9Sstevel@tonic-gate struct minor *next; 297*7c478bd9Sstevel@tonic-gate }; 298*7c478bd9Sstevel@tonic-gate 299*7c478bd9Sstevel@tonic-gate struct mlist { 300*7c478bd9Sstevel@tonic-gate struct minor *head; 301*7c478bd9Sstevel@tonic-gate struct minor *tail; 302*7c478bd9Sstevel@tonic-gate }; 303*7c478bd9Sstevel@tonic-gate 304*7c478bd9Sstevel@tonic-gate typedef struct remove_list { 305*7c478bd9Sstevel@tonic-gate devfsadm_remove_t *remove; 306*7c478bd9Sstevel@tonic-gate module_t *modptr; 307*7c478bd9Sstevel@tonic-gate struct remove_list *next; 308*7c478bd9Sstevel@tonic-gate } remove_list_t; 309*7c478bd9Sstevel@tonic-gate 310*7c478bd9Sstevel@tonic-gate typedef struct cleanup_data { 311*7c478bd9Sstevel@tonic-gate int flags; 312*7c478bd9Sstevel@tonic-gate char *phypath; 313*7c478bd9Sstevel@tonic-gate remove_list_t *rm; 314*7c478bd9Sstevel@tonic-gate } cleanup_data_t; 315*7c478bd9Sstevel@tonic-gate 316*7c478bd9Sstevel@tonic-gate typedef struct n2m { 317*7c478bd9Sstevel@tonic-gate major_t major; 318*7c478bd9Sstevel@tonic-gate char *driver; 319*7c478bd9Sstevel@tonic-gate struct n2m *next; 320*7c478bd9Sstevel@tonic-gate } n2m_t; 321*7c478bd9Sstevel@tonic-gate 322*7c478bd9Sstevel@tonic-gate /* structures for devfsadm_enumerate() */ 323*7c478bd9Sstevel@tonic-gate typedef struct numeral { 324*7c478bd9Sstevel@tonic-gate char *id; 325*7c478bd9Sstevel@tonic-gate char *full_path; 326*7c478bd9Sstevel@tonic-gate int rule_index; 327*7c478bd9Sstevel@tonic-gate char *cmp_str; 328*7c478bd9Sstevel@tonic-gate struct numeral *next; 329*7c478bd9Sstevel@tonic-gate } numeral_t; 330*7c478bd9Sstevel@tonic-gate 331*7c478bd9Sstevel@tonic-gate typedef struct numeral_set { 332*7c478bd9Sstevel@tonic-gate int re_count; 333*7c478bd9Sstevel@tonic-gate char **re; 334*7c478bd9Sstevel@tonic-gate numeral_t *headnumeral; 335*7c478bd9Sstevel@tonic-gate struct numeral_set *next; 336*7c478bd9Sstevel@tonic-gate } numeral_set_t; 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate typedef struct temp { 339*7c478bd9Sstevel@tonic-gate int integer; 340*7c478bd9Sstevel@tonic-gate struct temp *next; 341*7c478bd9Sstevel@tonic-gate } temp_t; 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate typedef struct driver_alias { 344*7c478bd9Sstevel@tonic-gate char *driver_name; 345*7c478bd9Sstevel@tonic-gate char *alias_name; 346*7c478bd9Sstevel@tonic-gate struct driver_alias *next; 347*7c478bd9Sstevel@tonic-gate } driver_alias_t; 348*7c478bd9Sstevel@tonic-gate 349*7c478bd9Sstevel@tonic-gate struct driver_list { 350*7c478bd9Sstevel@tonic-gate char driver_name[MAXNAMELEN]; 351*7c478bd9Sstevel@tonic-gate struct driver_list *next; 352*7c478bd9Sstevel@tonic-gate }; 353*7c478bd9Sstevel@tonic-gate 354*7c478bd9Sstevel@tonic-gate struct login_dev { 355*7c478bd9Sstevel@tonic-gate char *ldev_console; 356*7c478bd9Sstevel@tonic-gate int ldev_perms; 357*7c478bd9Sstevel@tonic-gate char *ldev_device; 358*7c478bd9Sstevel@tonic-gate regex_t ldev_device_regex; 359*7c478bd9Sstevel@tonic-gate struct driver_list *ldev_driver_list; 360*7c478bd9Sstevel@tonic-gate struct login_dev *ldev_next; 361*7c478bd9Sstevel@tonic-gate }; 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate #define MAX_DEV_NAME_COUNT 100 364*7c478bd9Sstevel@tonic-gate struct devlink_cb_arg { 365*7c478bd9Sstevel@tonic-gate char *dev_names[MAX_DEV_NAME_COUNT]; 366*7c478bd9Sstevel@tonic-gate char *link_contents[MAX_DEV_NAME_COUNT]; 367*7c478bd9Sstevel@tonic-gate int count; 368*7c478bd9Sstevel@tonic-gate int rv; 369*7c478bd9Sstevel@tonic-gate }; 370*7c478bd9Sstevel@tonic-gate 371*7c478bd9Sstevel@tonic-gate struct dca_impl { 372*7c478bd9Sstevel@tonic-gate char *dci_root; 373*7c478bd9Sstevel@tonic-gate char *dci_minor; 374*7c478bd9Sstevel@tonic-gate char *dci_driver; 375*7c478bd9Sstevel@tonic-gate void *dci_arg; 376*7c478bd9Sstevel@tonic-gate int dci_error; 377*7c478bd9Sstevel@tonic-gate int dci_flags; 378*7c478bd9Sstevel@tonic-gate }; 379*7c478bd9Sstevel@tonic-gate 380*7c478bd9Sstevel@tonic-gate struct zone_devinfo { 381*7c478bd9Sstevel@tonic-gate struct zone_devinfo *zone_next; 382*7c478bd9Sstevel@tonic-gate char *zone_path; 383*7c478bd9Sstevel@tonic-gate char *zone_name; 384*7c478bd9Sstevel@tonic-gate zone_dochandle_t zone_dochdl; 385*7c478bd9Sstevel@tonic-gate }; 386*7c478bd9Sstevel@tonic-gate 387*7c478bd9Sstevel@tonic-gate /* RCM related */ 388*7c478bd9Sstevel@tonic-gate struct rcm_eventq { 389*7c478bd9Sstevel@tonic-gate nvlist_t *nvl; 390*7c478bd9Sstevel@tonic-gate struct rcm_eventq *next; 391*7c478bd9Sstevel@tonic-gate }; 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate static int devfsadm_enumerate_int_start(char *devfs_path, 394*7c478bd9Sstevel@tonic-gate int index, char **buf, devfsadm_enumerate_t rules[], 395*7c478bd9Sstevel@tonic-gate int nrules, char *start); 396*7c478bd9Sstevel@tonic-gate static void startup_cache_sync_thread(void); 397*7c478bd9Sstevel@tonic-gate static void set_root_devices_dev_dir(char *dir, int zone_mode); 398*7c478bd9Sstevel@tonic-gate static void pre_and_post_cleanup(int flags); 399*7c478bd9Sstevel@tonic-gate static void hot_cleanup(char *, char *, char *, char *, int); 400*7c478bd9Sstevel@tonic-gate static void devfsadm_exit(int status); 401*7c478bd9Sstevel@tonic-gate static void rm_link_from_cache(char *devlink); 402*7c478bd9Sstevel@tonic-gate static void rm_all_links_from_cache(); 403*7c478bd9Sstevel@tonic-gate static void add_link_to_cache(char *devlink, char *physpath); 404*7c478bd9Sstevel@tonic-gate static linkhead_t *get_cached_links(char *dir_re); 405*7c478bd9Sstevel@tonic-gate static void build_devlink_list(char *check_link, void *data); 406*7c478bd9Sstevel@tonic-gate static void instance_flush_thread(void); 407*7c478bd9Sstevel@tonic-gate static void s_rmdir(char *path); 408*7c478bd9Sstevel@tonic-gate static void rm_parent_dir_if_empty(char *path); 409*7c478bd9Sstevel@tonic-gate static void free_link_list(link_list_t *head); 410*7c478bd9Sstevel@tonic-gate static void free_selector_list(selector_list_t *head); 411*7c478bd9Sstevel@tonic-gate void devfsadm_err_print(char *message, ...); 412*7c478bd9Sstevel@tonic-gate void defvsadm_print(int level, char *message, ...); 413*7c478bd9Sstevel@tonic-gate static int call_minor_init(module_t *module); 414*7c478bd9Sstevel@tonic-gate static void load_module(char *module, char *cdir); 415*7c478bd9Sstevel@tonic-gate static void invalidate_enumerate_cache(void); 416*7c478bd9Sstevel@tonic-gate static pid_t enter_dev_lock(void); 417*7c478bd9Sstevel@tonic-gate static void exit_dev_lock(void); 418*7c478bd9Sstevel@tonic-gate static pid_t enter_daemon_lock(void); 419*7c478bd9Sstevel@tonic-gate static void exit_daemon_lock(void); 420*7c478bd9Sstevel@tonic-gate static int process_devlink_compat(di_minor_t minor, di_node_t node); 421*7c478bd9Sstevel@tonic-gate static int alias(char *, char *); 422*7c478bd9Sstevel@tonic-gate static int devfsadm_copy(void); 423*7c478bd9Sstevel@tonic-gate static void flush_path_to_inst(void); 424*7c478bd9Sstevel@tonic-gate static void detachfromtty(void); 425*7c478bd9Sstevel@tonic-gate static void minor_process(di_node_t node, di_minor_t minor, 426*7c478bd9Sstevel@tonic-gate struct mlist *dep); 427*7c478bd9Sstevel@tonic-gate static void read_minor_perm_file(void); 428*7c478bd9Sstevel@tonic-gate static void read_driver_aliases_file(void); 429*7c478bd9Sstevel@tonic-gate static void load_modules(void); 430*7c478bd9Sstevel@tonic-gate static void unload_modules(void); 431*7c478bd9Sstevel@tonic-gate static void *s_malloc(const size_t size); 432*7c478bd9Sstevel@tonic-gate static void *s_zalloc(const size_t size); 433*7c478bd9Sstevel@tonic-gate static void devfs_instance_mod(void); 434*7c478bd9Sstevel@tonic-gate static void add_minor_pathname(char *, char *, char *); 435*7c478bd9Sstevel@tonic-gate static int check_minor_type(di_node_t node, di_minor_t minor, void *arg); 436*7c478bd9Sstevel@tonic-gate static void cache_deferred_minor(struct mlist *dep, di_node_t node, 437*7c478bd9Sstevel@tonic-gate di_minor_t minor); 438*7c478bd9Sstevel@tonic-gate static int compare_field(char *full_name, char *field_item, int field); 439*7c478bd9Sstevel@tonic-gate static int component_cat(char *link, char *name, int field); 440*7c478bd9Sstevel@tonic-gate static void recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd); 441*7c478bd9Sstevel@tonic-gate static void matching_dev(char *devpath, void *data); 442*7c478bd9Sstevel@tonic-gate static int resolve_link(char *devpath, char **content_p, int *type_p, 443*7c478bd9Sstevel@tonic-gate char **devfs_path, int dangle); 444*7c478bd9Sstevel@tonic-gate static int clean_ok(devfsadm_remove_t *remove); 445*7c478bd9Sstevel@tonic-gate static int translate_major(dev_t old_dev, dev_t *new_dev); 446*7c478bd9Sstevel@tonic-gate static int get_major_no(char *driver, major_t *major); 447*7c478bd9Sstevel@tonic-gate static int load_n2m_table(char *filename); 448*7c478bd9Sstevel@tonic-gate static int get_stat_info(char *, struct stat *); 449*7c478bd9Sstevel@tonic-gate static char *new_id(numeral_t *, int, char *); 450*7c478bd9Sstevel@tonic-gate static int find_enum_id(devfsadm_enumerate_t rules[], int nrules, 451*7c478bd9Sstevel@tonic-gate char *devfs_path, int index, char *min, int type, char **buf, int multiple); 452*7c478bd9Sstevel@tonic-gate static void daemon_update(void); 453*7c478bd9Sstevel@tonic-gate static void usage(void); 454*7c478bd9Sstevel@tonic-gate static int getnexttoken(char *next, char **nextp, char **tokenpp, char *tchar); 455*7c478bd9Sstevel@tonic-gate static int class_ok(char *class); 456*7c478bd9Sstevel@tonic-gate static int create_link_common(char *devlink, char *contents, int *exists); 457*7c478bd9Sstevel@tonic-gate static char *dequote(char *src); 458*7c478bd9Sstevel@tonic-gate static void parse_args(int argc, char *argv[]); 459*7c478bd9Sstevel@tonic-gate static void process_devinfo_tree(void); 460*7c478bd9Sstevel@tonic-gate static void call_minor_fini_thread(void *arg); 461*7c478bd9Sstevel@tonic-gate static void *s_realloc(void *ptr, const size_t size); 462*7c478bd9Sstevel@tonic-gate static void read_devlinktab_file(void); 463*7c478bd9Sstevel@tonic-gate static selector_list_t *create_selector_list(char *selector); 464*7c478bd9Sstevel@tonic-gate static int parse_selector(char **selector, char **key, char **val); 465*7c478bd9Sstevel@tonic-gate int devfsadm_noupdate(void); 466*7c478bd9Sstevel@tonic-gate const char *devfsadm_root_path(void); 467*7c478bd9Sstevel@tonic-gate static link_list_t *create_link_list(char *link); 468*7c478bd9Sstevel@tonic-gate static void s_unlink(const char *file); 469*7c478bd9Sstevel@tonic-gate static void s_closedir(DIR *dirp); 470*7c478bd9Sstevel@tonic-gate static void s_mkdirp(const char *path, const mode_t mode); 471*7c478bd9Sstevel@tonic-gate static int is_minor_node(char *contents, char **mn_root); 472*7c478bd9Sstevel@tonic-gate static int construct_devlink(char *link, link_list_t *link_build, 473*7c478bd9Sstevel@tonic-gate char *contents, di_minor_t minor, 474*7c478bd9Sstevel@tonic-gate di_node_t node, char *pattern); 475*7c478bd9Sstevel@tonic-gate static int split_devlinktab_entry(char *entry, char **selector, char **p_link, 476*7c478bd9Sstevel@tonic-gate char **s_link); 477*7c478bd9Sstevel@tonic-gate static int devlink_matches(devlinktab_list_t *entry, di_minor_t minor, 478*7c478bd9Sstevel@tonic-gate di_node_t node); 479*7c478bd9Sstevel@tonic-gate static int build_links(devlinktab_list_t *entry, di_minor_t minor, 480*7c478bd9Sstevel@tonic-gate di_node_t node); 481*7c478bd9Sstevel@tonic-gate static numeral_set_t *get_enum_cache(devfsadm_enumerate_t rules[], 482*7c478bd9Sstevel@tonic-gate int nrules); 483*7c478bd9Sstevel@tonic-gate static void enumerate_recurse(char *current_dir, char *path_left, 484*7c478bd9Sstevel@tonic-gate numeral_set_t *setp, devfsadm_enumerate_t rules[], int index); 485*7c478bd9Sstevel@tonic-gate 486*7c478bd9Sstevel@tonic-gate static int match_path_component(char *file_re, char *file, char **id, 487*7c478bd9Sstevel@tonic-gate int subexp); 488*7c478bd9Sstevel@tonic-gate static void create_cached_numeral(char *path, numeral_set_t *setp, 489*7c478bd9Sstevel@tonic-gate char *numeral_id, devfsadm_enumerate_t rules[], int index); 490*7c478bd9Sstevel@tonic-gate static int devfsadm_copy_file(const char *file, const struct stat *stat, 491*7c478bd9Sstevel@tonic-gate int flags, struct FTW *ftw); 492*7c478bd9Sstevel@tonic-gate static void getattr(char *devname, char *aminor, int spectype, dev_t dev, 493*7c478bd9Sstevel@tonic-gate mode_t *mode, uid_t *uid, gid_t *gid); 494*7c478bd9Sstevel@tonic-gate static int minor_matches_rule(di_node_t node, di_minor_t minor, 495*7c478bd9Sstevel@tonic-gate create_list_t *create); 496*7c478bd9Sstevel@tonic-gate static void add_verbose_id(char *mid); 497*7c478bd9Sstevel@tonic-gate static char *get_component(char *str, const char *comp_num); 498*7c478bd9Sstevel@tonic-gate static char *alloc_cmp_str(const char *devfs_path, devfsadm_enumerate_t *dep); 499*7c478bd9Sstevel@tonic-gate static int lookup_enum_cache(numeral_set_t *set, char *cmp_str, 500*7c478bd9Sstevel@tonic-gate devfsadm_enumerate_t rules[], int index, numeral_t **matchnpp); 501*7c478bd9Sstevel@tonic-gate static void sync_handler(void *cookie, char *ap, size_t asize, 502*7c478bd9Sstevel@tonic-gate door_desc_t *dp, uint_t ndesc); 503*7c478bd9Sstevel@tonic-gate static void zlist_insert(struct zone_devinfo *newzone); 504*7c478bd9Sstevel@tonic-gate static void delete_zone(struct zone_devinfo *z); 505*7c478bd9Sstevel@tonic-gate static struct zone_devinfo *zlist_remove(char *zone_name); 506*7c478bd9Sstevel@tonic-gate static void zlist_deleteall_unlocked(void); 507*7c478bd9Sstevel@tonic-gate static void call_zone_register(char *zone_name, int regop); 508*7c478bd9Sstevel@tonic-gate static int register_all_zones(void); 509*7c478bd9Sstevel@tonic-gate static void zone_reg_handler(void *cookie, char *ap, size_t asize, 510*7c478bd9Sstevel@tonic-gate door_desc_t *dp, uint_t ndesc); 511*7c478bd9Sstevel@tonic-gate static int zone_pathcheck(char *checkpath); 512*7c478bd9Sstevel@tonic-gate static void process_deferred_links(struct dca_impl *dcip, int flag); 513*7c478bd9Sstevel@tonic-gate static void event_handler(sysevent_t *ev); 514*7c478bd9Sstevel@tonic-gate static int rcm_init(void); 515*7c478bd9Sstevel@tonic-gate static int notify_rcm(di_node_t node, char *minor_name); 516*7c478bd9Sstevel@tonic-gate static void dca_impl_init(char *root, char *minor, struct dca_impl *dcip); 517*7c478bd9Sstevel@tonic-gate static void lock_dev(void); 518*7c478bd9Sstevel@tonic-gate static void unlock_dev(int flag); 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate int load_devpolicy(void); 521*7c478bd9Sstevel@tonic-gate static void load_dev_acl(void); 522*7c478bd9Sstevel@tonic-gate static void load_minor_perm_file(void); 523*7c478bd9Sstevel@tonic-gate 524*7c478bd9Sstevel@tonic-gate static int (*librcm_alloc_handle)(char *, uint_t, void *, rcm_handle_t **); 525*7c478bd9Sstevel@tonic-gate static void (*librcm_free_handle)(rcm_handle_t *); 526*7c478bd9Sstevel@tonic-gate static int (*librcm_notify_event)(rcm_handle_t *, char *, uint_t, nvlist_t *, 527*7c478bd9Sstevel@tonic-gate rcm_info_t *); 528*7c478bd9Sstevel@tonic-gate static nvlist_t *build_event_attributes(char *, char *, char *, 529*7c478bd9Sstevel@tonic-gate di_node_t, char *, int); 530*7c478bd9Sstevel@tonic-gate static void log_event(char *, char *, nvlist_t *); 531*7c478bd9Sstevel@tonic-gate static void build_and_log_event(char *, char *, char *, di_node_t); 532*7c478bd9Sstevel@tonic-gate 533*7c478bd9Sstevel@tonic-gate static void read_logindevperm_file(void); 534*7c478bd9Sstevel@tonic-gate static void set_logindev_perms(char *devlink); 535*7c478bd9Sstevel@tonic-gate 536*7c478bd9Sstevel@tonic-gate static void reset_node_permissions(di_node_t, di_minor_t); 537*7c478bd9Sstevel@tonic-gate 538*7c478bd9Sstevel@tonic-gate 539*7c478bd9Sstevel@tonic-gate /* convenient short hands */ 540*7c478bd9Sstevel@tonic-gate #define vprint devfsadm_print 541*7c478bd9Sstevel@tonic-gate #define err_print devfsadm_errprint 542*7c478bd9Sstevel@tonic-gate #define TRUE 1 543*7c478bd9Sstevel@tonic-gate #define FALSE 0 544*7c478bd9Sstevel@tonic-gate 545*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 546*7c478bd9Sstevel@tonic-gate } 547*7c478bd9Sstevel@tonic-gate #endif 548*7c478bd9Sstevel@tonic-gate 549*7c478bd9Sstevel@tonic-gate #endif /* _DEVFSADM_IMPL_H */ 550