xref: /titanic_52/usr/src/lib/libdevinfo/device_info.h (revision ff2aee480f8fc985fe6a84c8d593c7a13c7a0481)
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
5*ff2aee48Scth  * Common Development and Distribution License (the "License").
6*ff2aee48Scth  * 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*ff2aee48Scth  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * WARNING:
287c478bd9Sstevel@tonic-gate  * The interfaces defined in this header file are for Sun private use only.
297c478bd9Sstevel@tonic-gate  * The contents of this file are subject to change without notice in
307c478bd9Sstevel@tonic-gate  * future releases.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifndef	_DEVICE_INFO_H
347c478bd9Sstevel@tonic-gate #define	_DEVICE_INFO_H
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /* error return values */
437c478bd9Sstevel@tonic-gate #define	DEVFS_ERR	-1	/* operation not successful */
447c478bd9Sstevel@tonic-gate #define	DEVFS_INVAL	-2	/* invalid argument */
457c478bd9Sstevel@tonic-gate #define	DEVFS_NOMEM	-3	/* out of memory */
467c478bd9Sstevel@tonic-gate #define	DEVFS_PERM	-4 	/* permission denied - not root */
477c478bd9Sstevel@tonic-gate #define	DEVFS_NOTSUP	-5	/* operation not supported */
487c478bd9Sstevel@tonic-gate #define	DEVFS_LIMIT	-6	/* exceeded maximum size of property value */
497c478bd9Sstevel@tonic-gate #define	DEVFS_NOTFOUND	-7	/* request not found */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * for devfs_set_boot_dev()
537c478bd9Sstevel@tonic-gate  * default behavior is to translate the input logical device name
547c478bd9Sstevel@tonic-gate  * to most compact prom name(i.e. a prom alias, if one exists)
557c478bd9Sstevel@tonic-gate  * as possible.  And to prepend the new entry to the existing
567c478bd9Sstevel@tonic-gate  * list.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /* perform no translation on the input device path */
607c478bd9Sstevel@tonic-gate #define	BOOTDEV_LITERAL		0x1
617c478bd9Sstevel@tonic-gate /* convert the input device path only a prom device path; not an alias */
627c478bd9Sstevel@tonic-gate #define	BOOTDEV_PROMDEV		0x2
637c478bd9Sstevel@tonic-gate /* overwrite the existing entry in boot-device - default is to prepend */
647c478bd9Sstevel@tonic-gate #define	BOOTDEV_OVERWRITE	0x4
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * for devfs_get_prom_names()
687c478bd9Sstevel@tonic-gate  * returns a list of prom names for a given logical device name.
697c478bd9Sstevel@tonic-gate  * the list is sorted first in order of exact aliases, inexact alias
707c478bd9Sstevel@tonic-gate  * matches (where an option override was needed), and finally the
717c478bd9Sstevel@tonic-gate  * equivalent prom device path.  Each sublist is sorted in collating
727c478bd9Sstevel@tonic-gate  * order.
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate #define	BOOTDEV_NO_PROM_PATH		0x1
757c478bd9Sstevel@tonic-gate #define	BOOTDEV_NO_INEXACT_ALIAS	0x2
767c478bd9Sstevel@tonic-gate #define	BOOTDEV_NO_EXACT_ALIAS		0x4
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /* for devfs_get_boot_dev() */
797c478bd9Sstevel@tonic-gate struct boot_dev {
807c478bd9Sstevel@tonic-gate 	char *bootdev_element;	/* an entry from the boot-device variable */
817c478bd9Sstevel@tonic-gate 	char **bootdev_trans;	/* 0 or more logical dev translations */
827c478bd9Sstevel@tonic-gate };
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /* for devfs_get_all_prom_names() */
857c478bd9Sstevel@tonic-gate struct devfs_prom_path {
867c478bd9Sstevel@tonic-gate 	char *obp_path;
877c478bd9Sstevel@tonic-gate 	char **alias_list;
887c478bd9Sstevel@tonic-gate 	struct devfs_prom_path *next;
897c478bd9Sstevel@tonic-gate };
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /* prototypes */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* return the driver for a given device path */
947c478bd9Sstevel@tonic-gate extern int devfs_path_to_drv(char *devfs_path, char *drv_buf);
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /* convert a logical or physical device name to the equivalent prom path */
977c478bd9Sstevel@tonic-gate extern int devfs_dev_to_prom_name(char *, char *);
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /* return the driver name after resolving any aliases */
1007c478bd9Sstevel@tonic-gate extern char *devfs_resolve_aliases(char *drv);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* set the boot-device configuration variable */
1037c478bd9Sstevel@tonic-gate extern int devfs_bootdev_set_list(const char *, const uint_t);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /* is the boot-device variable modifiable on this platform? */
1067c478bd9Sstevel@tonic-gate extern int devfs_bootdev_modifiable(void);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * retrieve the boot-device config variable and corresponding logical
1107c478bd9Sstevel@tonic-gate  * device names
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate extern int devfs_bootdev_get_list(const char *, struct boot_dev ***);
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * free a list of bootdev structs
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate extern void devfs_bootdev_free_list(struct boot_dev **);
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * given a logical device name, return a list of equivalent
1197c478bd9Sstevel@tonic-gate  * prom names (aliases and device paths)
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate extern int devfs_get_prom_names(const char *, uint_t, char ***);
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate  * like devfs_get_prom_names(), but deals with 1 to many mappings
1247c478bd9Sstevel@tonic-gate  * introduced by mpxio devices
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate extern int devfs_get_all_prom_names(const char *, uint_t,
1277c478bd9Sstevel@tonic-gate     struct devfs_prom_path **);
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * free a list of devfs_prom_path structures
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate extern void devfs_free_all_prom_names(struct devfs_prom_path *);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * map a device name from install OS environment to target OS environment or
1357c478bd9Sstevel@tonic-gate  * vice-versa.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate extern int devfs_target2install(const char *, const char *, char *, size_t);
1387c478bd9Sstevel@tonic-gate extern int devfs_install2target(const char *, const char *, char *, size_t);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * Minor perm parsing library support for devfsadm, add_drv etc.
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate #define	MINOR_PERM_FILE		"/etc/minor_perm"
1447c478bd9Sstevel@tonic-gate #define	MAX_MINOR_PERM_LINE	256
1457c478bd9Sstevel@tonic-gate #define	DEFAULT_DEV_USER	"root"
1467c478bd9Sstevel@tonic-gate #define	DEFAULT_DEV_GROUP	"sys"
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * Possible errors the callers of devfs_read_minor_perm() need
1507c478bd9Sstevel@tonic-gate  * to be prepared to deal with via callback.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate typedef enum {
1537c478bd9Sstevel@tonic-gate 	MP_FOPEN_ERR,
1547c478bd9Sstevel@tonic-gate 	MP_FCLOSE_ERR,
1557c478bd9Sstevel@tonic-gate 	MP_IGNORING_LINE_ERR,
1567c478bd9Sstevel@tonic-gate 	MP_ALLOC_ERR,
1577c478bd9Sstevel@tonic-gate 	MP_NVLIST_ERR,
1587c478bd9Sstevel@tonic-gate 	MP_CANT_FIND_USER_ERR,
1597c478bd9Sstevel@tonic-gate 	MP_CANT_FIND_GROUP_ERR
1607c478bd9Sstevel@tonic-gate } minorperm_err_t;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate  * Create/free mperm list of minor perm entries
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate extern struct mperm *devfs_read_minor_perm(void (*)(minorperm_err_t, int));
1677c478bd9Sstevel@tonic-gate extern void devfs_free_minor_perm(struct mperm *);
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * Load all minor perm entries, and add/remove minor perm entry
1717c478bd9Sstevel@tonic-gate  */
1727c478bd9Sstevel@tonic-gate extern int devfs_load_minor_perm(struct mperm *,
1737c478bd9Sstevel@tonic-gate 	void (*)(minorperm_err_t, int));
1747c478bd9Sstevel@tonic-gate extern int devfs_add_minor_perm(char *, void (*)(minorperm_err_t, int));
1757c478bd9Sstevel@tonic-gate extern int devfs_rm_minor_perm(char *, void (*)(minorperm_err_t, int));
1767c478bd9Sstevel@tonic-gate 
177*ff2aee48Scth /* devfsadm dca_flags values: some are used by libdevinfo devlink_create() */
178*ff2aee48Scth #define	DCA_CREATE_LINK		0x000000001
179*ff2aee48Scth #define	DCA_FREE_LIST		0x000000002
180*ff2aee48Scth #define	DCA_LOAD_DRV		0x000000004
181*ff2aee48Scth #define	DCA_CHECK_TYPE		0x000000010
182*ff2aee48Scth #define	DCA_NOTIFY_RCM		0x000000020
183*ff2aee48Scth #define	DCA_FLUSH_PATHINST	0x000000040
184*ff2aee48Scth #define	DCA_HOT_PLUG		0x000000080
185*ff2aee48Scth #define	DCA_DEVLINK_SYNC	0x000000100
186*ff2aee48Scth #define	DCA_DEVLINK_CACHE	0x000000200
187*ff2aee48Scth 
1887c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate #endif
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate #endif	/* _DEVICE_INFO_H */
193