xref: /titanic_50/usr/src/cmd/devfsadm/devfsadm.h (revision e37c6c376a1a22a828db3bb5ab40c86cb08f9c86)
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  */
217c478bd9Sstevel@tonic-gate /*
22*e37c6c37Scth  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _DEVFSADM_H
277c478bd9Sstevel@tonic-gate #define	_DEVFSADM_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <libdevinfo.h>
337c478bd9Sstevel@tonic-gate #include <sys/devinfo_impl.h>
347c478bd9Sstevel@tonic-gate #include <regex.h>
357c478bd9Sstevel@tonic-gate 
368d483882Smlf #undef	DEBUG
378d483882Smlf #ifndef DEBUG
388d483882Smlf #define	NDEBUG 1
398d483882Smlf #else
408d483882Smlf #undef	NDEBUG
418d483882Smlf #endif
428d483882Smlf 
438d483882Smlf #include <assert.h>
448d483882Smlf 
457c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
467c478bd9Sstevel@tonic-gate extern "C" {
477c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	DEVFSADM_SUCCESS 0
507c478bd9Sstevel@tonic-gate #define	DEVFSADM_FAILURE -1
517c478bd9Sstevel@tonic-gate #define	DEVFSADM_MULTIPLE -2
527c478bd9Sstevel@tonic-gate #define	DEVFSADM_TRUE 0
537c478bd9Sstevel@tonic-gate #define	DEVFSADM_FALSE -1
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #define	ILEVEL_0 0
567c478bd9Sstevel@tonic-gate #define	ILEVEL_1 1
577c478bd9Sstevel@tonic-gate #define	ILEVEL_2 2
587c478bd9Sstevel@tonic-gate #define	ILEVEL_3 3
597c478bd9Sstevel@tonic-gate #define	ILEVEL_4 4
607c478bd9Sstevel@tonic-gate #define	ILEVEL_5 5
617c478bd9Sstevel@tonic-gate #define	ILEVEL_6 6
627c478bd9Sstevel@tonic-gate #define	ILEVEL_7 7
637c478bd9Sstevel@tonic-gate #define	ILEVEL_8 8
647c478bd9Sstevel@tonic-gate #define	ILEVEL_9 9
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #define	DEVFSADM_V0 0
67aa646b9dSvikram #define	DEVFSADM_V1 1
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #define	DEVFSADM_CONTINUE 0
707c478bd9Sstevel@tonic-gate #define	DEVFSADM_TERMINATE 1
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #define	INTEGER 0
737c478bd9Sstevel@tonic-gate #define	CHARACTER 1
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #define	RM_HOT 0x01
767c478bd9Sstevel@tonic-gate #define	RM_PRE 0x02
777c478bd9Sstevel@tonic-gate #define	RM_POST 0x04
787c478bd9Sstevel@tonic-gate #define	RM_ALWAYS 0x08
79aa646b9dSvikram #define	RM_NOINTERPOSE 0x10
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	TYPE_EXACT 0x01
827c478bd9Sstevel@tonic-gate #define	TYPE_RE 0x02
837c478bd9Sstevel@tonic-gate #define	TYPE_PARTIAL 0x04
847c478bd9Sstevel@tonic-gate #define	TYPE_MASK 0x07
857c478bd9Sstevel@tonic-gate #define	DRV_EXACT 0x10
867c478bd9Sstevel@tonic-gate #define	DRV_RE 0x20
877c478bd9Sstevel@tonic-gate #define	DRV_MASK 0x30
887c478bd9Sstevel@tonic-gate #define	CREATE_DEFER 0x100
897c478bd9Sstevel@tonic-gate #define	CREATE_MASK 0x100
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /* command to start daemon */
927c478bd9Sstevel@tonic-gate #define	DEVFSADMD_START_PATH	"/usr/lib/devfsadm/devfsadmd"
937c478bd9Sstevel@tonic-gate #define	DEVFSADMD_START		"devfsadmd"
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /* devfsadm event service door */
967c478bd9Sstevel@tonic-gate #define	DEVFSADM_SERVICE_DOOR	"/etc/sysevent/devfsadm_event_channel"
97facf4a8dSllai1 #define	DEVNAME_LOOKUP_DOOR	".devname_lookup_door"
98facf4a8dSllai1 
99facf4a8dSllai1 /* /dev device name binding rule locations */
100facf4a8dSllai1 #define	DEVNAME_MASTER_MAP	"/etc/dev/devname_master"
1017c478bd9Sstevel@tonic-gate 
1028d483882Smlf /* File of reserved devnames */
1038d483882Smlf #define	ENUMERATE_RESERVED "/etc/dev/reserved_devnames"
1048d483882Smlf 
1057c478bd9Sstevel@tonic-gate /* flags for devfsadm_mklink */
1067c478bd9Sstevel@tonic-gate #define	DEV_SYNC 0x02	/* synchronous mklink */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #define	INFO_MID		NULL		/* always prints */
1097c478bd9Sstevel@tonic-gate #define	VERBOSE_MID		"verbose"	/* prints with -v */
1107c478bd9Sstevel@tonic-gate #define	CHATTY_MID		"chatty" 	/* prints with -V chatty */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate typedef struct devfsadm_create {
1137c478bd9Sstevel@tonic-gate 	char	*device_class;	/* eg "disk", "tape", "display" */
1147c478bd9Sstevel@tonic-gate 	char	*node_type;	/* eg DDI_NT_TAPE, DDI_NT_BLOCK, etc */
1157c478bd9Sstevel@tonic-gate 	char	*drv_name;	/* eg sd, ssd */
1167c478bd9Sstevel@tonic-gate 	int	flags;		/* TYPE_{EXACT,RE,PARTIAL}, DRV_{EXACT,RE} */
1177c478bd9Sstevel@tonic-gate 	int interpose_lvl;	/* eg ILEVEL_0.. ILEVEL_10 */
1187c478bd9Sstevel@tonic-gate 	int (*callback_fcn)(di_minor_t minor, di_node_t node);
1197c478bd9Sstevel@tonic-gate } devfsadm_create_t;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate typedef struct devfsadm_remove {
1227c478bd9Sstevel@tonic-gate 	char 	*device_class;	/* eg "disk", "tape", "display" */
1237c478bd9Sstevel@tonic-gate 	char    *dev_dirs_re;   /* dev dirs regex selector */
1247c478bd9Sstevel@tonic-gate 	int	flags;		/* eg POST, PRE, HOT, ALWAYS */
1257c478bd9Sstevel@tonic-gate 	int	interpose_lvl;	/* eg ILEVEL_0 .. ILEVEL_10 */
126aa646b9dSvikram 	void	(*callback_fcn)(char *);
1277c478bd9Sstevel@tonic-gate } devfsadm_remove_t;
1287c478bd9Sstevel@tonic-gate 
129aa646b9dSvikram typedef struct devfsadm_remove_V1 {
130aa646b9dSvikram 	char 	*device_class;	/* eg "disk", "tape", "display" */
131aa646b9dSvikram 	char    *dev_dirs_re;   /* dev dirs regex selector */
132aa646b9dSvikram 	int	flags;		/* eg POST, PRE, HOT, ALWAYS */
133aa646b9dSvikram 	int	interpose_lvl;	/* eg ILEVEL_0 .. ILEVEL_10 */
134aa646b9dSvikram 	int	(*callback_fcn)(char *);
135aa646b9dSvikram } devfsadm_remove_V1_t;
136aa646b9dSvikram 
1377c478bd9Sstevel@tonic-gate typedef struct _devfsadm_create_reg {
1387c478bd9Sstevel@tonic-gate 	uint_t version;
1397c478bd9Sstevel@tonic-gate 	uint_t count;	/* number of node type registration */
1407c478bd9Sstevel@tonic-gate 			/* structures */
1417c478bd9Sstevel@tonic-gate 	devfsadm_create_t *tblp;
1427c478bd9Sstevel@tonic-gate } _devfsadm_create_reg_t;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate typedef struct _devfsadm_remove_reg {
1457c478bd9Sstevel@tonic-gate 	uint_t version;
1467c478bd9Sstevel@tonic-gate 	uint_t count;   /* number of node type registration */
1477c478bd9Sstevel@tonic-gate 			/* structures */
1487c478bd9Sstevel@tonic-gate 	devfsadm_remove_t *tblp;
1497c478bd9Sstevel@tonic-gate } _devfsadm_remove_reg_t;
1507c478bd9Sstevel@tonic-gate 
151aa646b9dSvikram typedef struct _devfsadm_remove_reg_V1 {
152aa646b9dSvikram 	uint_t version;
153aa646b9dSvikram 	uint_t count;   /* number of node type registration */
154aa646b9dSvikram 			/* structures */
155aa646b9dSvikram 	devfsadm_remove_V1_t *tblp;
156aa646b9dSvikram } _devfsadm_remove_reg_V1_t;
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * "flags" in the devfs_enumerate structure can take the following values.
1597c478bd9Sstevel@tonic-gate  * These values specify the substring of devfs path to be used for
1607c478bd9Sstevel@tonic-gate  * enumeration. Components (see MATCH_ADDR/MATCH_MINOR) may be specified
1617c478bd9Sstevel@tonic-gate  * by using the "match_arg" member in the devfsadm_enumerate structure.
1627c478bd9Sstevel@tonic-gate  */
1637c478bd9Sstevel@tonic-gate #define	MATCH_ALL	0x001	/* Match entire devfs path */
1647c478bd9Sstevel@tonic-gate #define	MATCH_PARENT	0x002	/* Match upto last '/' in devfs path */
1657c478bd9Sstevel@tonic-gate #define	MATCH_ADDR	0x004	/* Match upto nth component of last address */
1667c478bd9Sstevel@tonic-gate #define	MATCH_MINOR	0x008	/* Match upto nth component of minor name */
1677c478bd9Sstevel@tonic-gate #define	MATCH_CALLBACK	0x010	/* Use callback to derive match string */
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * The following flags are private to devfsadm and the disks module.
1717c478bd9Sstevel@tonic-gate  * NOT to be used by other modules.
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate #define	MATCH_NODE	0x020
1747c478bd9Sstevel@tonic-gate #define	MATCH_MASK	0x03F
1757c478bd9Sstevel@tonic-gate #define	MATCH_UNCACHED	0x040 /* retry flags for disks module */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate typedef struct devfsadm_enumerate {
1787c478bd9Sstevel@tonic-gate 	char *re;
1797c478bd9Sstevel@tonic-gate 	int subexp;
1807c478bd9Sstevel@tonic-gate 	uint_t flags;
1817c478bd9Sstevel@tonic-gate 	char *match_arg;
1827c478bd9Sstevel@tonic-gate 	char *(*sel_fcn)(const char *path, void *cb_arg);
1837c478bd9Sstevel@tonic-gate 	void *cb_arg;
1847c478bd9Sstevel@tonic-gate } devfsadm_enumerate_t;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate #define	DEVFSADM_CREATE_INIT_V0(tbl) \
1877c478bd9Sstevel@tonic-gate 	_devfsadm_create_reg_t _devfsadm_create_reg = { \
1887c478bd9Sstevel@tonic-gate 	DEVFSADM_V0, \
1897c478bd9Sstevel@tonic-gate 	(sizeof (tbl) / sizeof (devfsadm_create_t)), \
1907c478bd9Sstevel@tonic-gate 	((devfsadm_create_t *)(tbl)) }
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate #define	DEVFSADM_REMOVE_INIT_V0(tbl)\
1937c478bd9Sstevel@tonic-gate 	_devfsadm_remove_reg_t _devfsadm_remove_reg = {\
1947c478bd9Sstevel@tonic-gate 	DEVFSADM_V0, \
1957c478bd9Sstevel@tonic-gate 	(sizeof (tbl) / sizeof (devfsadm_remove_t)), \
1967c478bd9Sstevel@tonic-gate 	((devfsadm_remove_t *)(tbl)) }
1977c478bd9Sstevel@tonic-gate 
198aa646b9dSvikram #define	DEVFSADM_REMOVE_INIT_V1(tbl)\
199aa646b9dSvikram 	_devfsadm_remove_reg_V1_t _devfsadm_remove_reg = {\
200aa646b9dSvikram 	DEVFSADM_V1, \
201aa646b9dSvikram 	(sizeof (tbl) / sizeof (devfsadm_remove_V1_t)), \
202aa646b9dSvikram 	((devfsadm_remove_V1_t *)(tbl)) }
203aa646b9dSvikram 
2048d483882Smlf /* reserved devname support */
2058d483882Smlf typedef struct devlink_re {
2068d483882Smlf 	char *d_re;
2078d483882Smlf 	int d_subexp;
2088d483882Smlf 	regex_t d_rcomp;
2098d483882Smlf 	regmatch_t *d_pmatch;
2108d483882Smlf } devlink_re_t;
2118d483882Smlf 
2128d483882Smlf typedef struct enumerate_file {
2138d483882Smlf 	char *er_file;
2148d483882Smlf 	char *er_id;
2158d483882Smlf 	struct enumerate_file *er_next;
2168d483882Smlf } enumerate_file_t;
2178d483882Smlf 
2187c478bd9Sstevel@tonic-gate int devfsadm_noupdate(void);
2197c478bd9Sstevel@tonic-gate const char *devfsadm_root_path(void);
2207c478bd9Sstevel@tonic-gate int devfsadm_link_valid(char *link);
2217c478bd9Sstevel@tonic-gate int devfsadm_mklink(char *link, di_node_t node, di_minor_t minor, int flags);
2227c478bd9Sstevel@tonic-gate int devfsadm_secondary_link(char *link, char *primary_link, int flags);
2237c478bd9Sstevel@tonic-gate void devfsadm_rm_link(char *file);
2247c478bd9Sstevel@tonic-gate void devfsadm_rm_all(char *file);
2257c478bd9Sstevel@tonic-gate void devfsadm_rm_stale_links(char *dir_re, char *valid_link, di_node_t node,
2267c478bd9Sstevel@tonic-gate 		di_minor_t minor);
2277c478bd9Sstevel@tonic-gate void devfsadm_errprint(char *message, ...);
2287c478bd9Sstevel@tonic-gate void devfsadm_print(char *mid, char *message, ...);
2297c478bd9Sstevel@tonic-gate int devfsadm_enumerate_int(char *devfs_path, int index, char **buf,
2307c478bd9Sstevel@tonic-gate 			    devfsadm_enumerate_t rules[], int nrules);
2317c478bd9Sstevel@tonic-gate int devfsadm_enumerate_char(char *devfs_path, int index, char **buf,
2327c478bd9Sstevel@tonic-gate 			    devfsadm_enumerate_t rules[], int nrules);
2333c4226f9Spjha char **devfsadm_lookup_dev_names(char *phys_path, char *re, int *lenp);
2343c4226f9Spjha void devfsadm_free_dev_names(char **dev_names, int len);
2353c4226f9Spjha 
2368d483882Smlf /* devlink cache related */
2378d483882Smlf di_devlink_handle_t devfsadm_devlink_cache(void);
2388d483882Smlf 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * Private enumerate interface for disks and sgen modules
2417c478bd9Sstevel@tonic-gate  */
2427c478bd9Sstevel@tonic-gate int disk_enumerate_int(char *devfs_path, int index, char **buf,
2437c478bd9Sstevel@tonic-gate 			    devfsadm_enumerate_t rules[], int nrules);
2447c478bd9Sstevel@tonic-gate /*
2457c478bd9Sstevel@tonic-gate  * Private interfaces for ports module (port_link.c).
2467c478bd9Sstevel@tonic-gate  */
2477c478bd9Sstevel@tonic-gate int devfsadm_enumerate_char_start(char *devfs_path, int index,
2487c478bd9Sstevel@tonic-gate     char **buf, devfsadm_enumerate_t rules[], int nrules, char *start);
2497c478bd9Sstevel@tonic-gate int devfsadm_read_link(char *link, char **devfs_path);
2507c478bd9Sstevel@tonic-gate char *s_strdup(const char *ptr);
2517c478bd9Sstevel@tonic-gate 
2528d483882Smlf /* Private interface between reserve subsystm and disks link generator */
253*e37c6c37Scth int devfsadm_have_reserved(void);
2548d483882Smlf int devfsadm_is_reserved(devlink_re_t re_array[], char *devlink);
2558d483882Smlf int devfsadm_reserve_id_cache(devlink_re_t re_array[], enumerate_file_t *head);
2568d483882Smlf 
2577c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate #endif
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate #endif	/* _DEVFSADM_H */
262