1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate /* 34*0Sstevel@tonic-gate * autopush(1) is the command interface to the STREAMS autopush 35*0Sstevel@tonic-gate * mechanism. The autopush command can be used to configure autopush 36*0Sstevel@tonic-gate * information about a STREAMS driver, remove autopush information, 37*0Sstevel@tonic-gate * and report on current configuration information. Its use is as 38*0Sstevel@tonic-gate * follows: 39*0Sstevel@tonic-gate * 40*0Sstevel@tonic-gate * autopush -f file 41*0Sstevel@tonic-gate * autopush -r -M major -m minor 42*0Sstevel@tonic-gate * autopush -g -M major -m minor 43*0Sstevel@tonic-gate * 44*0Sstevel@tonic-gate * The -f option allows autopush information to be set from a file. The 45*0Sstevel@tonic-gate * format of the file is as follows: 46*0Sstevel@tonic-gate * 47*0Sstevel@tonic-gate * # Comment lines begin with a # in column one. 48*0Sstevel@tonic-gate * # The fields are separated by white space and are: 49*0Sstevel@tonic-gate * # major minor lastminor module1 module2 ... module8 50*0Sstevel@tonic-gate * 51*0Sstevel@tonic-gate * "lastminor" is used to configure ranges of minor devices, from "minor" 52*0Sstevel@tonic-gate * to "lastminor" inclusive. It should be set to zero when not in use. 53*0Sstevel@tonic-gate * The -r option allows autopush information to be removed for the given 54*0Sstevel@tonic-gate * major/minor pair. The -g option allows the configuration information 55*0Sstevel@tonic-gate * to be printed. The format of printing is the same as for the file. 56*0Sstevel@tonic-gate */ 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate /* 59*0Sstevel@tonic-gate * Use autopush version 1; keep before #include <sys/sad.h>. 60*0Sstevel@tonic-gate * See <sys/sad.h> for details. 61*0Sstevel@tonic-gate */ 62*0Sstevel@tonic-gate #define AP_VERSION 1 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate #include <sys/types.h> 65*0Sstevel@tonic-gate #include <sys/conf.h> 66*0Sstevel@tonic-gate #include <sys/modctl.h> 67*0Sstevel@tonic-gate #include <sys/sad.h> 68*0Sstevel@tonic-gate #include <stdio.h> 69*0Sstevel@tonic-gate #include <fcntl.h> 70*0Sstevel@tonic-gate #include <errno.h> 71*0Sstevel@tonic-gate #include <ctype.h> 72*0Sstevel@tonic-gate #include <stdlib.h> 73*0Sstevel@tonic-gate #include <unistd.h> 74*0Sstevel@tonic-gate #include <string.h> 75*0Sstevel@tonic-gate #include <locale.h> 76*0Sstevel@tonic-gate #include <sys/stat.h> 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate #define OPTIONS "M:f:gm:r" /* command line options for getopt(3C) */ 79*0Sstevel@tonic-gate #define COMMENT '#' 80*0Sstevel@tonic-gate #define MINUS '-' 81*0Sstevel@tonic-gate #define SLASH '/' 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate /* 84*0Sstevel@tonic-gate * Output format. 85*0Sstevel@tonic-gate */ 86*0Sstevel@tonic-gate #define OHEADER " Major Minor Lastminor\tModules\n" 87*0Sstevel@tonic-gate #define OFORMAT1_ONE "%10ld %10ld - \t" 88*0Sstevel@tonic-gate #define OFORMAT1_RANGE "%10ld %10ld %10ld\t" 89*0Sstevel@tonic-gate #define OFORMAT1_ALL "%10ld ALL - \t" 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate #define AP_ANCHOR "[anchor]" 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate #define Openerr gettext("%s: ERROR: Could not open %s: ") 94*0Sstevel@tonic-gate #define Digiterr gettext("%s: ERROR: argument to %s option must be " \ 95*0Sstevel@tonic-gate "numeric\n") 96*0Sstevel@tonic-gate #define Badline gettext("%s: WARNING: File %s: bad input line %d " \ 97*0Sstevel@tonic-gate "ignored\n") 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate static void usage(); 100*0Sstevel@tonic-gate static int rem_info(), get_info(), set_info(); 101*0Sstevel@tonic-gate static int is_white_space(), parse_line(); 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate static char *Cmdp; /* command name */ 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate /* 106*0Sstevel@tonic-gate * main(): 107*0Sstevel@tonic-gate * process command line arguments. 108*0Sstevel@tonic-gate */ 109*0Sstevel@tonic-gate int 110*0Sstevel@tonic-gate main(int argc, char *argv[]) 111*0Sstevel@tonic-gate { 112*0Sstevel@tonic-gate int c; /* character read by getopt(3C) */ 113*0Sstevel@tonic-gate char *filenamep; /* name of configuration file */ 114*0Sstevel@tonic-gate major_t major; /* major device number */ 115*0Sstevel@tonic-gate minor_t minor; /* minor device number */ 116*0Sstevel@tonic-gate char *cp; 117*0Sstevel@tonic-gate int exitcode; 118*0Sstevel@tonic-gate ushort_t minflag = 0; /* -m option used */ 119*0Sstevel@tonic-gate ushort_t majflag = 0; /* -M option used */ 120*0Sstevel@tonic-gate ushort_t fflag = 0; /* -f option used */ 121*0Sstevel@tonic-gate ushort_t rflag = 0; /* -r option used */ 122*0Sstevel@tonic-gate ushort_t gflag = 0; /* -g option used */ 123*0Sstevel@tonic-gate ushort_t errflag = 0; /* options usage error */ 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 126*0Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 127*0Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 128*0Sstevel@tonic-gate #endif 129*0Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate /* 132*0Sstevel@tonic-gate * Get command name. 133*0Sstevel@tonic-gate */ 134*0Sstevel@tonic-gate Cmdp = argv[0]; 135*0Sstevel@tonic-gate for (filenamep = argv[0]; *filenamep; filenamep++) 136*0Sstevel@tonic-gate if (*filenamep == SLASH) 137*0Sstevel@tonic-gate Cmdp = filenamep + 1; 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate /* 140*0Sstevel@tonic-gate * Get options. 141*0Sstevel@tonic-gate */ 142*0Sstevel@tonic-gate while (!errflag && ((c = getopt(argc, argv, OPTIONS)) != -1)) { 143*0Sstevel@tonic-gate switch (c) { 144*0Sstevel@tonic-gate case 'M': 145*0Sstevel@tonic-gate if (fflag|majflag) 146*0Sstevel@tonic-gate errflag++; 147*0Sstevel@tonic-gate else { 148*0Sstevel@tonic-gate majflag++; 149*0Sstevel@tonic-gate for (cp = optarg; *cp; cp++) 150*0Sstevel@tonic-gate if (!isdigit(*cp)) { 151*0Sstevel@tonic-gate (void) fprintf(stderr, 152*0Sstevel@tonic-gate Digiterr, Cmdp, "-M"); 153*0Sstevel@tonic-gate exit(1); 154*0Sstevel@tonic-gate } 155*0Sstevel@tonic-gate major = (major_t)atol(optarg); 156*0Sstevel@tonic-gate } 157*0Sstevel@tonic-gate break; 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate case 'm': 160*0Sstevel@tonic-gate if (fflag|minflag) 161*0Sstevel@tonic-gate errflag++; 162*0Sstevel@tonic-gate else { 163*0Sstevel@tonic-gate minflag++; 164*0Sstevel@tonic-gate for (cp = optarg; *cp; cp++) 165*0Sstevel@tonic-gate if (!isdigit(*cp)) { 166*0Sstevel@tonic-gate (void) fprintf(stderr, 167*0Sstevel@tonic-gate Digiterr, Cmdp, "-m"); 168*0Sstevel@tonic-gate exit(1); 169*0Sstevel@tonic-gate } 170*0Sstevel@tonic-gate minor = (minor_t)atol(optarg); 171*0Sstevel@tonic-gate } 172*0Sstevel@tonic-gate break; 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate case 'f': 175*0Sstevel@tonic-gate if (fflag|gflag|rflag|majflag|minflag) 176*0Sstevel@tonic-gate errflag++; 177*0Sstevel@tonic-gate else { 178*0Sstevel@tonic-gate fflag++; 179*0Sstevel@tonic-gate filenamep = optarg; 180*0Sstevel@tonic-gate } 181*0Sstevel@tonic-gate break; 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate case 'r': 184*0Sstevel@tonic-gate if (fflag|gflag|rflag) 185*0Sstevel@tonic-gate errflag++; 186*0Sstevel@tonic-gate else 187*0Sstevel@tonic-gate rflag++; 188*0Sstevel@tonic-gate break; 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate case 'g': 191*0Sstevel@tonic-gate if (fflag|gflag|rflag) 192*0Sstevel@tonic-gate errflag++; 193*0Sstevel@tonic-gate else 194*0Sstevel@tonic-gate gflag++; 195*0Sstevel@tonic-gate break; 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate default: 198*0Sstevel@tonic-gate errflag++; 199*0Sstevel@tonic-gate break; 200*0Sstevel@tonic-gate } /* switch */ 201*0Sstevel@tonic-gate if (errflag) { 202*0Sstevel@tonic-gate usage(); 203*0Sstevel@tonic-gate exit(1); 204*0Sstevel@tonic-gate } 205*0Sstevel@tonic-gate } /* while */ 206*0Sstevel@tonic-gate if (((gflag || rflag) && (!majflag || !minflag)) || (optind != argc)) { 207*0Sstevel@tonic-gate usage(); 208*0Sstevel@tonic-gate exit(1); 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate if (fflag) 211*0Sstevel@tonic-gate exitcode = set_info(filenamep); 212*0Sstevel@tonic-gate else if (rflag) 213*0Sstevel@tonic-gate exitcode = rem_info(major, minor); 214*0Sstevel@tonic-gate else if (gflag) 215*0Sstevel@tonic-gate exitcode = get_info(major, minor); 216*0Sstevel@tonic-gate else { 217*0Sstevel@tonic-gate usage(); 218*0Sstevel@tonic-gate exit(1); 219*0Sstevel@tonic-gate } 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate return (exitcode); 222*0Sstevel@tonic-gate } 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate /* 225*0Sstevel@tonic-gate * usage(): 226*0Sstevel@tonic-gate * print out usage statement. 227*0Sstevel@tonic-gate */ 228*0Sstevel@tonic-gate static void 229*0Sstevel@tonic-gate usage() 230*0Sstevel@tonic-gate { 231*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: USAGE:\n\t%s -f filename\n" 232*0Sstevel@tonic-gate "\t%s -r -M major -m minor\n" 233*0Sstevel@tonic-gate "\t%s -g -M major -m minor\n"), Cmdp, Cmdp, Cmdp, Cmdp); 234*0Sstevel@tonic-gate } 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate /* 237*0Sstevel@tonic-gate * set_info(): 238*0Sstevel@tonic-gate * set autopush configuration information. 239*0Sstevel@tonic-gate * namep: autopush configuration filename 240*0Sstevel@tonic-gate */ 241*0Sstevel@tonic-gate static int 242*0Sstevel@tonic-gate set_info(char *namep) 243*0Sstevel@tonic-gate { 244*0Sstevel@tonic-gate int line; /* line number of file */ 245*0Sstevel@tonic-gate FILE *fp; /* file pointer of config file */ 246*0Sstevel@tonic-gate char buf[256]; /* input buffer */ 247*0Sstevel@tonic-gate struct strapush push; /* configuration information */ 248*0Sstevel@tonic-gate int sadfd; /* file descriptor to SAD driver */ 249*0Sstevel@tonic-gate int retcode = 0; /* return code */ 250*0Sstevel@tonic-gate int parsecode; /* return value from parse function */ 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate if ((sadfd = open(ADMINDEV, O_RDWR)) < 0) { 253*0Sstevel@tonic-gate (void) fprintf(stderr, Openerr, Cmdp, ADMINDEV); 254*0Sstevel@tonic-gate perror(""); 255*0Sstevel@tonic-gate return (1); 256*0Sstevel@tonic-gate } 257*0Sstevel@tonic-gate if ((fp = fopen(namep, "r")) == NULL) { 258*0Sstevel@tonic-gate (void) fprintf(stderr, Openerr, Cmdp, namep); 259*0Sstevel@tonic-gate perror(""); 260*0Sstevel@tonic-gate return (1); 261*0Sstevel@tonic-gate } 262*0Sstevel@tonic-gate line = 0; 263*0Sstevel@tonic-gate while (fgets(buf, sizeof (buf), fp) != NULL) { 264*0Sstevel@tonic-gate line++; 265*0Sstevel@tonic-gate if ((buf[0] == COMMENT) || is_white_space(buf)) 266*0Sstevel@tonic-gate continue; 267*0Sstevel@tonic-gate (void) memset(&push, 0, sizeof (struct strapush)); 268*0Sstevel@tonic-gate 269*0Sstevel@tonic-gate parsecode = parse_line(buf, line, namep, &push); 270*0Sstevel@tonic-gate if (parsecode != 0) { 271*0Sstevel@tonic-gate retcode = parsecode; 272*0Sstevel@tonic-gate continue; 273*0Sstevel@tonic-gate } 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate if (push.sap_minor == (minor_t)-1) 276*0Sstevel@tonic-gate push.sap_cmd = SAP_ALL; 277*0Sstevel@tonic-gate else if (push.sap_lastminor == 0) 278*0Sstevel@tonic-gate push.sap_cmd = SAP_ONE; 279*0Sstevel@tonic-gate else 280*0Sstevel@tonic-gate push.sap_cmd = SAP_RANGE; 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate if (ioctl(sadfd, SAD_SAP, &push) < 0) { 283*0Sstevel@tonic-gate int error = errno; 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate retcode = 1; 286*0Sstevel@tonic-gate (void) fprintf(stderr, 287*0Sstevel@tonic-gate gettext("%s: ERROR: File %s: could not configure " 288*0Sstevel@tonic-gate "autopush for line %d\n"), Cmdp, namep, line); 289*0Sstevel@tonic-gate switch (error) { 290*0Sstevel@tonic-gate case EPERM: 291*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: " 292*0Sstevel@tonic-gate "You don't have permission to set autopush " 293*0Sstevel@tonic-gate "information\n"), Cmdp); 294*0Sstevel@tonic-gate break; 295*0Sstevel@tonic-gate 296*0Sstevel@tonic-gate case EINVAL: 297*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: " 298*0Sstevel@tonic-gate "Invalid major device number or invalid " 299*0Sstevel@tonic-gate "module name or too many modules\n"), Cmdp); 300*0Sstevel@tonic-gate break; 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gate case ENOSTR: 303*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: " 304*0Sstevel@tonic-gate "Major device is not a STREAMS " 305*0Sstevel@tonic-gate "driver\n"), Cmdp); 306*0Sstevel@tonic-gate break; 307*0Sstevel@tonic-gate 308*0Sstevel@tonic-gate case EEXIST: 309*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: " 310*0Sstevel@tonic-gate "Major/minor already configured\n"), Cmdp); 311*0Sstevel@tonic-gate break; 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gate case ENOSR: 314*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: Ran " 315*0Sstevel@tonic-gate "out of autopush structures\n"), Cmdp); 316*0Sstevel@tonic-gate break; 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gate case ERANGE: 319*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: " 320*0Sstevel@tonic-gate "lastminor must be greater than minor\n"), 321*0Sstevel@tonic-gate Cmdp); 322*0Sstevel@tonic-gate break; 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate default: 325*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: "), 326*0Sstevel@tonic-gate Cmdp); 327*0Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", strerror(error)); 328*0Sstevel@tonic-gate break; 329*0Sstevel@tonic-gate } /* switch */ 330*0Sstevel@tonic-gate } /* if */ 331*0Sstevel@tonic-gate } /* while */ 332*0Sstevel@tonic-gate return (retcode); 333*0Sstevel@tonic-gate } 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gate /* 336*0Sstevel@tonic-gate * rem_info(): 337*0Sstevel@tonic-gate * remove autopush configuration information. 338*0Sstevel@tonic-gate */ 339*0Sstevel@tonic-gate static int 340*0Sstevel@tonic-gate rem_info(major_t maj, minor_t min) 341*0Sstevel@tonic-gate { 342*0Sstevel@tonic-gate struct strapush push; /* configuration information */ 343*0Sstevel@tonic-gate int sadfd; /* file descriptor to SAD driver */ 344*0Sstevel@tonic-gate int retcode = 0; /* return code */ 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate if ((sadfd = open(ADMINDEV, O_RDWR)) < 0) { 347*0Sstevel@tonic-gate (void) fprintf(stderr, Openerr, Cmdp, ADMINDEV); 348*0Sstevel@tonic-gate perror(""); 349*0Sstevel@tonic-gate return (1); 350*0Sstevel@tonic-gate } 351*0Sstevel@tonic-gate push.sap_cmd = SAP_CLEAR; 352*0Sstevel@tonic-gate push.sap_minor = min; 353*0Sstevel@tonic-gate push.sap_major = maj; 354*0Sstevel@tonic-gate 355*0Sstevel@tonic-gate if (ioctl(sadfd, SAD_SAP, &push) < 0) { 356*0Sstevel@tonic-gate int error = errno; 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate retcode = 1; 359*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: Could not remove " 360*0Sstevel@tonic-gate "autopush information\n"), Cmdp); 361*0Sstevel@tonic-gate switch (error) { 362*0Sstevel@tonic-gate case EPERM: 363*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: You don't " 364*0Sstevel@tonic-gate "have permission to remove autopush " 365*0Sstevel@tonic-gate "information\n"), Cmdp); 366*0Sstevel@tonic-gate break; 367*0Sstevel@tonic-gate 368*0Sstevel@tonic-gate case EINVAL: 369*0Sstevel@tonic-gate if ((min != 0) && (ioctl(sadfd, SAD_GAP, &push) == 0) && 370*0Sstevel@tonic-gate (push.sap_cmd == SAP_ALL)) 371*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: " 372*0Sstevel@tonic-gate "When removing an entry for ALL minors, " 373*0Sstevel@tonic-gate "minor must be set to 0\n"), Cmdp); 374*0Sstevel@tonic-gate else 375*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: " 376*0Sstevel@tonic-gate "Invalid major device number\n"), Cmdp); 377*0Sstevel@tonic-gate break; 378*0Sstevel@tonic-gate 379*0Sstevel@tonic-gate case ENODEV: 380*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: Major/minor " 381*0Sstevel@tonic-gate "not configured for autopush\n"), Cmdp); 382*0Sstevel@tonic-gate break; 383*0Sstevel@tonic-gate 384*0Sstevel@tonic-gate case ERANGE: 385*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: minor must " 386*0Sstevel@tonic-gate "be set to begining of range when clearing\n"), 387*0Sstevel@tonic-gate Cmdp); 388*0Sstevel@tonic-gate break; 389*0Sstevel@tonic-gate 390*0Sstevel@tonic-gate default: 391*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: "), Cmdp); 392*0Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", strerror(error)); 393*0Sstevel@tonic-gate break; 394*0Sstevel@tonic-gate } /* switch */ 395*0Sstevel@tonic-gate } 396*0Sstevel@tonic-gate return (retcode); 397*0Sstevel@tonic-gate } 398*0Sstevel@tonic-gate 399*0Sstevel@tonic-gate /* 400*0Sstevel@tonic-gate * get_info(): 401*0Sstevel@tonic-gate * get autopush configuration information. 402*0Sstevel@tonic-gate */ 403*0Sstevel@tonic-gate static int 404*0Sstevel@tonic-gate get_info(major_t maj, minor_t min) 405*0Sstevel@tonic-gate { 406*0Sstevel@tonic-gate struct strapush push; /* configuration information */ 407*0Sstevel@tonic-gate int i; /* counter */ 408*0Sstevel@tonic-gate int sadfd; /* file descriptor to SAD driver */ 409*0Sstevel@tonic-gate 410*0Sstevel@tonic-gate if ((sadfd = open(USERDEV, O_RDWR)) < 0) { 411*0Sstevel@tonic-gate (void) fprintf(stderr, Openerr, Cmdp, USERDEV); 412*0Sstevel@tonic-gate perror(""); 413*0Sstevel@tonic-gate return (1); 414*0Sstevel@tonic-gate } 415*0Sstevel@tonic-gate push.sap_major = maj; 416*0Sstevel@tonic-gate push.sap_minor = min; 417*0Sstevel@tonic-gate 418*0Sstevel@tonic-gate if (ioctl(sadfd, SAD_GAP, &push) < 0) { 419*0Sstevel@tonic-gate int error = errno; 420*0Sstevel@tonic-gate 421*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: Could not get " 422*0Sstevel@tonic-gate "autopush information\n"), Cmdp); 423*0Sstevel@tonic-gate switch (error) { 424*0Sstevel@tonic-gate case EINVAL: 425*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: Invalid " 426*0Sstevel@tonic-gate "major device number\n"), Cmdp); 427*0Sstevel@tonic-gate break; 428*0Sstevel@tonic-gate 429*0Sstevel@tonic-gate case ENOSTR: 430*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: Major " 431*0Sstevel@tonic-gate "device is not a STREAMS driver\n"), Cmdp); 432*0Sstevel@tonic-gate break; 433*0Sstevel@tonic-gate 434*0Sstevel@tonic-gate case ENODEV: 435*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: Major/minor " 436*0Sstevel@tonic-gate "not configured for autopush\n"), Cmdp); 437*0Sstevel@tonic-gate break; 438*0Sstevel@tonic-gate 439*0Sstevel@tonic-gate default: 440*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: "), Cmdp); 441*0Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", strerror(error)); 442*0Sstevel@tonic-gate break; 443*0Sstevel@tonic-gate } /* switch */ 444*0Sstevel@tonic-gate return (1); 445*0Sstevel@tonic-gate } 446*0Sstevel@tonic-gate (void) printf(OHEADER); 447*0Sstevel@tonic-gate switch (push.sap_cmd) { 448*0Sstevel@tonic-gate case SAP_ONE: 449*0Sstevel@tonic-gate (void) printf(OFORMAT1_ONE, push.sap_major, push.sap_minor); 450*0Sstevel@tonic-gate break; 451*0Sstevel@tonic-gate 452*0Sstevel@tonic-gate case SAP_RANGE: 453*0Sstevel@tonic-gate (void) printf(OFORMAT1_RANGE, push.sap_major, push.sap_minor, 454*0Sstevel@tonic-gate push.sap_lastminor); 455*0Sstevel@tonic-gate break; 456*0Sstevel@tonic-gate 457*0Sstevel@tonic-gate case SAP_ALL: 458*0Sstevel@tonic-gate (void) printf(OFORMAT1_ALL, push.sap_major); 459*0Sstevel@tonic-gate break; 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gate default: 462*0Sstevel@tonic-gate (void) fprintf(stderr, 463*0Sstevel@tonic-gate gettext("%s: ERROR: Unknown configuration type\n"), Cmdp); 464*0Sstevel@tonic-gate return (1); 465*0Sstevel@tonic-gate } 466*0Sstevel@tonic-gate 467*0Sstevel@tonic-gate for (i = 0; i < push.sap_npush; i++) { 468*0Sstevel@tonic-gate 469*0Sstevel@tonic-gate (void) printf("%s", push.sap_list[i]); 470*0Sstevel@tonic-gate 471*0Sstevel@tonic-gate if (push.sap_anchor == (i + 1)) 472*0Sstevel@tonic-gate (void) printf(" %s", AP_ANCHOR); 473*0Sstevel@tonic-gate 474*0Sstevel@tonic-gate if (i < push.sap_npush - 1) 475*0Sstevel@tonic-gate (void) printf(" "); 476*0Sstevel@tonic-gate 477*0Sstevel@tonic-gate } 478*0Sstevel@tonic-gate 479*0Sstevel@tonic-gate (void) printf("\n"); 480*0Sstevel@tonic-gate return (0); 481*0Sstevel@tonic-gate } 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate /* 484*0Sstevel@tonic-gate * is_white_space(): 485*0Sstevel@tonic-gate * Return 1 if buffer is all white space. 486*0Sstevel@tonic-gate * Return 0 otherwise. 487*0Sstevel@tonic-gate */ 488*0Sstevel@tonic-gate static int 489*0Sstevel@tonic-gate is_white_space(char *bufp) 490*0Sstevel@tonic-gate { 491*0Sstevel@tonic-gate while (*bufp) { 492*0Sstevel@tonic-gate if (!isspace(*bufp)) 493*0Sstevel@tonic-gate return (0); 494*0Sstevel@tonic-gate bufp++; 495*0Sstevel@tonic-gate } 496*0Sstevel@tonic-gate return (1); 497*0Sstevel@tonic-gate } 498*0Sstevel@tonic-gate 499*0Sstevel@tonic-gate /* 500*0Sstevel@tonic-gate * parse_line(): 501*0Sstevel@tonic-gate * Parse input line from file and report any errors found. Fill 502*0Sstevel@tonic-gate * strapush structure along the way. Returns 1 if the line has 503*0Sstevel@tonic-gate * errors and 0 if the line is well-formed. Another hidden 504*0Sstevel@tonic-gate * dependency on MAXAPUSH. `linep' is the input buffer, `lineno' 505*0Sstevel@tonic-gate * is the current line number, and `namep' is the filename. 506*0Sstevel@tonic-gate */ 507*0Sstevel@tonic-gate static int 508*0Sstevel@tonic-gate parse_line(char *linep, int lineno, char *namep, struct strapush *pushp) 509*0Sstevel@tonic-gate { 510*0Sstevel@tonic-gate char *wp; /* word pointer */ 511*0Sstevel@tonic-gate char *cp; /* character pointer */ 512*0Sstevel@tonic-gate int midx; /* module index */ 513*0Sstevel@tonic-gate int npush; /* number of modules to push */ 514*0Sstevel@tonic-gate char c; 515*0Sstevel@tonic-gate major_t major_num; 516*0Sstevel@tonic-gate 517*0Sstevel@tonic-gate pushp->sap_anchor = 0; /* by default, no anchor */ 518*0Sstevel@tonic-gate 519*0Sstevel@tonic-gate /* 520*0Sstevel@tonic-gate * Find the major device number. 521*0Sstevel@tonic-gate */ 522*0Sstevel@tonic-gate for (wp = linep; isspace(*wp); wp++) 523*0Sstevel@tonic-gate ; 524*0Sstevel@tonic-gate for (cp = wp; !isspace(*cp); cp++) 525*0Sstevel@tonic-gate ; 526*0Sstevel@tonic-gate if (!isspace(*cp)) { 527*0Sstevel@tonic-gate (void) fprintf(stderr, Badline, Cmdp, namep, lineno); 528*0Sstevel@tonic-gate return (1); 529*0Sstevel@tonic-gate } 530*0Sstevel@tonic-gate c = *cp; 531*0Sstevel@tonic-gate *cp = '\0'; 532*0Sstevel@tonic-gate if (modctl(MODGETMAJBIND, wp, strlen(wp) + 1, &major_num) != 0) { 533*0Sstevel@tonic-gate (void) fprintf(stderr, Badline, Cmdp, namep, lineno); 534*0Sstevel@tonic-gate return (1); 535*0Sstevel@tonic-gate } 536*0Sstevel@tonic-gate *cp = c; 537*0Sstevel@tonic-gate pushp->sap_major = major_num; 538*0Sstevel@tonic-gate 539*0Sstevel@tonic-gate /* 540*0Sstevel@tonic-gate * Find the minor device number. Must handle negative values here. 541*0Sstevel@tonic-gate */ 542*0Sstevel@tonic-gate for (wp = cp; isspace(*wp); wp++) 543*0Sstevel@tonic-gate ; 544*0Sstevel@tonic-gate for (cp = wp; (isdigit(*cp) || (*cp == MINUS)); cp++) 545*0Sstevel@tonic-gate ; 546*0Sstevel@tonic-gate if (!isspace(*cp)) { 547*0Sstevel@tonic-gate (void) fprintf(stderr, Badline, Cmdp, namep, lineno); 548*0Sstevel@tonic-gate return (1); 549*0Sstevel@tonic-gate } 550*0Sstevel@tonic-gate pushp->sap_minor = (minor_t)atol(wp); 551*0Sstevel@tonic-gate 552*0Sstevel@tonic-gate /* 553*0Sstevel@tonic-gate * Find the lastminor. 554*0Sstevel@tonic-gate */ 555*0Sstevel@tonic-gate for (wp = cp; isspace(*wp); wp++) 556*0Sstevel@tonic-gate ; 557*0Sstevel@tonic-gate for (cp = wp; isdigit(*cp); cp++) 558*0Sstevel@tonic-gate ; 559*0Sstevel@tonic-gate if (!isspace(*cp)) { 560*0Sstevel@tonic-gate (void) fprintf(stderr, Badline, Cmdp, namep, lineno); 561*0Sstevel@tonic-gate return (1); 562*0Sstevel@tonic-gate } 563*0Sstevel@tonic-gate pushp->sap_lastminor = (minor_t)atol(wp); 564*0Sstevel@tonic-gate 565*0Sstevel@tonic-gate /* 566*0Sstevel@tonic-gate * Read the list of module names. 567*0Sstevel@tonic-gate */ 568*0Sstevel@tonic-gate npush = 0; 569*0Sstevel@tonic-gate while ((npush < MAXAPUSH) && (*cp)) { 570*0Sstevel@tonic-gate 571*0Sstevel@tonic-gate while (isspace(*cp)) 572*0Sstevel@tonic-gate cp++; 573*0Sstevel@tonic-gate 574*0Sstevel@tonic-gate if (strncasecmp(cp, AP_ANCHOR, sizeof (AP_ANCHOR) - 1) == 0) { 575*0Sstevel@tonic-gate if (pushp->sap_anchor != 0) { 576*0Sstevel@tonic-gate (void) fprintf(stderr, 577*0Sstevel@tonic-gate gettext("%s: ERROR: File %s: more than " 578*0Sstevel@tonic-gate "one anchor in line, line %d ignored\n"), 579*0Sstevel@tonic-gate Cmdp, namep, lineno); 580*0Sstevel@tonic-gate return (1); 581*0Sstevel@tonic-gate } 582*0Sstevel@tonic-gate if (npush == 0) 583*0Sstevel@tonic-gate (void) fprintf(stderr, 584*0Sstevel@tonic-gate gettext("%s: WARNING: File %s: anchor at " 585*0Sstevel@tonic-gate "beginning of stream on line %d ignored\n"), 586*0Sstevel@tonic-gate Cmdp, namep, lineno); 587*0Sstevel@tonic-gate pushp->sap_anchor = npush; 588*0Sstevel@tonic-gate cp += sizeof (AP_ANCHOR) - 1; 589*0Sstevel@tonic-gate continue; 590*0Sstevel@tonic-gate } 591*0Sstevel@tonic-gate 592*0Sstevel@tonic-gate for (midx = 0; !isspace(*cp) && *cp; midx++) { 593*0Sstevel@tonic-gate if (midx == FMNAMESZ) { 594*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: ERROR: " 595*0Sstevel@tonic-gate "File %s: module name too long, line %d " 596*0Sstevel@tonic-gate "ignored\n"), Cmdp, namep, lineno); 597*0Sstevel@tonic-gate return (1); 598*0Sstevel@tonic-gate } 599*0Sstevel@tonic-gate pushp->sap_list[npush][midx] = *cp++; 600*0Sstevel@tonic-gate } 601*0Sstevel@tonic-gate 602*0Sstevel@tonic-gate if (midx > 0) { 603*0Sstevel@tonic-gate pushp->sap_list[npush][midx] = '\0'; 604*0Sstevel@tonic-gate npush++; 605*0Sstevel@tonic-gate } 606*0Sstevel@tonic-gate } 607*0Sstevel@tonic-gate pushp->sap_npush = npush; 608*0Sstevel@tonic-gate 609*0Sstevel@tonic-gate /* 610*0Sstevel@tonic-gate * We have everything we want from the line. 611*0Sstevel@tonic-gate * Now make sure there is no extra garbage on the line. 612*0Sstevel@tonic-gate */ 613*0Sstevel@tonic-gate while (isspace(*cp)) 614*0Sstevel@tonic-gate cp++; 615*0Sstevel@tonic-gate if (*cp) { 616*0Sstevel@tonic-gate (void) fprintf(stderr, 617*0Sstevel@tonic-gate gettext("%s: ERROR: File %s: too many modules, line %d " 618*0Sstevel@tonic-gate "ignored\n"), Cmdp, namep, lineno); 619*0Sstevel@tonic-gate return (1); 620*0Sstevel@tonic-gate } 621*0Sstevel@tonic-gate return (0); 622*0Sstevel@tonic-gate } 623