xref: /titanic_50/usr/src/cmd/devfsadm/devfsadm_impl.h (revision 8d483882aa3390058094b043f3d62187b5d1de03)
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  *
21ff2aee48Scth  * Copyright 2007 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>
77facf4a8dSllai1 #include <sys/fs/sdev_node.h>
78facf4a8dSllai1 #include <sys/syscall.h>
79facf4a8dSllai1 #include <rpcsvc/ypclnt.h>
80facf4a8dSllai1 #include <sys/sysevent/eventdefs.h>
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	DEV_LOCK_FILE ".devfsadm_dev.lock"
837c478bd9Sstevel@tonic-gate #define	DAEMON_LOCK_FILE ".devfsadm_daemon.lock"
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #define	DEV "/dev"
86facf4a8dSllai1 #define	ETC "/etc"
87facf4a8dSllai1 #define	ETCDEV "/etc/dev"
887c478bd9Sstevel@tonic-gate #define	DEV_LEN 4
897c478bd9Sstevel@tonic-gate #define	DEVICES "/devices"
907c478bd9Sstevel@tonic-gate #define	DEVICES_LEN 8
917c478bd9Sstevel@tonic-gate #define	MODULE_DIRS "/usr/lib/devfsadm/linkmod"
927c478bd9Sstevel@tonic-gate #define	ALIASFILE "/etc/driver_aliases"
937c478bd9Sstevel@tonic-gate #define	NAME_TO_MAJOR "/etc/name_to_major"
947c478bd9Sstevel@tonic-gate #define	RECONFIG_BOOT "_INIT_RECONFIG"
957c478bd9Sstevel@tonic-gate #define	PID_STR_LEN 10
967c478bd9Sstevel@tonic-gate #define	EXTRA_PRIVS	"/etc/security/extra_privs"
977c478bd9Sstevel@tonic-gate #define	DEV_POLICY	"/etc/security/device_policy"
987c478bd9Sstevel@tonic-gate #define	LDEV_FILE	"/etc/logindevperm"
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #define	DEVFSADM_DEFAULT_FILE "/etc/default/devfsadm"
1017c478bd9Sstevel@tonic-gate 
102f05faa4eSjacobs #define	MINOR_FINI_TIMEOUT_DEFAULT 2
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	SYNCH_DOOR_PERMS	(S_IRUSR | S_IWUSR)
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #define	DRVCONFIG "drvconfig"
1077c478bd9Sstevel@tonic-gate #define	DEVFSADM "devfsadm"
1087c478bd9Sstevel@tonic-gate #define	DEVFSADMD "devfsadmd"
1097c478bd9Sstevel@tonic-gate #define	DEVLINKS "devlinks"
1107c478bd9Sstevel@tonic-gate #define	TAPES "tapes"
1117c478bd9Sstevel@tonic-gate #define	AUDLINKS "audlinks"
1127c478bd9Sstevel@tonic-gate #define	PORTS "ports"
1137c478bd9Sstevel@tonic-gate #define	DISKS "disks"
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate #define	MAX_IDLE_DELAY 5
1167c478bd9Sstevel@tonic-gate #define	MAX_DELAY 30
1177c478bd9Sstevel@tonic-gate #define	NAME 0x01
1187c478bd9Sstevel@tonic-gate #define	ADDR 0x03
1197c478bd9Sstevel@tonic-gate #define	MINOR 0x04
1207c478bd9Sstevel@tonic-gate #define	COUNTER 0x05
1217c478bd9Sstevel@tonic-gate #define	CONSTANT 0x06
1227c478bd9Sstevel@tonic-gate #define	TYPE 0x07
1237c478bd9Sstevel@tonic-gate #define	TYPE_S "type"
1247c478bd9Sstevel@tonic-gate #define	ADDR_S "addr"
1257c478bd9Sstevel@tonic-gate #define	ADDR_S_LEN 4
1267c478bd9Sstevel@tonic-gate #define	MINOR_S "minor"
1277c478bd9Sstevel@tonic-gate #define	MINOR_S_LEN 5
1287c478bd9Sstevel@tonic-gate #define	NAME_S "name"
1297c478bd9Sstevel@tonic-gate #define	TAB '\t'
1307c478bd9Sstevel@tonic-gate #define	NEWLINE '\n'
1317c478bd9Sstevel@tonic-gate #define	MAX_DEVLINK_LINE 4028
1327c478bd9Sstevel@tonic-gate #define	INTEGER 0
1337c478bd9Sstevel@tonic-gate #define	LETTER 1
1347c478bd9Sstevel@tonic-gate #define	MAX_PERM_LINE 256
1357c478bd9Sstevel@tonic-gate #define	MAX_LDEV_LINE 256
1367c478bd9Sstevel@tonic-gate #define	LDEV_DELIMS " \t\n"
1377c478bd9Sstevel@tonic-gate #define	LDEV_DRVLIST_DELIMS "="
1387c478bd9Sstevel@tonic-gate #define	LDEV_DRV_DELIMS ", \t\n"
1397c478bd9Sstevel@tonic-gate #define	LDEV_DEV_DELIM ":"
1407c478bd9Sstevel@tonic-gate #define	LDEV_DRVLIST_NAME "driver"
141aa646b9dSvikram #define	NFP_HASH_SZ 256
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #define	TYPE_LINK 0x00
1447c478bd9Sstevel@tonic-gate #define	TYPE_DEVICES 0x01
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #define	CREATE_LINK 0x01
1477c478bd9Sstevel@tonic-gate #define	READ_LINK 0x02
1487c478bd9Sstevel@tonic-gate #define	CREATE_NODE 0x01
1497c478bd9Sstevel@tonic-gate #define	READ_NODE 0x02
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #define	CACHE_STATE 0x0
1527c478bd9Sstevel@tonic-gate #define	SYNC_STATE 0x1
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #define	MODULE_ACTIVE 0x01
1557c478bd9Sstevel@tonic-gate 
156*8d483882Smlf /* Possible flag values for flag member of numeral_t */
157*8d483882Smlf #define	NUMERAL_RESERVED 0x01
158*8d483882Smlf 
1597c478bd9Sstevel@tonic-gate #define	MAX_SLEEP 120
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #define	DEVLINKTAB_FILE "/etc/devlink.tab"
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #define	MODULE_SUFFIX ".so"
1647c478bd9Sstevel@tonic-gate #define	MINOR_INIT "minor_init"
1657c478bd9Sstevel@tonic-gate #define	MINOR_FINI "minor_fini"
1667c478bd9Sstevel@tonic-gate #define	_DEVFSADM_CREATE_REG "_devfsadm_create_reg"
1677c478bd9Sstevel@tonic-gate #define	_DEVFSADM_REMOVE_REG "_devfsadm_remove_reg"
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #define	NUM_EV_STR		4
1707c478bd9Sstevel@tonic-gate #define	EV_TYPE			0
1717c478bd9Sstevel@tonic-gate #define	EV_CLASS		1
1727c478bd9Sstevel@tonic-gate #define	EV_PATH_NAME		2
1737c478bd9Sstevel@tonic-gate #define	EV_MINOR_NAME		3
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate /* add new debug level and meanings here */
1767c478bd9Sstevel@tonic-gate #define	DEVLINK_MID		"devfsadm:devlink"
1777c478bd9Sstevel@tonic-gate #define	MODLOAD_MID		"devfsadm:modload"
1787c478bd9Sstevel@tonic-gate #define	INITFINI_MID		"devfsadm:initfini"
1797c478bd9Sstevel@tonic-gate #define	EVENT_MID		"devfsadm:event"
1807c478bd9Sstevel@tonic-gate #define	REMOVE_MID		"devfsadm:remove"
1817c478bd9Sstevel@tonic-gate #define	LOCK_MID		"devfsadm:lock"
1827c478bd9Sstevel@tonic-gate #define	PATH2INST_MID		"devfsadm:path2inst"
1837c478bd9Sstevel@tonic-gate #define	CACHE_MID		"devfsadm:cache"
1847c478bd9Sstevel@tonic-gate #define	BUILDCACHE_MID		"devfsadm:buildcache"
1857c478bd9Sstevel@tonic-gate #define	RECURSEDEV_MID		"devfsadm:recursedev"
1867c478bd9Sstevel@tonic-gate #define	INSTSYNC_MID		"devfsadm:instsync"
1877c478bd9Sstevel@tonic-gate #define	FILES_MID		"devfsadm:files"
1887c478bd9Sstevel@tonic-gate #define	ENUM_MID		"devfsadm:enum"
189*8d483882Smlf #define	RSRV_MID		"devfsadm:rsrv"	/* enum interface reserve  */
190*8d483882Smlf #define	RSBY_MID		"devfsadm:rsby"	/* enum reserve bypass */
1917c478bd9Sstevel@tonic-gate #define	LINKCACHE_MID		"devfsadm:linkcache"
1927c478bd9Sstevel@tonic-gate #define	ADDREMCACHE_MID		"devfsadm:addremcache"
1937c478bd9Sstevel@tonic-gate #define	MALLOC_MID		"devfsadm:malloc"
194facf4a8dSllai1 #define	READDIR_MID		"devfsadm:readdir"
195facf4a8dSllai1 #define	READDIR_ALL_MID		"devfsadm:readdir_all"
196facf4a8dSllai1 #define	DEVNAME_MID		"devfsadm:devname"
1977c478bd9Sstevel@tonic-gate #define	ALL_MID			"all"
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate #define	DEVFSADM_DEBUG_ON	(verbose == NULL) ? FALSE : TRUE
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate typedef struct recurse_dev {
2027c478bd9Sstevel@tonic-gate 	void (*fcn)(char *, void *);
2037c478bd9Sstevel@tonic-gate 	void *data;
2047c478bd9Sstevel@tonic-gate } recurse_dev_t;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate typedef struct link {
2077c478bd9Sstevel@tonic-gate 	char *devlink; /* without ".../dev/"   prefix */
2087c478bd9Sstevel@tonic-gate 	char *contents; /* without "../devices" prefix */
2097c478bd9Sstevel@tonic-gate 	struct link *next;
2107c478bd9Sstevel@tonic-gate } link_t;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate typedef struct linkhead {
2137c478bd9Sstevel@tonic-gate 	regex_t dir_re_compiled;
2147c478bd9Sstevel@tonic-gate 	char *dir_re;
2157c478bd9Sstevel@tonic-gate 	link_t *link;
2167c478bd9Sstevel@tonic-gate 	link_t *nextlink;
2177c478bd9Sstevel@tonic-gate 	struct linkhead *nexthead;
2187c478bd9Sstevel@tonic-gate } linkhead_t;
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate typedef struct link_list  {
2217c478bd9Sstevel@tonic-gate 	int type;
2227c478bd9Sstevel@tonic-gate 	char *constant;
2237c478bd9Sstevel@tonic-gate 	int arg;
2247c478bd9Sstevel@tonic-gate 	struct link_list *next;
2257c478bd9Sstevel@tonic-gate } link_list_t;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate typedef struct selector_list {
2287c478bd9Sstevel@tonic-gate 	int key;
2297c478bd9Sstevel@tonic-gate 	char *val;
2307c478bd9Sstevel@tonic-gate 	int arg;
2317c478bd9Sstevel@tonic-gate 	struct selector_list *next;
2327c478bd9Sstevel@tonic-gate } selector_list_t;
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate typedef struct devlinktab_list {
2357c478bd9Sstevel@tonic-gate 	int line_number;
2367c478bd9Sstevel@tonic-gate 	char *selector_pattern;
2377c478bd9Sstevel@tonic-gate 	char *p_link_pattern;
2387c478bd9Sstevel@tonic-gate 	char *s_link_pattern;
2397c478bd9Sstevel@tonic-gate 	selector_list_t *selector;
2407c478bd9Sstevel@tonic-gate 	link_list_t *p_link;
2417c478bd9Sstevel@tonic-gate 	link_list_t *s_link;
2427c478bd9Sstevel@tonic-gate 	struct devlinktab_list *next;
2437c478bd9Sstevel@tonic-gate } devlinktab_list_t;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate typedef struct module {
2467c478bd9Sstevel@tonic-gate 	char *name;
2477c478bd9Sstevel@tonic-gate 	void *dlhandle;
2487c478bd9Sstevel@tonic-gate 	int (*minor_init)();
2497c478bd9Sstevel@tonic-gate 	int (*minor_fini)();
2507c478bd9Sstevel@tonic-gate 	int flags;
2517c478bd9Sstevel@tonic-gate 	struct module *next;
2527c478bd9Sstevel@tonic-gate } module_t;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate typedef struct create_list {
2557c478bd9Sstevel@tonic-gate 	devfsadm_create_t *create;
2567c478bd9Sstevel@tonic-gate 	module_t *modptr;
2577c478bd9Sstevel@tonic-gate 	regex_t node_type_comp;
2587c478bd9Sstevel@tonic-gate 	regex_t drv_name_comp;
2597c478bd9Sstevel@tonic-gate 	struct create_list *next;
2607c478bd9Sstevel@tonic-gate } create_list_t;
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate struct minor {
2637c478bd9Sstevel@tonic-gate 	di_node_t node;
2647c478bd9Sstevel@tonic-gate 	di_minor_t minor;
2657c478bd9Sstevel@tonic-gate 	struct minor *next;
2667c478bd9Sstevel@tonic-gate };
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate struct mlist {
2697c478bd9Sstevel@tonic-gate 	struct minor *head;
2707c478bd9Sstevel@tonic-gate 	struct minor *tail;
2717c478bd9Sstevel@tonic-gate };
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate typedef struct remove_list {
274aa646b9dSvikram 	devfsadm_remove_V1_t *remove;
2757c478bd9Sstevel@tonic-gate 	module_t *modptr;
2767c478bd9Sstevel@tonic-gate 	struct remove_list *next;
2777c478bd9Sstevel@tonic-gate } remove_list_t;
2787c478bd9Sstevel@tonic-gate 
279aa646b9dSvikram typedef struct item {
280aa646b9dSvikram 	char *i_key;
281aa646b9dSvikram 	struct item *i_next;
282aa646b9dSvikram } item_t;
283aa646b9dSvikram 
2847c478bd9Sstevel@tonic-gate typedef struct cleanup_data {
2857c478bd9Sstevel@tonic-gate 	int flags;
2867c478bd9Sstevel@tonic-gate 	char *phypath;
2877c478bd9Sstevel@tonic-gate 	remove_list_t *rm;
2887c478bd9Sstevel@tonic-gate } cleanup_data_t;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate typedef struct n2m {
2917c478bd9Sstevel@tonic-gate 	major_t major;
2927c478bd9Sstevel@tonic-gate 	char *driver;
2937c478bd9Sstevel@tonic-gate 	struct n2m *next;
2947c478bd9Sstevel@tonic-gate } n2m_t;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate /* structures for devfsadm_enumerate() */
2977c478bd9Sstevel@tonic-gate typedef struct numeral {
2987c478bd9Sstevel@tonic-gate 	char *id;
2997c478bd9Sstevel@tonic-gate 	char *full_path;
3007c478bd9Sstevel@tonic-gate 	int rule_index;
3017c478bd9Sstevel@tonic-gate 	char *cmp_str;
3027c478bd9Sstevel@tonic-gate 	struct numeral *next;
303*8d483882Smlf 	int flags;
3047c478bd9Sstevel@tonic-gate } numeral_t;
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate typedef struct numeral_set {
3077c478bd9Sstevel@tonic-gate 	int re_count;
3087c478bd9Sstevel@tonic-gate 	char **re;
3097c478bd9Sstevel@tonic-gate 	numeral_t *headnumeral;
3107c478bd9Sstevel@tonic-gate 	struct numeral_set *next;
3117c478bd9Sstevel@tonic-gate } numeral_set_t;
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate typedef struct temp {
3147c478bd9Sstevel@tonic-gate 	int integer;
3157c478bd9Sstevel@tonic-gate 	struct temp *next;
3167c478bd9Sstevel@tonic-gate } temp_t;
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate typedef struct driver_alias {
3197c478bd9Sstevel@tonic-gate 	char *driver_name;
3207c478bd9Sstevel@tonic-gate 	char *alias_name;
3217c478bd9Sstevel@tonic-gate 	struct driver_alias *next;
3227c478bd9Sstevel@tonic-gate } driver_alias_t;
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate struct driver_list {
3257c478bd9Sstevel@tonic-gate 	char driver_name[MAXNAMELEN];
3267c478bd9Sstevel@tonic-gate 	struct driver_list *next;
3277c478bd9Sstevel@tonic-gate };
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate struct login_dev {
3307c478bd9Sstevel@tonic-gate 	char *ldev_console;
3317c478bd9Sstevel@tonic-gate 	int ldev_perms;
3327c478bd9Sstevel@tonic-gate 	char *ldev_device;
3337c478bd9Sstevel@tonic-gate 	regex_t ldev_device_regex;
3347c478bd9Sstevel@tonic-gate 	struct driver_list *ldev_driver_list;
3357c478bd9Sstevel@tonic-gate 	struct login_dev *ldev_next;
3367c478bd9Sstevel@tonic-gate };
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate #define	MAX_DEV_NAME_COUNT	100
3397c478bd9Sstevel@tonic-gate struct devlink_cb_arg {
3407c478bd9Sstevel@tonic-gate 	char *dev_names[MAX_DEV_NAME_COUNT];
3417c478bd9Sstevel@tonic-gate 	char *link_contents[MAX_DEV_NAME_COUNT];
3427c478bd9Sstevel@tonic-gate 	int count;
3437c478bd9Sstevel@tonic-gate 	int rv;
3447c478bd9Sstevel@tonic-gate };
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate struct dca_impl {
3477c478bd9Sstevel@tonic-gate 	char *dci_root;
3487c478bd9Sstevel@tonic-gate 	char *dci_minor;
3497c478bd9Sstevel@tonic-gate 	char *dci_driver;
3507c478bd9Sstevel@tonic-gate 	void *dci_arg;
3517c478bd9Sstevel@tonic-gate 	int dci_error;
3527c478bd9Sstevel@tonic-gate 	int dci_flags;
3537c478bd9Sstevel@tonic-gate };
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate /* RCM related */
3567c478bd9Sstevel@tonic-gate struct rcm_eventq {
3577c478bd9Sstevel@tonic-gate 	nvlist_t *nvl;
3587c478bd9Sstevel@tonic-gate 	struct rcm_eventq *next;
3597c478bd9Sstevel@tonic-gate };
3607c478bd9Sstevel@tonic-gate 
361f05faa4eSjacobs /* sysevent queue related */
362f05faa4eSjacobs typedef struct syseventq_s {
363f05faa4eSjacobs 	struct syseventq_s *next;
364f05faa4eSjacobs 	char *class;
365f05faa4eSjacobs 	char *subclass;
366f05faa4eSjacobs 	nvlist_t *nvl;
367f05faa4eSjacobs } syseventq_t;
368f05faa4eSjacobs 
3697c478bd9Sstevel@tonic-gate static int devfsadm_enumerate_int_start(char *devfs_path,
3707c478bd9Sstevel@tonic-gate 	int index, char **buf, devfsadm_enumerate_t rules[],
3717c478bd9Sstevel@tonic-gate 	int nrules, char *start);
372facf4a8dSllai1 static void set_root_devices_dev_dir(char *dir);
3737c478bd9Sstevel@tonic-gate static void pre_and_post_cleanup(int flags);
3747c478bd9Sstevel@tonic-gate static void hot_cleanup(char *, char *, char *, char *, int);
3757c478bd9Sstevel@tonic-gate static void devfsadm_exit(int status);
3767c478bd9Sstevel@tonic-gate static void rm_link_from_cache(char *devlink);
3777c478bd9Sstevel@tonic-gate static void rm_all_links_from_cache();
3787c478bd9Sstevel@tonic-gate static void add_link_to_cache(char *devlink, char *physpath);
3797c478bd9Sstevel@tonic-gate static linkhead_t *get_cached_links(char *dir_re);
3807c478bd9Sstevel@tonic-gate static void build_devlink_list(char *check_link, void *data);
3817c478bd9Sstevel@tonic-gate static void instance_flush_thread(void);
3824bc0a2efScasper static int s_rmdir(char *path);
3837c478bd9Sstevel@tonic-gate static void rm_parent_dir_if_empty(char *path);
3847c478bd9Sstevel@tonic-gate static void free_link_list(link_list_t *head);
3857c478bd9Sstevel@tonic-gate static void free_selector_list(selector_list_t *head);
3867c478bd9Sstevel@tonic-gate void devfsadm_err_print(char *message, ...);
3877c478bd9Sstevel@tonic-gate void defvsadm_print(int level, char *message, ...);
3887c478bd9Sstevel@tonic-gate static int call_minor_init(module_t *module);
3897c478bd9Sstevel@tonic-gate static void load_module(char *module, char *cdir);
3907c478bd9Sstevel@tonic-gate static void invalidate_enumerate_cache(void);
3917c478bd9Sstevel@tonic-gate static pid_t enter_dev_lock(void);
3927c478bd9Sstevel@tonic-gate static void exit_dev_lock(void);
3937c478bd9Sstevel@tonic-gate static pid_t enter_daemon_lock(void);
3947c478bd9Sstevel@tonic-gate static void exit_daemon_lock(void);
3957c478bd9Sstevel@tonic-gate static int process_devlink_compat(di_minor_t minor, di_node_t node);
3967c478bd9Sstevel@tonic-gate static int alias(char *, char *);
3977c478bd9Sstevel@tonic-gate static int devfsadm_copy(void);
3987c478bd9Sstevel@tonic-gate static void flush_path_to_inst(void);
3997c478bd9Sstevel@tonic-gate static void detachfromtty(void);
4007c478bd9Sstevel@tonic-gate static void minor_process(di_node_t node, di_minor_t minor,
4017c478bd9Sstevel@tonic-gate     struct mlist *dep);
4027c478bd9Sstevel@tonic-gate static void read_minor_perm_file(void);
4037c478bd9Sstevel@tonic-gate static void read_driver_aliases_file(void);
4047c478bd9Sstevel@tonic-gate static void load_modules(void);
4057c478bd9Sstevel@tonic-gate static void unload_modules(void);
4067c478bd9Sstevel@tonic-gate static void *s_malloc(const size_t size);
4077c478bd9Sstevel@tonic-gate static void *s_zalloc(const size_t size);
4087c478bd9Sstevel@tonic-gate static void devfs_instance_mod(void);
4097c478bd9Sstevel@tonic-gate static void add_minor_pathname(char *, char *, char *);
4107c478bd9Sstevel@tonic-gate static int check_minor_type(di_node_t node, di_minor_t minor, void *arg);
4117c478bd9Sstevel@tonic-gate static void cache_deferred_minor(struct mlist *dep, di_node_t node,
4127c478bd9Sstevel@tonic-gate     di_minor_t minor);
4137c478bd9Sstevel@tonic-gate static int compare_field(char *full_name, char *field_item, int field);
4147c478bd9Sstevel@tonic-gate static int component_cat(char *link, char *name, int field);
4157c478bd9Sstevel@tonic-gate static void recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd);
4167c478bd9Sstevel@tonic-gate static void matching_dev(char *devpath, void *data);
4177c478bd9Sstevel@tonic-gate static int resolve_link(char *devpath, char **content_p, int *type_p,
4187c478bd9Sstevel@tonic-gate     char **devfs_path, int dangle);
419aa646b9dSvikram static int clean_ok(devfsadm_remove_V1_t *remove);
4207c478bd9Sstevel@tonic-gate static int translate_major(dev_t old_dev, dev_t *new_dev);
4217c478bd9Sstevel@tonic-gate static int get_major_no(char *driver, major_t *major);
4227c478bd9Sstevel@tonic-gate static int load_n2m_table(char *filename);
4237c478bd9Sstevel@tonic-gate static int get_stat_info(char *, struct stat *);
4247c478bd9Sstevel@tonic-gate static char *new_id(numeral_t *, int, char *);
4257c478bd9Sstevel@tonic-gate static int find_enum_id(devfsadm_enumerate_t rules[], int nrules,
4267c478bd9Sstevel@tonic-gate     char *devfs_path, int index, char *min, int type, char **buf, int multiple);
4277c478bd9Sstevel@tonic-gate static void daemon_update(void);
4287c478bd9Sstevel@tonic-gate static void usage(void);
4297c478bd9Sstevel@tonic-gate static int getnexttoken(char *next, char **nextp, char **tokenpp, char *tchar);
4307c478bd9Sstevel@tonic-gate static int class_ok(char *class);
4317c478bd9Sstevel@tonic-gate static int create_link_common(char *devlink, char *contents, int *exists);
4327c478bd9Sstevel@tonic-gate static char *dequote(char *src);
4337c478bd9Sstevel@tonic-gate static void parse_args(int argc, char *argv[]);
4347c478bd9Sstevel@tonic-gate static void process_devinfo_tree(void);
435ff2aee48Scth static void minor_fini_thread(void *arg);
4367c478bd9Sstevel@tonic-gate static void *s_realloc(void *ptr, const size_t size);
4377c478bd9Sstevel@tonic-gate static void read_devlinktab_file(void);
4387c478bd9Sstevel@tonic-gate static selector_list_t *create_selector_list(char *selector);
4397c478bd9Sstevel@tonic-gate static int parse_selector(char **selector, char **key, char **val);
4407c478bd9Sstevel@tonic-gate int devfsadm_noupdate(void);
4417c478bd9Sstevel@tonic-gate const char *devfsadm_root_path(void);
4427c478bd9Sstevel@tonic-gate static link_list_t *create_link_list(char *link);
4437c478bd9Sstevel@tonic-gate static void s_unlink(const char *file);
4447c478bd9Sstevel@tonic-gate static void s_closedir(DIR *dirp);
4457c478bd9Sstevel@tonic-gate static void s_mkdirp(const char *path, const mode_t mode);
4467c478bd9Sstevel@tonic-gate static int is_minor_node(char *contents, char **mn_root);
4477c478bd9Sstevel@tonic-gate static int construct_devlink(char *link, link_list_t *link_build,
4487c478bd9Sstevel@tonic-gate 				char *contents, di_minor_t minor,
4497c478bd9Sstevel@tonic-gate 				di_node_t node, char *pattern);
4507c478bd9Sstevel@tonic-gate static int split_devlinktab_entry(char *entry, char **selector, char **p_link,
4517c478bd9Sstevel@tonic-gate 	    char **s_link);
4527c478bd9Sstevel@tonic-gate static int devlink_matches(devlinktab_list_t *entry, di_minor_t minor,
4537c478bd9Sstevel@tonic-gate 			    di_node_t node);
4547c478bd9Sstevel@tonic-gate static int build_links(devlinktab_list_t *entry, di_minor_t minor,
4557c478bd9Sstevel@tonic-gate 			di_node_t node);
4567c478bd9Sstevel@tonic-gate static numeral_set_t *get_enum_cache(devfsadm_enumerate_t rules[],
4577c478bd9Sstevel@tonic-gate 				    int nrules);
4587c478bd9Sstevel@tonic-gate static void enumerate_recurse(char *current_dir, char *path_left,
4597c478bd9Sstevel@tonic-gate     numeral_set_t *setp, devfsadm_enumerate_t rules[], int index);
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate static int match_path_component(char *file_re, char *file, char **id,
4627c478bd9Sstevel@tonic-gate 				int subexp);
4637c478bd9Sstevel@tonic-gate static void create_cached_numeral(char *path, numeral_set_t *setp,
4647c478bd9Sstevel@tonic-gate     char *numeral_id, devfsadm_enumerate_t rules[], int index);
4657c478bd9Sstevel@tonic-gate static int devfsadm_copy_file(const char *file, const struct stat *stat,
4667c478bd9Sstevel@tonic-gate 			    int flags, struct FTW *ftw);
4677c478bd9Sstevel@tonic-gate static void getattr(char *devname, char *aminor, int spectype, dev_t dev,
4687c478bd9Sstevel@tonic-gate     mode_t *mode, uid_t *uid, gid_t *gid);
4697c478bd9Sstevel@tonic-gate static int minor_matches_rule(di_node_t node, di_minor_t minor,
4707c478bd9Sstevel@tonic-gate 				create_list_t *create);
4717c478bd9Sstevel@tonic-gate static void add_verbose_id(char *mid);
4727c478bd9Sstevel@tonic-gate static char *get_component(char *str, const char *comp_num);
4737c478bd9Sstevel@tonic-gate static char *alloc_cmp_str(const char *devfs_path, devfsadm_enumerate_t *dep);
4747c478bd9Sstevel@tonic-gate static int lookup_enum_cache(numeral_set_t *set, char *cmp_str,
4757c478bd9Sstevel@tonic-gate     devfsadm_enumerate_t rules[], int index, numeral_t **matchnpp);
4767c478bd9Sstevel@tonic-gate static void sync_handler(void *cookie, char *ap, size_t asize,
4777c478bd9Sstevel@tonic-gate     door_desc_t *dp, uint_t ndesc);
4787c478bd9Sstevel@tonic-gate static int zone_pathcheck(char *checkpath);
4797c478bd9Sstevel@tonic-gate static void process_deferred_links(struct dca_impl *dcip, int flag);
4807c478bd9Sstevel@tonic-gate static void event_handler(sysevent_t *ev);
4817c478bd9Sstevel@tonic-gate static int rcm_init(void);
4827c478bd9Sstevel@tonic-gate static int notify_rcm(di_node_t node, char *minor_name);
4837c478bd9Sstevel@tonic-gate static void dca_impl_init(char *root, char *minor, struct dca_impl *dcip);
4847c478bd9Sstevel@tonic-gate static void lock_dev(void);
4857c478bd9Sstevel@tonic-gate static void unlock_dev(int flag);
4863c4226f9Spjha static int devlink_cb(di_devlink_t dl, void *arg);
4873c4226f9Spjha static void free_dev_names(struct devlink_cb_arg *x);
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate int load_devpolicy(void);
4907c478bd9Sstevel@tonic-gate static void load_dev_acl(void);
4917c478bd9Sstevel@tonic-gate static void load_minor_perm_file(void);
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate static int (*librcm_alloc_handle)(char *, uint_t, void *, rcm_handle_t **);
4947c478bd9Sstevel@tonic-gate static void (*librcm_free_handle)(rcm_handle_t *);
4957c478bd9Sstevel@tonic-gate static int (*librcm_notify_event)(rcm_handle_t *, char *, uint_t, nvlist_t *,
4967c478bd9Sstevel@tonic-gate     rcm_info_t *);
4977c478bd9Sstevel@tonic-gate static nvlist_t *build_event_attributes(char *, char *, char *,
49830294554Sphitran     di_node_t, char *, int, char *);
4997c478bd9Sstevel@tonic-gate static void log_event(char *, char *, nvlist_t *);
50030294554Sphitran static void build_and_enq_event(char *, char *, char *, di_node_t, char *);
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate static void read_logindevperm_file(void);
5037c478bd9Sstevel@tonic-gate static void set_logindev_perms(char *devlink);
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate static void reset_node_permissions(di_node_t, di_minor_t);
5067c478bd9Sstevel@tonic-gate 
507facf4a8dSllai1 /*
508facf4a8dSllai1  * devname related
509facf4a8dSllai1  */
510facf4a8dSllai1 static void devname_lookup_handler(void *, char *, size_t,
511facf4a8dSllai1     door_desc_t *, uint_t);		/* /dev name lookup server */
512facf4a8dSllai1 static int devname_kcall(int, void *);	/* syscall into the devname fs */
513*8d483882Smlf 
514aa646b9dSvikram static void nfphash_create(void);
515aa646b9dSvikram static int nfphash_fcn(char *key);
516aa646b9dSvikram static item_t *nfphash_lookup(char *key);
517aa646b9dSvikram static void nfphash_insert(char *key);
518aa646b9dSvikram static void nfphash_destroy(void);
5197c478bd9Sstevel@tonic-gate 
520*8d483882Smlf /* Enumerate reserve related */
521*8d483882Smlf static void read_enumerate_file(void);
522*8d483882Smlf static int enumerate_parse(char *rsvstr, char *path_left, numeral_set_t *setp,
523*8d483882Smlf     devfsadm_enumerate_t rules[], int index);
524*8d483882Smlf static void create_reserved_numeral(numeral_set_t *setp, char *numeral_id);
525*8d483882Smlf 
5267c478bd9Sstevel@tonic-gate /* convenient short hands */
5277c478bd9Sstevel@tonic-gate #define	vprint		devfsadm_print
5287c478bd9Sstevel@tonic-gate #define	err_print	devfsadm_errprint
529facf4a8dSllai1 #ifndef TRUE
5307c478bd9Sstevel@tonic-gate #define	TRUE	1
531facf4a8dSllai1 #endif
532facf4a8dSllai1 #ifndef FALSE
5337c478bd9Sstevel@tonic-gate #define	FALSE	0
534facf4a8dSllai1 #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