10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52587Spjha * Common Development and Distribution License (the "License"). 62587Spjha * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12116SVikram.Hegde@Sun.COM * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _DEVFSADM_H 260Sstevel@tonic-gate #define _DEVFSADM_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <libdevinfo.h> 300Sstevel@tonic-gate #include <sys/devinfo_impl.h> 310Sstevel@tonic-gate #include <regex.h> 320Sstevel@tonic-gate 334876Smlf #undef DEBUG 344876Smlf #ifndef DEBUG 354876Smlf #define NDEBUG 1 364876Smlf #else 374876Smlf #undef NDEBUG 384876Smlf #endif 394876Smlf 404876Smlf #include <assert.h> 414876Smlf 420Sstevel@tonic-gate #ifdef __cplusplus 430Sstevel@tonic-gate extern "C" { 440Sstevel@tonic-gate #endif 450Sstevel@tonic-gate 460Sstevel@tonic-gate #define DEVFSADM_SUCCESS 0 470Sstevel@tonic-gate #define DEVFSADM_FAILURE -1 480Sstevel@tonic-gate #define DEVFSADM_MULTIPLE -2 490Sstevel@tonic-gate #define DEVFSADM_TRUE 0 500Sstevel@tonic-gate #define DEVFSADM_FALSE -1 510Sstevel@tonic-gate 520Sstevel@tonic-gate #define ILEVEL_0 0 530Sstevel@tonic-gate #define ILEVEL_1 1 540Sstevel@tonic-gate #define ILEVEL_2 2 550Sstevel@tonic-gate #define ILEVEL_3 3 560Sstevel@tonic-gate #define ILEVEL_4 4 570Sstevel@tonic-gate #define ILEVEL_5 5 580Sstevel@tonic-gate #define ILEVEL_6 6 590Sstevel@tonic-gate #define ILEVEL_7 7 600Sstevel@tonic-gate #define ILEVEL_8 8 610Sstevel@tonic-gate #define ILEVEL_9 9 620Sstevel@tonic-gate 630Sstevel@tonic-gate #define DEVFSADM_V0 0 642846Svikram #define DEVFSADM_V1 1 650Sstevel@tonic-gate 660Sstevel@tonic-gate #define DEVFSADM_CONTINUE 0 670Sstevel@tonic-gate #define DEVFSADM_TERMINATE 1 680Sstevel@tonic-gate 690Sstevel@tonic-gate #define INTEGER 0 700Sstevel@tonic-gate #define CHARACTER 1 710Sstevel@tonic-gate 720Sstevel@tonic-gate #define RM_HOT 0x01 730Sstevel@tonic-gate #define RM_PRE 0x02 740Sstevel@tonic-gate #define RM_POST 0x04 750Sstevel@tonic-gate #define RM_ALWAYS 0x08 762846Svikram #define RM_NOINTERPOSE 0x10 770Sstevel@tonic-gate 780Sstevel@tonic-gate #define TYPE_EXACT 0x01 790Sstevel@tonic-gate #define TYPE_RE 0x02 800Sstevel@tonic-gate #define TYPE_PARTIAL 0x04 810Sstevel@tonic-gate #define TYPE_MASK 0x07 820Sstevel@tonic-gate #define DRV_EXACT 0x10 830Sstevel@tonic-gate #define DRV_RE 0x20 840Sstevel@tonic-gate #define DRV_MASK 0x30 850Sstevel@tonic-gate #define CREATE_DEFER 0x100 860Sstevel@tonic-gate #define CREATE_MASK 0x100 870Sstevel@tonic-gate 880Sstevel@tonic-gate /* command to start daemon */ 890Sstevel@tonic-gate #define DEVFSADMD_START_PATH "/usr/lib/devfsadm/devfsadmd" 900Sstevel@tonic-gate #define DEVFSADMD_START "devfsadmd" 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* devfsadm event service door */ 930Sstevel@tonic-gate #define DEVFSADM_SERVICE_DOOR "/etc/sysevent/devfsadm_event_channel" 942621Sllai1 #define DEVNAME_LOOKUP_DOOR ".devname_lookup_door" 952621Sllai1 964876Smlf /* File of reserved devnames */ 974876Smlf #define ENUMERATE_RESERVED "/etc/dev/reserved_devnames" 984876Smlf 990Sstevel@tonic-gate /* flags for devfsadm_mklink */ 1000Sstevel@tonic-gate #define DEV_SYNC 0x02 /* synchronous mklink */ 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate #define INFO_MID NULL /* always prints */ 1030Sstevel@tonic-gate #define VERBOSE_MID "verbose" /* prints with -v */ 1040Sstevel@tonic-gate #define CHATTY_MID "chatty" /* prints with -V chatty */ 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate typedef struct devfsadm_create { 1070Sstevel@tonic-gate char *device_class; /* eg "disk", "tape", "display" */ 1080Sstevel@tonic-gate char *node_type; /* eg DDI_NT_TAPE, DDI_NT_BLOCK, etc */ 1090Sstevel@tonic-gate char *drv_name; /* eg sd, ssd */ 1100Sstevel@tonic-gate int flags; /* TYPE_{EXACT,RE,PARTIAL}, DRV_{EXACT,RE} */ 1110Sstevel@tonic-gate int interpose_lvl; /* eg ILEVEL_0.. ILEVEL_10 */ 1120Sstevel@tonic-gate int (*callback_fcn)(di_minor_t minor, di_node_t node); 1130Sstevel@tonic-gate } devfsadm_create_t; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate typedef struct devfsadm_remove { 1160Sstevel@tonic-gate char *device_class; /* eg "disk", "tape", "display" */ 1170Sstevel@tonic-gate char *dev_dirs_re; /* dev dirs regex selector */ 1180Sstevel@tonic-gate int flags; /* eg POST, PRE, HOT, ALWAYS */ 1190Sstevel@tonic-gate int interpose_lvl; /* eg ILEVEL_0 .. ILEVEL_10 */ 1202846Svikram void (*callback_fcn)(char *); 1210Sstevel@tonic-gate } devfsadm_remove_t; 1220Sstevel@tonic-gate 1232846Svikram typedef struct devfsadm_remove_V1 { 1242846Svikram char *device_class; /* eg "disk", "tape", "display" */ 1252846Svikram char *dev_dirs_re; /* dev dirs regex selector */ 1262846Svikram int flags; /* eg POST, PRE, HOT, ALWAYS */ 1272846Svikram int interpose_lvl; /* eg ILEVEL_0 .. ILEVEL_10 */ 1282846Svikram int (*callback_fcn)(char *); 1292846Svikram } devfsadm_remove_V1_t; 1302846Svikram 1310Sstevel@tonic-gate typedef struct _devfsadm_create_reg { 1320Sstevel@tonic-gate uint_t version; 1330Sstevel@tonic-gate uint_t count; /* number of node type registration */ 1340Sstevel@tonic-gate /* structures */ 1350Sstevel@tonic-gate devfsadm_create_t *tblp; 1360Sstevel@tonic-gate } _devfsadm_create_reg_t; 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate typedef struct _devfsadm_remove_reg { 1390Sstevel@tonic-gate uint_t version; 1400Sstevel@tonic-gate uint_t count; /* number of node type registration */ 1410Sstevel@tonic-gate /* structures */ 1420Sstevel@tonic-gate devfsadm_remove_t *tblp; 1430Sstevel@tonic-gate } _devfsadm_remove_reg_t; 1440Sstevel@tonic-gate 1452846Svikram typedef struct _devfsadm_remove_reg_V1 { 1462846Svikram uint_t version; 1472846Svikram uint_t count; /* number of node type registration */ 1482846Svikram /* structures */ 1492846Svikram devfsadm_remove_V1_t *tblp; 1502846Svikram } _devfsadm_remove_reg_V1_t; 1510Sstevel@tonic-gate /* 1520Sstevel@tonic-gate * "flags" in the devfs_enumerate structure can take the following values. 1530Sstevel@tonic-gate * These values specify the substring of devfs path to be used for 1540Sstevel@tonic-gate * enumeration. Components (see MATCH_ADDR/MATCH_MINOR) may be specified 1550Sstevel@tonic-gate * by using the "match_arg" member in the devfsadm_enumerate structure. 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate #define MATCH_ALL 0x001 /* Match entire devfs path */ 1580Sstevel@tonic-gate #define MATCH_PARENT 0x002 /* Match upto last '/' in devfs path */ 1590Sstevel@tonic-gate #define MATCH_ADDR 0x004 /* Match upto nth component of last address */ 1600Sstevel@tonic-gate #define MATCH_MINOR 0x008 /* Match upto nth component of minor name */ 1610Sstevel@tonic-gate #define MATCH_CALLBACK 0x010 /* Use callback to derive match string */ 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * The following flags are private to devfsadm and the disks module. 1650Sstevel@tonic-gate * NOT to be used by other modules. 1660Sstevel@tonic-gate */ 1670Sstevel@tonic-gate #define MATCH_NODE 0x020 1680Sstevel@tonic-gate #define MATCH_MASK 0x03F 1690Sstevel@tonic-gate #define MATCH_UNCACHED 0x040 /* retry flags for disks module */ 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate typedef struct devfsadm_enumerate { 1720Sstevel@tonic-gate char *re; 1730Sstevel@tonic-gate int subexp; 1740Sstevel@tonic-gate uint_t flags; 1750Sstevel@tonic-gate char *match_arg; 1760Sstevel@tonic-gate char *(*sel_fcn)(const char *path, void *cb_arg); 1770Sstevel@tonic-gate void *cb_arg; 1780Sstevel@tonic-gate } devfsadm_enumerate_t; 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate #define DEVFSADM_CREATE_INIT_V0(tbl) \ 1810Sstevel@tonic-gate _devfsadm_create_reg_t _devfsadm_create_reg = { \ 1820Sstevel@tonic-gate DEVFSADM_V0, \ 1830Sstevel@tonic-gate (sizeof (tbl) / sizeof (devfsadm_create_t)), \ 1840Sstevel@tonic-gate ((devfsadm_create_t *)(tbl)) } 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate #define DEVFSADM_REMOVE_INIT_V0(tbl)\ 1870Sstevel@tonic-gate _devfsadm_remove_reg_t _devfsadm_remove_reg = {\ 1880Sstevel@tonic-gate DEVFSADM_V0, \ 1890Sstevel@tonic-gate (sizeof (tbl) / sizeof (devfsadm_remove_t)), \ 1900Sstevel@tonic-gate ((devfsadm_remove_t *)(tbl)) } 1910Sstevel@tonic-gate 1922846Svikram #define DEVFSADM_REMOVE_INIT_V1(tbl)\ 1932846Svikram _devfsadm_remove_reg_V1_t _devfsadm_remove_reg = {\ 1942846Svikram DEVFSADM_V1, \ 1952846Svikram (sizeof (tbl) / sizeof (devfsadm_remove_V1_t)), \ 1962846Svikram ((devfsadm_remove_V1_t *)(tbl)) } 1972846Svikram 1984876Smlf /* reserved devname support */ 1994876Smlf typedef struct devlink_re { 2004876Smlf char *d_re; 2014876Smlf int d_subexp; 2024876Smlf regex_t d_rcomp; 2034876Smlf regmatch_t *d_pmatch; 2044876Smlf } devlink_re_t; 2054876Smlf 2064876Smlf typedef struct enumerate_file { 2074876Smlf char *er_file; 2084876Smlf char *er_id; 2094876Smlf struct enumerate_file *er_next; 2104876Smlf } enumerate_file_t; 2114876Smlf 2120Sstevel@tonic-gate int devfsadm_noupdate(void); 2130Sstevel@tonic-gate const char *devfsadm_root_path(void); 214*12116SVikram.Hegde@Sun.COM int devfsadm_link_valid(di_node_t anynode, char *link); 2150Sstevel@tonic-gate int devfsadm_mklink(char *link, di_node_t node, di_minor_t minor, int flags); 2160Sstevel@tonic-gate int devfsadm_secondary_link(char *link, char *primary_link, int flags); 2170Sstevel@tonic-gate void devfsadm_rm_link(char *file); 2180Sstevel@tonic-gate void devfsadm_rm_all(char *file); 2190Sstevel@tonic-gate void devfsadm_rm_stale_links(char *dir_re, char *valid_link, di_node_t node, 2200Sstevel@tonic-gate di_minor_t minor); 2210Sstevel@tonic-gate void devfsadm_errprint(char *message, ...); 2220Sstevel@tonic-gate void devfsadm_print(char *mid, char *message, ...); 2230Sstevel@tonic-gate int devfsadm_enumerate_int(char *devfs_path, int index, char **buf, 2240Sstevel@tonic-gate devfsadm_enumerate_t rules[], int nrules); 2250Sstevel@tonic-gate int devfsadm_enumerate_char(char *devfs_path, int index, char **buf, 2260Sstevel@tonic-gate devfsadm_enumerate_t rules[], int nrules); 2272587Spjha char **devfsadm_lookup_dev_names(char *phys_path, char *re, int *lenp); 2282587Spjha void devfsadm_free_dev_names(char **dev_names, int len); 2292587Spjha 2304876Smlf /* devlink cache related */ 2314876Smlf di_devlink_handle_t devfsadm_devlink_cache(void); 2324876Smlf 2330Sstevel@tonic-gate /* 2340Sstevel@tonic-gate * Private enumerate interface for disks and sgen modules 2350Sstevel@tonic-gate */ 2360Sstevel@tonic-gate int disk_enumerate_int(char *devfs_path, int index, char **buf, 2370Sstevel@tonic-gate devfsadm_enumerate_t rules[], int nrules); 2380Sstevel@tonic-gate /* 2390Sstevel@tonic-gate * Private interfaces for ports module (port_link.c). 2400Sstevel@tonic-gate */ 2410Sstevel@tonic-gate int devfsadm_enumerate_char_start(char *devfs_path, int index, 2420Sstevel@tonic-gate char **buf, devfsadm_enumerate_t rules[], int nrules, char *start); 243*12116SVikram.Hegde@Sun.COM int devfsadm_read_link(di_node_t node, char *link, char **devfs_path); 2440Sstevel@tonic-gate char *s_strdup(const char *ptr); 2450Sstevel@tonic-gate 2464876Smlf /* Private interface between reserve subsystm and disks link generator */ 2476065Scth int devfsadm_have_reserved(void); 2484876Smlf int devfsadm_is_reserved(devlink_re_t re_array[], char *devlink); 2494876Smlf int devfsadm_reserve_id_cache(devlink_re_t re_array[], enumerate_file_t *head); 2504876Smlf 2510Sstevel@tonic-gate #ifdef __cplusplus 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate #endif 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate #endif /* _DEVFSADM_H */ 256