xref: /illumos-gate/usr/src/cmd/devfsadm/devfsadm.h (revision 540b2cc7a3cce4677bb918fec08d34cfd5f8c545)
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 /*
2294c894bbSVikram Hegde  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
23*540b2cc7SHans Rosenfeld  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _DEVFSADM_H
277c478bd9Sstevel@tonic-gate #define	_DEVFSADM_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <libdevinfo.h>
317c478bd9Sstevel@tonic-gate #include <sys/devinfo_impl.h>
327c478bd9Sstevel@tonic-gate #include <regex.h>
337c478bd9Sstevel@tonic-gate 
348d483882Smlf #undef	DEBUG
358d483882Smlf #ifndef DEBUG
368d483882Smlf #define	NDEBUG 1
378d483882Smlf #else
388d483882Smlf #undef	NDEBUG
398d483882Smlf #endif
408d483882Smlf 
418d483882Smlf #include <assert.h>
428d483882Smlf 
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	DEVFSADM_SUCCESS 0
487c478bd9Sstevel@tonic-gate #define	DEVFSADM_FAILURE -1
497c478bd9Sstevel@tonic-gate #define	DEVFSADM_MULTIPLE -2
507c478bd9Sstevel@tonic-gate #define	DEVFSADM_TRUE 0
517c478bd9Sstevel@tonic-gate #define	DEVFSADM_FALSE -1
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #define	ILEVEL_0 0
547c478bd9Sstevel@tonic-gate #define	ILEVEL_1 1
557c478bd9Sstevel@tonic-gate #define	ILEVEL_2 2
567c478bd9Sstevel@tonic-gate #define	ILEVEL_3 3
577c478bd9Sstevel@tonic-gate #define	ILEVEL_4 4
587c478bd9Sstevel@tonic-gate #define	ILEVEL_5 5
597c478bd9Sstevel@tonic-gate #define	ILEVEL_6 6
607c478bd9Sstevel@tonic-gate #define	ILEVEL_7 7
617c478bd9Sstevel@tonic-gate #define	ILEVEL_8 8
627c478bd9Sstevel@tonic-gate #define	ILEVEL_9 9
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	DEVFSADM_V0 0
65aa646b9dSvikram #define	DEVFSADM_V1 1
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #define	DEVFSADM_CONTINUE 0
687c478bd9Sstevel@tonic-gate #define	DEVFSADM_TERMINATE 1
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	INTEGER 0
717c478bd9Sstevel@tonic-gate #define	CHARACTER 1
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	RM_HOT 0x01
747c478bd9Sstevel@tonic-gate #define	RM_PRE 0x02
757c478bd9Sstevel@tonic-gate #define	RM_POST 0x04
767c478bd9Sstevel@tonic-gate #define	RM_ALWAYS 0x08
77aa646b9dSvikram #define	RM_NOINTERPOSE 0x10
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	TYPE_EXACT 0x01
807c478bd9Sstevel@tonic-gate #define	TYPE_RE 0x02
817c478bd9Sstevel@tonic-gate #define	TYPE_PARTIAL 0x04
827c478bd9Sstevel@tonic-gate #define	TYPE_MASK 0x07
837c478bd9Sstevel@tonic-gate #define	DRV_EXACT 0x10
847c478bd9Sstevel@tonic-gate #define	DRV_RE 0x20
857c478bd9Sstevel@tonic-gate #define	DRV_MASK 0x30
867c478bd9Sstevel@tonic-gate #define	CREATE_DEFER 0x100
877c478bd9Sstevel@tonic-gate #define	CREATE_MASK 0x100
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /* command to start daemon */
907c478bd9Sstevel@tonic-gate #define	DEVFSADMD_START_PATH	"/usr/lib/devfsadm/devfsadmd"
917c478bd9Sstevel@tonic-gate #define	DEVFSADMD_START		"devfsadmd"
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* devfsadm event service door */
947c478bd9Sstevel@tonic-gate #define	DEVFSADM_SERVICE_DOOR	"/etc/sysevent/devfsadm_event_channel"
95facf4a8dSllai1 #define	DEVNAME_LOOKUP_DOOR	".devname_lookup_door"
96facf4a8dSllai1 
978d483882Smlf /* File of reserved devnames */
988d483882Smlf #define	ENUMERATE_RESERVED "/etc/dev/reserved_devnames"
998d483882Smlf 
1007c478bd9Sstevel@tonic-gate /* flags for devfsadm_mklink */
1017c478bd9Sstevel@tonic-gate #define	DEV_SYNC 0x02	/* synchronous mklink */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #define	INFO_MID		NULL		/* always prints */
1047c478bd9Sstevel@tonic-gate #define	VERBOSE_MID		"verbose"	/* prints with -v */
1057c478bd9Sstevel@tonic-gate #define	CHATTY_MID		"chatty" 	/* prints with -V chatty */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate typedef struct devfsadm_create {
1087c478bd9Sstevel@tonic-gate 	char	*device_class;	/* eg "disk", "tape", "display" */
1097c478bd9Sstevel@tonic-gate 	char	*node_type;	/* eg DDI_NT_TAPE, DDI_NT_BLOCK, etc */
1107c478bd9Sstevel@tonic-gate 	char	*drv_name;	/* eg sd, ssd */
1117c478bd9Sstevel@tonic-gate 	int	flags;		/* TYPE_{EXACT,RE,PARTIAL}, DRV_{EXACT,RE} */
1127c478bd9Sstevel@tonic-gate 	int interpose_lvl;	/* eg ILEVEL_0.. ILEVEL_10 */
1137c478bd9Sstevel@tonic-gate 	int (*callback_fcn)(di_minor_t minor, di_node_t node);
1147c478bd9Sstevel@tonic-gate } devfsadm_create_t;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate typedef struct devfsadm_remove {
1177c478bd9Sstevel@tonic-gate 	char 	*device_class;	/* eg "disk", "tape", "display" */
1187c478bd9Sstevel@tonic-gate 	char    *dev_dirs_re;   /* dev dirs regex selector */
1197c478bd9Sstevel@tonic-gate 	int	flags;		/* eg POST, PRE, HOT, ALWAYS */
1207c478bd9Sstevel@tonic-gate 	int	interpose_lvl;	/* eg ILEVEL_0 .. ILEVEL_10 */
121aa646b9dSvikram 	void	(*callback_fcn)(char *);
1227c478bd9Sstevel@tonic-gate } devfsadm_remove_t;
1237c478bd9Sstevel@tonic-gate 
124aa646b9dSvikram typedef struct devfsadm_remove_V1 {
125aa646b9dSvikram 	char 	*device_class;	/* eg "disk", "tape", "display" */
126aa646b9dSvikram 	char    *dev_dirs_re;   /* dev dirs regex selector */
127aa646b9dSvikram 	int	flags;		/* eg POST, PRE, HOT, ALWAYS */
128aa646b9dSvikram 	int	interpose_lvl;	/* eg ILEVEL_0 .. ILEVEL_10 */
129aa646b9dSvikram 	int	(*callback_fcn)(char *);
130aa646b9dSvikram } devfsadm_remove_V1_t;
131aa646b9dSvikram 
1327c478bd9Sstevel@tonic-gate typedef struct _devfsadm_create_reg {
1337c478bd9Sstevel@tonic-gate 	uint_t version;
1347c478bd9Sstevel@tonic-gate 	uint_t count;	/* number of node type registration */
1357c478bd9Sstevel@tonic-gate 			/* structures */
1367c478bd9Sstevel@tonic-gate 	devfsadm_create_t *tblp;
1377c478bd9Sstevel@tonic-gate } _devfsadm_create_reg_t;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate typedef struct _devfsadm_remove_reg {
1407c478bd9Sstevel@tonic-gate 	uint_t version;
1417c478bd9Sstevel@tonic-gate 	uint_t count;   /* number of node type registration */
1427c478bd9Sstevel@tonic-gate 			/* structures */
1437c478bd9Sstevel@tonic-gate 	devfsadm_remove_t *tblp;
1447c478bd9Sstevel@tonic-gate } _devfsadm_remove_reg_t;
1457c478bd9Sstevel@tonic-gate 
146aa646b9dSvikram typedef struct _devfsadm_remove_reg_V1 {
147aa646b9dSvikram 	uint_t version;
148aa646b9dSvikram 	uint_t count;   /* number of node type registration */
149aa646b9dSvikram 			/* structures */
150aa646b9dSvikram 	devfsadm_remove_V1_t *tblp;
151aa646b9dSvikram } _devfsadm_remove_reg_V1_t;
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate  * "flags" in the devfs_enumerate structure can take the following values.
1547c478bd9Sstevel@tonic-gate  * These values specify the substring of devfs path to be used for
1557c478bd9Sstevel@tonic-gate  * enumeration. Components (see MATCH_ADDR/MATCH_MINOR) may be specified
1567c478bd9Sstevel@tonic-gate  * by using the "match_arg" member in the devfsadm_enumerate structure.
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate #define	MATCH_ALL	0x001	/* Match entire devfs path */
1597c478bd9Sstevel@tonic-gate #define	MATCH_PARENT	0x002	/* Match upto last '/' in devfs path */
1607c478bd9Sstevel@tonic-gate #define	MATCH_ADDR	0x004	/* Match upto nth component of last address */
1617c478bd9Sstevel@tonic-gate #define	MATCH_MINOR	0x008	/* Match upto nth component of minor name */
1627c478bd9Sstevel@tonic-gate #define	MATCH_CALLBACK	0x010	/* Use callback to derive match string */
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate  * The following flags are private to devfsadm and the disks module.
1667c478bd9Sstevel@tonic-gate  * NOT to be used by other modules.
1677c478bd9Sstevel@tonic-gate  */
1687c478bd9Sstevel@tonic-gate #define	MATCH_NODE	0x020
1697c478bd9Sstevel@tonic-gate #define	MATCH_MASK	0x03F
1707c478bd9Sstevel@tonic-gate #define	MATCH_UNCACHED	0x040 /* retry flags for disks module */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate typedef struct devfsadm_enumerate {
1737c478bd9Sstevel@tonic-gate 	char *re;
1747c478bd9Sstevel@tonic-gate 	int subexp;
1757c478bd9Sstevel@tonic-gate 	uint_t flags;
1767c478bd9Sstevel@tonic-gate 	char *match_arg;
1777c478bd9Sstevel@tonic-gate 	char *(*sel_fcn)(const char *path, void *cb_arg);
1787c478bd9Sstevel@tonic-gate 	void *cb_arg;
1797c478bd9Sstevel@tonic-gate } devfsadm_enumerate_t;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate #define	DEVFSADM_CREATE_INIT_V0(tbl) \
1827c478bd9Sstevel@tonic-gate 	_devfsadm_create_reg_t _devfsadm_create_reg = { \
1837c478bd9Sstevel@tonic-gate 	DEVFSADM_V0, \
1847c478bd9Sstevel@tonic-gate 	(sizeof (tbl) / sizeof (devfsadm_create_t)), \
1857c478bd9Sstevel@tonic-gate 	((devfsadm_create_t *)(tbl)) }
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate #define	DEVFSADM_REMOVE_INIT_V0(tbl)\
1887c478bd9Sstevel@tonic-gate 	_devfsadm_remove_reg_t _devfsadm_remove_reg = {\
1897c478bd9Sstevel@tonic-gate 	DEVFSADM_V0, \
1907c478bd9Sstevel@tonic-gate 	(sizeof (tbl) / sizeof (devfsadm_remove_t)), \
1917c478bd9Sstevel@tonic-gate 	((devfsadm_remove_t *)(tbl)) }
1927c478bd9Sstevel@tonic-gate 
193aa646b9dSvikram #define	DEVFSADM_REMOVE_INIT_V1(tbl)\
194aa646b9dSvikram 	_devfsadm_remove_reg_V1_t _devfsadm_remove_reg = {\
195aa646b9dSvikram 	DEVFSADM_V1, \
196aa646b9dSvikram 	(sizeof (tbl) / sizeof (devfsadm_remove_V1_t)), \
197aa646b9dSvikram 	((devfsadm_remove_V1_t *)(tbl)) }
198aa646b9dSvikram 
1998d483882Smlf /* reserved devname support */
2008d483882Smlf typedef struct devlink_re {
2018d483882Smlf 	char *d_re;
2028d483882Smlf 	int d_subexp;
2038d483882Smlf 	regex_t d_rcomp;
2048d483882Smlf 	regmatch_t *d_pmatch;
2058d483882Smlf } devlink_re_t;
2068d483882Smlf 
2078d483882Smlf typedef struct enumerate_file {
2088d483882Smlf 	char *er_file;
2098d483882Smlf 	char *er_id;
2108d483882Smlf 	struct enumerate_file *er_next;
2118d483882Smlf } enumerate_file_t;
2128d483882Smlf 
2137c478bd9Sstevel@tonic-gate int devfsadm_noupdate(void);
2147c478bd9Sstevel@tonic-gate const char *devfsadm_root_path(void);
21594c894bbSVikram Hegde int devfsadm_link_valid(di_node_t anynode, char *link);
2167c478bd9Sstevel@tonic-gate int devfsadm_mklink(char *link, di_node_t node, di_minor_t minor, int flags);
2177c478bd9Sstevel@tonic-gate int devfsadm_secondary_link(char *link, char *primary_link, int flags);
2187c478bd9Sstevel@tonic-gate void devfsadm_rm_link(char *file);
2197c478bd9Sstevel@tonic-gate void devfsadm_rm_all(char *file);
2207c478bd9Sstevel@tonic-gate void devfsadm_rm_stale_links(char *dir_re, char *valid_link, di_node_t node,
2217c478bd9Sstevel@tonic-gate 		di_minor_t minor);
2227c478bd9Sstevel@tonic-gate void devfsadm_errprint(char *message, ...);
2237c478bd9Sstevel@tonic-gate void devfsadm_print(char *mid, char *message, ...);
2247c478bd9Sstevel@tonic-gate int devfsadm_enumerate_int(char *devfs_path, int index, char **buf,
2257c478bd9Sstevel@tonic-gate 			    devfsadm_enumerate_t rules[], int nrules);
2267c478bd9Sstevel@tonic-gate int devfsadm_enumerate_char(char *devfs_path, int index, char **buf,
2277c478bd9Sstevel@tonic-gate 			    devfsadm_enumerate_t rules[], int nrules);
2283c4226f9Spjha char **devfsadm_lookup_dev_names(char *phys_path, char *re, int *lenp);
2293c4226f9Spjha void devfsadm_free_dev_names(char **dev_names, int len);
2303c4226f9Spjha 
2318d483882Smlf /* devlink cache related */
2328d483882Smlf di_devlink_handle_t devfsadm_devlink_cache(void);
2338d483882Smlf 
2347c478bd9Sstevel@tonic-gate /*
235*540b2cc7SHans Rosenfeld  * Private enumerate interface for controllers, disks, and sgen modules
2367c478bd9Sstevel@tonic-gate  */
237*540b2cc7SHans Rosenfeld int ctrl_enumerate_int(char *devfs_path, int index, char **buf,
238*540b2cc7SHans Rosenfeld 			    devfsadm_enumerate_t rules[], int nrules,
239*540b2cc7SHans Rosenfeld 			    int multiple, boolean_t scsi_vhci);
2407c478bd9Sstevel@tonic-gate /*
2417c478bd9Sstevel@tonic-gate  * Private interfaces for ports module (port_link.c).
2427c478bd9Sstevel@tonic-gate  */
2437c478bd9Sstevel@tonic-gate int devfsadm_enumerate_char_start(char *devfs_path, int index,
2447c478bd9Sstevel@tonic-gate     char **buf, devfsadm_enumerate_t rules[], int nrules, char *start);
24594c894bbSVikram Hegde int devfsadm_read_link(di_node_t node, char *link, char **devfs_path);
2467c478bd9Sstevel@tonic-gate char *s_strdup(const char *ptr);
2477c478bd9Sstevel@tonic-gate 
2488d483882Smlf /* Private interface between reserve subsystm and disks link generator */
249e37c6c37Scth int devfsadm_have_reserved(void);
2508d483882Smlf int devfsadm_is_reserved(devlink_re_t re_array[], char *devlink);
2518d483882Smlf int devfsadm_reserve_id_cache(devlink_re_t re_array[], enumerate_file_t *head);
2528d483882Smlf 
2537c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate #endif
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate #endif	/* _DEVFSADM_H */
258