10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52587Spjha  * Common Development and Distribution License (the "License").
62587Spjha  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  *
212587Spjha  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
220Sstevel@tonic-gate  * Use is subject to license terms.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef _DEVFSADM_IMPL_H
260Sstevel@tonic-gate #define	_DEVFSADM_IMPL_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifdef	__cplusplus
310Sstevel@tonic-gate extern "C" {
320Sstevel@tonic-gate #endif
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <dlfcn.h>
350Sstevel@tonic-gate #include <stdarg.h>
360Sstevel@tonic-gate #include <fcntl.h>
370Sstevel@tonic-gate #include <sys/file.h>
380Sstevel@tonic-gate #include <locale.h>
390Sstevel@tonic-gate #include <libintl.h>
400Sstevel@tonic-gate #include <ctype.h>
410Sstevel@tonic-gate #include <signal.h>
420Sstevel@tonic-gate #include <deflt.h>
430Sstevel@tonic-gate #include <ftw.h>
440Sstevel@tonic-gate #include <sys/instance.h>
450Sstevel@tonic-gate #include <sys/types.h>
460Sstevel@tonic-gate #include <dirent.h>
470Sstevel@tonic-gate #include <pwd.h>
480Sstevel@tonic-gate #include <grp.h>
490Sstevel@tonic-gate #include <stdio.h>
500Sstevel@tonic-gate #include <stdlib.h>
510Sstevel@tonic-gate #include <sys/mkdev.h>
520Sstevel@tonic-gate #include <sys/stat.h>
530Sstevel@tonic-gate #include <fcntl.h>
540Sstevel@tonic-gate #include <errno.h>
550Sstevel@tonic-gate #include <unistd.h>
560Sstevel@tonic-gate #include <sys/stat.h>
570Sstevel@tonic-gate #include <sys/int_types.h>
580Sstevel@tonic-gate #include <limits.h>
590Sstevel@tonic-gate #include <strings.h>
600Sstevel@tonic-gate #include <devfsadm.h>
610Sstevel@tonic-gate #include <libdevinfo.h>
620Sstevel@tonic-gate #include <sys/devinfo_impl.h>
630Sstevel@tonic-gate #include <sys/modctl.h>
640Sstevel@tonic-gate #include <libgen.h>
650Sstevel@tonic-gate #include <sys/hwconf.h>
660Sstevel@tonic-gate #include <sys/sunddi.h>
670Sstevel@tonic-gate #include <door.h>
680Sstevel@tonic-gate #include <syslog.h>
690Sstevel@tonic-gate #include <libsysevent.h>
700Sstevel@tonic-gate #include <thread.h>
710Sstevel@tonic-gate #include <message.h>
720Sstevel@tonic-gate #include <sys/cladm.h>
730Sstevel@tonic-gate #include <librcm.h>
740Sstevel@tonic-gate #include <sys/sysevent/dev.h>
750Sstevel@tonic-gate #include <libzonecfg.h>
760Sstevel@tonic-gate #include <device_info.h>
77*2621Sllai1 #include <sys/fs/sdev_node.h>
78*2621Sllai1 #include <sys/syscall.h>
79*2621Sllai1 #include <rpcsvc/ypclnt.h>
80*2621Sllai1 #include <sys/sysevent/eventdefs.h>
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #undef	DEBUG
830Sstevel@tonic-gate #ifndef DEBUG
840Sstevel@tonic-gate #define	NDEBUG 1
850Sstevel@tonic-gate #else
860Sstevel@tonic-gate #undef	NDEBUG
870Sstevel@tonic-gate #endif
880Sstevel@tonic-gate 
890Sstevel@tonic-gate #include <assert.h>
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 
920Sstevel@tonic-gate #define	DEV_LOCK_FILE ".devfsadm_dev.lock"
930Sstevel@tonic-gate #define	DAEMON_LOCK_FILE ".devfsadm_daemon.lock"
940Sstevel@tonic-gate 
950Sstevel@tonic-gate #define	DEV "/dev"
96*2621Sllai1 #define	ETC "/etc"
97*2621Sllai1 #define	ETCDEV "/etc/dev"
980Sstevel@tonic-gate #define	DEV_LEN 4
990Sstevel@tonic-gate #define	DEVICES "/devices"
1000Sstevel@tonic-gate #define	DEVICES_LEN 8
1010Sstevel@tonic-gate #define	MODULE_DIRS "/usr/lib/devfsadm/linkmod"
1020Sstevel@tonic-gate #define	ALIASFILE "/etc/driver_aliases"
1030Sstevel@tonic-gate #define	NAME_TO_MAJOR "/etc/name_to_major"
1040Sstevel@tonic-gate #define	RECONFIG_BOOT "_INIT_RECONFIG"
1050Sstevel@tonic-gate #define	PID_STR_LEN 10
1060Sstevel@tonic-gate #define	EXTRA_PRIVS	"/etc/security/extra_privs"
1070Sstevel@tonic-gate #define	DEV_POLICY	"/etc/security/device_policy"
1080Sstevel@tonic-gate #define	LDEV_FILE	"/etc/logindevperm"
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate #define	DEVFSADM_DEFAULT_FILE "/etc/default/devfsadm"
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate #define	MINOR_FINI_TIMEOUT_DEFAULT 2
1130Sstevel@tonic-gate #define	FORCE_CALL_MINOR_FINI	10
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate #define	SYNCH_DOOR_PERMS	(S_IRUSR | S_IWUSR)
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate #define	DRVCONFIG "drvconfig"
1180Sstevel@tonic-gate #define	DEVFSADM "devfsadm"
1190Sstevel@tonic-gate #define	DEVFSADMD "devfsadmd"
1200Sstevel@tonic-gate #define	DEVLINKS "devlinks"
1210Sstevel@tonic-gate #define	TAPES "tapes"
1220Sstevel@tonic-gate #define	AUDLINKS "audlinks"
1230Sstevel@tonic-gate #define	PORTS "ports"
1240Sstevel@tonic-gate #define	DISKS "disks"
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate #define	MAX_IDLE_DELAY 5
1270Sstevel@tonic-gate #define	MAX_DELAY 30
1280Sstevel@tonic-gate #define	NAME 0x01
1290Sstevel@tonic-gate #define	ADDR 0x03
1300Sstevel@tonic-gate #define	MINOR 0x04
1310Sstevel@tonic-gate #define	COUNTER 0x05
1320Sstevel@tonic-gate #define	CONSTANT 0x06
1330Sstevel@tonic-gate #define	TYPE 0x07
1340Sstevel@tonic-gate #define	TYPE_S "type"
1350Sstevel@tonic-gate #define	ADDR_S "addr"
1360Sstevel@tonic-gate #define	ADDR_S_LEN 4
1370Sstevel@tonic-gate #define	MINOR_S "minor"
1380Sstevel@tonic-gate #define	MINOR_S_LEN 5
1390Sstevel@tonic-gate #define	NAME_S "name"
1400Sstevel@tonic-gate #define	TAB '\t'
1410Sstevel@tonic-gate #define	NEWLINE '\n'
1420Sstevel@tonic-gate #define	MAX_DEVLINK_LINE 4028
1430Sstevel@tonic-gate #define	INTEGER 0
1440Sstevel@tonic-gate #define	LETTER 1
1450Sstevel@tonic-gate #define	MAX_PERM_LINE 256
1460Sstevel@tonic-gate #define	MAX_LDEV_LINE 256
1470Sstevel@tonic-gate #define	LDEV_DELIMS " \t\n"
1480Sstevel@tonic-gate #define	LDEV_DRVLIST_DELIMS "="
1490Sstevel@tonic-gate #define	LDEV_DRV_DELIMS ", \t\n"
1500Sstevel@tonic-gate #define	LDEV_DEV_DELIM ":"
1510Sstevel@tonic-gate #define	LDEV_DRVLIST_NAME "driver"
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate #define	TYPE_LINK 0x00
1540Sstevel@tonic-gate #define	TYPE_DEVICES 0x01
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate #define	CREATE_LINK 0x01
1570Sstevel@tonic-gate #define	READ_LINK 0x02
1580Sstevel@tonic-gate #define	CREATE_NODE 0x01
1590Sstevel@tonic-gate #define	READ_NODE 0x02
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate #define	DCA_CREATE_LINK	0x01
1620Sstevel@tonic-gate #define	DCA_FREE_LIST 0x02
1630Sstevel@tonic-gate #define	DCA_LOAD_DRV 0x04
1640Sstevel@tonic-gate #define	DCA_CHECK_TYPE 0x10
1650Sstevel@tonic-gate #define	DCA_NOTIFY_RCM 0x20
1660Sstevel@tonic-gate #define	DCA_FLUSH_PATHINST 0x40
1670Sstevel@tonic-gate #define	DCA_HOT_PLUG 0x80
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate #define	CACHE_STATE 0x0
1700Sstevel@tonic-gate #define	SYNC_STATE 0x1
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate #define	MODULE_ACTIVE 0x01
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate #define	MAX_SLEEP 120
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate #define	DEVLINKTAB_FILE "/etc/devlink.tab"
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate #define	MODULE_SUFFIX ".so"
1790Sstevel@tonic-gate #define	MINOR_INIT "minor_init"
1800Sstevel@tonic-gate #define	MINOR_FINI "minor_fini"
1810Sstevel@tonic-gate #define	_DEVFSADM_CREATE_REG "_devfsadm_create_reg"
1820Sstevel@tonic-gate #define	_DEVFSADM_REMOVE_REG "_devfsadm_remove_reg"
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate #define	NUM_EV_STR		4
1850Sstevel@tonic-gate #define	EV_TYPE			0
1860Sstevel@tonic-gate #define	EV_CLASS		1
1870Sstevel@tonic-gate #define	EV_PATH_NAME		2
1880Sstevel@tonic-gate #define	EV_MINOR_NAME		3
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate /* add new debug level and meanings here */
1910Sstevel@tonic-gate #define	DEVLINK_MID		"devfsadm:devlink"
1920Sstevel@tonic-gate #define	MODLOAD_MID		"devfsadm:modload"
1930Sstevel@tonic-gate #define	INITFINI_MID		"devfsadm:initfini"
1940Sstevel@tonic-gate #define	EVENT_MID		"devfsadm:event"
1950Sstevel@tonic-gate #define	REMOVE_MID		"devfsadm:remove"
1960Sstevel@tonic-gate #define	LOCK_MID		"devfsadm:lock"
1970Sstevel@tonic-gate #define	PATH2INST_MID		"devfsadm:path2inst"
1980Sstevel@tonic-gate #define	CACHE_MID		"devfsadm:cache"
1990Sstevel@tonic-gate #define	BUILDCACHE_MID		"devfsadm:buildcache"
2000Sstevel@tonic-gate #define	RECURSEDEV_MID		"devfsadm:recursedev"
2010Sstevel@tonic-gate #define	INSTSYNC_MID		"devfsadm:instsync"
2020Sstevel@tonic-gate #define	FILES_MID		"devfsadm:files"
2030Sstevel@tonic-gate #define	ENUM_MID		"devfsadm:enum"
2040Sstevel@tonic-gate #define	LINKCACHE_MID		"devfsadm:linkcache"
2050Sstevel@tonic-gate #define	ADDREMCACHE_MID		"devfsadm:addremcache"
2060Sstevel@tonic-gate #define	MALLOC_MID		"devfsadm:malloc"
207*2621Sllai1 #define	READDIR_MID		"devfsadm:readdir"
208*2621Sllai1 #define	READDIR_ALL_MID		"devfsadm:readdir_all"
209*2621Sllai1 #define	DEVNAME_MID		"devfsadm:devname"
2100Sstevel@tonic-gate #define	ALL_MID			"all"
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate #define	DEVFSADM_DEBUG_ON	(verbose == NULL) ? FALSE : TRUE
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate typedef struct recurse_dev {
2150Sstevel@tonic-gate 	void (*fcn)(char *, void *);
2160Sstevel@tonic-gate 	void *data;
2170Sstevel@tonic-gate } recurse_dev_t;
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate typedef struct link {
2200Sstevel@tonic-gate 	char *devlink; /* without ".../dev/"   prefix */
2210Sstevel@tonic-gate 	char *contents; /* without "../devices" prefix */
2220Sstevel@tonic-gate 	struct link *next;
2230Sstevel@tonic-gate } link_t;
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate typedef struct linkhead {
2260Sstevel@tonic-gate 	regex_t dir_re_compiled;
2270Sstevel@tonic-gate 	char *dir_re;
2280Sstevel@tonic-gate 	link_t *link;
2290Sstevel@tonic-gate 	link_t *nextlink;
2300Sstevel@tonic-gate 	struct linkhead *nexthead;
2310Sstevel@tonic-gate } linkhead_t;
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate typedef struct link_list  {
2340Sstevel@tonic-gate 	int type;
2350Sstevel@tonic-gate 	char *constant;
2360Sstevel@tonic-gate 	int arg;
2370Sstevel@tonic-gate 	struct link_list *next;
2380Sstevel@tonic-gate } link_list_t;
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate typedef struct selector_list {
2410Sstevel@tonic-gate 	int key;
2420Sstevel@tonic-gate 	char *val;
2430Sstevel@tonic-gate 	int arg;
2440Sstevel@tonic-gate 	struct selector_list *next;
2450Sstevel@tonic-gate } selector_list_t;
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate typedef struct devlinktab_list {
2480Sstevel@tonic-gate 	int line_number;
2490Sstevel@tonic-gate 	char *selector_pattern;
2500Sstevel@tonic-gate 	char *p_link_pattern;
2510Sstevel@tonic-gate 	char *s_link_pattern;
2520Sstevel@tonic-gate 	selector_list_t *selector;
2530Sstevel@tonic-gate 	link_list_t *p_link;
2540Sstevel@tonic-gate 	link_list_t *s_link;
2550Sstevel@tonic-gate 	struct devlinktab_list *next;
2560Sstevel@tonic-gate } devlinktab_list_t;
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate typedef struct module {
2590Sstevel@tonic-gate 	char *name;
2600Sstevel@tonic-gate 	void *dlhandle;
2610Sstevel@tonic-gate 	int (*minor_init)();
2620Sstevel@tonic-gate 	int (*minor_fini)();
2630Sstevel@tonic-gate 	int flags;
2640Sstevel@tonic-gate 	struct module *next;
2650Sstevel@tonic-gate } module_t;
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate typedef struct create_list {
2680Sstevel@tonic-gate 	devfsadm_create_t *create;
2690Sstevel@tonic-gate 	module_t *modptr;
2700Sstevel@tonic-gate 	regex_t node_type_comp;
2710Sstevel@tonic-gate 	regex_t drv_name_comp;
2720Sstevel@tonic-gate 	struct create_list *next;
2730Sstevel@tonic-gate } create_list_t;
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate struct minor {
2760Sstevel@tonic-gate 	di_node_t node;
2770Sstevel@tonic-gate 	di_minor_t minor;
2780Sstevel@tonic-gate 	struct minor *next;
2790Sstevel@tonic-gate };
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate struct mlist {
2820Sstevel@tonic-gate 	struct minor *head;
2830Sstevel@tonic-gate 	struct minor *tail;
2840Sstevel@tonic-gate };
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate typedef struct remove_list {
2870Sstevel@tonic-gate 	devfsadm_remove_t *remove;
2880Sstevel@tonic-gate 	module_t *modptr;
2890Sstevel@tonic-gate 	struct remove_list *next;
2900Sstevel@tonic-gate } remove_list_t;
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate typedef struct cleanup_data {
2930Sstevel@tonic-gate 	int flags;
2940Sstevel@tonic-gate 	char *phypath;
2950Sstevel@tonic-gate 	remove_list_t *rm;
2960Sstevel@tonic-gate } cleanup_data_t;
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate typedef struct n2m {
2990Sstevel@tonic-gate 	major_t major;
3000Sstevel@tonic-gate 	char *driver;
3010Sstevel@tonic-gate 	struct n2m *next;
3020Sstevel@tonic-gate } n2m_t;
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate /* structures for devfsadm_enumerate() */
3050Sstevel@tonic-gate typedef struct numeral {
3060Sstevel@tonic-gate 	char *id;
3070Sstevel@tonic-gate 	char *full_path;
3080Sstevel@tonic-gate 	int rule_index;
3090Sstevel@tonic-gate 	char *cmp_str;
3100Sstevel@tonic-gate 	struct numeral *next;
3110Sstevel@tonic-gate } numeral_t;
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate typedef struct numeral_set {
3140Sstevel@tonic-gate 	int re_count;
3150Sstevel@tonic-gate 	char **re;
3160Sstevel@tonic-gate 	numeral_t *headnumeral;
3170Sstevel@tonic-gate 	struct numeral_set *next;
3180Sstevel@tonic-gate } numeral_set_t;
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate typedef struct temp {
3210Sstevel@tonic-gate 	int integer;
3220Sstevel@tonic-gate 	struct temp *next;
3230Sstevel@tonic-gate } temp_t;
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate typedef struct driver_alias {
3260Sstevel@tonic-gate 	char *driver_name;
3270Sstevel@tonic-gate 	char *alias_name;
3280Sstevel@tonic-gate 	struct driver_alias *next;
3290Sstevel@tonic-gate } driver_alias_t;
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate struct driver_list {
3320Sstevel@tonic-gate 	char driver_name[MAXNAMELEN];
3330Sstevel@tonic-gate 	struct driver_list *next;
3340Sstevel@tonic-gate };
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate struct login_dev {
3370Sstevel@tonic-gate 	char *ldev_console;
3380Sstevel@tonic-gate 	int ldev_perms;
3390Sstevel@tonic-gate 	char *ldev_device;
3400Sstevel@tonic-gate 	regex_t ldev_device_regex;
3410Sstevel@tonic-gate 	struct driver_list *ldev_driver_list;
3420Sstevel@tonic-gate 	struct login_dev *ldev_next;
3430Sstevel@tonic-gate };
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate #define	MAX_DEV_NAME_COUNT	100
3460Sstevel@tonic-gate struct devlink_cb_arg {
3470Sstevel@tonic-gate 	char *dev_names[MAX_DEV_NAME_COUNT];
3480Sstevel@tonic-gate 	char *link_contents[MAX_DEV_NAME_COUNT];
3490Sstevel@tonic-gate 	int count;
3500Sstevel@tonic-gate 	int rv;
3510Sstevel@tonic-gate };
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate struct dca_impl {
3540Sstevel@tonic-gate 	char *dci_root;
3550Sstevel@tonic-gate 	char *dci_minor;
3560Sstevel@tonic-gate 	char *dci_driver;
3570Sstevel@tonic-gate 	void *dci_arg;
3580Sstevel@tonic-gate 	int dci_error;
3590Sstevel@tonic-gate 	int dci_flags;
3600Sstevel@tonic-gate };
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate /* RCM related */
3630Sstevel@tonic-gate struct rcm_eventq {
3640Sstevel@tonic-gate 	nvlist_t *nvl;
3650Sstevel@tonic-gate 	struct rcm_eventq *next;
3660Sstevel@tonic-gate };
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate static int devfsadm_enumerate_int_start(char *devfs_path,
3690Sstevel@tonic-gate 	int index, char **buf, devfsadm_enumerate_t rules[],
3700Sstevel@tonic-gate 	int nrules, char *start);
3710Sstevel@tonic-gate static void startup_cache_sync_thread(void);
372*2621Sllai1 static void set_root_devices_dev_dir(char *dir);
3730Sstevel@tonic-gate static void pre_and_post_cleanup(int flags);
3740Sstevel@tonic-gate static void hot_cleanup(char *, char *, char *, char *, int);
3750Sstevel@tonic-gate static void devfsadm_exit(int status);
3760Sstevel@tonic-gate static void rm_link_from_cache(char *devlink);
3770Sstevel@tonic-gate static void rm_all_links_from_cache();
3780Sstevel@tonic-gate static void add_link_to_cache(char *devlink, char *physpath);
3790Sstevel@tonic-gate static linkhead_t *get_cached_links(char *dir_re);
3800Sstevel@tonic-gate static void build_devlink_list(char *check_link, void *data);
3810Sstevel@tonic-gate static void instance_flush_thread(void);
382871Scasper static int s_rmdir(char *path);
3830Sstevel@tonic-gate static void rm_parent_dir_if_empty(char *path);
3840Sstevel@tonic-gate static void free_link_list(link_list_t *head);
3850Sstevel@tonic-gate static void free_selector_list(selector_list_t *head);
3860Sstevel@tonic-gate void devfsadm_err_print(char *message, ...);
3870Sstevel@tonic-gate void defvsadm_print(int level, char *message, ...);
3880Sstevel@tonic-gate static int call_minor_init(module_t *module);
3890Sstevel@tonic-gate static void load_module(char *module, char *cdir);
3900Sstevel@tonic-gate static void invalidate_enumerate_cache(void);
3910Sstevel@tonic-gate static pid_t enter_dev_lock(void);
3920Sstevel@tonic-gate static void exit_dev_lock(void);
3930Sstevel@tonic-gate static pid_t enter_daemon_lock(void);
3940Sstevel@tonic-gate static void exit_daemon_lock(void);
3950Sstevel@tonic-gate static int process_devlink_compat(di_minor_t minor, di_node_t node);
3960Sstevel@tonic-gate static int alias(char *, char *);
3970Sstevel@tonic-gate static int devfsadm_copy(void);
3980Sstevel@tonic-gate static void flush_path_to_inst(void);
3990Sstevel@tonic-gate static void detachfromtty(void);
4000Sstevel@tonic-gate static void minor_process(di_node_t node, di_minor_t minor,
4010Sstevel@tonic-gate     struct mlist *dep);
4020Sstevel@tonic-gate static void read_minor_perm_file(void);
4030Sstevel@tonic-gate static void read_driver_aliases_file(void);
4040Sstevel@tonic-gate static void load_modules(void);
4050Sstevel@tonic-gate static void unload_modules(void);
4060Sstevel@tonic-gate static void *s_malloc(const size_t size);
4070Sstevel@tonic-gate static void *s_zalloc(const size_t size);
4080Sstevel@tonic-gate static void devfs_instance_mod(void);
4090Sstevel@tonic-gate static void add_minor_pathname(char *, char *, char *);
4100Sstevel@tonic-gate static int check_minor_type(di_node_t node, di_minor_t minor, void *arg);
4110Sstevel@tonic-gate static void cache_deferred_minor(struct mlist *dep, di_node_t node,
4120Sstevel@tonic-gate     di_minor_t minor);
4130Sstevel@tonic-gate static int compare_field(char *full_name, char *field_item, int field);
4140Sstevel@tonic-gate static int component_cat(char *link, char *name, int field);
4150Sstevel@tonic-gate static void recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd);
4160Sstevel@tonic-gate static void matching_dev(char *devpath, void *data);
4170Sstevel@tonic-gate static int resolve_link(char *devpath, char **content_p, int *type_p,
4180Sstevel@tonic-gate     char **devfs_path, int dangle);
4190Sstevel@tonic-gate static int clean_ok(devfsadm_remove_t *remove);
4200Sstevel@tonic-gate static int translate_major(dev_t old_dev, dev_t *new_dev);
4210Sstevel@tonic-gate static int get_major_no(char *driver, major_t *major);
4220Sstevel@tonic-gate static int load_n2m_table(char *filename);
4230Sstevel@tonic-gate static int get_stat_info(char *, struct stat *);
4240Sstevel@tonic-gate static char *new_id(numeral_t *, int, char *);
4250Sstevel@tonic-gate static int find_enum_id(devfsadm_enumerate_t rules[], int nrules,
4260Sstevel@tonic-gate     char *devfs_path, int index, char *min, int type, char **buf, int multiple);
4270Sstevel@tonic-gate static void daemon_update(void);
4280Sstevel@tonic-gate static void usage(void);
4290Sstevel@tonic-gate static int getnexttoken(char *next, char **nextp, char **tokenpp, char *tchar);
4300Sstevel@tonic-gate static int class_ok(char *class);
4310Sstevel@tonic-gate static int create_link_common(char *devlink, char *contents, int *exists);
4320Sstevel@tonic-gate static char *dequote(char *src);
4330Sstevel@tonic-gate static void parse_args(int argc, char *argv[]);
4340Sstevel@tonic-gate static void process_devinfo_tree(void);
4350Sstevel@tonic-gate static void call_minor_fini_thread(void *arg);
4360Sstevel@tonic-gate static void *s_realloc(void *ptr, const size_t size);
4370Sstevel@tonic-gate static void read_devlinktab_file(void);
4380Sstevel@tonic-gate static selector_list_t *create_selector_list(char *selector);
4390Sstevel@tonic-gate static int parse_selector(char **selector, char **key, char **val);
4400Sstevel@tonic-gate int devfsadm_noupdate(void);
4410Sstevel@tonic-gate const char *devfsadm_root_path(void);
4420Sstevel@tonic-gate static link_list_t *create_link_list(char *link);
4430Sstevel@tonic-gate static void s_unlink(const char *file);
4440Sstevel@tonic-gate static void s_closedir(DIR *dirp);
4450Sstevel@tonic-gate static void s_mkdirp(const char *path, const mode_t mode);
4460Sstevel@tonic-gate static int is_minor_node(char *contents, char **mn_root);
4470Sstevel@tonic-gate static int construct_devlink(char *link, link_list_t *link_build,
4480Sstevel@tonic-gate 				char *contents, di_minor_t minor,
4490Sstevel@tonic-gate 				di_node_t node, char *pattern);
4500Sstevel@tonic-gate static int split_devlinktab_entry(char *entry, char **selector, char **p_link,
4510Sstevel@tonic-gate 	    char **s_link);
4520Sstevel@tonic-gate static int devlink_matches(devlinktab_list_t *entry, di_minor_t minor,
4530Sstevel@tonic-gate 			    di_node_t node);
4540Sstevel@tonic-gate static int build_links(devlinktab_list_t *entry, di_minor_t minor,
4550Sstevel@tonic-gate 			di_node_t node);
4560Sstevel@tonic-gate static numeral_set_t *get_enum_cache(devfsadm_enumerate_t rules[],
4570Sstevel@tonic-gate 				    int nrules);
4580Sstevel@tonic-gate static void enumerate_recurse(char *current_dir, char *path_left,
4590Sstevel@tonic-gate     numeral_set_t *setp, devfsadm_enumerate_t rules[], int index);
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate static int match_path_component(char *file_re, char *file, char **id,
4620Sstevel@tonic-gate 				int subexp);
4630Sstevel@tonic-gate static void create_cached_numeral(char *path, numeral_set_t *setp,
4640Sstevel@tonic-gate     char *numeral_id, devfsadm_enumerate_t rules[], int index);
4650Sstevel@tonic-gate static int devfsadm_copy_file(const char *file, const struct stat *stat,
4660Sstevel@tonic-gate 			    int flags, struct FTW *ftw);
4670Sstevel@tonic-gate static void getattr(char *devname, char *aminor, int spectype, dev_t dev,
4680Sstevel@tonic-gate     mode_t *mode, uid_t *uid, gid_t *gid);
4690Sstevel@tonic-gate static int minor_matches_rule(di_node_t node, di_minor_t minor,
4700Sstevel@tonic-gate 				create_list_t *create);
4710Sstevel@tonic-gate static void add_verbose_id(char *mid);
4720Sstevel@tonic-gate static char *get_component(char *str, const char *comp_num);
4730Sstevel@tonic-gate static char *alloc_cmp_str(const char *devfs_path, devfsadm_enumerate_t *dep);
4740Sstevel@tonic-gate static int lookup_enum_cache(numeral_set_t *set, char *cmp_str,
4750Sstevel@tonic-gate     devfsadm_enumerate_t rules[], int index, numeral_t **matchnpp);
4760Sstevel@tonic-gate static void sync_handler(void *cookie, char *ap, size_t asize,
4770Sstevel@tonic-gate     door_desc_t *dp, uint_t ndesc);
4780Sstevel@tonic-gate static int zone_pathcheck(char *checkpath);
4790Sstevel@tonic-gate static void process_deferred_links(struct dca_impl *dcip, int flag);
4800Sstevel@tonic-gate static void event_handler(sysevent_t *ev);
4810Sstevel@tonic-gate static int rcm_init(void);
4820Sstevel@tonic-gate static int notify_rcm(di_node_t node, char *minor_name);
4830Sstevel@tonic-gate static void dca_impl_init(char *root, char *minor, struct dca_impl *dcip);
4840Sstevel@tonic-gate static void lock_dev(void);
4850Sstevel@tonic-gate static void unlock_dev(int flag);
4862587Spjha static int devlink_cb(di_devlink_t dl, void *arg);
4872587Spjha static void free_dev_names(struct devlink_cb_arg *x);
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate int load_devpolicy(void);
4900Sstevel@tonic-gate static void load_dev_acl(void);
4910Sstevel@tonic-gate static void load_minor_perm_file(void);
4920Sstevel@tonic-gate 
4930Sstevel@tonic-gate static int (*librcm_alloc_handle)(char *, uint_t, void *, rcm_handle_t **);
4940Sstevel@tonic-gate static void (*librcm_free_handle)(rcm_handle_t *);
4950Sstevel@tonic-gate static int (*librcm_notify_event)(rcm_handle_t *, char *, uint_t, nvlist_t *,
4960Sstevel@tonic-gate     rcm_info_t *);
4970Sstevel@tonic-gate static nvlist_t *build_event_attributes(char *, char *, char *,
4980Sstevel@tonic-gate     di_node_t, char *, int);
4990Sstevel@tonic-gate static void log_event(char *, char *, nvlist_t *);
5000Sstevel@tonic-gate static void build_and_log_event(char *, char *, char *, di_node_t);
501*2621Sllai1 static char *dev_readdir(char *);
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate static void read_logindevperm_file(void);
5040Sstevel@tonic-gate static void set_logindev_perms(char *devlink);
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate static void reset_node_permissions(di_node_t, di_minor_t);
5070Sstevel@tonic-gate 
508*2621Sllai1 /*
509*2621Sllai1  * devname related
510*2621Sllai1  */
511*2621Sllai1 static void devname_lookup_handler(void *, char *, size_t,
512*2621Sllai1     door_desc_t *, uint_t);		/* /dev name lookup server */
513*2621Sllai1 static int devname_kcall(int, void *);	/* syscall into the devname fs */
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate /* convenient short hands */
5160Sstevel@tonic-gate #define	vprint		devfsadm_print
5170Sstevel@tonic-gate #define	err_print	devfsadm_errprint
518*2621Sllai1 #ifndef TRUE
5190Sstevel@tonic-gate #define	TRUE	1
520*2621Sllai1 #endif
521*2621Sllai1 #ifndef FALSE
5220Sstevel@tonic-gate #define	FALSE	0
523*2621Sllai1 #endif
5240Sstevel@tonic-gate 
5250Sstevel@tonic-gate #ifdef	__cplusplus
5260Sstevel@tonic-gate }
5270Sstevel@tonic-gate #endif
5280Sstevel@tonic-gate 
5290Sstevel@tonic-gate #endif /* _DEVFSADM_IMPL_H */
530