xref: /titanic_51/usr/src/lib/libdevinfo/device_info.h (revision a31148363f598def767ac48c5d82e1572e44b935)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * WARNING:
28  * The interfaces defined in this header file are for Sun private use only.
29  * The contents of this file are subject to change without notice in
30  * future releases.
31  */
32 
33 #ifndef	_DEVICE_INFO_H
34 #define	_DEVICE_INFO_H
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /* error return values */
41 #define	DEVFS_ERR	-1	/* operation not successful */
42 #define	DEVFS_INVAL	-2	/* invalid argument */
43 #define	DEVFS_NOMEM	-3	/* out of memory */
44 #define	DEVFS_PERM	-4 	/* permission denied - not root */
45 #define	DEVFS_NOTSUP	-5	/* operation not supported */
46 #define	DEVFS_LIMIT	-6	/* exceeded maximum size of property value */
47 #define	DEVFS_NOTFOUND	-7	/* request not found */
48 
49 /*
50  * for devfs_set_boot_dev()
51  * default behavior is to translate the input logical device name
52  * to most compact prom name(i.e. a prom alias, if one exists)
53  * as possible.  And to prepend the new entry to the existing
54  * list.
55  */
56 
57 /* perform no translation on the input device path */
58 #define	BOOTDEV_LITERAL		0x1
59 /* convert the input device path only a prom device path; not an alias */
60 #define	BOOTDEV_PROMDEV		0x2
61 /* overwrite the existing entry in boot-device - default is to prepend */
62 #define	BOOTDEV_OVERWRITE	0x4
63 
64 /*
65  * for devfs_get_prom_names()
66  * returns a list of prom names for a given logical device name.
67  * the list is sorted first in order of exact aliases, inexact alias
68  * matches (where an option override was needed), and finally the
69  * equivalent prom device path.  Each sublist is sorted in collating
70  * order.
71  */
72 #define	BOOTDEV_NO_PROM_PATH		0x1
73 #define	BOOTDEV_NO_INEXACT_ALIAS	0x2
74 #define	BOOTDEV_NO_EXACT_ALIAS		0x4
75 
76 /* for devfs_get_boot_dev() */
77 struct boot_dev {
78 	char *bootdev_element;	/* an entry from the boot-device variable */
79 	char **bootdev_trans;	/* 0 or more logical dev translations */
80 };
81 
82 /* for devfs_get_all_prom_names() */
83 struct devfs_prom_path {
84 	char *obp_path;
85 	char **alias_list;
86 	struct devfs_prom_path *next;
87 };
88 
89 /* prototypes */
90 
91 /* return the driver for a given device path */
92 extern int devfs_path_to_drv(char *devfs_path, char *drv_buf);
93 
94 /* convert a logical or physical device name to the equivalent prom path */
95 extern int devfs_dev_to_prom_name(char *, char *);
96 
97 /* return the driver name after resolving any aliases */
98 extern char *devfs_resolve_aliases(char *drv);
99 
100 /* set the boot-device configuration variable */
101 extern int devfs_bootdev_set_list(const char *, const uint_t);
102 
103 /* is the boot-device variable modifiable on this platform? */
104 extern int devfs_bootdev_modifiable(void);
105 
106 /*
107  * retrieve the boot-device config variable and corresponding logical
108  * device names
109  */
110 extern int devfs_bootdev_get_list(const char *, struct boot_dev ***);
111 /*
112  * free a list of bootdev structs
113  */
114 extern void devfs_bootdev_free_list(struct boot_dev **);
115 /*
116  * given a logical device name, return a list of equivalent
117  * prom names (aliases and device paths)
118  */
119 extern int devfs_get_prom_names(const char *, uint_t, char ***);
120 /*
121  * like devfs_get_prom_names(), but deals with 1 to many mappings
122  * introduced by mpxio devices
123  */
124 extern int devfs_get_all_prom_names(const char *, uint_t,
125     struct devfs_prom_path **);
126 /*
127  * free a list of devfs_prom_path structures
128  */
129 extern void devfs_free_all_prom_names(struct devfs_prom_path *);
130 
131 /*
132  *  Interpret a /dev link to its /devices path (does not require path to
133  *  still exist, as long as the links exist)
134  */
135 extern int devfs_resolve_link(char *, char **);
136 
137 /*
138  * map a device name from install OS environment to target OS environment or
139  * vice-versa.
140  */
141 extern int devfs_target2install(const char *, const char *, char *, size_t);
142 extern int devfs_install2target(const char *, const char *, char *, size_t);
143 
144 /*
145  * Minor perm parsing library support for devfsadm, add_drv etc.
146  */
147 #define	MINOR_PERM_FILE		"/etc/minor_perm"
148 #define	MAX_MINOR_PERM_LINE	256
149 #define	DEFAULT_DEV_USER	"root"
150 #define	DEFAULT_DEV_GROUP	"sys"
151 
152 /*
153  * Possible errors the callers of devfs_read_minor_perm() need
154  * to be prepared to deal with via callback.
155  */
156 typedef enum {
157 	MP_FOPEN_ERR,
158 	MP_FCLOSE_ERR,
159 	MP_IGNORING_LINE_ERR,
160 	MP_ALLOC_ERR,
161 	MP_NVLIST_ERR,
162 	MP_CANT_FIND_USER_ERR,
163 	MP_CANT_FIND_GROUP_ERR
164 } minorperm_err_t;
165 
166 
167 /*
168  * Create/free mperm list of minor perm entries
169  */
170 extern struct mperm *devfs_read_minor_perm(void (*)(minorperm_err_t, int));
171 extern void devfs_free_minor_perm(struct mperm *);
172 
173 /*
174  * Load all minor perm entries, and add/remove minor perm entry
175  */
176 extern int devfs_load_minor_perm(struct mperm *,
177 	void (*)(minorperm_err_t, int));
178 extern int devfs_add_minor_perm(char *, void (*)(minorperm_err_t, int));
179 extern int devfs_rm_minor_perm(char *, void (*)(minorperm_err_t, int));
180 
181 /* devfsadm dca_flags values: some are used by libdevinfo devlink_create() */
182 #define	DCA_CREATE_LINK		0x000000001
183 #define	DCA_FREE_LIST		0x000000002
184 #define	DCA_LOAD_DRV		0x000000004
185 #define	DCA_CHECK_TYPE		0x000000010
186 /* UNUSED was DCA_NOTIFY_RCM	0x000000020 (can be recycled) */
187 #define	DCA_FLUSH_PATHINST	0x000000040
188 #define	DCA_HOT_PLUG		0x000000080
189 #define	DCA_DEVLINK_SYNC	0x000000100
190 #define	DCA_DEVLINK_CACHE	0x000000200
191 
192 #ifdef	__cplusplus
193 }
194 #endif
195 
196 #endif	/* _DEVICE_INFO_H */
197