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