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