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 53c4226f9Spjha * Common Development and Distribution License (the "License"). 63c4226f9Spjha * 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 /* 223c4226f9Spjha * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _DEVFSADM_H 277c478bd9Sstevel@tonic-gate #define _DEVFSADM_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <libdevinfo.h> 337c478bd9Sstevel@tonic-gate #include <sys/devinfo_impl.h> 347c478bd9Sstevel@tonic-gate #include <regex.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef __cplusplus 377c478bd9Sstevel@tonic-gate extern "C" { 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #define DEVFSADM_SUCCESS 0 417c478bd9Sstevel@tonic-gate #define DEVFSADM_FAILURE -1 427c478bd9Sstevel@tonic-gate #define DEVFSADM_MULTIPLE -2 437c478bd9Sstevel@tonic-gate #define DEVFSADM_TRUE 0 447c478bd9Sstevel@tonic-gate #define DEVFSADM_FALSE -1 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #define ILEVEL_0 0 477c478bd9Sstevel@tonic-gate #define ILEVEL_1 1 487c478bd9Sstevel@tonic-gate #define ILEVEL_2 2 497c478bd9Sstevel@tonic-gate #define ILEVEL_3 3 507c478bd9Sstevel@tonic-gate #define ILEVEL_4 4 517c478bd9Sstevel@tonic-gate #define ILEVEL_5 5 527c478bd9Sstevel@tonic-gate #define ILEVEL_6 6 537c478bd9Sstevel@tonic-gate #define ILEVEL_7 7 547c478bd9Sstevel@tonic-gate #define ILEVEL_8 8 557c478bd9Sstevel@tonic-gate #define ILEVEL_9 9 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate #define DEVFSADM_V0 0 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate #define DEVFSADM_CONTINUE 0 607c478bd9Sstevel@tonic-gate #define DEVFSADM_TERMINATE 1 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #define INTEGER 0 637c478bd9Sstevel@tonic-gate #define CHARACTER 1 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate #define RM_HOT 0x01 667c478bd9Sstevel@tonic-gate #define RM_PRE 0x02 677c478bd9Sstevel@tonic-gate #define RM_POST 0x04 687c478bd9Sstevel@tonic-gate #define RM_ALWAYS 0x08 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #define TYPE_EXACT 0x01 717c478bd9Sstevel@tonic-gate #define TYPE_RE 0x02 727c478bd9Sstevel@tonic-gate #define TYPE_PARTIAL 0x04 737c478bd9Sstevel@tonic-gate #define TYPE_MASK 0x07 747c478bd9Sstevel@tonic-gate #define DRV_EXACT 0x10 757c478bd9Sstevel@tonic-gate #define DRV_RE 0x20 767c478bd9Sstevel@tonic-gate #define DRV_MASK 0x30 777c478bd9Sstevel@tonic-gate #define CREATE_DEFER 0x100 787c478bd9Sstevel@tonic-gate #define CREATE_MASK 0x100 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* command to start daemon */ 817c478bd9Sstevel@tonic-gate #define DEVFSADMD_START_PATH "/usr/lib/devfsadm/devfsadmd" 827c478bd9Sstevel@tonic-gate #define DEVFSADMD_START "devfsadmd" 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* devfsadm event service door */ 857c478bd9Sstevel@tonic-gate #define DEVFSADM_SERVICE_DOOR "/etc/sysevent/devfsadm_event_channel" 86*facf4a8dSllai1 #define DEVNAME_LOOKUP_DOOR ".devname_lookup_door" 87*facf4a8dSllai1 88*facf4a8dSllai1 /* /dev device name binding rule locations */ 89*facf4a8dSllai1 #define DEVNAME_MASTER_MAP "/etc/dev/devname_master" 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* flags for devfsadm_mklink */ 927c478bd9Sstevel@tonic-gate #define DEV_SYNC 0x02 /* synchronous mklink */ 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate #define INFO_MID NULL /* always prints */ 957c478bd9Sstevel@tonic-gate #define VERBOSE_MID "verbose" /* prints with -v */ 967c478bd9Sstevel@tonic-gate #define CHATTY_MID "chatty" /* prints with -V chatty */ 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate typedef struct devfsadm_create { 997c478bd9Sstevel@tonic-gate char *device_class; /* eg "disk", "tape", "display" */ 1007c478bd9Sstevel@tonic-gate char *node_type; /* eg DDI_NT_TAPE, DDI_NT_BLOCK, etc */ 1017c478bd9Sstevel@tonic-gate char *drv_name; /* eg sd, ssd */ 1027c478bd9Sstevel@tonic-gate int flags; /* TYPE_{EXACT,RE,PARTIAL}, DRV_{EXACT,RE} */ 1037c478bd9Sstevel@tonic-gate int interpose_lvl; /* eg ILEVEL_0.. ILEVEL_10 */ 1047c478bd9Sstevel@tonic-gate int (*callback_fcn)(di_minor_t minor, di_node_t node); 1057c478bd9Sstevel@tonic-gate } devfsadm_create_t; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate typedef struct devfsadm_remove { 1087c478bd9Sstevel@tonic-gate char *device_class; /* eg "disk", "tape", "display" */ 1097c478bd9Sstevel@tonic-gate char *dev_dirs_re; /* dev dirs regex selector */ 1107c478bd9Sstevel@tonic-gate int flags; /* eg POST, PRE, HOT, ALWAYS */ 1117c478bd9Sstevel@tonic-gate int interpose_lvl; /* eg ILEVEL_0 .. ILEVEL_10 */ 1127c478bd9Sstevel@tonic-gate void (*callback_fcn)(char *logical_link); 1137c478bd9Sstevel@tonic-gate } devfsadm_remove_t; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate typedef struct _devfsadm_create_reg { 1167c478bd9Sstevel@tonic-gate uint_t version; 1177c478bd9Sstevel@tonic-gate uint_t count; /* number of node type registration */ 1187c478bd9Sstevel@tonic-gate /* structures */ 1197c478bd9Sstevel@tonic-gate devfsadm_create_t *tblp; 1207c478bd9Sstevel@tonic-gate } _devfsadm_create_reg_t; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate typedef struct _devfsadm_remove_reg { 1237c478bd9Sstevel@tonic-gate uint_t version; 1247c478bd9Sstevel@tonic-gate uint_t count; /* number of node type registration */ 1257c478bd9Sstevel@tonic-gate /* structures */ 1267c478bd9Sstevel@tonic-gate devfsadm_remove_t *tblp; 1277c478bd9Sstevel@tonic-gate } _devfsadm_remove_reg_t; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* 1307c478bd9Sstevel@tonic-gate * "flags" in the devfs_enumerate structure can take the following values. 1317c478bd9Sstevel@tonic-gate * These values specify the substring of devfs path to be used for 1327c478bd9Sstevel@tonic-gate * enumeration. Components (see MATCH_ADDR/MATCH_MINOR) may be specified 1337c478bd9Sstevel@tonic-gate * by using the "match_arg" member in the devfsadm_enumerate structure. 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate #define MATCH_ALL 0x001 /* Match entire devfs path */ 1367c478bd9Sstevel@tonic-gate #define MATCH_PARENT 0x002 /* Match upto last '/' in devfs path */ 1377c478bd9Sstevel@tonic-gate #define MATCH_ADDR 0x004 /* Match upto nth component of last address */ 1387c478bd9Sstevel@tonic-gate #define MATCH_MINOR 0x008 /* Match upto nth component of minor name */ 1397c478bd9Sstevel@tonic-gate #define MATCH_CALLBACK 0x010 /* Use callback to derive match string */ 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * The following flags are private to devfsadm and the disks module. 1437c478bd9Sstevel@tonic-gate * NOT to be used by other modules. 1447c478bd9Sstevel@tonic-gate */ 1457c478bd9Sstevel@tonic-gate #define MATCH_NODE 0x020 1467c478bd9Sstevel@tonic-gate #define MATCH_MASK 0x03F 1477c478bd9Sstevel@tonic-gate #define MATCH_UNCACHED 0x040 /* retry flags for disks module */ 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate typedef struct devfsadm_enumerate { 1507c478bd9Sstevel@tonic-gate char *re; 1517c478bd9Sstevel@tonic-gate int subexp; 1527c478bd9Sstevel@tonic-gate uint_t flags; 1537c478bd9Sstevel@tonic-gate char *match_arg; 1547c478bd9Sstevel@tonic-gate char *(*sel_fcn)(const char *path, void *cb_arg); 1557c478bd9Sstevel@tonic-gate void *cb_arg; 1567c478bd9Sstevel@tonic-gate } devfsadm_enumerate_t; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #define DEVFSADM_CREATE_INIT_V0(tbl) \ 1597c478bd9Sstevel@tonic-gate _devfsadm_create_reg_t _devfsadm_create_reg = { \ 1607c478bd9Sstevel@tonic-gate DEVFSADM_V0, \ 1617c478bd9Sstevel@tonic-gate (sizeof (tbl) / sizeof (devfsadm_create_t)), \ 1627c478bd9Sstevel@tonic-gate ((devfsadm_create_t *)(tbl)) } 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate #define DEVFSADM_REMOVE_INIT_V0(tbl)\ 1657c478bd9Sstevel@tonic-gate _devfsadm_remove_reg_t _devfsadm_remove_reg = {\ 1667c478bd9Sstevel@tonic-gate DEVFSADM_V0, \ 1677c478bd9Sstevel@tonic-gate (sizeof (tbl) / sizeof (devfsadm_remove_t)), \ 1687c478bd9Sstevel@tonic-gate ((devfsadm_remove_t *)(tbl)) } 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate int devfsadm_noupdate(void); 1717c478bd9Sstevel@tonic-gate const char *devfsadm_root_path(void); 1727c478bd9Sstevel@tonic-gate int devfsadm_link_valid(char *link); 1737c478bd9Sstevel@tonic-gate int devfsadm_mklink(char *link, di_node_t node, di_minor_t minor, int flags); 1747c478bd9Sstevel@tonic-gate int devfsadm_secondary_link(char *link, char *primary_link, int flags); 1757c478bd9Sstevel@tonic-gate void devfsadm_rm_link(char *file); 1767c478bd9Sstevel@tonic-gate void devfsadm_rm_all(char *file); 1777c478bd9Sstevel@tonic-gate void devfsadm_rm_stale_links(char *dir_re, char *valid_link, di_node_t node, 1787c478bd9Sstevel@tonic-gate di_minor_t minor); 1797c478bd9Sstevel@tonic-gate void devfsadm_errprint(char *message, ...); 1807c478bd9Sstevel@tonic-gate void devfsadm_print(char *mid, char *message, ...); 1817c478bd9Sstevel@tonic-gate int devfsadm_enumerate_int(char *devfs_path, int index, char **buf, 1827c478bd9Sstevel@tonic-gate devfsadm_enumerate_t rules[], int nrules); 1837c478bd9Sstevel@tonic-gate int devfsadm_enumerate_char(char *devfs_path, int index, char **buf, 1847c478bd9Sstevel@tonic-gate devfsadm_enumerate_t rules[], int nrules); 1853c4226f9Spjha char **devfsadm_lookup_dev_names(char *phys_path, char *re, int *lenp); 1863c4226f9Spjha void devfsadm_free_dev_names(char **dev_names, int len); 1873c4226f9Spjha 1887c478bd9Sstevel@tonic-gate /* 1897c478bd9Sstevel@tonic-gate * Private enumerate interface for disks and sgen modules 1907c478bd9Sstevel@tonic-gate */ 1917c478bd9Sstevel@tonic-gate int disk_enumerate_int(char *devfs_path, int index, char **buf, 1927c478bd9Sstevel@tonic-gate devfsadm_enumerate_t rules[], int nrules); 1937c478bd9Sstevel@tonic-gate /* 1947c478bd9Sstevel@tonic-gate * Private interfaces for ports module (port_link.c). 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate int devfsadm_enumerate_char_start(char *devfs_path, int index, 1977c478bd9Sstevel@tonic-gate char **buf, devfsadm_enumerate_t rules[], int nrules, char *start); 1987c478bd9Sstevel@tonic-gate int devfsadm_read_link(char *link, char **devfs_path); 1997c478bd9Sstevel@tonic-gate char *s_strdup(const char *ptr); 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate #endif 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate #endif /* _DEVFSADM_H */ 206