xref: /onnv-gate/usr/src/cmd/devfsadm/devfsadm_impl.h (revision 10097:e33d224110c9)
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*10097SEric.Taylor@Sun.COM  * Copyright 2009 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 #ifdef	__cplusplus
290Sstevel@tonic-gate extern "C" {
300Sstevel@tonic-gate #endif
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <dlfcn.h>
330Sstevel@tonic-gate #include <stdarg.h>
340Sstevel@tonic-gate #include <fcntl.h>
350Sstevel@tonic-gate #include <sys/file.h>
360Sstevel@tonic-gate #include <locale.h>
370Sstevel@tonic-gate #include <libintl.h>
380Sstevel@tonic-gate #include <ctype.h>
390Sstevel@tonic-gate #include <signal.h>
400Sstevel@tonic-gate #include <deflt.h>
410Sstevel@tonic-gate #include <ftw.h>
420Sstevel@tonic-gate #include <sys/instance.h>
430Sstevel@tonic-gate #include <sys/types.h>
440Sstevel@tonic-gate #include <dirent.h>
450Sstevel@tonic-gate #include <pwd.h>
460Sstevel@tonic-gate #include <grp.h>
470Sstevel@tonic-gate #include <stdio.h>
480Sstevel@tonic-gate #include <stdlib.h>
490Sstevel@tonic-gate #include <sys/mkdev.h>
500Sstevel@tonic-gate #include <sys/stat.h>
510Sstevel@tonic-gate #include <fcntl.h>
520Sstevel@tonic-gate #include <errno.h>
530Sstevel@tonic-gate #include <unistd.h>
540Sstevel@tonic-gate #include <sys/stat.h>
550Sstevel@tonic-gate #include <sys/int_types.h>
560Sstevel@tonic-gate #include <limits.h>
570Sstevel@tonic-gate #include <strings.h>
580Sstevel@tonic-gate #include <devfsadm.h>
590Sstevel@tonic-gate #include <libdevinfo.h>
600Sstevel@tonic-gate #include <sys/devinfo_impl.h>
610Sstevel@tonic-gate #include <sys/modctl.h>
620Sstevel@tonic-gate #include <libgen.h>
630Sstevel@tonic-gate #include <sys/hwconf.h>
640Sstevel@tonic-gate #include <sys/sunddi.h>
650Sstevel@tonic-gate #include <door.h>
660Sstevel@tonic-gate #include <syslog.h>
670Sstevel@tonic-gate #include <libsysevent.h>
680Sstevel@tonic-gate #include <thread.h>
690Sstevel@tonic-gate #include <message.h>
700Sstevel@tonic-gate #include <sys/cladm.h>
710Sstevel@tonic-gate #include <sys/sysevent/dev.h>
720Sstevel@tonic-gate #include <libzonecfg.h>
730Sstevel@tonic-gate #include <device_info.h>
74*10097SEric.Taylor@Sun.COM #include <sys/fs/sdev_impl.h>
752621Sllai1 #include <sys/syscall.h>
762621Sllai1 #include <rpcsvc/ypclnt.h>
772621Sllai1 #include <sys/sysevent/eventdefs.h>
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define	DEV_LOCK_FILE ".devfsadm_dev.lock"
800Sstevel@tonic-gate #define	DAEMON_LOCK_FILE ".devfsadm_daemon.lock"
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #define	DEV "/dev"
832621Sllai1 #define	ETC "/etc"
842621Sllai1 #define	ETCDEV "/etc/dev"
850Sstevel@tonic-gate #define	DEV_LEN 4
860Sstevel@tonic-gate #define	DEVICES "/devices"
870Sstevel@tonic-gate #define	DEVICES_LEN 8
880Sstevel@tonic-gate #define	MODULE_DIRS "/usr/lib/devfsadm/linkmod"
890Sstevel@tonic-gate #define	ALIASFILE "/etc/driver_aliases"
900Sstevel@tonic-gate #define	NAME_TO_MAJOR "/etc/name_to_major"
910Sstevel@tonic-gate #define	RECONFIG_BOOT "_INIT_RECONFIG"
920Sstevel@tonic-gate #define	PID_STR_LEN 10
930Sstevel@tonic-gate #define	EXTRA_PRIVS	"/etc/security/extra_privs"
940Sstevel@tonic-gate #define	DEV_POLICY	"/etc/security/device_policy"
950Sstevel@tonic-gate #define	LDEV_FILE	"/etc/logindevperm"
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #define	DEVFSADM_DEFAULT_FILE "/etc/default/devfsadm"
980Sstevel@tonic-gate 
993854Sjacobs #define	MINOR_FINI_TIMEOUT_DEFAULT 2
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate #define	SYNCH_DOOR_PERMS	(S_IRUSR | S_IWUSR)
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate #define	DRVCONFIG "drvconfig"
1040Sstevel@tonic-gate #define	DEVFSADM "devfsadm"
1050Sstevel@tonic-gate #define	DEVFSADMD "devfsadmd"
1060Sstevel@tonic-gate #define	DEVLINKS "devlinks"
1070Sstevel@tonic-gate #define	TAPES "tapes"
1080Sstevel@tonic-gate #define	AUDLINKS "audlinks"
1090Sstevel@tonic-gate #define	PORTS "ports"
1100Sstevel@tonic-gate #define	DISKS "disks"
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate #define	MAX_IDLE_DELAY 5
1130Sstevel@tonic-gate #define	MAX_DELAY 30
1140Sstevel@tonic-gate #define	NAME 0x01
1150Sstevel@tonic-gate #define	ADDR 0x03
1160Sstevel@tonic-gate #define	MINOR 0x04
1170Sstevel@tonic-gate #define	COUNTER 0x05
1180Sstevel@tonic-gate #define	CONSTANT 0x06
1190Sstevel@tonic-gate #define	TYPE 0x07
1200Sstevel@tonic-gate #define	TYPE_S "type"
1210Sstevel@tonic-gate #define	ADDR_S "addr"
1220Sstevel@tonic-gate #define	ADDR_S_LEN 4
1230Sstevel@tonic-gate #define	MINOR_S "minor"
1240Sstevel@tonic-gate #define	MINOR_S_LEN 5
1250Sstevel@tonic-gate #define	NAME_S "name"
1260Sstevel@tonic-gate #define	TAB '\t'
1270Sstevel@tonic-gate #define	NEWLINE '\n'
1280Sstevel@tonic-gate #define	MAX_DEVLINK_LINE 4028
1290Sstevel@tonic-gate #define	INTEGER 0
1300Sstevel@tonic-gate #define	LETTER 1
1310Sstevel@tonic-gate #define	MAX_PERM_LINE 256
1320Sstevel@tonic-gate #define	MAX_LDEV_LINE 256
1330Sstevel@tonic-gate #define	LDEV_DELIMS " \t\n"
1340Sstevel@tonic-gate #define	LDEV_DRVLIST_DELIMS "="
1350Sstevel@tonic-gate #define	LDEV_DRV_DELIMS ", \t\n"
1360Sstevel@tonic-gate #define	LDEV_DEV_DELIM ":"
1370Sstevel@tonic-gate #define	LDEV_DRVLIST_NAME "driver"
1382846Svikram #define	NFP_HASH_SZ 256
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate #define	TYPE_LINK 0x00
1410Sstevel@tonic-gate #define	TYPE_DEVICES 0x01
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate #define	CREATE_LINK 0x01
1440Sstevel@tonic-gate #define	READ_LINK 0x02
1450Sstevel@tonic-gate #define	CREATE_NODE 0x01
1460Sstevel@tonic-gate #define	READ_NODE 0x02
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate #define	CACHE_STATE 0x0
1490Sstevel@tonic-gate #define	SYNC_STATE 0x1
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate #define	MODULE_ACTIVE 0x01
1520Sstevel@tonic-gate 
1534876Smlf /* Possible flag values for flag member of numeral_t */
1544876Smlf #define	NUMERAL_RESERVED 0x01
1554876Smlf 
1560Sstevel@tonic-gate #define	MAX_SLEEP 120
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate #define	DEVLINKTAB_FILE "/etc/devlink.tab"
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate #define	MODULE_SUFFIX ".so"
1610Sstevel@tonic-gate #define	MINOR_INIT "minor_init"
1620Sstevel@tonic-gate #define	MINOR_FINI "minor_fini"
1630Sstevel@tonic-gate #define	_DEVFSADM_CREATE_REG "_devfsadm_create_reg"
1640Sstevel@tonic-gate #define	_DEVFSADM_REMOVE_REG "_devfsadm_remove_reg"
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate #define	NUM_EV_STR		4
1670Sstevel@tonic-gate #define	EV_TYPE			0
1680Sstevel@tonic-gate #define	EV_CLASS		1
1690Sstevel@tonic-gate #define	EV_PATH_NAME		2
1700Sstevel@tonic-gate #define	EV_MINOR_NAME		3
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate /* add new debug level and meanings here */
1730Sstevel@tonic-gate #define	DEVLINK_MID		"devfsadm:devlink"
1740Sstevel@tonic-gate #define	MODLOAD_MID		"devfsadm:modload"
1750Sstevel@tonic-gate #define	INITFINI_MID		"devfsadm:initfini"
1760Sstevel@tonic-gate #define	EVENT_MID		"devfsadm:event"
1770Sstevel@tonic-gate #define	REMOVE_MID		"devfsadm:remove"
1780Sstevel@tonic-gate #define	LOCK_MID		"devfsadm:lock"
1790Sstevel@tonic-gate #define	PATH2INST_MID		"devfsadm:path2inst"
1800Sstevel@tonic-gate #define	CACHE_MID		"devfsadm:cache"
1810Sstevel@tonic-gate #define	BUILDCACHE_MID		"devfsadm:buildcache"
1820Sstevel@tonic-gate #define	RECURSEDEV_MID		"devfsadm:recursedev"
1830Sstevel@tonic-gate #define	INSTSYNC_MID		"devfsadm:instsync"
1840Sstevel@tonic-gate #define	FILES_MID		"devfsadm:files"
1850Sstevel@tonic-gate #define	ENUM_MID		"devfsadm:enum"
1864876Smlf #define	RSRV_MID		"devfsadm:rsrv"	/* enum interface reserve  */
1874876Smlf #define	RSBY_MID		"devfsadm:rsby"	/* enum reserve bypass */
1880Sstevel@tonic-gate #define	LINKCACHE_MID		"devfsadm:linkcache"
1890Sstevel@tonic-gate #define	ADDREMCACHE_MID		"devfsadm:addremcache"
1900Sstevel@tonic-gate #define	MALLOC_MID		"devfsadm:malloc"
1912621Sllai1 #define	READDIR_MID		"devfsadm:readdir"
1922621Sllai1 #define	READDIR_ALL_MID		"devfsadm:readdir_all"
1932621Sllai1 #define	DEVNAME_MID		"devfsadm:devname"
1940Sstevel@tonic-gate #define	ALL_MID			"all"
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate #define	DEVFSADM_DEBUG_ON	(verbose == NULL) ? FALSE : TRUE
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate typedef struct recurse_dev {
1990Sstevel@tonic-gate 	void (*fcn)(char *, void *);
2000Sstevel@tonic-gate 	void *data;
2010Sstevel@tonic-gate } recurse_dev_t;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate typedef struct link {
2040Sstevel@tonic-gate 	char *devlink; /* without ".../dev/"   prefix */
2050Sstevel@tonic-gate 	char *contents; /* without "../devices" prefix */
2060Sstevel@tonic-gate 	struct link *next;
2070Sstevel@tonic-gate } link_t;
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate typedef struct linkhead {
2100Sstevel@tonic-gate 	regex_t dir_re_compiled;
2110Sstevel@tonic-gate 	char *dir_re;
2120Sstevel@tonic-gate 	link_t *link;
2130Sstevel@tonic-gate 	link_t *nextlink;
2140Sstevel@tonic-gate 	struct linkhead *nexthead;
2150Sstevel@tonic-gate } linkhead_t;
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate typedef struct link_list  {
2180Sstevel@tonic-gate 	int type;
2190Sstevel@tonic-gate 	char *constant;
2200Sstevel@tonic-gate 	int arg;
2210Sstevel@tonic-gate 	struct link_list *next;
2220Sstevel@tonic-gate } link_list_t;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate typedef struct selector_list {
2250Sstevel@tonic-gate 	int key;
2260Sstevel@tonic-gate 	char *val;
2270Sstevel@tonic-gate 	int arg;
2280Sstevel@tonic-gate 	struct selector_list *next;
2290Sstevel@tonic-gate } selector_list_t;
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate typedef struct devlinktab_list {
2320Sstevel@tonic-gate 	int line_number;
2330Sstevel@tonic-gate 	char *selector_pattern;
2340Sstevel@tonic-gate 	char *p_link_pattern;
2350Sstevel@tonic-gate 	char *s_link_pattern;
2360Sstevel@tonic-gate 	selector_list_t *selector;
2370Sstevel@tonic-gate 	link_list_t *p_link;
2380Sstevel@tonic-gate 	link_list_t *s_link;
2390Sstevel@tonic-gate 	struct devlinktab_list *next;
2400Sstevel@tonic-gate } devlinktab_list_t;
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate typedef struct module {
2430Sstevel@tonic-gate 	char *name;
2440Sstevel@tonic-gate 	void *dlhandle;
2450Sstevel@tonic-gate 	int (*minor_init)();
2460Sstevel@tonic-gate 	int (*minor_fini)();
2470Sstevel@tonic-gate 	int flags;
2480Sstevel@tonic-gate 	struct module *next;
2490Sstevel@tonic-gate } module_t;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate typedef struct create_list {
2520Sstevel@tonic-gate 	devfsadm_create_t *create;
2530Sstevel@tonic-gate 	module_t *modptr;
2540Sstevel@tonic-gate 	regex_t node_type_comp;
2550Sstevel@tonic-gate 	regex_t drv_name_comp;
2560Sstevel@tonic-gate 	struct create_list *next;
2570Sstevel@tonic-gate } create_list_t;
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate struct minor {
2600Sstevel@tonic-gate 	di_node_t node;
2610Sstevel@tonic-gate 	di_minor_t minor;
2620Sstevel@tonic-gate 	struct minor *next;
2630Sstevel@tonic-gate };
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate struct mlist {
2660Sstevel@tonic-gate 	struct minor *head;
2670Sstevel@tonic-gate 	struct minor *tail;
2680Sstevel@tonic-gate };
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate typedef struct remove_list {
2712846Svikram 	devfsadm_remove_V1_t *remove;
2720Sstevel@tonic-gate 	module_t *modptr;
2730Sstevel@tonic-gate 	struct remove_list *next;
2740Sstevel@tonic-gate } remove_list_t;
2750Sstevel@tonic-gate 
2762846Svikram typedef struct item {
2772846Svikram 	char *i_key;
2782846Svikram 	struct item *i_next;
2792846Svikram } item_t;
2802846Svikram 
2810Sstevel@tonic-gate typedef struct cleanup_data {
2820Sstevel@tonic-gate 	int flags;
2830Sstevel@tonic-gate 	char *phypath;
2840Sstevel@tonic-gate 	remove_list_t *rm;
2850Sstevel@tonic-gate } cleanup_data_t;
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate typedef struct n2m {
2880Sstevel@tonic-gate 	major_t major;
2890Sstevel@tonic-gate 	char *driver;
2900Sstevel@tonic-gate 	struct n2m *next;
2910Sstevel@tonic-gate } n2m_t;
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate /* structures for devfsadm_enumerate() */
2940Sstevel@tonic-gate typedef struct numeral {
2950Sstevel@tonic-gate 	char *id;
2960Sstevel@tonic-gate 	char *full_path;
2970Sstevel@tonic-gate 	int rule_index;
2980Sstevel@tonic-gate 	char *cmp_str;
2990Sstevel@tonic-gate 	struct numeral *next;
3004876Smlf 	int flags;
3010Sstevel@tonic-gate } numeral_t;
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate typedef struct numeral_set {
3040Sstevel@tonic-gate 	int re_count;
3050Sstevel@tonic-gate 	char **re;
3060Sstevel@tonic-gate 	numeral_t *headnumeral;
3070Sstevel@tonic-gate 	struct numeral_set *next;
3080Sstevel@tonic-gate } numeral_set_t;
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate typedef struct temp {
3110Sstevel@tonic-gate 	int integer;
3120Sstevel@tonic-gate 	struct temp *next;
3130Sstevel@tonic-gate } temp_t;
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate typedef struct driver_alias {
3160Sstevel@tonic-gate 	char *driver_name;
3170Sstevel@tonic-gate 	char *alias_name;
3180Sstevel@tonic-gate 	struct driver_alias *next;
3190Sstevel@tonic-gate } driver_alias_t;
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate struct driver_list {
3220Sstevel@tonic-gate 	char driver_name[MAXNAMELEN];
3230Sstevel@tonic-gate 	struct driver_list *next;
3240Sstevel@tonic-gate };
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate struct login_dev {
3270Sstevel@tonic-gate 	char *ldev_console;
3280Sstevel@tonic-gate 	int ldev_perms;
3290Sstevel@tonic-gate 	char *ldev_device;
3300Sstevel@tonic-gate 	regex_t ldev_device_regex;
3310Sstevel@tonic-gate 	struct driver_list *ldev_driver_list;
3320Sstevel@tonic-gate 	struct login_dev *ldev_next;
3330Sstevel@tonic-gate };
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate #define	MAX_DEV_NAME_COUNT	100
3360Sstevel@tonic-gate struct devlink_cb_arg {
3370Sstevel@tonic-gate 	char *dev_names[MAX_DEV_NAME_COUNT];
3380Sstevel@tonic-gate 	char *link_contents[MAX_DEV_NAME_COUNT];
3390Sstevel@tonic-gate 	int count;
3400Sstevel@tonic-gate 	int rv;
3410Sstevel@tonic-gate };
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate struct dca_impl {
3440Sstevel@tonic-gate 	char *dci_root;
3450Sstevel@tonic-gate 	char *dci_minor;
3460Sstevel@tonic-gate 	char *dci_driver;
3470Sstevel@tonic-gate 	void *dci_arg;
3480Sstevel@tonic-gate 	int dci_error;
3490Sstevel@tonic-gate 	int dci_flags;
3500Sstevel@tonic-gate };
3510Sstevel@tonic-gate 
3523854Sjacobs /* sysevent queue related */
3533854Sjacobs typedef struct syseventq_s {
3543854Sjacobs 	struct syseventq_s *next;
3553854Sjacobs 	char *class;
3563854Sjacobs 	char *subclass;
3573854Sjacobs 	nvlist_t *nvl;
3583854Sjacobs } syseventq_t;
3593854Sjacobs 
3600Sstevel@tonic-gate static int devfsadm_enumerate_int_start(char *devfs_path,
3610Sstevel@tonic-gate 	int index, char **buf, devfsadm_enumerate_t rules[],
3620Sstevel@tonic-gate 	int nrules, char *start);
3632621Sllai1 static void set_root_devices_dev_dir(char *dir);
3640Sstevel@tonic-gate static void pre_and_post_cleanup(int flags);
3650Sstevel@tonic-gate static void hot_cleanup(char *, char *, char *, char *, int);
3660Sstevel@tonic-gate static void devfsadm_exit(int status);
3670Sstevel@tonic-gate static void rm_link_from_cache(char *devlink);
3680Sstevel@tonic-gate static void rm_all_links_from_cache();
3690Sstevel@tonic-gate static void add_link_to_cache(char *devlink, char *physpath);
3700Sstevel@tonic-gate static linkhead_t *get_cached_links(char *dir_re);
3710Sstevel@tonic-gate static void build_devlink_list(char *check_link, void *data);
3720Sstevel@tonic-gate static void instance_flush_thread(void);
373871Scasper static int s_rmdir(char *path);
3740Sstevel@tonic-gate static void rm_parent_dir_if_empty(char *path);
3750Sstevel@tonic-gate static void free_link_list(link_list_t *head);
3760Sstevel@tonic-gate static void free_selector_list(selector_list_t *head);
3770Sstevel@tonic-gate void devfsadm_err_print(char *message, ...);
3780Sstevel@tonic-gate void defvsadm_print(int level, char *message, ...);
3790Sstevel@tonic-gate static int call_minor_init(module_t *module);
3800Sstevel@tonic-gate static void load_module(char *module, char *cdir);
3810Sstevel@tonic-gate static void invalidate_enumerate_cache(void);
3820Sstevel@tonic-gate static pid_t enter_dev_lock(void);
3837286Svikram static void exit_dev_lock(int exiting);
3840Sstevel@tonic-gate static pid_t enter_daemon_lock(void);
3857286Svikram static void exit_daemon_lock(int exiting);
3860Sstevel@tonic-gate static int process_devlink_compat(di_minor_t minor, di_node_t node);
3870Sstevel@tonic-gate static int alias(char *, char *);
3880Sstevel@tonic-gate static int devfsadm_copy(void);
3890Sstevel@tonic-gate static void flush_path_to_inst(void);
3900Sstevel@tonic-gate static void detachfromtty(void);
3910Sstevel@tonic-gate static void minor_process(di_node_t node, di_minor_t minor,
3920Sstevel@tonic-gate     struct mlist *dep);
3930Sstevel@tonic-gate static void read_minor_perm_file(void);
3940Sstevel@tonic-gate static void read_driver_aliases_file(void);
3950Sstevel@tonic-gate static void load_modules(void);
3960Sstevel@tonic-gate static void unload_modules(void);
3970Sstevel@tonic-gate static void *s_malloc(const size_t size);
3980Sstevel@tonic-gate static void *s_zalloc(const size_t size);
3990Sstevel@tonic-gate static void devfs_instance_mod(void);
4000Sstevel@tonic-gate static void add_minor_pathname(char *, char *, char *);
4010Sstevel@tonic-gate static int check_minor_type(di_node_t node, di_minor_t minor, void *arg);
4020Sstevel@tonic-gate static void cache_deferred_minor(struct mlist *dep, di_node_t node,
4030Sstevel@tonic-gate     di_minor_t minor);
4040Sstevel@tonic-gate static int compare_field(char *full_name, char *field_item, int field);
4050Sstevel@tonic-gate static int component_cat(char *link, char *name, int field);
4060Sstevel@tonic-gate static void recurse_dev_re(char *current_dir, char *path_re, recurse_dev_t *rd);
4070Sstevel@tonic-gate static void matching_dev(char *devpath, void *data);
4080Sstevel@tonic-gate static int resolve_link(char *devpath, char **content_p, int *type_p,
4090Sstevel@tonic-gate     char **devfs_path, int dangle);
4102846Svikram static int clean_ok(devfsadm_remove_V1_t *remove);
4110Sstevel@tonic-gate static int translate_major(dev_t old_dev, dev_t *new_dev);
4120Sstevel@tonic-gate static int get_major_no(char *driver, major_t *major);
4130Sstevel@tonic-gate static int load_n2m_table(char *filename);
4140Sstevel@tonic-gate static int get_stat_info(char *, struct stat *);
4150Sstevel@tonic-gate static char *new_id(numeral_t *, int, char *);
4160Sstevel@tonic-gate static int find_enum_id(devfsadm_enumerate_t rules[], int nrules,
4170Sstevel@tonic-gate     char *devfs_path, int index, char *min, int type, char **buf, int multiple);
4180Sstevel@tonic-gate static void daemon_update(void);
4190Sstevel@tonic-gate static void usage(void);
4200Sstevel@tonic-gate static int getnexttoken(char *next, char **nextp, char **tokenpp, char *tchar);
4210Sstevel@tonic-gate static int class_ok(char *class);
4220Sstevel@tonic-gate static int create_link_common(char *devlink, char *contents, int *exists);
4230Sstevel@tonic-gate static char *dequote(char *src);
4240Sstevel@tonic-gate static void parse_args(int argc, char *argv[]);
4250Sstevel@tonic-gate static void process_devinfo_tree(void);
4263496Scth static void minor_fini_thread(void *arg);
4270Sstevel@tonic-gate static void *s_realloc(void *ptr, const size_t size);
4280Sstevel@tonic-gate static void read_devlinktab_file(void);
4290Sstevel@tonic-gate static selector_list_t *create_selector_list(char *selector);
4300Sstevel@tonic-gate static int parse_selector(char **selector, char **key, char **val);
4310Sstevel@tonic-gate int devfsadm_noupdate(void);
4320Sstevel@tonic-gate const char *devfsadm_root_path(void);
4330Sstevel@tonic-gate static link_list_t *create_link_list(char *link);
4340Sstevel@tonic-gate static void s_unlink(const char *file);
4350Sstevel@tonic-gate static void s_closedir(DIR *dirp);
4360Sstevel@tonic-gate static void s_mkdirp(const char *path, const mode_t mode);
4370Sstevel@tonic-gate static int is_minor_node(char *contents, char **mn_root);
4380Sstevel@tonic-gate static int construct_devlink(char *link, link_list_t *link_build,
4390Sstevel@tonic-gate 				char *contents, di_minor_t minor,
4400Sstevel@tonic-gate 				di_node_t node, char *pattern);
4410Sstevel@tonic-gate static int split_devlinktab_entry(char *entry, char **selector, char **p_link,
4420Sstevel@tonic-gate 	    char **s_link);
4430Sstevel@tonic-gate static int devlink_matches(devlinktab_list_t *entry, di_minor_t minor,
4440Sstevel@tonic-gate 			    di_node_t node);
4450Sstevel@tonic-gate static int build_links(devlinktab_list_t *entry, di_minor_t minor,
4460Sstevel@tonic-gate 			di_node_t node);
4470Sstevel@tonic-gate static numeral_set_t *get_enum_cache(devfsadm_enumerate_t rules[],
4480Sstevel@tonic-gate 				    int nrules);
4490Sstevel@tonic-gate static void enumerate_recurse(char *current_dir, char *path_left,
4500Sstevel@tonic-gate     numeral_set_t *setp, devfsadm_enumerate_t rules[], int index);
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate static int match_path_component(char *file_re, char *file, char **id,
4530Sstevel@tonic-gate 				int subexp);
4540Sstevel@tonic-gate static void create_cached_numeral(char *path, numeral_set_t *setp,
4550Sstevel@tonic-gate     char *numeral_id, devfsadm_enumerate_t rules[], int index);
4560Sstevel@tonic-gate static int devfsadm_copy_file(const char *file, const struct stat *stat,
4570Sstevel@tonic-gate 			    int flags, struct FTW *ftw);
4580Sstevel@tonic-gate static void getattr(char *devname, char *aminor, int spectype, dev_t dev,
4590Sstevel@tonic-gate     mode_t *mode, uid_t *uid, gid_t *gid);
4600Sstevel@tonic-gate static int minor_matches_rule(di_node_t node, di_minor_t minor,
4610Sstevel@tonic-gate 				create_list_t *create);
4620Sstevel@tonic-gate static void add_verbose_id(char *mid);
4630Sstevel@tonic-gate static char *get_component(char *str, const char *comp_num);
4640Sstevel@tonic-gate static char *alloc_cmp_str(const char *devfs_path, devfsadm_enumerate_t *dep);
4650Sstevel@tonic-gate static int lookup_enum_cache(numeral_set_t *set, char *cmp_str,
4660Sstevel@tonic-gate     devfsadm_enumerate_t rules[], int index, numeral_t **matchnpp);
4670Sstevel@tonic-gate static void sync_handler(void *cookie, char *ap, size_t asize,
4680Sstevel@tonic-gate     door_desc_t *dp, uint_t ndesc);
4690Sstevel@tonic-gate static int zone_pathcheck(char *checkpath);
4700Sstevel@tonic-gate static void process_deferred_links(struct dca_impl *dcip, int flag);
4710Sstevel@tonic-gate static void event_handler(sysevent_t *ev);
4720Sstevel@tonic-gate static void dca_impl_init(char *root, char *minor, struct dca_impl *dcip);
4730Sstevel@tonic-gate static void lock_dev(void);
4740Sstevel@tonic-gate static void unlock_dev(int flag);
4752587Spjha static int devlink_cb(di_devlink_t dl, void *arg);
4762587Spjha static void free_dev_names(struct devlink_cb_arg *x);
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate int load_devpolicy(void);
4790Sstevel@tonic-gate static void load_dev_acl(void);
4800Sstevel@tonic-gate static void load_minor_perm_file(void);
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate static nvlist_t *build_event_attributes(char *, char *, char *,
4834211Sphitran     di_node_t, char *, int, char *);
4840Sstevel@tonic-gate static void log_event(char *, char *, nvlist_t *);
4854211Sphitran static void build_and_enq_event(char *, char *, char *, di_node_t, char *);
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate static void read_logindevperm_file(void);
4880Sstevel@tonic-gate static void set_logindev_perms(char *devlink);
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate static void reset_node_permissions(di_node_t, di_minor_t);
4910Sstevel@tonic-gate 
4922621Sllai1 /*
4932621Sllai1  * devname related
4942621Sllai1  */
4952621Sllai1 static void devname_lookup_handler(void *, char *, size_t,
4962621Sllai1     door_desc_t *, uint_t);		/* /dev name lookup server */
4972621Sllai1 static int devname_kcall(int, void *);	/* syscall into the devname fs */
4984876Smlf 
4992846Svikram static void nfphash_create(void);
5002846Svikram static int nfphash_fcn(char *key);
5012846Svikram static item_t *nfphash_lookup(char *key);
5022846Svikram static void nfphash_insert(char *key);
5032846Svikram static void nfphash_destroy(void);
5040Sstevel@tonic-gate 
5054876Smlf /* Enumerate reserve related */
5064876Smlf static void read_enumerate_file(void);
5074876Smlf static int enumerate_parse(char *rsvstr, char *path_left, numeral_set_t *setp,
5084876Smlf     devfsadm_enumerate_t rules[], int index);
5094876Smlf static void create_reserved_numeral(numeral_set_t *setp, char *numeral_id);
5104876Smlf 
5110Sstevel@tonic-gate /* convenient short hands */
5120Sstevel@tonic-gate #define	vprint		devfsadm_print
5130Sstevel@tonic-gate #define	err_print	devfsadm_errprint
5142621Sllai1 #ifndef TRUE
5150Sstevel@tonic-gate #define	TRUE	1
5162621Sllai1 #endif
5172621Sllai1 #ifndef FALSE
5180Sstevel@tonic-gate #define	FALSE	0
5192621Sllai1 #endif
5200Sstevel@tonic-gate 
5210Sstevel@tonic-gate #ifdef	__cplusplus
5220Sstevel@tonic-gate }
5230Sstevel@tonic-gate #endif
5240Sstevel@tonic-gate 
5250Sstevel@tonic-gate #endif /* _DEVFSADM_IMPL_H */
526