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