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 /* 22*94c894bbSVikram Hegde * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #ifndef _DEVFSADM_H 267c478bd9Sstevel@tonic-gate #define _DEVFSADM_H 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <libdevinfo.h> 307c478bd9Sstevel@tonic-gate #include <sys/devinfo_impl.h> 317c478bd9Sstevel@tonic-gate #include <regex.h> 327c478bd9Sstevel@tonic-gate 338d483882Smlf #undef DEBUG 348d483882Smlf #ifndef DEBUG 358d483882Smlf #define NDEBUG 1 368d483882Smlf #else 378d483882Smlf #undef NDEBUG 388d483882Smlf #endif 398d483882Smlf 408d483882Smlf #include <assert.h> 418d483882Smlf 427c478bd9Sstevel@tonic-gate #ifdef __cplusplus 437c478bd9Sstevel@tonic-gate extern "C" { 447c478bd9Sstevel@tonic-gate #endif 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #define DEVFSADM_SUCCESS 0 477c478bd9Sstevel@tonic-gate #define DEVFSADM_FAILURE -1 487c478bd9Sstevel@tonic-gate #define DEVFSADM_MULTIPLE -2 497c478bd9Sstevel@tonic-gate #define DEVFSADM_TRUE 0 507c478bd9Sstevel@tonic-gate #define DEVFSADM_FALSE -1 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #define ILEVEL_0 0 537c478bd9Sstevel@tonic-gate #define ILEVEL_1 1 547c478bd9Sstevel@tonic-gate #define ILEVEL_2 2 557c478bd9Sstevel@tonic-gate #define ILEVEL_3 3 567c478bd9Sstevel@tonic-gate #define ILEVEL_4 4 577c478bd9Sstevel@tonic-gate #define ILEVEL_5 5 587c478bd9Sstevel@tonic-gate #define ILEVEL_6 6 597c478bd9Sstevel@tonic-gate #define ILEVEL_7 7 607c478bd9Sstevel@tonic-gate #define ILEVEL_8 8 617c478bd9Sstevel@tonic-gate #define ILEVEL_9 9 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #define DEVFSADM_V0 0 64aa646b9dSvikram #define DEVFSADM_V1 1 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #define DEVFSADM_CONTINUE 0 677c478bd9Sstevel@tonic-gate #define DEVFSADM_TERMINATE 1 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #define INTEGER 0 707c478bd9Sstevel@tonic-gate #define CHARACTER 1 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate #define RM_HOT 0x01 737c478bd9Sstevel@tonic-gate #define RM_PRE 0x02 747c478bd9Sstevel@tonic-gate #define RM_POST 0x04 757c478bd9Sstevel@tonic-gate #define RM_ALWAYS 0x08 76aa646b9dSvikram #define RM_NOINTERPOSE 0x10 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate #define TYPE_EXACT 0x01 797c478bd9Sstevel@tonic-gate #define TYPE_RE 0x02 807c478bd9Sstevel@tonic-gate #define TYPE_PARTIAL 0x04 817c478bd9Sstevel@tonic-gate #define TYPE_MASK 0x07 827c478bd9Sstevel@tonic-gate #define DRV_EXACT 0x10 837c478bd9Sstevel@tonic-gate #define DRV_RE 0x20 847c478bd9Sstevel@tonic-gate #define DRV_MASK 0x30 857c478bd9Sstevel@tonic-gate #define CREATE_DEFER 0x100 867c478bd9Sstevel@tonic-gate #define CREATE_MASK 0x100 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* command to start daemon */ 897c478bd9Sstevel@tonic-gate #define DEVFSADMD_START_PATH "/usr/lib/devfsadm/devfsadmd" 907c478bd9Sstevel@tonic-gate #define DEVFSADMD_START "devfsadmd" 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate /* devfsadm event service door */ 937c478bd9Sstevel@tonic-gate #define DEVFSADM_SERVICE_DOOR "/etc/sysevent/devfsadm_event_channel" 94facf4a8dSllai1 #define DEVNAME_LOOKUP_DOOR ".devname_lookup_door" 95facf4a8dSllai1 968d483882Smlf /* File of reserved devnames */ 978d483882Smlf #define ENUMERATE_RESERVED "/etc/dev/reserved_devnames" 988d483882Smlf 997c478bd9Sstevel@tonic-gate /* flags for devfsadm_mklink */ 1007c478bd9Sstevel@tonic-gate #define DEV_SYNC 0x02 /* synchronous mklink */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate #define INFO_MID NULL /* always prints */ 1037c478bd9Sstevel@tonic-gate #define VERBOSE_MID "verbose" /* prints with -v */ 1047c478bd9Sstevel@tonic-gate #define CHATTY_MID "chatty" /* prints with -V chatty */ 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate typedef struct devfsadm_create { 1077c478bd9Sstevel@tonic-gate char *device_class; /* eg "disk", "tape", "display" */ 1087c478bd9Sstevel@tonic-gate char *node_type; /* eg DDI_NT_TAPE, DDI_NT_BLOCK, etc */ 1097c478bd9Sstevel@tonic-gate char *drv_name; /* eg sd, ssd */ 1107c478bd9Sstevel@tonic-gate int flags; /* TYPE_{EXACT,RE,PARTIAL}, DRV_{EXACT,RE} */ 1117c478bd9Sstevel@tonic-gate int interpose_lvl; /* eg ILEVEL_0.. ILEVEL_10 */ 1127c478bd9Sstevel@tonic-gate int (*callback_fcn)(di_minor_t minor, di_node_t node); 1137c478bd9Sstevel@tonic-gate } devfsadm_create_t; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate typedef struct devfsadm_remove { 1167c478bd9Sstevel@tonic-gate char *device_class; /* eg "disk", "tape", "display" */ 1177c478bd9Sstevel@tonic-gate char *dev_dirs_re; /* dev dirs regex selector */ 1187c478bd9Sstevel@tonic-gate int flags; /* eg POST, PRE, HOT, ALWAYS */ 1197c478bd9Sstevel@tonic-gate int interpose_lvl; /* eg ILEVEL_0 .. ILEVEL_10 */ 120aa646b9dSvikram void (*callback_fcn)(char *); 1217c478bd9Sstevel@tonic-gate } devfsadm_remove_t; 1227c478bd9Sstevel@tonic-gate 123aa646b9dSvikram typedef struct devfsadm_remove_V1 { 124aa646b9dSvikram char *device_class; /* eg "disk", "tape", "display" */ 125aa646b9dSvikram char *dev_dirs_re; /* dev dirs regex selector */ 126aa646b9dSvikram int flags; /* eg POST, PRE, HOT, ALWAYS */ 127aa646b9dSvikram int interpose_lvl; /* eg ILEVEL_0 .. ILEVEL_10 */ 128aa646b9dSvikram int (*callback_fcn)(char *); 129aa646b9dSvikram } devfsadm_remove_V1_t; 130aa646b9dSvikram 1317c478bd9Sstevel@tonic-gate typedef struct _devfsadm_create_reg { 1327c478bd9Sstevel@tonic-gate uint_t version; 1337c478bd9Sstevel@tonic-gate uint_t count; /* number of node type registration */ 1347c478bd9Sstevel@tonic-gate /* structures */ 1357c478bd9Sstevel@tonic-gate devfsadm_create_t *tblp; 1367c478bd9Sstevel@tonic-gate } _devfsadm_create_reg_t; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate typedef struct _devfsadm_remove_reg { 1397c478bd9Sstevel@tonic-gate uint_t version; 1407c478bd9Sstevel@tonic-gate uint_t count; /* number of node type registration */ 1417c478bd9Sstevel@tonic-gate /* structures */ 1427c478bd9Sstevel@tonic-gate devfsadm_remove_t *tblp; 1437c478bd9Sstevel@tonic-gate } _devfsadm_remove_reg_t; 1447c478bd9Sstevel@tonic-gate 145aa646b9dSvikram typedef struct _devfsadm_remove_reg_V1 { 146aa646b9dSvikram uint_t version; 147aa646b9dSvikram uint_t count; /* number of node type registration */ 148aa646b9dSvikram /* structures */ 149aa646b9dSvikram devfsadm_remove_V1_t *tblp; 150aa646b9dSvikram } _devfsadm_remove_reg_V1_t; 1517c478bd9Sstevel@tonic-gate /* 1527c478bd9Sstevel@tonic-gate * "flags" in the devfs_enumerate structure can take the following values. 1537c478bd9Sstevel@tonic-gate * These values specify the substring of devfs path to be used for 1547c478bd9Sstevel@tonic-gate * enumeration. Components (see MATCH_ADDR/MATCH_MINOR) may be specified 1557c478bd9Sstevel@tonic-gate * by using the "match_arg" member in the devfsadm_enumerate structure. 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate #define MATCH_ALL 0x001 /* Match entire devfs path */ 1587c478bd9Sstevel@tonic-gate #define MATCH_PARENT 0x002 /* Match upto last '/' in devfs path */ 1597c478bd9Sstevel@tonic-gate #define MATCH_ADDR 0x004 /* Match upto nth component of last address */ 1607c478bd9Sstevel@tonic-gate #define MATCH_MINOR 0x008 /* Match upto nth component of minor name */ 1617c478bd9Sstevel@tonic-gate #define MATCH_CALLBACK 0x010 /* Use callback to derive match string */ 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * The following flags are private to devfsadm and the disks module. 1657c478bd9Sstevel@tonic-gate * NOT to be used by other modules. 1667c478bd9Sstevel@tonic-gate */ 1677c478bd9Sstevel@tonic-gate #define MATCH_NODE 0x020 1687c478bd9Sstevel@tonic-gate #define MATCH_MASK 0x03F 1697c478bd9Sstevel@tonic-gate #define MATCH_UNCACHED 0x040 /* retry flags for disks module */ 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate typedef struct devfsadm_enumerate { 1727c478bd9Sstevel@tonic-gate char *re; 1737c478bd9Sstevel@tonic-gate int subexp; 1747c478bd9Sstevel@tonic-gate uint_t flags; 1757c478bd9Sstevel@tonic-gate char *match_arg; 1767c478bd9Sstevel@tonic-gate char *(*sel_fcn)(const char *path, void *cb_arg); 1777c478bd9Sstevel@tonic-gate void *cb_arg; 1787c478bd9Sstevel@tonic-gate } devfsadm_enumerate_t; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate #define DEVFSADM_CREATE_INIT_V0(tbl) \ 1817c478bd9Sstevel@tonic-gate _devfsadm_create_reg_t _devfsadm_create_reg = { \ 1827c478bd9Sstevel@tonic-gate DEVFSADM_V0, \ 1837c478bd9Sstevel@tonic-gate (sizeof (tbl) / sizeof (devfsadm_create_t)), \ 1847c478bd9Sstevel@tonic-gate ((devfsadm_create_t *)(tbl)) } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate #define DEVFSADM_REMOVE_INIT_V0(tbl)\ 1877c478bd9Sstevel@tonic-gate _devfsadm_remove_reg_t _devfsadm_remove_reg = {\ 1887c478bd9Sstevel@tonic-gate DEVFSADM_V0, \ 1897c478bd9Sstevel@tonic-gate (sizeof (tbl) / sizeof (devfsadm_remove_t)), \ 1907c478bd9Sstevel@tonic-gate ((devfsadm_remove_t *)(tbl)) } 1917c478bd9Sstevel@tonic-gate 192aa646b9dSvikram #define DEVFSADM_REMOVE_INIT_V1(tbl)\ 193aa646b9dSvikram _devfsadm_remove_reg_V1_t _devfsadm_remove_reg = {\ 194aa646b9dSvikram DEVFSADM_V1, \ 195aa646b9dSvikram (sizeof (tbl) / sizeof (devfsadm_remove_V1_t)), \ 196aa646b9dSvikram ((devfsadm_remove_V1_t *)(tbl)) } 197aa646b9dSvikram 1988d483882Smlf /* reserved devname support */ 1998d483882Smlf typedef struct devlink_re { 2008d483882Smlf char *d_re; 2018d483882Smlf int d_subexp; 2028d483882Smlf regex_t d_rcomp; 2038d483882Smlf regmatch_t *d_pmatch; 2048d483882Smlf } devlink_re_t; 2058d483882Smlf 2068d483882Smlf typedef struct enumerate_file { 2078d483882Smlf char *er_file; 2088d483882Smlf char *er_id; 2098d483882Smlf struct enumerate_file *er_next; 2108d483882Smlf } enumerate_file_t; 2118d483882Smlf 2127c478bd9Sstevel@tonic-gate int devfsadm_noupdate(void); 2137c478bd9Sstevel@tonic-gate const char *devfsadm_root_path(void); 214*94c894bbSVikram Hegde int devfsadm_link_valid(di_node_t anynode, char *link); 2157c478bd9Sstevel@tonic-gate int devfsadm_mklink(char *link, di_node_t node, di_minor_t minor, int flags); 2167c478bd9Sstevel@tonic-gate int devfsadm_secondary_link(char *link, char *primary_link, int flags); 2177c478bd9Sstevel@tonic-gate void devfsadm_rm_link(char *file); 2187c478bd9Sstevel@tonic-gate void devfsadm_rm_all(char *file); 2197c478bd9Sstevel@tonic-gate void devfsadm_rm_stale_links(char *dir_re, char *valid_link, di_node_t node, 2207c478bd9Sstevel@tonic-gate di_minor_t minor); 2217c478bd9Sstevel@tonic-gate void devfsadm_errprint(char *message, ...); 2227c478bd9Sstevel@tonic-gate void devfsadm_print(char *mid, char *message, ...); 2237c478bd9Sstevel@tonic-gate int devfsadm_enumerate_int(char *devfs_path, int index, char **buf, 2247c478bd9Sstevel@tonic-gate devfsadm_enumerate_t rules[], int nrules); 2257c478bd9Sstevel@tonic-gate int devfsadm_enumerate_char(char *devfs_path, int index, char **buf, 2267c478bd9Sstevel@tonic-gate devfsadm_enumerate_t rules[], int nrules); 2273c4226f9Spjha char **devfsadm_lookup_dev_names(char *phys_path, char *re, int *lenp); 2283c4226f9Spjha void devfsadm_free_dev_names(char **dev_names, int len); 2293c4226f9Spjha 2308d483882Smlf /* devlink cache related */ 2318d483882Smlf di_devlink_handle_t devfsadm_devlink_cache(void); 2328d483882Smlf 2337c478bd9Sstevel@tonic-gate /* 2347c478bd9Sstevel@tonic-gate * Private enumerate interface for disks and sgen modules 2357c478bd9Sstevel@tonic-gate */ 2367c478bd9Sstevel@tonic-gate int disk_enumerate_int(char *devfs_path, int index, char **buf, 2377c478bd9Sstevel@tonic-gate devfsadm_enumerate_t rules[], int nrules); 2387c478bd9Sstevel@tonic-gate /* 2397c478bd9Sstevel@tonic-gate * Private interfaces for ports module (port_link.c). 2407c478bd9Sstevel@tonic-gate */ 2417c478bd9Sstevel@tonic-gate int devfsadm_enumerate_char_start(char *devfs_path, int index, 2427c478bd9Sstevel@tonic-gate char **buf, devfsadm_enumerate_t rules[], int nrules, char *start); 243*94c894bbSVikram Hegde int devfsadm_read_link(di_node_t node, char *link, char **devfs_path); 2447c478bd9Sstevel@tonic-gate char *s_strdup(const char *ptr); 2457c478bd9Sstevel@tonic-gate 2468d483882Smlf /* Private interface between reserve subsystm and disks link generator */ 247e37c6c37Scth int devfsadm_have_reserved(void); 2488d483882Smlf int devfsadm_is_reserved(devlink_re_t re_array[], char *devlink); 2498d483882Smlf int devfsadm_reserve_id_cache(devlink_re_t re_array[], enumerate_file_t *head); 2508d483882Smlf 2517c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate #endif 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate #endif /* _DEVFSADM_H */ 256