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 53c4226f9Spjha * Common Development and Distribution License (the "License"). 63c4226f9Spjha * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate * 21*3c5e027bSEric Taylor * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 227c478bd9Sstevel@tonic-gate * Use is subject to license terms. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #ifndef _DEVFSADM_IMPL_H 267c478bd9Sstevel@tonic-gate #define _DEVFSADM_IMPL_H 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #ifdef __cplusplus 297c478bd9Sstevel@tonic-gate extern "C" { 307c478bd9Sstevel@tonic-gate #endif 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <dlfcn.h> 337c478bd9Sstevel@tonic-gate #include <stdarg.h> 347c478bd9Sstevel@tonic-gate #include <fcntl.h> 357c478bd9Sstevel@tonic-gate #include <sys/file.h> 367c478bd9Sstevel@tonic-gate #include <locale.h> 377c478bd9Sstevel@tonic-gate #include <libintl.h> 387c478bd9Sstevel@tonic-gate #include <ctype.h> 397c478bd9Sstevel@tonic-gate #include <signal.h> 407c478bd9Sstevel@tonic-gate #include <deflt.h> 417c478bd9Sstevel@tonic-gate #include <ftw.h> 427c478bd9Sstevel@tonic-gate #include <sys/instance.h> 437c478bd9Sstevel@tonic-gate #include <sys/types.h> 447c478bd9Sstevel@tonic-gate #include <dirent.h> 457c478bd9Sstevel@tonic-gate #include <pwd.h> 467c478bd9Sstevel@tonic-gate #include <grp.h> 477c478bd9Sstevel@tonic-gate #include <stdio.h> 487c478bd9Sstevel@tonic-gate #include <stdlib.h> 497c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 507c478bd9Sstevel@tonic-gate #include <sys/stat.h> 517c478bd9Sstevel@tonic-gate #include <fcntl.h> 527c478bd9Sstevel@tonic-gate #include <errno.h> 537c478bd9Sstevel@tonic-gate #include <unistd.h> 547c478bd9Sstevel@tonic-gate #include <sys/stat.h> 557c478bd9Sstevel@tonic-gate #include <sys/int_types.h> 567c478bd9Sstevel@tonic-gate #include <limits.h> 577c478bd9Sstevel@tonic-gate #include <strings.h> 587c478bd9Sstevel@tonic-gate #include <devfsadm.h> 597c478bd9Sstevel@tonic-gate #include <libdevinfo.h> 607c478bd9Sstevel@tonic-gate #include <sys/devinfo_impl.h> 617c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 627c478bd9Sstevel@tonic-gate #include <libgen.h> 637c478bd9Sstevel@tonic-gate #include <sys/hwconf.h> 647c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 657c478bd9Sstevel@tonic-gate #include <door.h> 667c478bd9Sstevel@tonic-gate #include <syslog.h> 677c478bd9Sstevel@tonic-gate #include <libsysevent.h> 687c478bd9Sstevel@tonic-gate #include <thread.h> 697c478bd9Sstevel@tonic-gate #include <message.h> 707c478bd9Sstevel@tonic-gate #include <sys/cladm.h> 717c478bd9Sstevel@tonic-gate #include <sys/sysevent/dev.h> 727c478bd9Sstevel@tonic-gate #include <libzonecfg.h> 737c478bd9Sstevel@tonic-gate #include <device_info.h> 74*3c5e027bSEric Taylor #include <sys/fs/sdev_impl.h> 75facf4a8dSllai1 #include <sys/syscall.h> 76facf4a8dSllai1 #include <rpcsvc/ypclnt.h> 77facf4a8dSllai1 #include <sys/sysevent/eventdefs.h> 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate #define DEV_LOCK_FILE ".devfsadm_dev.lock" 807c478bd9Sstevel@tonic-gate #define DAEMON_LOCK_FILE ".devfsadm_daemon.lock" 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #define DEV "/dev" 83facf4a8dSllai1 #define ETC "/etc" 84facf4a8dSllai1 #define ETCDEV "/etc/dev" 857c478bd9Sstevel@tonic-gate #define DEV_LEN 4 867c478bd9Sstevel@tonic-gate #define DEVICES "/devices" 877c478bd9Sstevel@tonic-gate #define DEVICES_LEN 8 887c478bd9Sstevel@tonic-gate #define MODULE_DIRS "/usr/lib/devfsadm/linkmod" 897c478bd9Sstevel@tonic-gate #define ALIASFILE "/etc/driver_aliases" 907c478bd9Sstevel@tonic-gate #define NAME_TO_MAJOR "/etc/name_to_major" 917c478bd9Sstevel@tonic-gate #define RECONFIG_BOOT "_INIT_RECONFIG" 927c478bd9Sstevel@tonic-gate #define PID_STR_LEN 10 937c478bd9Sstevel@tonic-gate #define EXTRA_PRIVS "/etc/security/extra_privs" 947c478bd9Sstevel@tonic-gate #define DEV_POLICY "/etc/security/device_policy" 957c478bd9Sstevel@tonic-gate #define LDEV_FILE "/etc/logindevperm" 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #define DEVFSADM_DEFAULT_FILE "/etc/default/devfsadm" 987c478bd9Sstevel@tonic-gate 99f05faa4eSjacobs #define MINOR_FINI_TIMEOUT_DEFAULT 2 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate #define SYNCH_DOOR_PERMS (S_IRUSR | S_IWUSR) 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #define DRVCONFIG "drvconfig" 1047c478bd9Sstevel@tonic-gate #define DEVFSADM "devfsadm" 1057c478bd9Sstevel@tonic-gate #define DEVFSADMD "devfsadmd" 1067c478bd9Sstevel@tonic-gate #define DEVLINKS "devlinks" 1077c478bd9Sstevel@tonic-gate #define TAPES "tapes" 1087c478bd9Sstevel@tonic-gate #define AUDLINKS "audlinks" 1097c478bd9Sstevel@tonic-gate #define PORTS "ports" 1107c478bd9Sstevel@tonic-gate #define DISKS "disks" 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate #define MAX_IDLE_DELAY 5 1137c478bd9Sstevel@tonic-gate #define MAX_DELAY 30 1147c478bd9Sstevel@tonic-gate #define NAME 0x01 1157c478bd9Sstevel@tonic-gate #define ADDR 0x03 1167c478bd9Sstevel@tonic-gate #define MINOR 0x04 1177c478bd9Sstevel@tonic-gate #define COUNTER 0x05 1187c478bd9Sstevel@tonic-gate #define CONSTANT 0x06 1197c478bd9Sstevel@tonic-gate #define TYPE 0x07 1207c478bd9Sstevel@tonic-gate #define TYPE_S "type" 1217c478bd9Sstevel@tonic-gate #define ADDR_S "addr" 1227c478bd9Sstevel@tonic-gate #define ADDR_S_LEN 4 1237c478bd9Sstevel@tonic-gate #define MINOR_S "minor" 1247c478bd9Sstevel@tonic-gate #define MINOR_S_LEN 5 1257c478bd9Sstevel@tonic-gate #define NAME_S "name" 1267c478bd9Sstevel@tonic-gate #define TAB '\t' 1277c478bd9Sstevel@tonic-gate #define NEWLINE '\n' 1287c478bd9Sstevel@tonic-gate #define MAX_DEVLINK_LINE 4028 1297c478bd9Sstevel@tonic-gate #define INTEGER 0 1307c478bd9Sstevel@tonic-gate #define LETTER 1 1317c478bd9Sstevel@tonic-gate #define MAX_PERM_LINE 256 1327c478bd9Sstevel@tonic-gate #define MAX_LDEV_LINE 256 1337c478bd9Sstevel@tonic-gate #define LDEV_DELIMS " \t\n" 1347c478bd9Sstevel@tonic-gate #define LDEV_DRVLIST_DELIMS "=" 1357c478bd9Sstevel@tonic-gate #define LDEV_DRV_DELIMS ", \t\n" 1367c478bd9Sstevel@tonic-gate #define LDEV_DEV_DELIM ":" 1377c478bd9Sstevel@tonic-gate #define LDEV_DRVLIST_NAME "driver" 138aa646b9dSvikram #define NFP_HASH_SZ 256 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate #define TYPE_LINK 0x00 1417c478bd9Sstevel@tonic-gate #define TYPE_DEVICES 0x01 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #define CREATE_LINK 0x01 1447c478bd9Sstevel@tonic-gate #define READ_LINK 0x02 1457c478bd9Sstevel@tonic-gate #define CREATE_NODE 0x01 1467c478bd9Sstevel@tonic-gate #define READ_NODE 0x02 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate #define CACHE_STATE 0x0 1497c478bd9Sstevel@tonic-gate #define SYNC_STATE 0x1 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate #define MODULE_ACTIVE 0x01 1527c478bd9Sstevel@tonic-gate 1538d483882Smlf /* Possible flag values for flag member of numeral_t */ 1548d483882Smlf #define NUMERAL_RESERVED 0x01 1558d483882Smlf 1567c478bd9Sstevel@tonic-gate #define MAX_SLEEP 120 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #define DEVLINKTAB_FILE "/etc/devlink.tab" 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate #define MODULE_SUFFIX ".so" 1617c478bd9Sstevel@tonic-gate #define MINOR_INIT "minor_init" 1627c478bd9Sstevel@tonic-gate #define MINOR_FINI "minor_fini" 1637c478bd9Sstevel@tonic-gate #define _DEVFSADM_CREATE_REG "_devfsadm_create_reg" 1647c478bd9Sstevel@tonic-gate #define _DEVFSADM_REMOVE_REG "_devfsadm_remove_reg" 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate #define NUM_EV_STR 4 1677c478bd9Sstevel@tonic-gate #define EV_TYPE 0 1687c478bd9Sstevel@tonic-gate #define EV_CLASS 1 1697c478bd9Sstevel@tonic-gate #define EV_PATH_NAME 2 1707c478bd9Sstevel@tonic-gate #define EV_MINOR_NAME 3 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate /* add new debug level and meanings here */ 1737c478bd9Sstevel@tonic-gate #define DEVLINK_MID "devfsadm:devlink" 1747c478bd9Sstevel@tonic-gate #define MODLOAD_MID "devfsadm:modload" 1757c478bd9Sstevel@tonic-gate #define INITFINI_MID "devfsadm:initfini" 1767c478bd9Sstevel@tonic-gate #define EVENT_MID "devfsadm:event" 1777c478bd9Sstevel@tonic-gate #define REMOVE_MID "devfsadm:remove" 1787c478bd9Sstevel@tonic-gate #define LOCK_MID "devfsadm:lock" 1797c478bd9Sstevel@tonic-gate #define PATH2INST_MID "devfsadm:path2inst" 1807c478bd9Sstevel@tonic-gate #define CACHE_MID "devfsadm:cache" 1817c478bd9Sstevel@tonic-gate #define BUILDCACHE_MID "devfsadm:buildcache" 1827c478bd9Sstevel@tonic-gate #define RECURSEDEV_MID "devfsadm:recursedev" 1837c478bd9Sstevel@tonic-gate #define INSTSYNC_MID "devfsadm:instsync" 1847c478bd9Sstevel@tonic-gate #define FILES_MID "devfsadm:files" 1857c478bd9Sstevel@tonic-gate #define ENUM_MID "devfsadm:enum" 1868d483882Smlf #define RSRV_MID "devfsadm:rsrv" /* enum interface reserve */ 1878d483882Smlf #define RSBY_MID "devfsadm:rsby" /* enum reserve bypass */ 1887c478bd9Sstevel@tonic-gate #define LINKCACHE_MID "devfsadm:linkcache" 1897c478bd9Sstevel@tonic-gate #define ADDREMCACHE_MID "devfsadm:addremcache" 1907c478bd9Sstevel@tonic-gate #define MALLOC_MID "devfsadm:malloc" 191facf4a8dSllai1 #define READDIR_MID "devfsadm:readdir" 192facf4a8dSllai1 #define READDIR_ALL_MID "devfsadm:readdir_all" 193facf4a8dSllai1 #define DEVNAME_MID "devfsadm:devname" 1947c478bd9Sstevel@tonic-gate #define ALL_MID "all" 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate #define DEVFSADM_DEBUG_ON (verbose == NULL) ? FALSE : TRUE 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate typedef struct recurse_dev { 1997c478bd9Sstevel@tonic-gate void (*fcn)(char *, void *); 2007c478bd9Sstevel@tonic-gate void *data; 2017c478bd9Sstevel@tonic-gate } recurse_dev_t; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate typedef struct link { 2047c478bd9Sstevel@tonic-gate char *devlink; /* without ".../dev/" prefix */ 2057c478bd9Sstevel@tonic-gate char *contents; /* without "../devices" prefix */ 2067c478bd9Sstevel@tonic-gate struct link *next; 2077c478bd9Sstevel@tonic-gate } link_t; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate typedef struct linkhead { 2107c478bd9Sstevel@tonic-gate regex_t dir_re_compiled; 2117c478bd9Sstevel@tonic-gate char *dir_re; 2127c478bd9Sstevel@tonic-gate link_t *link; 2137c478bd9Sstevel@tonic-gate link_t *nextlink; 2147c478bd9Sstevel@tonic-gate struct linkhead *nexthead; 2157c478bd9Sstevel@tonic-gate } linkhead_t; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate typedef struct link_list { 2187c478bd9Sstevel@tonic-gate int type; 2197c478bd9Sstevel@tonic-gate char *constant; 2207c478bd9Sstevel@tonic-gate int arg; 2217c478bd9Sstevel@tonic-gate struct link_list *next; 2227c478bd9Sstevel@tonic-gate } link_list_t; 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate typedef struct selector_list { 2257c478bd9Sstevel@tonic-gate int key; 2267c478bd9Sstevel@tonic-gate char *val; 2277c478bd9Sstevel@tonic-gate int arg; 2287c478bd9Sstevel@tonic-gate struct selector_list *next; 2297c478bd9Sstevel@tonic-gate } selector_list_t; 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate typedef struct devlinktab_list { 2327c478bd9Sstevel@tonic-gate int line_number; 2337c478bd9Sstevel@tonic-gate char *selector_pattern; 2347c478bd9Sstevel@tonic-gate char *p_link_pattern; 2357c478bd9Sstevel@tonic-gate char *s_link_pattern; 2367c478bd9Sstevel@tonic-gate selector_list_t *selector; 2377c478bd9Sstevel@tonic-gate link_list_t *p_link; 2387c478bd9Sstevel@tonic-gate link_list_t *s_link; 2397c478bd9Sstevel@tonic-gate struct devlinktab_list *next; 2407c478bd9Sstevel@tonic-gate } devlinktab_list_t; 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate typedef struct module { 2437c478bd9Sstevel@tonic-gate char *name; 2447c478bd9Sstevel@tonic-gate void *dlhandle; 2457c478bd9Sstevel@tonic-gate int (*minor_init)(); 2467c478bd9Sstevel@tonic-gate int (*minor_fini)(); 2477c478bd9Sstevel@tonic-gate int flags; 2487c478bd9Sstevel@tonic-gate struct module *next; 2497c478bd9Sstevel@tonic-gate } module_t; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate typedef struct create_list { 2527c478bd9Sstevel@tonic-gate devfsadm_create_t *create; 2537c478bd9Sstevel@tonic-gate module_t *modptr; 2547c478bd9Sstevel@tonic-gate regex_t node_type_comp; 2557c478bd9Sstevel@tonic-gate regex_t drv_name_comp; 2567c478bd9Sstevel@tonic-gate struct create_list *next; 2577c478bd9Sstevel@tonic-gate } create_list_t; 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate struct minor { 2607c478bd9Sstevel@tonic-gate di_node_t node; 2617c478bd9Sstevel@tonic-gate di_minor_t minor; 2627c478bd9Sstevel@tonic-gate struct minor *next; 2637c478bd9Sstevel@tonic-gate }; 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate struct mlist { 2667c478bd9Sstevel@tonic-gate struct minor *head; 2677c478bd9Sstevel@tonic-gate struct minor *tail; 2687c478bd9Sstevel@tonic-gate }; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate typedef struct remove_list { 271aa646b9dSvikram devfsadm_remove_V1_t *remove; 2727c478bd9Sstevel@tonic-gate module_t *modptr; 2737c478bd9Sstevel@tonic-gate struct remove_list *next; 2747c478bd9Sstevel@tonic-gate } remove_list_t; 2757c478bd9Sstevel@tonic-gate 276aa646b9dSvikram typedef struct item { 277aa646b9dSvikram char *i_key; 278aa646b9dSvikram struct item *i_next; 279aa646b9dSvikram } item_t; 280aa646b9dSvikram 2817c478bd9Sstevel@tonic-gate typedef struct cleanup_data { 2827c478bd9Sstevel@tonic-gate int flags; 2837c478bd9Sstevel@tonic-gate char *phypath; 2847c478bd9Sstevel@tonic-gate remove_list_t *rm; 2857c478bd9Sstevel@tonic-gate } cleanup_data_t; 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate typedef struct n2m { 2887c478bd9Sstevel@tonic-gate major_t major; 2897c478bd9Sstevel@tonic-gate char *driver; 2907c478bd9Sstevel@tonic-gate struct n2m *next; 2917c478bd9Sstevel@tonic-gate } n2m_t; 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* structures for devfsadm_enumerate() */ 2947c478bd9Sstevel@tonic-gate typedef struct numeral { 2957c478bd9Sstevel@tonic-gate char *id; 2967c478bd9Sstevel@tonic-gate char *full_path; 2977c478bd9Sstevel@tonic-gate int rule_index; 2987c478bd9Sstevel@tonic-gate char *cmp_str; 2997c478bd9Sstevel@tonic-gate struct numeral *next; 3008d483882Smlf int flags; 3017c478bd9Sstevel@tonic-gate } numeral_t; 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate typedef struct numeral_set { 3047c478bd9Sstevel@tonic-gate int re_count; 3057c478bd9Sstevel@tonic-gate char **re; 3067c478bd9Sstevel@tonic-gate numeral_t *headnumeral; 3077c478bd9Sstevel@tonic-gate struct numeral_set *next; 3087c478bd9Sstevel@tonic-gate } numeral_set_t; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate typedef struct temp { 3117c478bd9Sstevel@tonic-gate int integer; 3127c478bd9Sstevel@tonic-gate struct temp *next; 3137c478bd9Sstevel@tonic-gate } temp_t; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate typedef struct driver_alias { 3167c478bd9Sstevel@tonic-gate char *driver_name; 3177c478bd9Sstevel@tonic-gate char *alias_name; 3187c478bd9Sstevel@tonic-gate struct driver_alias *next; 3197c478bd9Sstevel@tonic-gate } driver_alias_t; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate struct driver_list { 3227c478bd9Sstevel@tonic-gate char driver_name[MAXNAMELEN]; 3237c478bd9Sstevel@tonic-gate struct driver_list *next; 3247c478bd9Sstevel@tonic-gate }; 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate struct login_dev { 3277c478bd9Sstevel@tonic-gate char *ldev_console; 3287c478bd9Sstevel@tonic-gate int ldev_perms; 3297c478bd9Sstevel@tonic-gate char *ldev_device; 3307c478bd9Sstevel@tonic-gate regex_t ldev_device_regex; 3317c478bd9Sstevel@tonic-gate struct driver_list *ldev_driver_list; 3327c478bd9Sstevel@tonic-gate struct login_dev *ldev_next; 3337c478bd9Sstevel@tonic-gate }; 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate #define MAX_DEV_NAME_COUNT 100 3367c478bd9Sstevel@tonic-gate struct devlink_cb_arg { 3377c478bd9Sstevel@tonic-gate char *dev_names[MAX_DEV_NAME_COUNT]; 3387c478bd9Sstevel@tonic-gate char *link_contents[MAX_DEV_NAME_COUNT]; 3397c478bd9Sstevel@tonic-gate int count; 3407c478bd9Sstevel@tonic-gate int rv; 3417c478bd9Sstevel@tonic-gate }; 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate struct dca_impl { 3447c478bd9Sstevel@tonic-gate char *dci_root; 3457c478bd9Sstevel@tonic-gate char *dci_minor; 3467c478bd9Sstevel@tonic-gate char *dci_driver; 3477c478bd9Sstevel@tonic-gate void *dci_arg; 3487c478bd9Sstevel@tonic-gate int dci_error; 3497c478bd9Sstevel@tonic-gate int dci_flags; 3507c478bd9Sstevel@tonic-gate }; 3517c478bd9Sstevel@tonic-gate 352f05faa4eSjacobs /* sysevent queue related */ 353f05faa4eSjacobs typedef struct syseventq_s { 354f05faa4eSjacobs struct syseventq_s *next; 355f05faa4eSjacobs char *class; 356f05faa4eSjacobs char *subclass; 357f05faa4eSjacobs nvlist_t *nvl; 358f05faa4eSjacobs } syseventq_t; 359f05faa4eSjacobs 3607c478bd9Sstevel@tonic-gate static int devfsadm_enumerate_int_start(char *devfs_path, 3617c478bd9Sstevel@tonic-gate int index, char **buf, devfsadm_enumerate_t rules[], 3627c478bd9Sstevel@tonic-gate int nrules, char *start); 363facf4a8dSllai1 static void set_root_devices_dev_dir(char *dir); 3647c478bd9Sstevel@tonic-gate static void pre_and_post_cleanup(int flags); 3657c478bd9Sstevel@tonic-gate static void hot_cleanup(char *, char *, char *, char *, int); 3667c478bd9Sstevel@tonic-gate static void devfsadm_exit(int status); 3677c478bd9Sstevel@tonic-gate static void rm_link_from_cache(char *devlink); 3687c478bd9Sstevel@tonic-gate static void rm_all_links_from_cache(); 3697c478bd9Sstevel@tonic-gate static void add_link_to_cache(char *devlink, char *physpath); 3707c478bd9Sstevel@tonic-gate static linkhead_t *get_cached_links(char *dir_re); 3717c478bd9Sstevel@tonic-gate static void build_devlink_list(char *check_link, void *data); 3727c478bd9Sstevel@tonic-gate static void instance_flush_thread(void); 3734bc0a2efScasper static int s_rmdir(char *path); 3747c478bd9Sstevel@tonic-gate static void rm_parent_dir_if_empty(char *path); 3757c478bd9Sstevel@tonic-gate static void free_link_list(link_list_t *head); 3767c478bd9Sstevel@tonic-gate static void free_selector_list(selector_list_t *head); 3777c478bd9Sstevel@tonic-gate void devfsadm_err_print(char *message, ...); 3787c478bd9Sstevel@tonic-gate void defvsadm_print(int level, char *message, ...); 3797c478bd9Sstevel@tonic-gate static int call_minor_init(module_t *module); 3807c478bd9Sstevel@tonic-gate static void load_module(char *module, char *cdir); 3817c478bd9Sstevel@tonic-gate static void invalidate_enumerate_cache(void); 3827c478bd9Sstevel@tonic-gate static pid_t enter_dev_lock(void); 383537714daSvikram static void exit_dev_lock(int exiting); 3847c478bd9Sstevel@tonic-gate static pid_t enter_daemon_lock(void); 385537714daSvikram static void exit_daemon_lock(int exiting); 3867c478bd9Sstevel@tonic-gate static int process_devlink_compat(di_minor_t minor, di_node_t node); 3877c478bd9Sstevel@tonic-gate static int alias(char *, char *); 3887c478bd9Sstevel@tonic-gate static int devfsadm_copy(void); 3897c478bd9Sstevel@tonic-gate static void flush_path_to_inst(void); 3907c478bd9Sstevel@tonic-gate static void detachfromtty(void); 3917c478bd9Sstevel@tonic-gate static void minor_process(di_node_t node, di_minor_t minor, 3927c478bd9Sstevel@tonic-gate struct mlist *dep); 3937c478bd9Sstevel@tonic-gate static void read_minor_perm_file(void); 3947c478bd9Sstevel@tonic-gate static void read_driver_aliases_file(void); 3957c478bd9Sstevel@tonic-gate static void load_modules(void); 3967c478bd9Sstevel@tonic-gate static void unload_modules(void); 3977c478bd9Sstevel@tonic-gate static void *s_malloc(const size_t size); 3987c478bd9Sstevel@tonic-gate static void *s_zalloc(const size_t size); 3997c478bd9Sstevel@tonic-gate static void devfs_instance_mod(void); 4007c478bd9Sstevel@tonic-gate static void add_minor_pathname(char *, char *, char *); 4017c478bd9Sstevel@tonic-gate static int check_minor_type(di_node_t node, di_minor_t minor, void *arg); 4027c478bd9Sstevel@tonic-gate static void cache_deferred_minor(struct mlist *dep, di_node_t node, 4037c478bd9Sstevel@tonic-gate di_minor_t minor); 4047c478bd9Sstevel@tonic-gate static int compare_field(char *full_name, char *field_item, int field); 4057c478bd9Sstevel@tonic-gate static int component_cat(char *link, char *name, int field); 4067c478bd9Sstevel@tonic-gate static void recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd); 4077c478bd9Sstevel@tonic-gate static void matching_dev(char *devpath, void *data); 4087c478bd9Sstevel@tonic-gate static int resolve_link(char *devpath, char **content_p, int *type_p, 4097c478bd9Sstevel@tonic-gate char **devfs_path, int dangle); 410aa646b9dSvikram static int clean_ok(devfsadm_remove_V1_t *remove); 4117c478bd9Sstevel@tonic-gate static int translate_major(dev_t old_dev, dev_t *new_dev); 4127c478bd9Sstevel@tonic-gate static int get_major_no(char *driver, major_t *major); 4137c478bd9Sstevel@tonic-gate static int load_n2m_table(char *filename); 4147c478bd9Sstevel@tonic-gate static int get_stat_info(char *, struct stat *); 4157c478bd9Sstevel@tonic-gate static char *new_id(numeral_t *, int, char *); 4167c478bd9Sstevel@tonic-gate static int find_enum_id(devfsadm_enumerate_t rules[], int nrules, 4177c478bd9Sstevel@tonic-gate char *devfs_path, int index, char *min, int type, char **buf, int multiple); 4187c478bd9Sstevel@tonic-gate static void daemon_update(void); 4197c478bd9Sstevel@tonic-gate static void usage(void); 4207c478bd9Sstevel@tonic-gate static int getnexttoken(char *next, char **nextp, char **tokenpp, char *tchar); 4217c478bd9Sstevel@tonic-gate static int class_ok(char *class); 4227c478bd9Sstevel@tonic-gate static int create_link_common(char *devlink, char *contents, int *exists); 4237c478bd9Sstevel@tonic-gate static char *dequote(char *src); 4247c478bd9Sstevel@tonic-gate static void parse_args(int argc, char *argv[]); 4257c478bd9Sstevel@tonic-gate static void process_devinfo_tree(void); 426ff2aee48Scth static void minor_fini_thread(void *arg); 4277c478bd9Sstevel@tonic-gate static void *s_realloc(void *ptr, const size_t size); 4287c478bd9Sstevel@tonic-gate static void read_devlinktab_file(void); 4297c478bd9Sstevel@tonic-gate static selector_list_t *create_selector_list(char *selector); 4307c478bd9Sstevel@tonic-gate static int parse_selector(char **selector, char **key, char **val); 4317c478bd9Sstevel@tonic-gate int devfsadm_noupdate(void); 4327c478bd9Sstevel@tonic-gate const char *devfsadm_root_path(void); 4337c478bd9Sstevel@tonic-gate static link_list_t *create_link_list(char *link); 4347c478bd9Sstevel@tonic-gate static void s_unlink(const char *file); 4357c478bd9Sstevel@tonic-gate static void s_closedir(DIR *dirp); 4367c478bd9Sstevel@tonic-gate static void s_mkdirp(const char *path, const mode_t mode); 4377c478bd9Sstevel@tonic-gate static int is_minor_node(char *contents, char **mn_root); 4387c478bd9Sstevel@tonic-gate static int construct_devlink(char *link, link_list_t *link_build, 4397c478bd9Sstevel@tonic-gate char *contents, di_minor_t minor, 4407c478bd9Sstevel@tonic-gate di_node_t node, char *pattern); 4417c478bd9Sstevel@tonic-gate static int split_devlinktab_entry(char *entry, char **selector, char **p_link, 4427c478bd9Sstevel@tonic-gate char **s_link); 4437c478bd9Sstevel@tonic-gate static int devlink_matches(devlinktab_list_t *entry, di_minor_t minor, 4447c478bd9Sstevel@tonic-gate di_node_t node); 4457c478bd9Sstevel@tonic-gate static int build_links(devlinktab_list_t *entry, di_minor_t minor, 4467c478bd9Sstevel@tonic-gate di_node_t node); 4477c478bd9Sstevel@tonic-gate static numeral_set_t *get_enum_cache(devfsadm_enumerate_t rules[], 4487c478bd9Sstevel@tonic-gate int nrules); 4497c478bd9Sstevel@tonic-gate static void enumerate_recurse(char *current_dir, char *path_left, 4507c478bd9Sstevel@tonic-gate numeral_set_t *setp, devfsadm_enumerate_t rules[], int index); 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate static int match_path_component(char *file_re, char *file, char **id, 4537c478bd9Sstevel@tonic-gate int subexp); 4547c478bd9Sstevel@tonic-gate static void create_cached_numeral(char *path, numeral_set_t *setp, 4557c478bd9Sstevel@tonic-gate char *numeral_id, devfsadm_enumerate_t rules[], int index); 4567c478bd9Sstevel@tonic-gate static int devfsadm_copy_file(const char *file, const struct stat *stat, 4577c478bd9Sstevel@tonic-gate int flags, struct FTW *ftw); 4587c478bd9Sstevel@tonic-gate static void getattr(char *devname, char *aminor, int spectype, dev_t dev, 4597c478bd9Sstevel@tonic-gate mode_t *mode, uid_t *uid, gid_t *gid); 4607c478bd9Sstevel@tonic-gate static int minor_matches_rule(di_node_t node, di_minor_t minor, 4617c478bd9Sstevel@tonic-gate create_list_t *create); 4627c478bd9Sstevel@tonic-gate static void add_verbose_id(char *mid); 4637c478bd9Sstevel@tonic-gate static char *get_component(char *str, const char *comp_num); 4647c478bd9Sstevel@tonic-gate static char *alloc_cmp_str(const char *devfs_path, devfsadm_enumerate_t *dep); 4657c478bd9Sstevel@tonic-gate static int lookup_enum_cache(numeral_set_t *set, char *cmp_str, 4667c478bd9Sstevel@tonic-gate devfsadm_enumerate_t rules[], int index, numeral_t **matchnpp); 4677c478bd9Sstevel@tonic-gate static void sync_handler(void *cookie, char *ap, size_t asize, 4687c478bd9Sstevel@tonic-gate door_desc_t *dp, uint_t ndesc); 4697c478bd9Sstevel@tonic-gate static int zone_pathcheck(char *checkpath); 4707c478bd9Sstevel@tonic-gate static void process_deferred_links(struct dca_impl *dcip, int flag); 4717c478bd9Sstevel@tonic-gate static void event_handler(sysevent_t *ev); 4727c478bd9Sstevel@tonic-gate static void dca_impl_init(char *root, char *minor, struct dca_impl *dcip); 4737c478bd9Sstevel@tonic-gate static void lock_dev(void); 4747c478bd9Sstevel@tonic-gate static void unlock_dev(int flag); 4753c4226f9Spjha static int devlink_cb(di_devlink_t dl, void *arg); 4763c4226f9Spjha static void free_dev_names(struct devlink_cb_arg *x); 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate int load_devpolicy(void); 4797c478bd9Sstevel@tonic-gate static void load_dev_acl(void); 4807c478bd9Sstevel@tonic-gate static void load_minor_perm_file(void); 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate static nvlist_t *build_event_attributes(char *, char *, char *, 48330294554Sphitran di_node_t, char *, int, char *); 4847c478bd9Sstevel@tonic-gate static void log_event(char *, char *, nvlist_t *); 48530294554Sphitran static void build_and_enq_event(char *, char *, char *, di_node_t, char *); 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate static void read_logindevperm_file(void); 4887c478bd9Sstevel@tonic-gate static void set_logindev_perms(char *devlink); 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate static void reset_node_permissions(di_node_t, di_minor_t); 4917c478bd9Sstevel@tonic-gate 492facf4a8dSllai1 /* 493facf4a8dSllai1 * devname related 494facf4a8dSllai1 */ 495facf4a8dSllai1 static void devname_lookup_handler(void *, char *, size_t, 496facf4a8dSllai1 door_desc_t *, uint_t); /* /dev name lookup server */ 497facf4a8dSllai1 static int devname_kcall(int, void *); /* syscall into the devname fs */ 4988d483882Smlf 499aa646b9dSvikram static void nfphash_create(void); 500aa646b9dSvikram static int nfphash_fcn(char *key); 501aa646b9dSvikram static item_t *nfphash_lookup(char *key); 502aa646b9dSvikram static void nfphash_insert(char *key); 503aa646b9dSvikram static void nfphash_destroy(void); 5047c478bd9Sstevel@tonic-gate 5058d483882Smlf /* Enumerate reserve related */ 5068d483882Smlf static void read_enumerate_file(void); 5078d483882Smlf static int enumerate_parse(char *rsvstr, char *path_left, numeral_set_t *setp, 5088d483882Smlf devfsadm_enumerate_t rules[], int index); 5098d483882Smlf static void create_reserved_numeral(numeral_set_t *setp, char *numeral_id); 5108d483882Smlf 5117c478bd9Sstevel@tonic-gate /* convenient short hands */ 5127c478bd9Sstevel@tonic-gate #define vprint devfsadm_print 5137c478bd9Sstevel@tonic-gate #define err_print devfsadm_errprint 514facf4a8dSllai1 #ifndef TRUE 5157c478bd9Sstevel@tonic-gate #define TRUE 1 516facf4a8dSllai1 #endif 517facf4a8dSllai1 #ifndef FALSE 5187c478bd9Sstevel@tonic-gate #define FALSE 0 519facf4a8dSllai1 #endif 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate #ifdef __cplusplus 5227c478bd9Sstevel@tonic-gate } 5237c478bd9Sstevel@tonic-gate #endif 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate #endif /* _DEVFSADM_IMPL_H */ 526