Home | History | Annotate | Download | only in libdevinfo
      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 2008 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  * map a device name from install OS environment to target OS environment or
    133  * vice-versa.
    134  */
    135 extern int devfs_target2install(const char *, const char *, char *, size_t);
    136 extern int devfs_install2target(const char *, const char *, char *, size_t);
    137 
    138 /*
    139  * Minor perm parsing library support for devfsadm, add_drv etc.
    140  */
    141 #define	MINOR_PERM_FILE		"/etc/minor_perm"
    142 #define	MAX_MINOR_PERM_LINE	256
    143 #define	DEFAULT_DEV_USER	"root"
    144 #define	DEFAULT_DEV_GROUP	"sys"
    145 
    146 /*
    147  * Possible errors the callers of devfs_read_minor_perm() need
    148  * to be prepared to deal with via callback.
    149  */
    150 typedef enum {
    151 	MP_FOPEN_ERR,
    152 	MP_FCLOSE_ERR,
    153 	MP_IGNORING_LINE_ERR,
    154 	MP_ALLOC_ERR,
    155 	MP_NVLIST_ERR,
    156 	MP_CANT_FIND_USER_ERR,
    157 	MP_CANT_FIND_GROUP_ERR
    158 } minorperm_err_t;
    159 
    160 
    161 /*
    162  * Create/free mperm list of minor perm entries
    163  */
    164 extern struct mperm *devfs_read_minor_perm(void (*)(minorperm_err_t, int));
    165 extern void devfs_free_minor_perm(struct mperm *);
    166 
    167 /*
    168  * Load all minor perm entries, and add/remove minor perm entry
    169  */
    170 extern int devfs_load_minor_perm(struct mperm *,
    171 	void (*)(minorperm_err_t, int));
    172 extern int devfs_add_minor_perm(char *, void (*)(minorperm_err_t, int));
    173 extern int devfs_rm_minor_perm(char *, void (*)(minorperm_err_t, int));
    174 
    175 /* devfsadm dca_flags values: some are used by libdevinfo devlink_create() */
    176 #define	DCA_CREATE_LINK		0x000000001
    177 #define	DCA_FREE_LIST		0x000000002
    178 #define	DCA_LOAD_DRV		0x000000004
    179 #define	DCA_CHECK_TYPE		0x000000010
    180 /* UNUSED was DCA_NOTIFY_RCM	0x000000020 (can be recycled) */
    181 #define	DCA_FLUSH_PATHINST	0x000000040
    182 #define	DCA_HOT_PLUG		0x000000080
    183 #define	DCA_DEVLINK_SYNC	0x000000100
    184 #define	DCA_DEVLINK_CACHE	0x000000200
    185 
    186 #ifdef	__cplusplus
    187 }
    188 #endif
    189 
    190 #endif	/* _DEVICE_INFO_H */
    191