17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate * 227c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _DEVFSADM_IMPL_H 277c478bd9Sstevel@tonic-gate #define _DEVFSADM_IMPL_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 327c478bd9Sstevel@tonic-gate extern "C" { 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <dlfcn.h> 367c478bd9Sstevel@tonic-gate #include <stdarg.h> 377c478bd9Sstevel@tonic-gate #include <fcntl.h> 387c478bd9Sstevel@tonic-gate #include <sys/file.h> 397c478bd9Sstevel@tonic-gate #include <locale.h> 407c478bd9Sstevel@tonic-gate #include <libintl.h> 417c478bd9Sstevel@tonic-gate #include <ctype.h> 427c478bd9Sstevel@tonic-gate #include <signal.h> 437c478bd9Sstevel@tonic-gate #include <deflt.h> 447c478bd9Sstevel@tonic-gate #include <ftw.h> 457c478bd9Sstevel@tonic-gate #include <sys/instance.h> 467c478bd9Sstevel@tonic-gate #include <sys/types.h> 477c478bd9Sstevel@tonic-gate #include <dirent.h> 487c478bd9Sstevel@tonic-gate #include <pwd.h> 497c478bd9Sstevel@tonic-gate #include <grp.h> 507c478bd9Sstevel@tonic-gate #include <stdio.h> 517c478bd9Sstevel@tonic-gate #include <stdlib.h> 527c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 537c478bd9Sstevel@tonic-gate #include <sys/stat.h> 547c478bd9Sstevel@tonic-gate #include <fcntl.h> 557c478bd9Sstevel@tonic-gate #include <errno.h> 567c478bd9Sstevel@tonic-gate #include <unistd.h> 577c478bd9Sstevel@tonic-gate #include <sys/stat.h> 587c478bd9Sstevel@tonic-gate #include <sys/int_types.h> 597c478bd9Sstevel@tonic-gate #include <limits.h> 607c478bd9Sstevel@tonic-gate #include <strings.h> 617c478bd9Sstevel@tonic-gate #include <devfsadm.h> 627c478bd9Sstevel@tonic-gate #include <libdevinfo.h> 637c478bd9Sstevel@tonic-gate #include <sys/devinfo_impl.h> 647c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 657c478bd9Sstevel@tonic-gate #include <libgen.h> 667c478bd9Sstevel@tonic-gate #include <sys/hwconf.h> 677c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 687c478bd9Sstevel@tonic-gate #include <door.h> 697c478bd9Sstevel@tonic-gate #include <syslog.h> 707c478bd9Sstevel@tonic-gate #include <libsysevent.h> 717c478bd9Sstevel@tonic-gate #include <thread.h> 727c478bd9Sstevel@tonic-gate #include <message.h> 737c478bd9Sstevel@tonic-gate #include <sys/cladm.h> 747c478bd9Sstevel@tonic-gate #include <librcm.h> 757c478bd9Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 767c478bd9Sstevel@tonic-gate #include <sys/sysevent/dev.h> 777c478bd9Sstevel@tonic-gate #include <libzonecfg.h> 787c478bd9Sstevel@tonic-gate #include <device_info.h> 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate #undef DEBUG 817c478bd9Sstevel@tonic-gate #ifndef DEBUG 827c478bd9Sstevel@tonic-gate #define NDEBUG 1 837c478bd9Sstevel@tonic-gate #else 847c478bd9Sstevel@tonic-gate #undef NDEBUG 857c478bd9Sstevel@tonic-gate #endif 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #include <assert.h> 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate #define DEV_LOCK_FILE ".devfsadm_dev.lock" 917c478bd9Sstevel@tonic-gate #define DAEMON_LOCK_FILE ".devfsadm_daemon.lock" 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #define DEV "/dev" 947c478bd9Sstevel@tonic-gate #define DEV_LEN 4 957c478bd9Sstevel@tonic-gate #define DEVICES "/devices" 967c478bd9Sstevel@tonic-gate #define DEVICES_LEN 8 977c478bd9Sstevel@tonic-gate #define MODULE_DIRS "/usr/lib/devfsadm/linkmod" 987c478bd9Sstevel@tonic-gate #define ALIASFILE "/etc/driver_aliases" 997c478bd9Sstevel@tonic-gate #define NAME_TO_MAJOR "/etc/name_to_major" 1007c478bd9Sstevel@tonic-gate #define RECONFIG_BOOT "_INIT_RECONFIG" 1017c478bd9Sstevel@tonic-gate #define PID_STR_LEN 10 1027c478bd9Sstevel@tonic-gate #define EXTRA_PRIVS "/etc/security/extra_privs" 1037c478bd9Sstevel@tonic-gate #define DEV_POLICY "/etc/security/device_policy" 1047c478bd9Sstevel@tonic-gate #define LDEV_FILE "/etc/logindevperm" 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #define DEVFSADM_DEFAULT_FILE "/etc/default/devfsadm" 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #define MINOR_FINI_TIMEOUT_DEFAULT 2 1097c478bd9Sstevel@tonic-gate #define FORCE_CALL_MINOR_FINI 10 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate #define SYNCH_DOOR_PERMS (S_IRUSR | S_IWUSR) 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate #define ZONE_DOOR_PERMS (S_IRUSR | S_IWUSR) 1157c478bd9Sstevel@tonic-gate #define ZONE_REG_DOOR ".zone_reg_door" 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate enum zreg_op { 1187c478bd9Sstevel@tonic-gate ZONE_REG = 1, 1197c478bd9Sstevel@tonic-gate ZONE_UNREG = 2 1207c478bd9Sstevel@tonic-gate }; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate enum zreg_err { 1237c478bd9Sstevel@tonic-gate ZONE_SUCCESS = 0, 1247c478bd9Sstevel@tonic-gate ZONE_ERR_NOZONE = 1, 1257c478bd9Sstevel@tonic-gate ZONE_ERR_DOOR = 2, 1267c478bd9Sstevel@tonic-gate ZONE_ERR_REPOSITORY = 3, 1277c478bd9Sstevel@tonic-gate ZONE_ERR_NOLIB = 4 1287c478bd9Sstevel@tonic-gate }; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate struct zreg { 1317c478bd9Sstevel@tonic-gate char zreg_zonename[ZONENAME_MAX]; 1327c478bd9Sstevel@tonic-gate enum zreg_op zreg_op; 1337c478bd9Sstevel@tonic-gate enum zreg_err zreg_error; 1347c478bd9Sstevel@tonic-gate int zreg_errno; 1357c478bd9Sstevel@tonic-gate }; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate #define DRVCONFIG "drvconfig" 1387c478bd9Sstevel@tonic-gate #define DEVFSADM "devfsadm" 1397c478bd9Sstevel@tonic-gate #define DEVFSADMD "devfsadmd" 1407c478bd9Sstevel@tonic-gate #define DEVLINKS "devlinks" 1417c478bd9Sstevel@tonic-gate #define TAPES "tapes" 1427c478bd9Sstevel@tonic-gate #define AUDLINKS "audlinks" 1437c478bd9Sstevel@tonic-gate #define PORTS "ports" 1447c478bd9Sstevel@tonic-gate #define DISKS "disks" 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate #define MAX_IDLE_DELAY 5 1477c478bd9Sstevel@tonic-gate #define MAX_DELAY 30 1487c478bd9Sstevel@tonic-gate #define NAME 0x01 1497c478bd9Sstevel@tonic-gate #define ADDR 0x03 1507c478bd9Sstevel@tonic-gate #define MINOR 0x04 1517c478bd9Sstevel@tonic-gate #define COUNTER 0x05 1527c478bd9Sstevel@tonic-gate #define CONSTANT 0x06 1537c478bd9Sstevel@tonic-gate #define TYPE 0x07 1547c478bd9Sstevel@tonic-gate #define TYPE_S "type" 1557c478bd9Sstevel@tonic-gate #define ADDR_S "addr" 1567c478bd9Sstevel@tonic-gate #define ADDR_S_LEN 4 1577c478bd9Sstevel@tonic-gate #define MINOR_S "minor" 1587c478bd9Sstevel@tonic-gate #define MINOR_S_LEN 5 1597c478bd9Sstevel@tonic-gate #define NAME_S "name" 1607c478bd9Sstevel@tonic-gate #define TAB '\t' 1617c478bd9Sstevel@tonic-gate #define NEWLINE '\n' 1627c478bd9Sstevel@tonic-gate #define MAX_DEVLINK_LINE 4028 1637c478bd9Sstevel@tonic-gate #define INTEGER 0 1647c478bd9Sstevel@tonic-gate #define LETTER 1 1657c478bd9Sstevel@tonic-gate #define MAX_PERM_LINE 256 1667c478bd9Sstevel@tonic-gate #define MAX_LDEV_LINE 256 1677c478bd9Sstevel@tonic-gate #define LDEV_DELIMS " \t\n" 1687c478bd9Sstevel@tonic-gate #define LDEV_DRVLIST_DELIMS "=" 1697c478bd9Sstevel@tonic-gate #define LDEV_DRV_DELIMS ", \t\n" 1707c478bd9Sstevel@tonic-gate #define LDEV_DEV_DELIM ":" 1717c478bd9Sstevel@tonic-gate #define LDEV_DRVLIST_NAME "driver" 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate #define TYPE_LINK 0x00 1747c478bd9Sstevel@tonic-gate #define TYPE_DEVICES 0x01 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate #define CREATE_LINK 0x01 1777c478bd9Sstevel@tonic-gate #define READ_LINK 0x02 1787c478bd9Sstevel@tonic-gate #define CREATE_NODE 0x01 1797c478bd9Sstevel@tonic-gate #define READ_NODE 0x02 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #define DCA_CREATE_LINK 0x01 1827c478bd9Sstevel@tonic-gate #define DCA_FREE_LIST 0x02 1837c478bd9Sstevel@tonic-gate #define DCA_LOAD_DRV 0x04 1847c478bd9Sstevel@tonic-gate #define DCA_CHECK_TYPE 0x10 1857c478bd9Sstevel@tonic-gate #define DCA_NOTIFY_RCM 0x20 1867c478bd9Sstevel@tonic-gate #define DCA_FLUSH_PATHINST 0x40 1877c478bd9Sstevel@tonic-gate #define DCA_HOT_PLUG 0x80 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate #define CACHE_STATE 0x0 1907c478bd9Sstevel@tonic-gate #define SYNC_STATE 0x1 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate #define MODULE_ACTIVE 0x01 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate #define MAX_SLEEP 120 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate #define DEVLINKTAB_FILE "/etc/devlink.tab" 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate #define MODULE_SUFFIX ".so" 1997c478bd9Sstevel@tonic-gate #define MINOR_INIT "minor_init" 2007c478bd9Sstevel@tonic-gate #define MINOR_FINI "minor_fini" 2017c478bd9Sstevel@tonic-gate #define _DEVFSADM_CREATE_REG "_devfsadm_create_reg" 2027c478bd9Sstevel@tonic-gate #define _DEVFSADM_REMOVE_REG "_devfsadm_remove_reg" 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate #define NUM_EV_STR 4 2057c478bd9Sstevel@tonic-gate #define EV_TYPE 0 2067c478bd9Sstevel@tonic-gate #define EV_CLASS 1 2077c478bd9Sstevel@tonic-gate #define EV_PATH_NAME 2 2087c478bd9Sstevel@tonic-gate #define EV_MINOR_NAME 3 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* add new debug level and meanings here */ 2117c478bd9Sstevel@tonic-gate #define DEVLINK_MID "devfsadm:devlink" 2127c478bd9Sstevel@tonic-gate #define MODLOAD_MID "devfsadm:modload" 2137c478bd9Sstevel@tonic-gate #define INITFINI_MID "devfsadm:initfini" 2147c478bd9Sstevel@tonic-gate #define EVENT_MID "devfsadm:event" 2157c478bd9Sstevel@tonic-gate #define REMOVE_MID "devfsadm:remove" 2167c478bd9Sstevel@tonic-gate #define LOCK_MID "devfsadm:lock" 2177c478bd9Sstevel@tonic-gate #define PATH2INST_MID "devfsadm:path2inst" 2187c478bd9Sstevel@tonic-gate #define CACHE_MID "devfsadm:cache" 2197c478bd9Sstevel@tonic-gate #define BUILDCACHE_MID "devfsadm:buildcache" 2207c478bd9Sstevel@tonic-gate #define RECURSEDEV_MID "devfsadm:recursedev" 2217c478bd9Sstevel@tonic-gate #define INSTSYNC_MID "devfsadm:instsync" 2227c478bd9Sstevel@tonic-gate #define FILES_MID "devfsadm:files" 2237c478bd9Sstevel@tonic-gate #define ENUM_MID "devfsadm:enum" 2247c478bd9Sstevel@tonic-gate #define LINKCACHE_MID "devfsadm:linkcache" 2257c478bd9Sstevel@tonic-gate #define ADDREMCACHE_MID "devfsadm:addremcache" 2267c478bd9Sstevel@tonic-gate #define MALLOC_MID "devfsadm:malloc" 2277c478bd9Sstevel@tonic-gate #define ZONE_MID "devfsadm:zone" 2287c478bd9Sstevel@tonic-gate #define ALL_MID "all" 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate #define DEVFSADM_DEBUG_ON (verbose == NULL) ? FALSE : TRUE 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate typedef struct recurse_dev { 2337c478bd9Sstevel@tonic-gate void (*fcn)(char *, void *); 2347c478bd9Sstevel@tonic-gate void *data; 2357c478bd9Sstevel@tonic-gate } recurse_dev_t; 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate typedef struct link { 2387c478bd9Sstevel@tonic-gate char *devlink; /* without ".../dev/" prefix */ 2397c478bd9Sstevel@tonic-gate char *contents; /* without "../devices" prefix */ 2407c478bd9Sstevel@tonic-gate struct link *next; 2417c478bd9Sstevel@tonic-gate } link_t; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate typedef struct linkhead { 2447c478bd9Sstevel@tonic-gate regex_t dir_re_compiled; 2457c478bd9Sstevel@tonic-gate char *dir_re; 2467c478bd9Sstevel@tonic-gate link_t *link; 2477c478bd9Sstevel@tonic-gate link_t *nextlink; 2487c478bd9Sstevel@tonic-gate struct linkhead *nexthead; 2497c478bd9Sstevel@tonic-gate } linkhead_t; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate typedef struct link_list { 2527c478bd9Sstevel@tonic-gate int type; 2537c478bd9Sstevel@tonic-gate char *constant; 2547c478bd9Sstevel@tonic-gate int arg; 2557c478bd9Sstevel@tonic-gate struct link_list *next; 2567c478bd9Sstevel@tonic-gate } link_list_t; 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate typedef struct selector_list { 2597c478bd9Sstevel@tonic-gate int key; 2607c478bd9Sstevel@tonic-gate char *val; 2617c478bd9Sstevel@tonic-gate int arg; 2627c478bd9Sstevel@tonic-gate struct selector_list *next; 2637c478bd9Sstevel@tonic-gate } selector_list_t; 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate typedef struct devlinktab_list { 2667c478bd9Sstevel@tonic-gate int line_number; 2677c478bd9Sstevel@tonic-gate char *selector_pattern; 2687c478bd9Sstevel@tonic-gate char *p_link_pattern; 2697c478bd9Sstevel@tonic-gate char *s_link_pattern; 2707c478bd9Sstevel@tonic-gate selector_list_t *selector; 2717c478bd9Sstevel@tonic-gate link_list_t *p_link; 2727c478bd9Sstevel@tonic-gate link_list_t *s_link; 2737c478bd9Sstevel@tonic-gate struct devlinktab_list *next; 2747c478bd9Sstevel@tonic-gate } devlinktab_list_t; 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate typedef struct module { 2777c478bd9Sstevel@tonic-gate char *name; 2787c478bd9Sstevel@tonic-gate void *dlhandle; 2797c478bd9Sstevel@tonic-gate int (*minor_init)(); 2807c478bd9Sstevel@tonic-gate int (*minor_fini)(); 2817c478bd9Sstevel@tonic-gate int flags; 2827c478bd9Sstevel@tonic-gate struct module *next; 2837c478bd9Sstevel@tonic-gate } module_t; 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate typedef struct create_list { 2867c478bd9Sstevel@tonic-gate devfsadm_create_t *create; 2877c478bd9Sstevel@tonic-gate module_t *modptr; 2887c478bd9Sstevel@tonic-gate regex_t node_type_comp; 2897c478bd9Sstevel@tonic-gate regex_t drv_name_comp; 2907c478bd9Sstevel@tonic-gate struct create_list *next; 2917c478bd9Sstevel@tonic-gate } create_list_t; 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate struct minor { 2947c478bd9Sstevel@tonic-gate di_node_t node; 2957c478bd9Sstevel@tonic-gate di_minor_t minor; 2967c478bd9Sstevel@tonic-gate struct minor *next; 2977c478bd9Sstevel@tonic-gate }; 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate struct mlist { 3007c478bd9Sstevel@tonic-gate struct minor *head; 3017c478bd9Sstevel@tonic-gate struct minor *tail; 3027c478bd9Sstevel@tonic-gate }; 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate typedef struct remove_list { 3057c478bd9Sstevel@tonic-gate devfsadm_remove_t *remove; 3067c478bd9Sstevel@tonic-gate module_t *modptr; 3077c478bd9Sstevel@tonic-gate struct remove_list *next; 3087c478bd9Sstevel@tonic-gate } remove_list_t; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate typedef struct cleanup_data { 3117c478bd9Sstevel@tonic-gate int flags; 3127c478bd9Sstevel@tonic-gate char *phypath; 3137c478bd9Sstevel@tonic-gate remove_list_t *rm; 3147c478bd9Sstevel@tonic-gate } cleanup_data_t; 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate typedef struct n2m { 3177c478bd9Sstevel@tonic-gate major_t major; 3187c478bd9Sstevel@tonic-gate char *driver; 3197c478bd9Sstevel@tonic-gate struct n2m *next; 3207c478bd9Sstevel@tonic-gate } n2m_t; 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate /* structures for devfsadm_enumerate() */ 3237c478bd9Sstevel@tonic-gate typedef struct numeral { 3247c478bd9Sstevel@tonic-gate char *id; 3257c478bd9Sstevel@tonic-gate char *full_path; 3267c478bd9Sstevel@tonic-gate int rule_index; 3277c478bd9Sstevel@tonic-gate char *cmp_str; 3287c478bd9Sstevel@tonic-gate struct numeral *next; 3297c478bd9Sstevel@tonic-gate } numeral_t; 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate typedef struct numeral_set { 3327c478bd9Sstevel@tonic-gate int re_count; 3337c478bd9Sstevel@tonic-gate char **re; 3347c478bd9Sstevel@tonic-gate numeral_t *headnumeral; 3357c478bd9Sstevel@tonic-gate struct numeral_set *next; 3367c478bd9Sstevel@tonic-gate } numeral_set_t; 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate typedef struct temp { 3397c478bd9Sstevel@tonic-gate int integer; 3407c478bd9Sstevel@tonic-gate struct temp *next; 3417c478bd9Sstevel@tonic-gate } temp_t; 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate typedef struct driver_alias { 3447c478bd9Sstevel@tonic-gate char *driver_name; 3457c478bd9Sstevel@tonic-gate char *alias_name; 3467c478bd9Sstevel@tonic-gate struct driver_alias *next; 3477c478bd9Sstevel@tonic-gate } driver_alias_t; 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate struct driver_list { 3507c478bd9Sstevel@tonic-gate char driver_name[MAXNAMELEN]; 3517c478bd9Sstevel@tonic-gate struct driver_list *next; 3527c478bd9Sstevel@tonic-gate }; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate struct login_dev { 3557c478bd9Sstevel@tonic-gate char *ldev_console; 3567c478bd9Sstevel@tonic-gate int ldev_perms; 3577c478bd9Sstevel@tonic-gate char *ldev_device; 3587c478bd9Sstevel@tonic-gate regex_t ldev_device_regex; 3597c478bd9Sstevel@tonic-gate struct driver_list *ldev_driver_list; 3607c478bd9Sstevel@tonic-gate struct login_dev *ldev_next; 3617c478bd9Sstevel@tonic-gate }; 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate #define MAX_DEV_NAME_COUNT 100 3647c478bd9Sstevel@tonic-gate struct devlink_cb_arg { 3657c478bd9Sstevel@tonic-gate char *dev_names[MAX_DEV_NAME_COUNT]; 3667c478bd9Sstevel@tonic-gate char *link_contents[MAX_DEV_NAME_COUNT]; 3677c478bd9Sstevel@tonic-gate int count; 3687c478bd9Sstevel@tonic-gate int rv; 3697c478bd9Sstevel@tonic-gate }; 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate struct dca_impl { 3727c478bd9Sstevel@tonic-gate char *dci_root; 3737c478bd9Sstevel@tonic-gate char *dci_minor; 3747c478bd9Sstevel@tonic-gate char *dci_driver; 3757c478bd9Sstevel@tonic-gate void *dci_arg; 3767c478bd9Sstevel@tonic-gate int dci_error; 3777c478bd9Sstevel@tonic-gate int dci_flags; 3787c478bd9Sstevel@tonic-gate }; 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate struct zone_devinfo { 3817c478bd9Sstevel@tonic-gate struct zone_devinfo *zone_next; 3827c478bd9Sstevel@tonic-gate char *zone_path; 3837c478bd9Sstevel@tonic-gate char *zone_name; 3847c478bd9Sstevel@tonic-gate zone_dochandle_t zone_dochdl; 3857c478bd9Sstevel@tonic-gate }; 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate /* RCM related */ 3887c478bd9Sstevel@tonic-gate struct rcm_eventq { 3897c478bd9Sstevel@tonic-gate nvlist_t *nvl; 3907c478bd9Sstevel@tonic-gate struct rcm_eventq *next; 3917c478bd9Sstevel@tonic-gate }; 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate static int devfsadm_enumerate_int_start(char *devfs_path, 3947c478bd9Sstevel@tonic-gate int index, char **buf, devfsadm_enumerate_t rules[], 3957c478bd9Sstevel@tonic-gate int nrules, char *start); 3967c478bd9Sstevel@tonic-gate static void startup_cache_sync_thread(void); 3977c478bd9Sstevel@tonic-gate static void set_root_devices_dev_dir(char *dir, int zone_mode); 3987c478bd9Sstevel@tonic-gate static void pre_and_post_cleanup(int flags); 3997c478bd9Sstevel@tonic-gate static void hot_cleanup(char *, char *, char *, char *, int); 4007c478bd9Sstevel@tonic-gate static void devfsadm_exit(int status); 4017c478bd9Sstevel@tonic-gate static void rm_link_from_cache(char *devlink); 4027c478bd9Sstevel@tonic-gate static void rm_all_links_from_cache(); 4037c478bd9Sstevel@tonic-gate static void add_link_to_cache(char *devlink, char *physpath); 4047c478bd9Sstevel@tonic-gate static linkhead_t *get_cached_links(char *dir_re); 4057c478bd9Sstevel@tonic-gate static void build_devlink_list(char *check_link, void *data); 4067c478bd9Sstevel@tonic-gate static void instance_flush_thread(void); 407*4bc0a2efScasper static int s_rmdir(char *path); 4087c478bd9Sstevel@tonic-gate static void rm_parent_dir_if_empty(char *path); 4097c478bd9Sstevel@tonic-gate static void free_link_list(link_list_t *head); 4107c478bd9Sstevel@tonic-gate static void free_selector_list(selector_list_t *head); 4117c478bd9Sstevel@tonic-gate void devfsadm_err_print(char *message, ...); 4127c478bd9Sstevel@tonic-gate void defvsadm_print(int level, char *message, ...); 4137c478bd9Sstevel@tonic-gate static int call_minor_init(module_t *module); 4147c478bd9Sstevel@tonic-gate static void load_module(char *module, char *cdir); 4157c478bd9Sstevel@tonic-gate static void invalidate_enumerate_cache(void); 4167c478bd9Sstevel@tonic-gate static pid_t enter_dev_lock(void); 4177c478bd9Sstevel@tonic-gate static void exit_dev_lock(void); 4187c478bd9Sstevel@tonic-gate static pid_t enter_daemon_lock(void); 4197c478bd9Sstevel@tonic-gate static void exit_daemon_lock(void); 4207c478bd9Sstevel@tonic-gate static int process_devlink_compat(di_minor_t minor, di_node_t node); 4217c478bd9Sstevel@tonic-gate static int alias(char *, char *); 4227c478bd9Sstevel@tonic-gate static int devfsadm_copy(void); 4237c478bd9Sstevel@tonic-gate static void flush_path_to_inst(void); 4247c478bd9Sstevel@tonic-gate static void detachfromtty(void); 4257c478bd9Sstevel@tonic-gate static void minor_process(di_node_t node, di_minor_t minor, 4267c478bd9Sstevel@tonic-gate struct mlist *dep); 4277c478bd9Sstevel@tonic-gate static void read_minor_perm_file(void); 4287c478bd9Sstevel@tonic-gate static void read_driver_aliases_file(void); 4297c478bd9Sstevel@tonic-gate static void load_modules(void); 4307c478bd9Sstevel@tonic-gate static void unload_modules(void); 4317c478bd9Sstevel@tonic-gate static void *s_malloc(const size_t size); 4327c478bd9Sstevel@tonic-gate static void *s_zalloc(const size_t size); 4337c478bd9Sstevel@tonic-gate static void devfs_instance_mod(void); 4347c478bd9Sstevel@tonic-gate static void add_minor_pathname(char *, char *, char *); 4357c478bd9Sstevel@tonic-gate static int check_minor_type(di_node_t node, di_minor_t minor, void *arg); 4367c478bd9Sstevel@tonic-gate static void cache_deferred_minor(struct mlist *dep, di_node_t node, 4377c478bd9Sstevel@tonic-gate di_minor_t minor); 4387c478bd9Sstevel@tonic-gate static int compare_field(char *full_name, char *field_item, int field); 4397c478bd9Sstevel@tonic-gate static int component_cat(char *link, char *name, int field); 4407c478bd9Sstevel@tonic-gate static void recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd); 4417c478bd9Sstevel@tonic-gate static void matching_dev(char *devpath, void *data); 4427c478bd9Sstevel@tonic-gate static int resolve_link(char *devpath, char **content_p, int *type_p, 4437c478bd9Sstevel@tonic-gate char **devfs_path, int dangle); 4447c478bd9Sstevel@tonic-gate static int clean_ok(devfsadm_remove_t *remove); 4457c478bd9Sstevel@tonic-gate static int translate_major(dev_t old_dev, dev_t *new_dev); 4467c478bd9Sstevel@tonic-gate static int get_major_no(char *driver, major_t *major); 4477c478bd9Sstevel@tonic-gate static int load_n2m_table(char *filename); 4487c478bd9Sstevel@tonic-gate static int get_stat_info(char *, struct stat *); 4497c478bd9Sstevel@tonic-gate static char *new_id(numeral_t *, int, char *); 4507c478bd9Sstevel@tonic-gate static int find_enum_id(devfsadm_enumerate_t rules[], int nrules, 4517c478bd9Sstevel@tonic-gate char *devfs_path, int index, char *min, int type, char **buf, int multiple); 4527c478bd9Sstevel@tonic-gate static void daemon_update(void); 4537c478bd9Sstevel@tonic-gate static void usage(void); 4547c478bd9Sstevel@tonic-gate static int getnexttoken(char *next, char **nextp, char **tokenpp, char *tchar); 4557c478bd9Sstevel@tonic-gate static int class_ok(char *class); 4567c478bd9Sstevel@tonic-gate static int create_link_common(char *devlink, char *contents, int *exists); 4577c478bd9Sstevel@tonic-gate static char *dequote(char *src); 4587c478bd9Sstevel@tonic-gate static void parse_args(int argc, char *argv[]); 4597c478bd9Sstevel@tonic-gate static void process_devinfo_tree(void); 4607c478bd9Sstevel@tonic-gate static void call_minor_fini_thread(void *arg); 4617c478bd9Sstevel@tonic-gate static void *s_realloc(void *ptr, const size_t size); 4627c478bd9Sstevel@tonic-gate static void read_devlinktab_file(void); 4637c478bd9Sstevel@tonic-gate static selector_list_t *create_selector_list(char *selector); 4647c478bd9Sstevel@tonic-gate static int parse_selector(char **selector, char **key, char **val); 4657c478bd9Sstevel@tonic-gate int devfsadm_noupdate(void); 4667c478bd9Sstevel@tonic-gate const char *devfsadm_root_path(void); 4677c478bd9Sstevel@tonic-gate static link_list_t *create_link_list(char *link); 4687c478bd9Sstevel@tonic-gate static void s_unlink(const char *file); 4697c478bd9Sstevel@tonic-gate static void s_closedir(DIR *dirp); 4707c478bd9Sstevel@tonic-gate static void s_mkdirp(const char *path, const mode_t mode); 4717c478bd9Sstevel@tonic-gate static int is_minor_node(char *contents, char **mn_root); 4727c478bd9Sstevel@tonic-gate static int construct_devlink(char *link, link_list_t *link_build, 4737c478bd9Sstevel@tonic-gate char *contents, di_minor_t minor, 4747c478bd9Sstevel@tonic-gate di_node_t node, char *pattern); 4757c478bd9Sstevel@tonic-gate static int split_devlinktab_entry(char *entry, char **selector, char **p_link, 4767c478bd9Sstevel@tonic-gate char **s_link); 4777c478bd9Sstevel@tonic-gate static int devlink_matches(devlinktab_list_t *entry, di_minor_t minor, 4787c478bd9Sstevel@tonic-gate di_node_t node); 4797c478bd9Sstevel@tonic-gate static int build_links(devlinktab_list_t *entry, di_minor_t minor, 4807c478bd9Sstevel@tonic-gate di_node_t node); 4817c478bd9Sstevel@tonic-gate static numeral_set_t *get_enum_cache(devfsadm_enumerate_t rules[], 4827c478bd9Sstevel@tonic-gate int nrules); 4837c478bd9Sstevel@tonic-gate static void enumerate_recurse(char *current_dir, char *path_left, 4847c478bd9Sstevel@tonic-gate numeral_set_t *setp, devfsadm_enumerate_t rules[], int index); 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate static int match_path_component(char *file_re, char *file, char **id, 4877c478bd9Sstevel@tonic-gate int subexp); 4887c478bd9Sstevel@tonic-gate static void create_cached_numeral(char *path, numeral_set_t *setp, 4897c478bd9Sstevel@tonic-gate char *numeral_id, devfsadm_enumerate_t rules[], int index); 4907c478bd9Sstevel@tonic-gate static int devfsadm_copy_file(const char *file, const struct stat *stat, 4917c478bd9Sstevel@tonic-gate int flags, struct FTW *ftw); 4927c478bd9Sstevel@tonic-gate static void getattr(char *devname, char *aminor, int spectype, dev_t dev, 4937c478bd9Sstevel@tonic-gate mode_t *mode, uid_t *uid, gid_t *gid); 4947c478bd9Sstevel@tonic-gate static int minor_matches_rule(di_node_t node, di_minor_t minor, 4957c478bd9Sstevel@tonic-gate create_list_t *create); 4967c478bd9Sstevel@tonic-gate static void add_verbose_id(char *mid); 4977c478bd9Sstevel@tonic-gate static char *get_component(char *str, const char *comp_num); 4987c478bd9Sstevel@tonic-gate static char *alloc_cmp_str(const char *devfs_path, devfsadm_enumerate_t *dep); 4997c478bd9Sstevel@tonic-gate static int lookup_enum_cache(numeral_set_t *set, char *cmp_str, 5007c478bd9Sstevel@tonic-gate devfsadm_enumerate_t rules[], int index, numeral_t **matchnpp); 5017c478bd9Sstevel@tonic-gate static void sync_handler(void *cookie, char *ap, size_t asize, 5027c478bd9Sstevel@tonic-gate door_desc_t *dp, uint_t ndesc); 5037c478bd9Sstevel@tonic-gate static void zlist_insert(struct zone_devinfo *newzone); 5047c478bd9Sstevel@tonic-gate static void delete_zone(struct zone_devinfo *z); 5057c478bd9Sstevel@tonic-gate static struct zone_devinfo *zlist_remove(char *zone_name); 5067c478bd9Sstevel@tonic-gate static void zlist_deleteall_unlocked(void); 5077c478bd9Sstevel@tonic-gate static void call_zone_register(char *zone_name, int regop); 5087c478bd9Sstevel@tonic-gate static int register_all_zones(void); 5097c478bd9Sstevel@tonic-gate static void zone_reg_handler(void *cookie, char *ap, size_t asize, 5107c478bd9Sstevel@tonic-gate door_desc_t *dp, uint_t ndesc); 5117c478bd9Sstevel@tonic-gate static int zone_pathcheck(char *checkpath); 5127c478bd9Sstevel@tonic-gate static void process_deferred_links(struct dca_impl *dcip, int flag); 5137c478bd9Sstevel@tonic-gate static void event_handler(sysevent_t *ev); 5147c478bd9Sstevel@tonic-gate static int rcm_init(void); 5157c478bd9Sstevel@tonic-gate static int notify_rcm(di_node_t node, char *minor_name); 5167c478bd9Sstevel@tonic-gate static void dca_impl_init(char *root, char *minor, struct dca_impl *dcip); 5177c478bd9Sstevel@tonic-gate static void lock_dev(void); 5187c478bd9Sstevel@tonic-gate static void unlock_dev(int flag); 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate int load_devpolicy(void); 5217c478bd9Sstevel@tonic-gate static void load_dev_acl(void); 5227c478bd9Sstevel@tonic-gate static void load_minor_perm_file(void); 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate static int (*librcm_alloc_handle)(char *, uint_t, void *, rcm_handle_t **); 5257c478bd9Sstevel@tonic-gate static void (*librcm_free_handle)(rcm_handle_t *); 5267c478bd9Sstevel@tonic-gate static int (*librcm_notify_event)(rcm_handle_t *, char *, uint_t, nvlist_t *, 5277c478bd9Sstevel@tonic-gate rcm_info_t *); 5287c478bd9Sstevel@tonic-gate static nvlist_t *build_event_attributes(char *, char *, char *, 5297c478bd9Sstevel@tonic-gate di_node_t, char *, int); 5307c478bd9Sstevel@tonic-gate static void log_event(char *, char *, nvlist_t *); 5317c478bd9Sstevel@tonic-gate static void build_and_log_event(char *, char *, char *, di_node_t); 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate static void read_logindevperm_file(void); 5347c478bd9Sstevel@tonic-gate static void set_logindev_perms(char *devlink); 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate static void reset_node_permissions(di_node_t, di_minor_t); 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate /* convenient short hands */ 5407c478bd9Sstevel@tonic-gate #define vprint devfsadm_print 5417c478bd9Sstevel@tonic-gate #define err_print devfsadm_errprint 5427c478bd9Sstevel@tonic-gate #define TRUE 1 5437c478bd9Sstevel@tonic-gate #define FALSE 0 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate #ifdef __cplusplus 5467c478bd9Sstevel@tonic-gate } 5477c478bd9Sstevel@tonic-gate #endif 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate #endif /* _DEVFSADM_IMPL_H */ 550