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  *
21*7286Svikram  * Copyright 2008 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>
772621Sllai1 #include <sys/fs/sdev_node.h>
782621Sllai1 #include <sys/syscall.h>
792621Sllai1 #include <rpcsvc/ypclnt.h>
802621Sllai1 #include <sys/sysevent/eventdefs.h>
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #define	DEV_LOCK_FILE ".devfsadm_dev.lock"
830Sstevel@tonic-gate #define	DAEMON_LOCK_FILE ".devfsadm_daemon.lock"
840Sstevel@tonic-gate 
850Sstevel@tonic-gate #define	DEV "/dev"
862621Sllai1 #define	ETC "/etc"
872621Sllai1 #define	ETCDEV "/etc/dev"
880Sstevel@tonic-gate #define	DEV_LEN 4
890Sstevel@tonic-gate #define	DEVICES "/devices"
900Sstevel@tonic-gate #define	DEVICES_LEN 8
910Sstevel@tonic-gate #define	MODULE_DIRS "/usr/lib/devfsadm/linkmod"
920Sstevel@tonic-gate #define	ALIASFILE "/etc/driver_aliases"
930Sstevel@tonic-gate #define	NAME_TO_MAJOR "/etc/name_to_major"
940Sstevel@tonic-gate #define	RECONFIG_BOOT "_INIT_RECONFIG"
950Sstevel@tonic-gate #define	PID_STR_LEN 10
960Sstevel@tonic-gate #define	EXTRA_PRIVS	"/etc/security/extra_privs"
970Sstevel@tonic-gate #define	DEV_POLICY	"/etc/security/device_policy"
980Sstevel@tonic-gate #define	LDEV_FILE	"/etc/logindevperm"
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate #define	DEVFSADM_DEFAULT_FILE "/etc/default/devfsadm"
1010Sstevel@tonic-gate 
1023854Sjacobs #define	MINOR_FINI_TIMEOUT_DEFAULT 2
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate #define	SYNCH_DOOR_PERMS	(S_IRUSR | S_IWUSR)
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate #define	DRVCONFIG "drvconfig"
1070Sstevel@tonic-gate #define	DEVFSADM "devfsadm"
1080Sstevel@tonic-gate #define	DEVFSADMD "devfsadmd"
1090Sstevel@tonic-gate #define	DEVLINKS "devlinks"
1100Sstevel@tonic-gate #define	TAPES "tapes"
1110Sstevel@tonic-gate #define	AUDLINKS "audlinks"
1120Sstevel@tonic-gate #define	PORTS "ports"
1130Sstevel@tonic-gate #define	DISKS "disks"
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate #define	MAX_IDLE_DELAY 5
1160Sstevel@tonic-gate #define	MAX_DELAY 30
1170Sstevel@tonic-gate #define	NAME 0x01
1180Sstevel@tonic-gate #define	ADDR 0x03
1190Sstevel@tonic-gate #define	MINOR 0x04
1200Sstevel@tonic-gate #define	COUNTER 0x05
1210Sstevel@tonic-gate #define	CONSTANT 0x06
1220Sstevel@tonic-gate #define	TYPE 0x07
1230Sstevel@tonic-gate #define	TYPE_S "type"
1240Sstevel@tonic-gate #define	ADDR_S "addr"
1250Sstevel@tonic-gate #define	ADDR_S_LEN 4
1260Sstevel@tonic-gate #define	MINOR_S "minor"
1270Sstevel@tonic-gate #define	MINOR_S_LEN 5
1280Sstevel@tonic-gate #define	NAME_S "name"
1290Sstevel@tonic-gate #define	TAB '\t'
1300Sstevel@tonic-gate #define	NEWLINE '\n'
1310Sstevel@tonic-gate #define	MAX_DEVLINK_LINE 4028
1320Sstevel@tonic-gate #define	INTEGER 0
1330Sstevel@tonic-gate #define	LETTER 1
1340Sstevel@tonic-gate #define	MAX_PERM_LINE 256
1350Sstevel@tonic-gate #define	MAX_LDEV_LINE 256
1360Sstevel@tonic-gate #define	LDEV_DELIMS " \t\n"
1370Sstevel@tonic-gate #define	LDEV_DRVLIST_DELIMS "="
1380Sstevel@tonic-gate #define	LDEV_DRV_DELIMS ", \t\n"
1390Sstevel@tonic-gate #define	LDEV_DEV_DELIM ":"
1400Sstevel@tonic-gate #define	LDEV_DRVLIST_NAME "driver"
1412846Svikram #define	NFP_HASH_SZ 256
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate #define	TYPE_LINK 0x00
1440Sstevel@tonic-gate #define	TYPE_DEVICES 0x01
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate #define	CREATE_LINK 0x01
1470Sstevel@tonic-gate #define	READ_LINK 0x02
1480Sstevel@tonic-gate #define	CREATE_NODE 0x01
1490Sstevel@tonic-gate #define	READ_NODE 0x02
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate #define	CACHE_STATE 0x0
1520Sstevel@tonic-gate #define	SYNC_STATE 0x1
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate #define	MODULE_ACTIVE 0x01
1550Sstevel@tonic-gate 
1564876Smlf /* Possible flag values for flag member of numeral_t */
1574876Smlf #define	NUMERAL_RESERVED 0x01
1584876Smlf 
1590Sstevel@tonic-gate #define	MAX_SLEEP 120
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate #define	DEVLINKTAB_FILE "/etc/devlink.tab"
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate #define	MODULE_SUFFIX ".so"
1640Sstevel@tonic-gate #define	MINOR_INIT "minor_init"
1650Sstevel@tonic-gate #define	MINOR_FINI "minor_fini"
1660Sstevel@tonic-gate #define	_DEVFSADM_CREATE_REG "_devfsadm_create_reg"
1670Sstevel@tonic-gate #define	_DEVFSADM_REMOVE_REG "_devfsadm_remove_reg"
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate #define	NUM_EV_STR		4
1700Sstevel@tonic-gate #define	EV_TYPE			0
1710Sstevel@tonic-gate #define	EV_CLASS		1
1720Sstevel@tonic-gate #define	EV_PATH_NAME		2
1730Sstevel@tonic-gate #define	EV_MINOR_NAME		3
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate /* add new debug level and meanings here */
1760Sstevel@tonic-gate #define	DEVLINK_MID		"devfsadm:devlink"
1770Sstevel@tonic-gate #define	MODLOAD_MID		"devfsadm:modload"
1780Sstevel@tonic-gate #define	INITFINI_MID		"devfsadm:initfini"
1790Sstevel@tonic-gate #define	EVENT_MID		"devfsadm:event"
1800Sstevel@tonic-gate #define	REMOVE_MID		"devfsadm:remove"
1810Sstevel@tonic-gate #define	LOCK_MID		"devfsadm:lock"
1820Sstevel@tonic-gate #define	PATH2INST_MID		"devfsadm:path2inst"
1830Sstevel@tonic-gate #define	CACHE_MID		"devfsadm:cache"
1840Sstevel@tonic-gate #define	BUILDCACHE_MID		"devfsadm:buildcache"
1850Sstevel@tonic-gate #define	RECURSEDEV_MID		"devfsadm:recursedev"
1860Sstevel@tonic-gate #define	INSTSYNC_MID		"devfsadm:instsync"
1870Sstevel@tonic-gate #define	FILES_MID		"devfsadm:files"
1880Sstevel@tonic-gate #define	ENUM_MID		"devfsadm:enum"
1894876Smlf #define	RSRV_MID		"devfsadm:rsrv"	/* enum interface reserve  */
1904876Smlf #define	RSBY_MID		"devfsadm:rsby"	/* enum reserve bypass */
1910Sstevel@tonic-gate #define	LINKCACHE_MID		"devfsadm:linkcache"
1920Sstevel@tonic-gate #define	ADDREMCACHE_MID		"devfsadm:addremcache"
1930Sstevel@tonic-gate #define	MALLOC_MID		"devfsadm:malloc"
1942621Sllai1 #define	READDIR_MID		"devfsadm:readdir"
1952621Sllai1 #define	READDIR_ALL_MID		"devfsadm:readdir_all"
1962621Sllai1 #define	DEVNAME_MID		"devfsadm:devname"
1970Sstevel@tonic-gate #define	ALL_MID			"all"
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate #define	DEVFSADM_DEBUG_ON	(verbose == NULL) ? FALSE : TRUE
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate typedef struct recurse_dev {
2020Sstevel@tonic-gate 	void (*fcn)(char *, void *);
2030Sstevel@tonic-gate 	void *data;
2040Sstevel@tonic-gate } recurse_dev_t;
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate typedef struct link {
2070Sstevel@tonic-gate 	char *devlink; /* without ".../dev/"   prefix */
2080Sstevel@tonic-gate 	char *contents; /* without "../devices" prefix */
2090Sstevel@tonic-gate 	struct link *next;
2100Sstevel@tonic-gate } link_t;
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate typedef struct linkhead {
2130Sstevel@tonic-gate 	regex_t dir_re_compiled;
2140Sstevel@tonic-gate 	char *dir_re;
2150Sstevel@tonic-gate 	link_t *link;
2160Sstevel@tonic-gate 	link_t *nextlink;
2170Sstevel@tonic-gate 	struct linkhead *nexthead;
2180Sstevel@tonic-gate } linkhead_t;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate typedef struct link_list  {
2210Sstevel@tonic-gate 	int type;
2220Sstevel@tonic-gate 	char *constant;
2230Sstevel@tonic-gate 	int arg;
2240Sstevel@tonic-gate 	struct link_list *next;
2250Sstevel@tonic-gate } link_list_t;
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate typedef struct selector_list {
2280Sstevel@tonic-gate 	int key;
2290Sstevel@tonic-gate 	char *val;
2300Sstevel@tonic-gate 	int arg;
2310Sstevel@tonic-gate 	struct selector_list *next;
2320Sstevel@tonic-gate } selector_list_t;
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate typedef struct devlinktab_list {
2350Sstevel@tonic-gate 	int line_number;
2360Sstevel@tonic-gate 	char *selector_pattern;
2370Sstevel@tonic-gate 	char *p_link_pattern;
2380Sstevel@tonic-gate 	char *s_link_pattern;
2390Sstevel@tonic-gate 	selector_list_t *selector;
2400Sstevel@tonic-gate 	link_list_t *p_link;
2410Sstevel@tonic-gate 	link_list_t *s_link;
2420Sstevel@tonic-gate 	struct devlinktab_list *next;
2430Sstevel@tonic-gate } devlinktab_list_t;
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate typedef struct module {
2460Sstevel@tonic-gate 	char *name;
2470Sstevel@tonic-gate 	void *dlhandle;
2480Sstevel@tonic-gate 	int (*minor_init)();
2490Sstevel@tonic-gate 	int (*minor_fini)();
2500Sstevel@tonic-gate 	int flags;
2510Sstevel@tonic-gate 	struct module *next;
2520Sstevel@tonic-gate } module_t;
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate typedef struct create_list {
2550Sstevel@tonic-gate 	devfsadm_create_t *create;
2560Sstevel@tonic-gate 	module_t *modptr;
2570Sstevel@tonic-gate 	regex_t node_type_comp;
2580Sstevel@tonic-gate 	regex_t drv_name_comp;
2590Sstevel@tonic-gate 	struct create_list *next;
2600Sstevel@tonic-gate } create_list_t;
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate struct minor {
2630Sstevel@tonic-gate 	di_node_t node;
2640Sstevel@tonic-gate 	di_minor_t minor;
2650Sstevel@tonic-gate 	struct minor *next;
2660Sstevel@tonic-gate };
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate struct mlist {
2690Sstevel@tonic-gate 	struct minor *head;
2700Sstevel@tonic-gate 	struct minor *tail;
2710Sstevel@tonic-gate };
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate typedef struct remove_list {
2742846Svikram 	devfsadm_remove_V1_t *remove;
2750Sstevel@tonic-gate 	module_t *modptr;
2760Sstevel@tonic-gate 	struct remove_list *next;
2770Sstevel@tonic-gate } remove_list_t;
2780Sstevel@tonic-gate 
2792846Svikram typedef struct item {
2802846Svikram 	char *i_key;
2812846Svikram 	struct item *i_next;
2822846Svikram } item_t;
2832846Svikram 
2840Sstevel@tonic-gate typedef struct cleanup_data {
2850Sstevel@tonic-gate 	int flags;
2860Sstevel@tonic-gate 	char *phypath;
2870Sstevel@tonic-gate 	remove_list_t *rm;
2880Sstevel@tonic-gate } cleanup_data_t;
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate typedef struct n2m {
2910Sstevel@tonic-gate 	major_t major;
2920Sstevel@tonic-gate 	char *driver;
2930Sstevel@tonic-gate 	struct n2m *next;
2940Sstevel@tonic-gate } n2m_t;
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate /* structures for devfsadm_enumerate() */
2970Sstevel@tonic-gate typedef struct numeral {
2980Sstevel@tonic-gate 	char *id;
2990Sstevel@tonic-gate 	char *full_path;
3000Sstevel@tonic-gate 	int rule_index;
3010Sstevel@tonic-gate 	char *cmp_str;
3020Sstevel@tonic-gate 	struct numeral *next;
3034876Smlf 	int flags;
3040Sstevel@tonic-gate } numeral_t;
3050Sstevel@tonic-gate 
3060Sstevel@tonic-gate typedef struct numeral_set {
3070Sstevel@tonic-gate 	int re_count;
3080Sstevel@tonic-gate 	char **re;
3090Sstevel@tonic-gate 	numeral_t *headnumeral;
3100Sstevel@tonic-gate 	struct numeral_set *next;
3110Sstevel@tonic-gate } numeral_set_t;
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate typedef struct temp {
3140Sstevel@tonic-gate 	int integer;
3150Sstevel@tonic-gate 	struct temp *next;
3160Sstevel@tonic-gate } temp_t;
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate typedef struct driver_alias {
3190Sstevel@tonic-gate 	char *driver_name;
3200Sstevel@tonic-gate 	char *alias_name;
3210Sstevel@tonic-gate 	struct driver_alias *next;
3220Sstevel@tonic-gate } driver_alias_t;
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate struct driver_list {
3250Sstevel@tonic-gate 	char driver_name[MAXNAMELEN];
3260Sstevel@tonic-gate 	struct driver_list *next;
3270Sstevel@tonic-gate };
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate struct login_dev {
3300Sstevel@tonic-gate 	char *ldev_console;
3310Sstevel@tonic-gate 	int ldev_perms;
3320Sstevel@tonic-gate 	char *ldev_device;
3330Sstevel@tonic-gate 	regex_t ldev_device_regex;
3340Sstevel@tonic-gate 	struct driver_list *ldev_driver_list;
3350Sstevel@tonic-gate 	struct login_dev *ldev_next;
3360Sstevel@tonic-gate };
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate #define	MAX_DEV_NAME_COUNT	100
3390Sstevel@tonic-gate struct devlink_cb_arg {
3400Sstevel@tonic-gate 	char *dev_names[MAX_DEV_NAME_COUNT];
3410Sstevel@tonic-gate 	char *link_contents[MAX_DEV_NAME_COUNT];
3420Sstevel@tonic-gate 	int count;
3430Sstevel@tonic-gate 	int rv;
3440Sstevel@tonic-gate };
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate struct dca_impl {
3470Sstevel@tonic-gate 	char *dci_root;
3480Sstevel@tonic-gate 	char *dci_minor;
3490Sstevel@tonic-gate 	char *dci_driver;
3500Sstevel@tonic-gate 	void *dci_arg;
3510Sstevel@tonic-gate 	int dci_error;
3520Sstevel@tonic-gate 	int dci_flags;
3530Sstevel@tonic-gate };
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate /* RCM related */
3560Sstevel@tonic-gate struct rcm_eventq {
3570Sstevel@tonic-gate 	nvlist_t *nvl;
3580Sstevel@tonic-gate 	struct rcm_eventq *next;
3590Sstevel@tonic-gate };
3600Sstevel@tonic-gate 
3613854Sjacobs /* sysevent queue related */
3623854Sjacobs typedef struct syseventq_s {
3633854Sjacobs 	struct syseventq_s *next;
3643854Sjacobs 	char *class;
3653854Sjacobs 	char *subclass;
3663854Sjacobs 	nvlist_t *nvl;
3673854Sjacobs } syseventq_t;
3683854Sjacobs 
3690Sstevel@tonic-gate static int devfsadm_enumerate_int_start(char *devfs_path,
3700Sstevel@tonic-gate 	int index, char **buf, devfsadm_enumerate_t rules[],
3710Sstevel@tonic-gate 	int nrules, char *start);
3722621Sllai1 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);
392*7286Svikram static void exit_dev_lock(int exiting);
3930Sstevel@tonic-gate static pid_t enter_daemon_lock(void);
394*7286Svikram static void exit_daemon_lock(int exiting);
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);
4192846Svikram static int clean_ok(devfsadm_remove_V1_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);
4353496Scth static void 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 *,
4984211Sphitran     di_node_t, char *, int, char *);
4990Sstevel@tonic-gate static void log_event(char *, char *, nvlist_t *);
5004211Sphitran static void build_and_enq_event(char *, char *, char *, di_node_t, char *);
5010Sstevel@tonic-gate 
5020Sstevel@tonic-gate static void read_logindevperm_file(void);
5030Sstevel@tonic-gate static void set_logindev_perms(char *devlink);
5040Sstevel@tonic-gate 
5050Sstevel@tonic-gate static void reset_node_permissions(di_node_t, di_minor_t);
5060Sstevel@tonic-gate 
5072621Sllai1 /*
5082621Sllai1  * devname related
5092621Sllai1  */
5102621Sllai1 static void devname_lookup_handler(void *, char *, size_t,
5112621Sllai1     door_desc_t *, uint_t);		/* /dev name lookup server */
5122621Sllai1 static int devname_kcall(int, void *);	/* syscall into the devname fs */
5134876Smlf 
5142846Svikram static void nfphash_create(void);
5152846Svikram static int nfphash_fcn(char *key);
5162846Svikram static item_t *nfphash_lookup(char *key);
5172846Svikram static void nfphash_insert(char *key);
5182846Svikram static void nfphash_destroy(void);
5190Sstevel@tonic-gate 
5204876Smlf /* Enumerate reserve related */
5214876Smlf static void read_enumerate_file(void);
5224876Smlf static int enumerate_parse(char *rsvstr, char *path_left, numeral_set_t *setp,
5234876Smlf     devfsadm_enumerate_t rules[], int index);
5244876Smlf static void create_reserved_numeral(numeral_set_t *setp, char *numeral_id);
5254876Smlf 
5260Sstevel@tonic-gate /* convenient short hands */
5270Sstevel@tonic-gate #define	vprint		devfsadm_print
5280Sstevel@tonic-gate #define	err_print	devfsadm_errprint
5292621Sllai1 #ifndef TRUE
5300Sstevel@tonic-gate #define	TRUE	1
5312621Sllai1 #endif
5322621Sllai1 #ifndef FALSE
5330Sstevel@tonic-gate #define	FALSE	0
5342621Sllai1 #endif
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate #ifdef	__cplusplus
5370Sstevel@tonic-gate }
5380Sstevel@tonic-gate #endif
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate #endif /* _DEVFSADM_IMPL_H */
541