17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
23113f423akaplan * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bdstevel@tonic-gate/*	  All Rights Reserved  	*/
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate
317c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bdstevel@tonic-gate
337c478bdstevel@tonic-gate/*
347c478bdstevel@tonic-gate *	Implements the "putdgrp" command.
357c478bdstevel@tonic-gate */
367c478bdstevel@tonic-gate#include	<sys/types.h>
377c478bdstevel@tonic-gate#include	<stdio.h>
387c478bdstevel@tonic-gate#include	<stdlib.h>
397c478bdstevel@tonic-gate#include	<string.h>
407c478bdstevel@tonic-gate#include	<errno.h>
417c478bdstevel@tonic-gate#include	<unistd.h>
427c478bdstevel@tonic-gate#include	<fmtmsg.h>
437c478bdstevel@tonic-gate#include	<devmgmt.h>
447c478bdstevel@tonic-gate#include	<devtab.h>
457c478bdstevel@tonic-gate
467c478bdstevel@tonic-gate
477c478bdstevel@tonic-gate/*
487c478bdstevel@tonic-gate * General Purpose Constants
497c478bdstevel@tonic-gate *	TRUE		Boolean TRUE (if not already defined)
507c478bdstevel@tonic-gate *	FALSE		Boolean FALSE (if not already defined)
517c478bdstevel@tonic-gate */
527c478bdstevel@tonic-gate
537c478bdstevel@tonic-gate#ifndef	TRUE
547c478bdstevel@tonic-gate#define	TRUE	(1)
557c478bdstevel@tonic-gate#endif
567c478bdstevel@tonic-gate
577c478bdstevel@tonic-gate#ifndef	FALSE
587c478bdstevel@tonic-gate#define	FALSE	(0)
597c478bdstevel@tonic-gate#endif
607c478bdstevel@tonic-gate
617c478bdstevel@tonic-gate/*
627c478bdstevel@tonic-gate * Exit codes
637c478bdstevel@tonic-gate *	EX_OK		All went well
647c478bdstevel@tonic-gate *	EX_ERROR	Usage or internal error
657c478bdstevel@tonic-gate *	EX_DGROUP	Had trouble accessing/reading/writing the
667c478bdstevel@tonic-gate *			device-group table
677c478bdstevel@tonic-gate *	EX_NODGRP	The specified device-group does not exist
687c478bdstevel@tonic-gate *	EX_NOMEM	One or more device-group members requested for
697c478bdstevel@tonic-gate *			removal was not defined for the device
707c478bdstevel@tonic-gate */
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate#define	EX_OK		0
737c478bdstevel@tonic-gate#define	EX_ERROR	1
747c478bdstevel@tonic-gate#define	EX_DGROUP	2
757c478bdstevel@tonic-gate#define	EX_NODGRP	3
767c478bdstevel@tonic-gate#define	EX_NOMEM	4
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate
797c478bdstevel@tonic-gate/*
807c478bdstevel@tonic-gate * Error messages
817c478bdstevel@tonic-gate */
827c478bdstevel@tonic-gate
837c478bdstevel@tonic-gate#define	E_USAGE		"usage: putdgrp [-d] dgroup [device [...]]"
847c478bdstevel@tonic-gate#define	E_NODGRP	"Device-group does not exist in table: %s"
857c478bdstevel@tonic-gate#define	E_NOTAMEM	"Device-group member not found: %s"
867c478bdstevel@tonic-gate#define	E_NODGRPTAB	"Cannot open the device-group table: %s"
877c478bdstevel@tonic-gate#define	E_NOMKTAB	"Cannot create a new device-group table: %s"
887c478bdstevel@tonic-gate#define	E_INTERNAL	"Internal error, errno=%d"
897c478bdstevel@tonic-gate
907c478bdstevel@tonic-gate
917c478bdstevel@tonic-gate/*
927c478bdstevel@tonic-gate * Macros
937c478bdstevel@tonic-gate *	stdmsg(r,l,s,t)	    Using fmtmsg(), write a standard message to the
947c478bdstevel@tonic-gate *			    standard error stream.
957c478bdstevel@tonic-gate *			    Where:
967c478bdstevel@tonic-gate *				r   The recoverability of the error
977c478bdstevel@tonic-gate *				l   The label-component
987c478bdstevel@tonic-gate *				s   The severity-component
997c478bdstevel@tonic-gate *				t   The text-component
1007c478bdstevel@tonic-gate */
1017c478bdstevel@tonic-gate
1027c478bdstevel@tonic-gate#define stdmsg(r,l,s,t) (void) fmtmsg(MM_PRINT|MM_UTIL|r,l,s,t,MM_NULLACT,MM_NULLTAG)
1037c478bdstevel@tonic-gate
1047c478bdstevel@tonic-gate
1057c478bdstevel@tonic-gate/*
1067c478bdstevel@tonic-gate * Static data
1077c478bdstevel@tonic-gate *	msg		Space for message's text-component
1087c478bdstevel@tonic-gate */
1097c478bdstevel@tonic-gate
1107c478bdstevel@tonic-gatestatic	char		msg[256];	/* Space for text of message */
1117c478bdstevel@tonic-gate
1127c478bdstevel@tonic-gate/*
1137c478bdstevel@tonic-gate * char *mklbl(cmd)
1147c478bdstevel@tonic-gate *	char   *cmd
1157c478bdstevel@tonic-gate *
1167c478bdstevel@tonic-gate *	This function builds a standard label from the command used to invoke
1177c478bdstevel@tonic-gate *	this process and the standard label prefix ("UX:")
1187c478bdstevel@tonic-gate *
1197c478bdstevel@tonic-gate * Arguments:
1207c478bdstevel@tonic-gate *	char *cmd	The command used to invoke this process.
1217c478bdstevel@tonic-gate *
1227c478bdstevel@tonic-gate * Returns:  char *
1237c478bdstevel@tonic-gate *	Pointer to malloc()ed space containing the standard label,
1247c478bdstevel@tonic-gate *	or (char *) NULL if an error occurred.
1257c478bdstevel@tonic-gate */
1267c478bdstevel@tonic-gate
1277c478bdstevel@tonic-gatestatic char *
1287c478bdstevel@tonic-gatemklbl(cmd)
1297c478bdstevel@tonic-gate	char   *cmd;
1307c478bdstevel@tonic-gate{
1317c478bdstevel@tonic-gate	/* Automatic data */
1327c478bdstevel@tonic-gate	char   *rtn;		/* Value to return */
1337c478bdstevel@tonic-gate	char   *p;		/* Temporary */
1347c478bdstevel@tonic-gate
1357c478bdstevel@tonic-gate	/* Find the 1st char of the basename of the command */
1367c478bdstevel@tonic-gate	if (p = strrchr(cmd, '/')) p++;
1377c478bdstevel@tonic-gate	else p = cmd;
1387c478bdstevel@tonic-gate
1397c478bdstevel@tonic-gate	/* Allocate and build the string value to return */
1407c478bdstevel@tonic-gate	if (rtn = (char *) malloc(strlen("UX:")+strlen(p)+1)) {
1417c478bdstevel@tonic-gate	    (void) strcpy(rtn, "UX:");
1427c478bdstevel@tonic-gate	    (void) strcat(rtn, p);
1437c478bdstevel@tonic-gate	}
1447c478bdstevel@tonic-gate
1457c478bdstevel@tonic-gate	/* Now that we've done all of this work, set up the environemnt
1467c478bdstevel@tonic-gate	 * so that only the text-component is written (some requirements
1477c478bdstevel@tonic-gate	 * say that standard messages are to be non-standard in SVR4.0,
1487c478bdstevel@tonic-gate	 * this is supposed to change in SVR4.1)
1497c478bdstevel@tonic-gate	 */
1507c478bdstevel@tonic-gate
1517c478bdstevel@tonic-gate	(void) putenv("MSGVERB=text");
1527c478bdstevel@tonic-gate
1537c478bdstevel@tonic-gate	/* Done */
1547c478bdstevel@tonic-gate	return(rtn);
1557c478bdstevel@tonic-gate}
1567c478bdstevel@tonic-gate
1577c478bdstevel@tonic-gate/*
1587c478bdstevel@tonic-gate * putdgrp [-d] dgroup [device [...]]
1597c478bdstevel@tonic-gate *
1607c478bdstevel@tonic-gate * Options:
1617c478bdstevel@tonic-gate *	-d
1627c478bdstevel@tonic-gate *
1637c478bdstevel@tonic-gate * Arguments:
1647c478bdstevel@tonic-gate *	dgroup
1657c478bdstevel@tonic-gate *	device
1667c478bdstevel@tonic-gate *
1677c478bdstevel@tonic-gate * Exit values:
1687c478bdstevel@tonic-gate */
1697c478bdstevel@tonic-gate
170113f423akaplanint
171113f423akaplanmain(int argc, char *argv[])
1727c478bdstevel@tonic-gate{
1737c478bdstevel@tonic-gate	/* Automatic data */
1747c478bdstevel@tonic-gate	char	      **plist;		/* Ptr to list of nonmembers */
1757c478bdstevel@tonic-gate	char	       *lbl;		/* Ptr to label for messages */
1767c478bdstevel@tonic-gate	char	       *dgroup;		/* Ptr to <dgroup> on command-line */
1777c478bdstevel@tonic-gate	char	       *p;		/* Temp ptr to char */
1787c478bdstevel@tonic-gate	int		noerr;		/* FLAG, TRUE if all's well */
1797c478bdstevel@tonic-gate	int		d_seen;		/* TRUE if -a seen on command-line */
1807c478bdstevel@tonic-gate	int		optchar;	/* Option extracted */
1817c478bdstevel@tonic-gate	int		exitcd;		/* Value to return at exit */
1827c478bdstevel@tonic-gate	int		nmems;		/* Number of members on the cmd */
1837c478bdstevel@tonic-gate
1847c478bdstevel@tonic-gate
1857c478bdstevel@tonic-gate	/* Generate the label for messages */
1867c478bdstevel@tonic-gate	lbl = mklbl(argv[0]);
1877c478bdstevel@tonic-gate
1887c478bdstevel@tonic-gate	/* Extract arguments - validate usage */
1897c478bdstevel@tonic-gate	noerr = TRUE;
1907c478bdstevel@tonic-gate	d_seen = FALSE;
1917c478bdstevel@tonic-gate	opterr = FALSE;
1927c478bdstevel@tonic-gate	while ((optchar = getopt(argc, argv, "d:")) != EOF) switch (optchar) {
1937c478bdstevel@tonic-gate
1947c478bdstevel@tonic-gate	case 'd':
1957c478bdstevel@tonic-gate	    if (!d_seen)
1967c478bdstevel@tonic-gate	    {
1977c478bdstevel@tonic-gate		d_seen = TRUE;
1987c478bdstevel@tonic-gate		dgroup = optarg;
1997c478bdstevel@tonic-gate	    }
2007c478bdstevel@tonic-gate	    else noerr = FALSE;
2017c478bdstevel@tonic-gate	    break;
2027c478bdstevel@tonic-gate
2037c478bdstevel@tonic-gate	case '?':
2047c478bdstevel@tonic-gate	default:
2057c478bdstevel@tonic-gate	    noerr = FALSE;
2067c478bdstevel@tonic-gate	}
2077c478bdstevel@tonic-gate
2087c478bdstevel@tonic-gate
2097c478bdstevel@tonic-gate	/* Write a usage message if we've seen a blatant error */
2107c478bdstevel@tonic-gate	if (!noerr || (!d_seen && ((nmems = argc - optind - 1) < 0)) ||
2117c478bdstevel@tonic-gate		      (d_seen && ((nmems = argc - optind) < 0))) {
2127c478bdstevel@tonic-gate	    stdmsg(MM_NRECOV, lbl, MM_ERROR, E_USAGE);
2137c478bdstevel@tonic-gate	    exit(EX_ERROR);
2147c478bdstevel@tonic-gate	}
2157c478bdstevel@tonic-gate
2167c478bdstevel@tonic-gate
2177c478bdstevel@tonic-gate	/* Set up */
2187c478bdstevel@tonic-gate	exitcd = EX_OK;
2197c478bdstevel@tonic-gate
2207c478bdstevel@tonic-gate
2217c478bdstevel@tonic-gate	/* -d on the command line ? */
2227c478bdstevel@tonic-gate	if (d_seen) {
2237c478bdstevel@tonic-gate
2247c478bdstevel@tonic-gate	    /*
2257c478bdstevel@tonic-gate	     * Determine case (removing a device group or members
2267c478bdstevel@tonic-gate	     * of that device group.
2277c478bdstevel@tonic-gate	     */
2287c478bdstevel@tonic-gate
2297c478bdstevel@tonic-gate	    if (nmems == 0) {
2307c478bdstevel@tonic-gate
2317c478bdstevel@tonic-gate		/* putdgrp -d dgroup */
2327c478bdstevel@tonic-gate
2337c478bdstevel@tonic-gate		/* Attempt to remove the specified device */
2347c478bdstevel@tonic-gate		if (!(_rmdgrptabrec(dgroup))) switch(errno) {
2357c478bdstevel@tonic-gate
2367c478bdstevel@tonic-gate		    /*
2377c478bdstevel@tonic-gate		     * EINVAL indicates that the named device-group was
2387c478bdstevel@tonic-gate		     * not found in the device-group table.
2397c478bdstevel@tonic-gate		     */
2407c478bdstevel@tonic-gate
2417c478bdstevel@tonic-gate		case EINVAL:
2427c478bdstevel@tonic-gate		    (void) snprintf(msg, sizeof(msg), E_NODGRP, dgroup);
2437c478bdstevel@tonic-gate		    stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
2447c478bdstevel@tonic-gate		    exitcd = EX_NODGRP;
2457c478bdstevel@tonic-gate		    break;
2467c478bdstevel@tonic-gate
2477c478bdstevel@tonic-gate		    /*
2487c478bdstevel@tonic-gate		     * ENOENT indicates that the device-group table can't
2497c478bdstevel@tonic-gate		     * be found.
2507c478bdstevel@tonic-gate		     */
2517c478bdstevel@tonic-gate
2527c478bdstevel@tonic-gate		case ENOENT:
2537c478bdstevel@tonic-gate		    (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, _dgrptabpath());
2547c478bdstevel@tonic-gate		    stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
2557c478bdstevel@tonic-gate		    exitcd = EX_DGROUP;
2567c478bdstevel@tonic-gate		    break;
2577c478bdstevel@tonic-gate
2587c478bdstevel@tonic-gate		    /*
2597c478bdstevel@tonic-gate		     * EACCES indicates that there was a problem reading the
2607c478bdstevel@tonic-gate		     * old device-group table or creating the new table.  If the
2617c478bdstevel@tonic-gate		     * old table is readable, assume that we can't create the
2627c478bdstevel@tonic-gate		     * new table.  Otherwise, assume that the old table isn't
2637c478bdstevel@tonic-gate		     * accessible.
2647c478bdstevel@tonic-gate		     */
2657c478bdstevel@tonic-gate
2667c478bdstevel@tonic-gate		case EACCES:
2677c478bdstevel@tonic-gate		    p = _dgrptabpath();
2687c478bdstevel@tonic-gate		    if (access(p, R_OK) == 0)
2697c478bdstevel@tonic-gate			(void) snprintf(msg, sizeof(msg), E_NOMKTAB, p);
2707c478bdstevel@tonic-gate		    else
2717c478bdstevel@tonic-gate			(void) snprintf(msg, sizeof(msg), E_NODGRPTAB, p);
2727c478bdstevel@tonic-gate		    stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
2737c478bdstevel@tonic-gate		    exitcd = EX_DGROUP;
2747c478bdstevel@tonic-gate		    break;
2757c478bdstevel@tonic-gate
2767c478bdstevel@tonic-gate		    /*
2777c478bdstevel@tonic-gate		     * Some strange problem...
2787c478bdstevel@tonic-gate		     */
2797c478bdstevel@tonic-gate
2807c478bdstevel@tonic-gate		default:
2817c478bdstevel@tonic-gate		    (void) snprintf(msg, sizeof(msg), E_INTERNAL, errno);
2827c478bdstevel@tonic-gate		    stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
2837c478bdstevel@tonic-gate		    exitcd = EX_ERROR;
2847c478bdstevel@tonic-gate
2857c478bdstevel@tonic-gate		}   /* End switch */
2867c478bdstevel@tonic-gate	    }
2877c478bdstevel@tonic-gate	    else {
2887c478bdstevel@tonic-gate
2897c478bdstevel@tonic-gate		/* putdgrp -d dgroup device [device [...]] */
2907c478bdstevel@tonic-gate
2917c478bdstevel@tonic-gate		/*
2927c478bdstevel@tonic-gate		 * Attempt to remove the specified devices from the
2937c478bdstevel@tonic-gate		 * specified device-group.
2947c478bdstevel@tonic-gate		 */
2957c478bdstevel@tonic-gate		if (!(_rmdgrpmems(dgroup, &argv[optind], &plist))) switch(errno) {
2967c478bdstevel@tonic-gate
2977c478bdstevel@tonic-gate		    /*
2987c478bdstevel@tonic-gate		     * ENODEV indicates that a named device was not part
2997c478bdstevel@tonic-gate		     * of the specified device group.
3007c478bdstevel@tonic-gate		     */
3017c478bdstevel@tonic-gate
3027c478bdstevel@tonic-gate		case ENODEV:
3037c478bdstevel@tonic-gate		    exitcd = EX_NOMEM;
3047c478bdstevel@tonic-gate		    for (; *plist; plist++) {
3057c478bdstevel@tonic-gate			(void) snprintf(msg, sizeof(msg), E_NOTAMEM, *plist);
3067c478bdstevel@tonic-gate			stdmsg(MM_RECOVER, lbl, MM_WARNING, msg);
3077c478bdstevel@tonic-gate		    }
3087c478bdstevel@tonic-gate		    break;
3097c478bdstevel@tonic-gate
3107c478bdstevel@tonic-gate		    /*
3117c478bdstevel@tonic-gate		     * EINVAL indicates that the named device-group is not
3127c478bdstevel@tonic-gate		     * defined in the device-group table.
3137c478bdstevel@tonic-gate		     */
3147c478bdstevel@tonic-gate
3157c478bdstevel@tonic-gate		case EINVAL:
3167c478bdstevel@tonic-gate		    (void) snprintf(msg, sizeof(msg), E_NODGRP, dgroup);
3177c478bdstevel@tonic-gate		    stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
3187c478bdstevel@tonic-gate		    exitcd = EX_NODGRP;
3197c478bdstevel@tonic-gate		    break;
3207c478bdstevel@tonic-gate
3217c478bdstevel@tonic-gate		    /*
3227c478bdstevel@tonic-gate		     * ENOENT indicates that the device table can't
3237c478bdstevel@tonic-gate		     * be found.
3247c478bdstevel@tonic-gate		     */
3257c478bdstevel@tonic-gate
3267c478bdstevel@tonic-gate		case ENOENT:
3277c478bdstevel@tonic-gate		    (void) snprintf(msg, sizeof(msg), E_NODGRPTAB, _dgrptabpath());
3287c478bdstevel@tonic-gate		    stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
3297c478bdstevel@tonic-gate		    exitcd = EX_DGROUP;
3307c478bdstevel@tonic-gate		    break;
3317c478bdstevel@tonic-gate
3327c478bdstevel@tonic-gate		    /*
3337c478bdstevel@tonic-gate		     * EACCES indicates that there was a problem reading the
3347c478bdstevel@tonic-gate		     * old device table or creating the new table.  If the
3357c478bdstevel@tonic-gate		     * old table is readable, assume that we can't create the
3367c478bdstevel@tonic-gate		     * new table.  Otherwise, assume that the old table isn't
3377c478bdstevel@tonic-gate		     * accessible.
3387c478bdstevel@tonic-gate		     */
3397c478bdstevel@tonic-gate
3407c478bdstevel@tonic-gate		case EACCES:
3417c478bdstevel@tonic-gate		    p = _dgrptabpath();
3427c478bdstevel@tonic-gate		    if (access(p, R_OK) == 0)
3437c478bdstevel@tonic-gate			(void) snprintf(msg, sizeof(msg), E_NOMKTAB, p);
3447c478bdstevel@tonic-gate		    else
3457c478bdstevel@tonic-gate			(void) snprintf(msg, sizeof(msg), E_NODGRPTAB, p);
3467c478bdstevel@tonic-gate		    stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
3477c478bdstevel@tonic-gate		    exitcd = EX_DGROUP;
3487c478bdstevel@tonic-gate		    break;
3497c478bdstevel@tonic-gate
3507c478bdstevel@tonic-gate		    /*
3517c478bdstevel@tonic-gate		     * Some strange problem...
3527c478bdstevel@tonic-gate		     */
3537c478bdstevel@tonic-gate
3547c478bdstevel@tonic-gate		default:
3557c478bdstevel@tonic-gate		    (void) sprintf(msg, E_INTERNAL, errno);
3567c478bdstevel@tonic-gate		    stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
3577c478bdstevel@tonic-gate		    exitcd = EX_ERROR;
3587c478bdstevel@tonic-gate
3597c478bdstevel@tonic-gate		}  /* End switch */
3607c478bdstevel@tonic-gate
3617c478bdstevel@tonic-gate	    }   /* End "putdgrp -d device attr [...]" case */
3627c478bdstevel@tonic-gate
3637c478bdstevel@tonic-gate
3647c478bdstevel@tonic-gate	}   /* End -d case */
3657c478bdstevel@tonic-gate
3667c478bdstevel@tonic-gate	else {
3677c478bdstevel@tonic-gate	    /* Standard case (no -d on the command) */
3687c478bdstevel@tonic-gate	    if (!(_adddgrptabrec(argv[optind], &argv[optind+1]))) switch(errno) {
3697c478bdstevel@tonic-gate
3707c478bdstevel@tonic-gate		/*
3717c478bdstevel@tonic-gate		 * ENOENT indicates that the device-group table does not exist.
3727c478bdstevel@tonic-gate		 */
3737c478bdstevel@tonic-gate
3747c478bdstevel@tonic-gate	    case ENOENT:
3757c478bdstevel@tonic-gate		(void) snprintf(msg, sizeof(msg), E_NODGRPTAB, _dgrptabpath());
3767c478bdstevel@tonic-gate		stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
3777c478bdstevel@tonic-gate		exitcd = EX_DGROUP;
3787c478bdstevel@tonic-gate		break;
3797c478bdstevel@tonic-gate
3807c478bdstevel@tonic-gate		/*
3817c478bdstevel@tonic-gate		 * EACCES indicates that the device-group table could not be
3827c478bdstevel@tonic-gate		 * opened or the new device-group table could not be created.
3837c478bdstevel@tonic-gate		 */
3847c478bdstevel@tonic-gate
3857c478bdstevel@tonic-gate	    case EACCES:
3867c478bdstevel@tonic-gate		p = _dgrptabpath();
3877c478bdstevel@tonic-gate		if (access(p, R_OK) == 0)
3887c478bdstevel@tonic-gate			(void) snprintf(msg, sizeof(msg), E_NOMKTAB, p);
3897c478bdstevel@tonic-gate		else
3907c478bdstevel@tonic-gate			(void) snprintf(msg, sizeof(msg), E_NODGRPTAB, p);
3917c478bdstevel@tonic-gate		stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
3927c478bdstevel@tonic-gate		exitcd = EX_DGROUP;
3937c478bdstevel@tonic-gate		break;
3947c478bdstevel@tonic-gate
3957c478bdstevel@tonic-gate		/*
3967c478bdstevel@tonic-gate		 * Some strange error (memory?)
3977c478bdstevel@tonic-gate		 */
3987c478bdstevel@tonic-gate
3997c478bdstevel@tonic-gate	    default:
4007c478bdstevel@tonic-gate		(void) sprintf(msg, E_INTERNAL, errno);
4017c478bdstevel@tonic-gate		stdmsg(MM_NRECOV, lbl, MM_ERROR, msg);
4027c478bdstevel@tonic-gate		exitcd = EX_ERROR;
4037c478bdstevel@tonic-gate	    }
4047c478bdstevel@tonic-gate	}
4057c478bdstevel@tonic-gate
4067c478bdstevel@tonic-gate	/* Done.  Return exit code (determined above) */
4077c478bdstevel@tonic-gate	return(exitcd);
4087c478bdstevel@tonic-gate}  /* main() */
409