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 /*
23113f4232Sakaplan * 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 * Implements the "putdgrp" command.
327c478bd9Sstevel@tonic-gate */
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate #include <errno.h>
387c478bd9Sstevel@tonic-gate #include <unistd.h>
397c478bd9Sstevel@tonic-gate #include <fmtmsg.h>
407c478bd9Sstevel@tonic-gate #include <devmgmt.h>
417c478bd9Sstevel@tonic-gate #include <devtab.h>
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate * General Purpose Constants
467c478bd9Sstevel@tonic-gate * TRUE Boolean TRUE (if not already defined)
477c478bd9Sstevel@tonic-gate * FALSE Boolean FALSE (if not already defined)
487c478bd9Sstevel@tonic-gate */
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate #ifndef TRUE
517c478bd9Sstevel@tonic-gate #define TRUE (1)
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate #ifndef FALSE
557c478bd9Sstevel@tonic-gate #define FALSE (0)
567c478bd9Sstevel@tonic-gate #endif
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate * Exit codes
607c478bd9Sstevel@tonic-gate * EX_OK All went well
61*2a8bcb4eSToomas Soome * EX_ERROR Usage or internal error
62*2a8bcb4eSToomas Soome * EX_DGROUP Had trouble accessing/reading/writing the
637c478bd9Sstevel@tonic-gate * device-group table
647c478bd9Sstevel@tonic-gate * EX_NODGRP The specified device-group does not exist
65*2a8bcb4eSToomas Soome * EX_NOMEM One or more device-group members requested for
667c478bd9Sstevel@tonic-gate * removal was not defined for the device
677c478bd9Sstevel@tonic-gate */
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate #define EX_OK 0
707c478bd9Sstevel@tonic-gate #define EX_ERROR 1
717c478bd9Sstevel@tonic-gate #define EX_DGROUP 2
727c478bd9Sstevel@tonic-gate #define EX_NODGRP 3
737c478bd9Sstevel@tonic-gate #define EX_NOMEM 4
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate * Error messages
787c478bd9Sstevel@tonic-gate */
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate #define E_USAGE "usage: putdgrp [-d] dgroup [device [...]]"
817c478bd9Sstevel@tonic-gate #define E_NODGRP "Device-group does not exist in table: %s"
827c478bd9Sstevel@tonic-gate #define E_NOTAMEM "Device-group member not found: %s"
837c478bd9Sstevel@tonic-gate #define E_NODGRPTAB "Cannot open the device-group table: %s"
847c478bd9Sstevel@tonic-gate #define E_NOMKTAB "Cannot create a new device-group table: %s"
857c478bd9Sstevel@tonic-gate #define E_INTERNAL "Internal error, errno=%d"
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate * Macros
907c478bd9Sstevel@tonic-gate * stdmsg(r,l,s,t) Using fmtmsg(), write a standard message to the
917c478bd9Sstevel@tonic-gate * standard error stream.
927c478bd9Sstevel@tonic-gate * Where:
937c478bd9Sstevel@tonic-gate * r The recoverability of the error
947c478bd9Sstevel@tonic-gate * l The label-component
957c478bd9Sstevel@tonic-gate * s The severity-component
967c478bd9Sstevel@tonic-gate * t The text-component
977c478bd9Sstevel@tonic-gate */
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate #define stdmsg(r,l,s,t) (void) fmtmsg(MM_PRINT|MM_UTIL|r,l,s,t,MM_NULLACT,MM_NULLTAG)
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate * Static data
1047c478bd9Sstevel@tonic-gate * msg Space for message's text-component
1057c478bd9Sstevel@tonic-gate */
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate static char msg[256]; /* Space for text of message */
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate * char *mklbl(cmd)
1117c478bd9Sstevel@tonic-gate * char *cmd
1127c478bd9Sstevel@tonic-gate *
1137c478bd9Sstevel@tonic-gate * This function builds a standard label from the command used to invoke
1147c478bd9Sstevel@tonic-gate * this process and the standard label prefix ("UX:")
1157c478bd9Sstevel@tonic-gate *
1167c478bd9Sstevel@tonic-gate * Arguments:
1177c478bd9Sstevel@tonic-gate * char *cmd The command used to invoke this process.
1187c478bd9Sstevel@tonic-gate *
1197c478bd9Sstevel@tonic-gate * Returns: char *
1207c478bd9Sstevel@tonic-gate * Pointer to malloc()ed space containing the standard label,
1217c478bd9Sstevel@tonic-gate * or (char *) NULL if an error occurred.
1227c478bd9Sstevel@tonic-gate */
123*2a8bcb4eSToomas Soome
1247c478bd9Sstevel@tonic-gate static char *
mklbl(cmd)1257c478bd9Sstevel@tonic-gate mklbl(cmd)
1267c478bd9Sstevel@tonic-gate char *cmd;
1277c478bd9Sstevel@tonic-gate {
1287c478bd9Sstevel@tonic-gate /* Automatic data */
1297c478bd9Sstevel@tonic-gate char *rtn; /* Value to return */
1307c478bd9Sstevel@tonic-gate char *p; /* Temporary */
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate /* Find the 1st char of the basename of the command */
1337c478bd9Sstevel@tonic-gate if (p = strrchr(cmd, '/')) p++;
1347c478bd9Sstevel@tonic-gate else p = cmd;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate /* Allocate and build the string value to return */
1377c478bd9Sstevel@tonic-gate if (rtn = (char *) malloc(strlen("UX:")+strlen(p)+1)) {
1387c478bd9Sstevel@tonic-gate (void) strcpy(rtn, "UX:");
1397c478bd9Sstevel@tonic-gate (void) strcat(rtn, p);
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate /* Now that we've done all of this work, set up the environemnt
1437c478bd9Sstevel@tonic-gate * so that only the text-component is written (some requirements
1447c478bd9Sstevel@tonic-gate * say that standard messages are to be non-standard in SVR4.0,
1457c478bd9Sstevel@tonic-gate * this is supposed to change in SVR4.1)
1467c478bd9Sstevel@tonic-gate */
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate (void) putenv("MSGVERB=text");
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate /* Done */
1517c478bd9Sstevel@tonic-gate return(rtn);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate * putdgrp [-d] dgroup [device [...]]
1567c478bd9Sstevel@tonic-gate *
1577c478bd9Sstevel@tonic-gate * Options:
158*2a8bcb4eSToomas Soome * -d
1597c478bd9Sstevel@tonic-gate *
1607c478bd9Sstevel@tonic-gate * Arguments:
1617c478bd9Sstevel@tonic-gate * dgroup
1627c478bd9Sstevel@tonic-gate * device
1637c478bd9Sstevel@tonic-gate *
1647c478bd9Sstevel@tonic-gate * Exit values:
1657c478bd9Sstevel@tonic-gate */
1667c478bd9Sstevel@tonic-gate
167113f4232Sakaplan int
main(int argc,char * argv[])168113f4232Sakaplan main(int argc, char *argv[])
1697c478bd9Sstevel@tonic-gate {
1707c478bd9Sstevel@tonic-gate /* Automatic data */
1717c478bd9Sstevel@tonic-gate char **plist; /* Ptr to list of nonmembers */
1727c478bd9Sstevel@tonic-gate char *lbl; /* Ptr to label for messages */
1737c478bd9Sstevel@tonic-gate char *dgroup; /* Ptr to <dgroup> on command-line */
1747c478bd9Sstevel@tonic-gate char *p; /* Temp ptr to char */
1757c478bd9Sstevel@tonic-gate int noerr; /* FLAG, TRUE if all's well */
1767c478bd9Sstevel@tonic-gate int d_seen; /* TRUE if -a seen on command-line */
1777c478bd9Sstevel@tonic-gate int optchar; /* Option extracted */
1787c478bd9Sstevel@tonic-gate int exitcd; /* Value to return at exit */
1797c478bd9Sstevel@tonic-gate int nmems; /* Number of members on the cmd */
1807c478bd9Sstevel@tonic-gate
181*2a8bcb4eSToomas Soome
1827c478bd9Sstevel@tonic-gate /* Generate the label for messages */
1837c478bd9Sstevel@tonic-gate lbl = mklbl(argv[0]);
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate /* Extract arguments - validate usage */
1867c478bd9Sstevel@tonic-gate noerr = TRUE;
1877c478bd9Sstevel@tonic-gate d_seen = FALSE;
1887c478bd9Sstevel@tonic-gate opterr = FALSE;
1897c478bd9Sstevel@tonic-gate while ((optchar = getopt(argc, argv, "d:")) != EOF) switch (optchar) {
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate case 'd':
192*2a8bcb4eSToomas Soome if (!d_seen)
1937c478bd9Sstevel@tonic-gate {
1947c478bd9Sstevel@tonic-gate d_seen = TRUE;
1957c478bd9Sstevel@tonic-gate dgroup = optarg;
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate else noerr = FALSE;
1987c478bd9Sstevel@tonic-gate break;
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate case '?':
2017c478bd9Sstevel@tonic-gate default:
2027c478bd9Sstevel@tonic-gate noerr = FALSE;
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate /* Write a usage message if we've seen a blatant error */
207*2a8bcb4eSToomas Soome if (!noerr || (!d_seen && ((nmems = argc - optind - 1) < 0)) ||
2087c478bd9Sstevel@tonic-gate (d_seen && ((nmems = argc - optind) < 0))) {
2097c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, E_USAGE);
2107c478bd9Sstevel@tonic-gate exit(EX_ERROR);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate /* Set up */
2157c478bd9Sstevel@tonic-gate exitcd = EX_OK;
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate /* -d on the command line ? */
2197c478bd9Sstevel@tonic-gate if (d_seen) {
2207c478bd9Sstevel@tonic-gate
221*2a8bcb4eSToomas Soome /*
2227c478bd9Sstevel@tonic-gate * Determine case (removing a device group or members
2237c478bd9Sstevel@tonic-gate * of that device group.
2247c478bd9Sstevel@tonic-gate */
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate if (nmems == 0) {
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate /* putdgrp -d dgroup */
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate /* Attempt to remove the specified device */
2317c478bd9Sstevel@tonic-gate if (!(_rmdgrptabrec(dgroup))) switch(errno) {
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate * EINVAL indicates that the named device-group was
2357c478bd9Sstevel@tonic-gate * not found in the device-group table.
2367c478bd9Sstevel@tonic-gate */
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate case EINVAL:
2397c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRP, dgroup);
2407c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
2417c478bd9Sstevel@tonic-gate exitcd = EX_NODGRP;
2427c478bd9Sstevel@tonic-gate break;
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate /*
2457c478bd9Sstevel@tonic-gate * ENOENT indicates that the device-group table can't
2467c478bd9Sstevel@tonic-gate * be found.
2477c478bd9Sstevel@tonic-gate */
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate case ENOENT:
2507c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, _dgrptabpath());
2517c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
252*2a8bcb4eSToomas Soome exitcd = EX_DGROUP;
2537c478bd9Sstevel@tonic-gate break;
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate /*
256*2a8bcb4eSToomas Soome * EACCES indicates that there was a problem reading the
2577c478bd9Sstevel@tonic-gate * old device-group table or creating the new table. If the
2587c478bd9Sstevel@tonic-gate * old table is readable, assume that we can't create the
2597c478bd9Sstevel@tonic-gate * new table. Otherwise, assume that the old table isn't
2607c478bd9Sstevel@tonic-gate * accessible.
2617c478bd9Sstevel@tonic-gate */
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate case EACCES:
2647c478bd9Sstevel@tonic-gate p = _dgrptabpath();
265*2a8bcb4eSToomas Soome if (access(p, R_OK) == 0)
2667c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKTAB, p);
267*2a8bcb4eSToomas Soome else
2687c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, p);
2697c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
270*2a8bcb4eSToomas Soome exitcd = EX_DGROUP;
2717c478bd9Sstevel@tonic-gate break;
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate * Some strange problem...
2757c478bd9Sstevel@tonic-gate */
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate default:
2787c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_INTERNAL, errno);
2797c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
2807c478bd9Sstevel@tonic-gate exitcd = EX_ERROR;
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate } /* End switch */
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate else {
2857c478bd9Sstevel@tonic-gate
2867c478bd9Sstevel@tonic-gate /* putdgrp -d dgroup device [device [...]] */
2877c478bd9Sstevel@tonic-gate
288*2a8bcb4eSToomas Soome /*
2897c478bd9Sstevel@tonic-gate * Attempt to remove the specified devices from the
2907c478bd9Sstevel@tonic-gate * specified device-group.
2917c478bd9Sstevel@tonic-gate */
2927c478bd9Sstevel@tonic-gate if (!(_rmdgrpmems(dgroup, &argv[optind], &plist))) switch(errno) {
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate /*
2957c478bd9Sstevel@tonic-gate * ENODEV indicates that a named device was not part
2967c478bd9Sstevel@tonic-gate * of the specified device group.
2977c478bd9Sstevel@tonic-gate */
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate case ENODEV:
3007c478bd9Sstevel@tonic-gate exitcd = EX_NOMEM;
3017c478bd9Sstevel@tonic-gate for (; *plist; plist++) {
3027c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOTAMEM, *plist);
3037c478bd9Sstevel@tonic-gate stdmsg(MM_RECOVER, lbl, MM_WARNING, msg);
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate break;
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate /*
308*2a8bcb4eSToomas Soome * EINVAL indicates that the named device-group is not
3097c478bd9Sstevel@tonic-gate * defined in the device-group table.
3107c478bd9Sstevel@tonic-gate */
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate case EINVAL:
3137c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRP, dgroup);
3147c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
3157c478bd9Sstevel@tonic-gate exitcd = EX_NODGRP;
3167c478bd9Sstevel@tonic-gate break;
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate /*
3197c478bd9Sstevel@tonic-gate * ENOENT indicates that the device table can't
3207c478bd9Sstevel@tonic-gate * be found.
3217c478bd9Sstevel@tonic-gate */
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate case ENOENT:
3247c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, _dgrptabpath());
3257c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
326*2a8bcb4eSToomas Soome exitcd = EX_DGROUP;
3277c478bd9Sstevel@tonic-gate break;
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate /*
330*2a8bcb4eSToomas Soome * EACCES indicates that there was a problem reading the
3317c478bd9Sstevel@tonic-gate * old device table or creating the new table. If the
3327c478bd9Sstevel@tonic-gate * old table is readable, assume that we can't create the
3337c478bd9Sstevel@tonic-gate * new table. Otherwise, assume that the old table isn't
3347c478bd9Sstevel@tonic-gate * accessible.
3357c478bd9Sstevel@tonic-gate */
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate case EACCES:
3387c478bd9Sstevel@tonic-gate p = _dgrptabpath();
339*2a8bcb4eSToomas Soome if (access(p, R_OK) == 0)
3407c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKTAB, p);
341*2a8bcb4eSToomas Soome else
3427c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, p);
3437c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
344*2a8bcb4eSToomas Soome exitcd = EX_DGROUP;
3457c478bd9Sstevel@tonic-gate break;
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate /*
3487c478bd9Sstevel@tonic-gate * Some strange problem...
3497c478bd9Sstevel@tonic-gate */
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate default:
3527c478bd9Sstevel@tonic-gate (void) sprintf(msg, E_INTERNAL, errno);
3537c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
3547c478bd9Sstevel@tonic-gate exitcd = EX_ERROR;
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate } /* End switch */
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate } /* End "putdgrp -d device attr [...]" case */
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate } /* End -d case */
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate else {
3647c478bd9Sstevel@tonic-gate /* Standard case (no -d on the command) */
3657c478bd9Sstevel@tonic-gate if (!(_adddgrptabrec(argv[optind], &argv[optind+1]))) switch(errno) {
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate /*
3687c478bd9Sstevel@tonic-gate * ENOENT indicates that the device-group table does not exist.
3697c478bd9Sstevel@tonic-gate */
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate case ENOENT:
3727c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, _dgrptabpath());
3737c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
374*2a8bcb4eSToomas Soome exitcd = EX_DGROUP;
3757c478bd9Sstevel@tonic-gate break;
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate /*
3787c478bd9Sstevel@tonic-gate * EACCES indicates that the device-group table could not be
3797c478bd9Sstevel@tonic-gate * opened or the new device-group table could not be created.
3807c478bd9Sstevel@tonic-gate */
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate case EACCES:
3837c478bd9Sstevel@tonic-gate p = _dgrptabpath();
3847c478bd9Sstevel@tonic-gate if (access(p, R_OK) == 0)
3857c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NOMKTAB, p);
3867c478bd9Sstevel@tonic-gate else
3877c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, p);
3887c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
389*2a8bcb4eSToomas Soome exitcd = EX_DGROUP;
3907c478bd9Sstevel@tonic-gate break;
3917c478bd9Sstevel@tonic-gate
392*2a8bcb4eSToomas Soome /*
393*2a8bcb4eSToomas Soome * Some strange error (memory?)
3947c478bd9Sstevel@tonic-gate */
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate default:
3977c478bd9Sstevel@tonic-gate (void) sprintf(msg, E_INTERNAL, errno);
3987c478bd9Sstevel@tonic-gate stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
3997c478bd9Sstevel@tonic-gate exitcd = EX_ERROR;
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate /* Done. Return exit code (determined above) */
4047c478bd9Sstevel@tonic-gate return(exitcd);
4057c478bd9Sstevel@tonic-gate } /* main() */
406