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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*113f4232Sakaplan * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate /* 347c478bd9Sstevel@tonic-gate * Implements the "putdev" command. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate #include <sys/types.h> 377c478bd9Sstevel@tonic-gate #include <stdio.h> 387c478bd9Sstevel@tonic-gate #include <stdlib.h> 397c478bd9Sstevel@tonic-gate #include <string.h> 407c478bd9Sstevel@tonic-gate #include <errno.h> 417c478bd9Sstevel@tonic-gate #include <unistd.h> 427c478bd9Sstevel@tonic-gate #include <fmtmsg.h> 437c478bd9Sstevel@tonic-gate #include <devmgmt.h> 447c478bd9Sstevel@tonic-gate #include <devtab.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * General Purpose Constants 497c478bd9Sstevel@tonic-gate * TRUE Boolean TRUE (if not already defined) 507c478bd9Sstevel@tonic-gate * FALSE Boolean FALSE (if not already defined) 517c478bd9Sstevel@tonic-gate * NULL Null address (if not already defined) 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #ifndef TRUE 557c478bd9Sstevel@tonic-gate #define TRUE (1) 567c478bd9Sstevel@tonic-gate #endif 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #ifndef FALSE 597c478bd9Sstevel@tonic-gate #define FALSE (0) 607c478bd9Sstevel@tonic-gate #endif 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * Exit codes 647c478bd9Sstevel@tonic-gate * EX_OK All went well 657c478bd9Sstevel@tonic-gate * EX_ERROR Usage or internal error 667c478bd9Sstevel@tonic-gate * EX_DEVTAB Had trouble accessing/reading/writing the device table 677c478bd9Sstevel@tonic-gate * EX_EXISTS The specified alias already exists 687c478bd9Sstevel@tonic-gate * EX_ATTRIB One or more attributes requested for removal was not 697c478bd9Sstevel@tonic-gate * defined for the device 707c478bd9Sstevel@tonic-gate * EX_RELPATH Pathname supplied for cdevice, bdevice or pathname 717c478bd9Sstevel@tonic-gate * attributes was not a full pathname 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate #define EX_OK 0 757c478bd9Sstevel@tonic-gate #define EX_ERROR 1 767c478bd9Sstevel@tonic-gate #define EX_DEVTAB 2 777c478bd9Sstevel@tonic-gate #define EX_EXISTS 3 787c478bd9Sstevel@tonic-gate #define EX_ATTRIB 4 797c478bd9Sstevel@tonic-gate #define EX_RELPATH 4 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * Error messages 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate #define E_USAGE "usage: putdev -a alias [attribute=value [...]]\n putdev -m device attribute=value [attribute=value [...]]\n putdev -d device [attribute [...]]" 877c478bd9Sstevel@tonic-gate #define E_ALIASIS "Alias already exists in table: %s" 887c478bd9Sstevel@tonic-gate #define E_NODEV "Device does not exist in table: %s" 897c478bd9Sstevel@tonic-gate #define E_NOALIAS "Cannot use \"alias\" as an attribute" 907c478bd9Sstevel@tonic-gate #define E_NOATTR "Attribute not found: %s" 917c478bd9Sstevel@tonic-gate #define E_NODEVTAB "Cannot open the device table: %s" 927c478bd9Sstevel@tonic-gate #define E_NOMKDTAB "Cannot create a new device table: %s" 937c478bd9Sstevel@tonic-gate #define E_INVALIAS "Not a valid device alias: %s" 947c478bd9Sstevel@tonic-gate #define E_MULTIPLE "Multiple definitions of an attribute are not allowed." 957c478bd9Sstevel@tonic-gate #define E_INTERNAL "Internal error, errno=%d" 967c478bd9Sstevel@tonic-gate #define E_RELPATH "Full pathname required for cdevice,bdevice and pathname attributes." 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * Macros 1017c478bd9Sstevel@tonic-gate * stdmsg(r,l,s,t) Using fmtmsg(), write a standard message to the 1027c478bd9Sstevel@tonic-gate * standard error stream. 1037c478bd9Sstevel@tonic-gate * Where: 1047c478bd9Sstevel@tonic-gate * r The recoverability of the error 1057c478bd9Sstevel@tonic-gate * l The label-component 1067c478bd9Sstevel@tonic-gate * s The severity-component 1077c478bd9Sstevel@tonic-gate * t The text-component 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #define stdmsg(r,l,s,t) (void) fmtmsg(MM_PRINT|MM_UTIL|r,l,s,t,MM_NULLACT,MM_NULLTAG) 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate /* 1147c478bd9Sstevel@tonic-gate * Static data 1157c478bd9Sstevel@tonic-gate * msg Space for message's text-component 1167c478bd9Sstevel@tonic-gate */ 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate static char msg[256]; /* Space for text of message */ 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* 1217c478bd9Sstevel@tonic-gate * char *mklbl(cmd) 1227c478bd9Sstevel@tonic-gate * char *cmd 1237c478bd9Sstevel@tonic-gate * 1247c478bd9Sstevel@tonic-gate * This function builds a standard label from the command used to invoke 1257c478bd9Sstevel@tonic-gate * this process and the standard label prefix ("UX:") 1267c478bd9Sstevel@tonic-gate * 1277c478bd9Sstevel@tonic-gate * Arguments: 1287c478bd9Sstevel@tonic-gate * char *cmd The command used to invoke this process. 1297c478bd9Sstevel@tonic-gate * 1307c478bd9Sstevel@tonic-gate * Returns: char * 1317c478bd9Sstevel@tonic-gate * Pointer to malloc()ed space containing the standard label, 1327c478bd9Sstevel@tonic-gate * or (char *) NULL if an error occurred. 1337c478bd9Sstevel@tonic-gate */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate static char * 1367c478bd9Sstevel@tonic-gate mklbl(cmd) 1377c478bd9Sstevel@tonic-gate char *cmd; 1387c478bd9Sstevel@tonic-gate { 1397c478bd9Sstevel@tonic-gate /* Automatic data */ 1407c478bd9Sstevel@tonic-gate char *rtn; /* Value to return */ 1417c478bd9Sstevel@tonic-gate char *p; /* Temporary */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate /* Find the 1st char of the basename of the command */ 1447c478bd9Sstevel@tonic-gate if (p = strrchr(cmd, '/')) p++; 1457c478bd9Sstevel@tonic-gate else p = cmd; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* Allocate and build the string value to return */ 1487c478bd9Sstevel@tonic-gate if (rtn = (char *) malloc(strlen("UX:")+strlen(p)+1)) { 1497c478bd9Sstevel@tonic-gate (void) strcpy(rtn, "UX:"); 1507c478bd9Sstevel@tonic-gate (void) strcat(rtn, p); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* Now that we've done all of that work, change the environment 1557c478bd9Sstevel@tonic-gate * so that only the text-component is written by fmtmsg(). 1567c478bd9Sstevel@tonic-gate * (This should go away in SVR4.1) 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate (void) putenv("MSGVERB=text"); 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate /* Done */ 1637c478bd9Sstevel@tonic-gate return(rtn); 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * putdev -a alias [attribute=value [...]] 1687c478bd9Sstevel@tonic-gate * putdev -m alias attribute=value [attribute=value [...]] 1697c478bd9Sstevel@tonic-gate * putdev -d alias [attribute [...]] 1707c478bd9Sstevel@tonic-gate * 1717c478bd9Sstevel@tonic-gate * Modify the device-table. If -a specified, add a record for <alias> 1727c478bd9Sstevel@tonic-gate * to the table. If -m specified, modify the attributes specified for 1737c478bd9Sstevel@tonic-gate * the <device> specified. If -d specified, remove the specified 1747c478bd9Sstevel@tonic-gate * attributes from the specified device or remove the specified device. 1757c478bd9Sstevel@tonic-gate * 1767c478bd9Sstevel@tonic-gate * Options: 1777c478bd9Sstevel@tonic-gate * -a Add an alias description to the device table 1787c478bd9Sstevel@tonic-gate * -m Modify an existing device description 1797c478bd9Sstevel@tonic-gate * -d (if no attributes specified) remove the specified 1807c478bd9Sstevel@tonic-gate * device from the device table, or (if attributes 1817c478bd9Sstevel@tonic-gate * specified) remove the specified attributes from 1827c478bd9Sstevel@tonic-gate * the specified device. 1837c478bd9Sstevel@tonic-gate * 1847c478bd9Sstevel@tonic-gate * Exit values: 1857c478bd9Sstevel@tonic-gate * 0 All went well 1867c478bd9Sstevel@tonic-gate * 1 Usage error (includes specifying "alias" as an 1877c478bd9Sstevel@tonic-gate * <attribute>) 1887c478bd9Sstevel@tonic-gate * 2 The device table file could not be opened, read 1897c478bd9Sstevel@tonic-gate * or modified 1907c478bd9Sstevel@tonic-gate * 3 If -a, the alias already exists. Otherwise, the 1917c478bd9Sstevel@tonic-gate * specified device does not exist in the table 1927c478bd9Sstevel@tonic-gate * 4 One of the specified attributes did not exist 1937c478bd9Sstevel@tonic-gate * for the device and therefore wasn't removed 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate 196*113f4232Sakaplan int 197*113f4232Sakaplan main(int argc, char *argv[]) 1987c478bd9Sstevel@tonic-gate { 1997c478bd9Sstevel@tonic-gate /* Automatic data */ 2007c478bd9Sstevel@tonic-gate char **plist; /* Ptr to list of undef'nd attrs */ 2017c478bd9Sstevel@tonic-gate char *lbl; /* Ptr to label for messages */ 2027c478bd9Sstevel@tonic-gate char *alias; /* Ptr to <alias> on command-line */ 2037c478bd9Sstevel@tonic-gate char *device; /* Ptr to <device> on command-line */ 2047c478bd9Sstevel@tonic-gate char *p; /* Temp ptr to char */ 2057c478bd9Sstevel@tonic-gate int noerr; /* FLAG, TRUE if all's well */ 2067c478bd9Sstevel@tonic-gate int a_seen; /* TRUE if -a seen on command-line */ 2077c478bd9Sstevel@tonic-gate int m_seen; /* TRUE if -m seen on command-line */ 2087c478bd9Sstevel@tonic-gate int d_seen; /* TRUE if -a seen on command-line */ 2097c478bd9Sstevel@tonic-gate int optchar; /* Option extracted */ 2107c478bd9Sstevel@tonic-gate int exitcd; /* Value to return at exit */ 2117c478bd9Sstevel@tonic-gate int nattrs; /* Number of attributes on command */ 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate /* Generate the label for messages */ 2157c478bd9Sstevel@tonic-gate lbl = mklbl(argv[0]); 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate /* Extract arguments - validate usage */ 2187c478bd9Sstevel@tonic-gate noerr = TRUE; 2197c478bd9Sstevel@tonic-gate a_seen = FALSE; 2207c478bd9Sstevel@tonic-gate m_seen = FALSE; 2217c478bd9Sstevel@tonic-gate d_seen = FALSE; 2227c478bd9Sstevel@tonic-gate opterr = FALSE; 2237c478bd9Sstevel@tonic-gate while ((optchar = getopt(argc, argv, "a:d:m:")) != EOF) switch (optchar) { 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate case 'a': 2267c478bd9Sstevel@tonic-gate if (!(a_seen || m_seen || d_seen)) { 2277c478bd9Sstevel@tonic-gate a_seen = TRUE; 2287c478bd9Sstevel@tonic-gate alias = optarg; 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate else noerr = FALSE; 2317c478bd9Sstevel@tonic-gate break; 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate case 'd': 2347c478bd9Sstevel@tonic-gate if (!(a_seen || m_seen || d_seen)) { 2357c478bd9Sstevel@tonic-gate d_seen = TRUE; 2367c478bd9Sstevel@tonic-gate device = optarg; 2377c478bd9Sstevel@tonic-gate } 2387c478bd9Sstevel@tonic-gate else noerr = FALSE; 2397c478bd9Sstevel@tonic-gate break; 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate case 'm': 2427c478bd9Sstevel@tonic-gate if (!(a_seen || m_seen || d_seen)) { 2437c478bd9Sstevel@tonic-gate m_seen = TRUE; 2447c478bd9Sstevel@tonic-gate device = optarg; 2457c478bd9Sstevel@tonic-gate } 2467c478bd9Sstevel@tonic-gate else noerr = FALSE; 2477c478bd9Sstevel@tonic-gate break; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate case '?': 2507c478bd9Sstevel@tonic-gate default: 2517c478bd9Sstevel@tonic-gate noerr = FALSE; 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* Write a usage message if we've seen a blatant error */ 2567c478bd9Sstevel@tonic-gate if (!(a_seen || m_seen || d_seen) || !noerr) { 2577c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_USAGE); 2587c478bd9Sstevel@tonic-gate exit(EX_ERROR); 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate /* Set up */ 2637c478bd9Sstevel@tonic-gate exitcd = EX_OK; 2647c478bd9Sstevel@tonic-gate nattrs = argc - optind; 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate /* putdev -a alias [attr=value [...]] */ 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate if (a_seen) { 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate /* Syntax check */ 2727c478bd9Sstevel@tonic-gate if (nattrs < 0) { 2737c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_USAGE); 2747c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 2757c478bd9Sstevel@tonic-gate } else { 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate /* Attempt to add the new alias */ 2787c478bd9Sstevel@tonic-gate if (!(_adddevtabrec(alias, &argv[optind]))) { 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate /* Attempt failed. Write appropriate error message. */ 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate switch(errno) { 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate /* 2857c478bd9Sstevel@tonic-gate * EINVAL indicates that <alias> is not valid or "alias" 2867c478bd9Sstevel@tonic-gate * was mentioned as <attr> in <attr>=<value> pair. If the 2877c478bd9Sstevel@tonic-gate * alias is a valid alias, assume that's the problem. 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate case EINVAL: 2917c478bd9Sstevel@tonic-gate if (_validalias(alias)) 2927c478bd9Sstevel@tonic-gate p = E_NOALIAS; 2937c478bd9Sstevel@tonic-gate else (void) snprintf(p=msg, sizeof(msg), E_INVALIAS, alias); 2947c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, p); 2957c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 2967c478bd9Sstevel@tonic-gate break; 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate /* 2997c478bd9Sstevel@tonic-gate * EEXIST indicates that the alias <alias> already exists 3007c478bd9Sstevel@tonic-gate * in the device table. 3017c478bd9Sstevel@tonic-gate */ 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate case EEXIST: 3047c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_ALIASIS, alias); 3057c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3067c478bd9Sstevel@tonic-gate exitcd = EX_EXISTS; 3077c478bd9Sstevel@tonic-gate break; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate /* 3107c478bd9Sstevel@tonic-gate * EACCES and ENOENT indicate problems reading or writing 3117c478bd9Sstevel@tonic-gate * the device table. 3127c478bd9Sstevel@tonic-gate */ 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate case EACCES: 3157c478bd9Sstevel@tonic-gate case ENOENT: 3167c478bd9Sstevel@tonic-gate p = _devtabpath(); 3177c478bd9Sstevel@tonic-gate if (access(p, R_OK) == 0) 3187c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKDTAB, p); 3197c478bd9Sstevel@tonic-gate else 3207c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEVTAB, p); 3217c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3227c478bd9Sstevel@tonic-gate exitcd = EX_DEVTAB; 3237c478bd9Sstevel@tonic-gate break; 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /* 3267c478bd9Sstevel@tonic-gate * EAGAIN indicates that an attribute was defined on the 3277c478bd9Sstevel@tonic-gate * command line more than once. 3287c478bd9Sstevel@tonic-gate */ 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate case EAGAIN: 3317c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_MULTIPLE); 3327c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 3337c478bd9Sstevel@tonic-gate break; 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate /* 3367c478bd9Sstevel@tonic-gate * ENXIO indicates that a relative pathname was supplied 3377c478bd9Sstevel@tonic-gate * for the cdevice, bdevice or pathname attributes. Full 3387c478bd9Sstevel@tonic-gate * pathnames are required for these attributes. 3397c478bd9Sstevel@tonic-gate */ 3407c478bd9Sstevel@tonic-gate case ENXIO: 3417c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_RELPATH); 3427c478bd9Sstevel@tonic-gate exitcd = EX_RELPATH; 3437c478bd9Sstevel@tonic-gate break; 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate /* 3467c478bd9Sstevel@tonic-gate * Some other problem (odd?) 3477c478bd9Sstevel@tonic-gate */ 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate default: 3507c478bd9Sstevel@tonic-gate (void) sprintf(msg, E_INTERNAL, errno); 3517c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3527c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 3537c478bd9Sstevel@tonic-gate } 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate } 3567c478bd9Sstevel@tonic-gate } /* End -a case */ 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate /* putdev -m device attr=value [...] */ 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate else if (m_seen) { 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate /* Check usage */ 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate if (nattrs <= 0) { 3667c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_USAGE); 3677c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 3687c478bd9Sstevel@tonic-gate } else { 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate /* Attempt to modify a device's record */ 3717c478bd9Sstevel@tonic-gate if (!(_moddevtabrec(device, &argv[optind]))) { 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate /* Modification attempt failed */ 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate switch(errno) { 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate /* 3787c478bd9Sstevel@tonic-gate * EINVAL indicates that "alias" was used as an attribute 3797c478bd9Sstevel@tonic-gate * in an <attr>=<value> pair. 3807c478bd9Sstevel@tonic-gate */ 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate case EINVAL: 3837c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_NOALIAS); 3847c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 3857c478bd9Sstevel@tonic-gate break; 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate /* 3887c478bd9Sstevel@tonic-gate * ENODEV indicates that the device that was to 3897c478bd9Sstevel@tonic-gate * be modified doesn't exist. 3907c478bd9Sstevel@tonic-gate */ 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate case ENODEV: 3937c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEV, device); 3947c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 3957c478bd9Sstevel@tonic-gate exitcd = EX_EXISTS; 3967c478bd9Sstevel@tonic-gate break; 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate /* 3997c478bd9Sstevel@tonic-gate * ENOENT indicates that the device-table doesn't exist. 4007c478bd9Sstevel@tonic-gate */ 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate case ENOENT: 4037c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEVTAB, _devtabpath()); 4047c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 4057c478bd9Sstevel@tonic-gate exitcd = EX_DEVTAB; 4067c478bd9Sstevel@tonic-gate break; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate /* 4097c478bd9Sstevel@tonic-gate * EACCES indicates that there was a problem reading the 4107c478bd9Sstevel@tonic-gate * old device table or creating the new table. If the 4117c478bd9Sstevel@tonic-gate * old table is readable, assume that we can't create the 4127c478bd9Sstevel@tonic-gate * new table. Otherwise, assume that the old table isn't 4137c478bd9Sstevel@tonic-gate * accessible. 4147c478bd9Sstevel@tonic-gate */ 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate case EACCES: 4177c478bd9Sstevel@tonic-gate p = _devtabpath(); 4187c478bd9Sstevel@tonic-gate if (access(p, R_OK) == 0) 4197c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKDTAB, p); 4207c478bd9Sstevel@tonic-gate else 4217c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEVTAB, p); 4227c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 4237c478bd9Sstevel@tonic-gate exitcd = EX_DEVTAB; 4247c478bd9Sstevel@tonic-gate break; 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate /* 4277c478bd9Sstevel@tonic-gate * EAGAIN indicates that an attribute was specified more than 4287c478bd9Sstevel@tonic-gate * once on the command line. 4297c478bd9Sstevel@tonic-gate */ 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate case EAGAIN: 4327c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_MULTIPLE); 4337c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 4347c478bd9Sstevel@tonic-gate break; 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate /* 4377c478bd9Sstevel@tonic-gate * ENXIO indicates that a relative pathname was supplied 4387c478bd9Sstevel@tonic-gate * for the cdevice, bdevice or pathname attributes. Full 4397c478bd9Sstevel@tonic-gate * pathnames are required for these attributes. 4407c478bd9Sstevel@tonic-gate */ 4417c478bd9Sstevel@tonic-gate case ENXIO: 4427c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_RELPATH); 4437c478bd9Sstevel@tonic-gate exitcd = EX_RELPATH; 4447c478bd9Sstevel@tonic-gate break; 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate /* 4477c478bd9Sstevel@tonic-gate * Some strange problem... 4487c478bd9Sstevel@tonic-gate */ 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate default: 4517c478bd9Sstevel@tonic-gate (void) sprintf(msg, E_INTERNAL, errno); 4527c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 4537c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 4547c478bd9Sstevel@tonic-gate } 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate } /* End -m case */ 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate else if (d_seen) { 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate /* putdev -d device [attr [...]] */ 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate /* Check usage */ 4647c478bd9Sstevel@tonic-gate if (nattrs < 0) { 4657c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_USAGE); 4667c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 4677c478bd9Sstevel@tonic-gate } else { 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate /* 4707c478bd9Sstevel@tonic-gate * Determine case (removing a device or attributes 4717c478bd9Sstevel@tonic-gate * to a device. 4727c478bd9Sstevel@tonic-gate */ 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate if (nattrs == 0) { 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate /* putdev -d device */ 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate /* Attempt to remove the specified device */ 4797c478bd9Sstevel@tonic-gate if (!(_rmdevtabrec(device))) switch(errno) { 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate /* 4827c478bd9Sstevel@tonic-gate * ENODEV indicates that the named device is not 4837c478bd9Sstevel@tonic-gate * defined in the device table. 4847c478bd9Sstevel@tonic-gate */ 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate case ENODEV: 4877c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEV, device); 4887c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 4897c478bd9Sstevel@tonic-gate exitcd = EX_EXISTS; 4907c478bd9Sstevel@tonic-gate break; 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate /* 4937c478bd9Sstevel@tonic-gate * ENOENT indicates that the device table can't 4947c478bd9Sstevel@tonic-gate * be found. 4957c478bd9Sstevel@tonic-gate */ 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate case ENOENT: 4987c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEVTAB, _devtabpath()); 4997c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 5007c478bd9Sstevel@tonic-gate exitcd = EX_DEVTAB; 5017c478bd9Sstevel@tonic-gate break; 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate /* 5047c478bd9Sstevel@tonic-gate * EACCES indicates that there was a problem reading the 5057c478bd9Sstevel@tonic-gate * old device table or creating the new table. If the 5067c478bd9Sstevel@tonic-gate * old table is readable, assume that we can't create the 5077c478bd9Sstevel@tonic-gate * new table. Otherwise, assume that the old table isn't 5087c478bd9Sstevel@tonic-gate * accessible. 5097c478bd9Sstevel@tonic-gate */ 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate case EACCES: 5127c478bd9Sstevel@tonic-gate p = _devtabpath(); 5137c478bd9Sstevel@tonic-gate if (access(p, R_OK) == 0) 5147c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKDTAB, p); 5157c478bd9Sstevel@tonic-gate else 5167c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEVTAB, p); 5177c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 5187c478bd9Sstevel@tonic-gate exitcd = EX_DEVTAB; 5197c478bd9Sstevel@tonic-gate break; 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate /* 5227c478bd9Sstevel@tonic-gate * Some strange problem... 5237c478bd9Sstevel@tonic-gate */ 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate default: 5267c478bd9Sstevel@tonic-gate (void) sprintf(msg, E_INTERNAL, errno); 5277c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 5287c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate } /* End switch */ 5317c478bd9Sstevel@tonic-gate } 5327c478bd9Sstevel@tonic-gate else { 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate /* putdev -d device attr [attr [...]] */ 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate /* 5377c478bd9Sstevel@tonic-gate * Attempt to remove the specified attributes from the 5387c478bd9Sstevel@tonic-gate * specified device. 5397c478bd9Sstevel@tonic-gate */ 5407c478bd9Sstevel@tonic-gate if (!(_rmdevtabattrs(device, &argv[optind], &plist))) switch(errno) { 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate /* 5437c478bd9Sstevel@tonic-gate * EINVAL indicates that a named attribute was not 5447c478bd9Sstevel@tonic-gate * defined for the specified device or "alias" was 5457c478bd9Sstevel@tonic-gate * requested. If "plist" points to a list of attrs, 5467c478bd9Sstevel@tonic-gate * the former is the problem. Otherwise, the latter 5477c478bd9Sstevel@tonic-gate * is the problem. 5487c478bd9Sstevel@tonic-gate */ 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate case EINVAL: 5517c478bd9Sstevel@tonic-gate if (plist) { 5527c478bd9Sstevel@tonic-gate exitcd = EX_ATTRIB; 5537c478bd9Sstevel@tonic-gate for (; *plist; plist++) { 5547c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOATTR, *plist); 5557c478bd9Sstevel@tonic-gate stdmsg(MM_RECOVER, lbl, MM_WARNING, msg); 5567c478bd9Sstevel@tonic-gate } 5577c478bd9Sstevel@tonic-gate } else { 5587c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_NOALIAS); 5597c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 5607c478bd9Sstevel@tonic-gate } 5617c478bd9Sstevel@tonic-gate break; 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate /* 5647c478bd9Sstevel@tonic-gate * ENODEV indicates that the named device is not 5657c478bd9Sstevel@tonic-gate * defined in the device table. 5667c478bd9Sstevel@tonic-gate */ 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate case ENODEV: 5697c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEV, device); 5707c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 5717c478bd9Sstevel@tonic-gate exitcd = EX_EXISTS; 5727c478bd9Sstevel@tonic-gate break; 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate /* 5757c478bd9Sstevel@tonic-gate * ENOENT indicates that the device table can't 5767c478bd9Sstevel@tonic-gate * be found. 5777c478bd9Sstevel@tonic-gate */ 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate case ENOENT: 5807c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEVTAB, _devtabpath()); 5817c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 5827c478bd9Sstevel@tonic-gate exitcd = EX_DEVTAB; 5837c478bd9Sstevel@tonic-gate break; 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate /* 5867c478bd9Sstevel@tonic-gate * EACCES indicates that there was a problem reading the 5877c478bd9Sstevel@tonic-gate * old device table or creating the new table. If the 5887c478bd9Sstevel@tonic-gate * old table is readable, assume that we can't create the 5897c478bd9Sstevel@tonic-gate * new table. Otherwise, assume that the old table isn't 5907c478bd9Sstevel@tonic-gate * accessible. 5917c478bd9Sstevel@tonic-gate */ 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate case EACCES: 5947c478bd9Sstevel@tonic-gate p = _devtabpath(); 5957c478bd9Sstevel@tonic-gate if (access(p, R_OK) == 0) 5967c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKDTAB, p); 5977c478bd9Sstevel@tonic-gate else 5987c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODEVTAB, p); 5997c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 6007c478bd9Sstevel@tonic-gate exitcd = EX_DEVTAB; 6017c478bd9Sstevel@tonic-gate break; 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate /* 6047c478bd9Sstevel@tonic-gate * Some strange problem... 6057c478bd9Sstevel@tonic-gate */ 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate default: 6087c478bd9Sstevel@tonic-gate (void) sprintf(msg, E_INTERNAL, errno); 6097c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg); 6107c478bd9Sstevel@tonic-gate exitcd = EX_ERROR; 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate } /* End switch */ 6137c478bd9Sstevel@tonic-gate 6147c478bd9Sstevel@tonic-gate } /* End "putdev -d device attr [...]" case */ 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate } /* End passes usage-check case */ 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate } /* End -d case */ 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate /* Done. Return exit code (determined above) */ 6227c478bd9Sstevel@tonic-gate return(exitcd); 6237c478bd9Sstevel@tonic-gate } /* main() */ 624