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