1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1995-1997 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * routines in this module are meant to be called by other libvolmgt 31*7c478bd9Sstevel@tonic-gate * routines only 32*7c478bd9Sstevel@tonic-gate */ 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include <stdio.h> 35*7c478bd9Sstevel@tonic-gate #include <string.h> 36*7c478bd9Sstevel@tonic-gate #include <dirent.h> 37*7c478bd9Sstevel@tonic-gate #include <string.h> 38*7c478bd9Sstevel@tonic-gate #include <libintl.h> 39*7c478bd9Sstevel@tonic-gate #include <limits.h> 40*7c478bd9Sstevel@tonic-gate #include <unistd.h> 41*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/vol.h> 46*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 47*7c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 48*7c478bd9Sstevel@tonic-gate #endif 49*7c478bd9Sstevel@tonic-gate #include "volmgt_private.h" 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate /* 54*7c478bd9Sstevel@tonic-gate * We have been passed a path which (presumably) is a volume. 55*7c478bd9Sstevel@tonic-gate * We look through the directory until we find a name which is 56*7c478bd9Sstevel@tonic-gate * a character device. 57*7c478bd9Sstevel@tonic-gate */ 58*7c478bd9Sstevel@tonic-gate char * 59*7c478bd9Sstevel@tonic-gate getrawpart0(char *path) 60*7c478bd9Sstevel@tonic-gate { 61*7c478bd9Sstevel@tonic-gate DIR *dirp = NULL; 62*7c478bd9Sstevel@tonic-gate struct dirent64 *dp; 63*7c478bd9Sstevel@tonic-gate static char fname[MAXPATHLEN+1]; 64*7c478bd9Sstevel@tonic-gate struct stat64 sb; 65*7c478bd9Sstevel@tonic-gate char *res; 66*7c478bd9Sstevel@tonic-gate int len; 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* open the directory */ 71*7c478bd9Sstevel@tonic-gate if ((dirp = opendir(path)) == NULL) { 72*7c478bd9Sstevel@tonic-gate res = NULL; 73*7c478bd9Sstevel@tonic-gate goto dun; 74*7c478bd9Sstevel@tonic-gate } 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate /* get length of directory part */ 77*7c478bd9Sstevel@tonic-gate len = strlen(path); 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* scan the directory */ 80*7c478bd9Sstevel@tonic-gate while (dp = readdir64(dirp)) { 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate /* skip "." and ".." */ 83*7c478bd9Sstevel@tonic-gate if (strcmp(dp->d_name, ".") == 0) { 84*7c478bd9Sstevel@tonic-gate continue; 85*7c478bd9Sstevel@tonic-gate } 86*7c478bd9Sstevel@tonic-gate if (strcmp(dp->d_name, "..") == 0) { 87*7c478bd9Sstevel@tonic-gate continue; 88*7c478bd9Sstevel@tonic-gate } 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate /* ensure we have room for this name */ 91*7c478bd9Sstevel@tonic-gate if ((len + strlen(dp->d_name) + 1) > MAXPATHLEN) { 92*7c478bd9Sstevel@tonic-gate /* XXX: just give up? */ 93*7c478bd9Sstevel@tonic-gate continue; 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate /* create a pathname for this device */ 97*7c478bd9Sstevel@tonic-gate (void) concat_paths(fname, path, dp->d_name, NULL); 98*7c478bd9Sstevel@tonic-gate if (stat64(fname, &sb) < 0) { 99*7c478bd9Sstevel@tonic-gate continue; /* this shouldn't happen */ 100*7c478bd9Sstevel@tonic-gate } 101*7c478bd9Sstevel@tonic-gate /* check for a char-spcl device */ 102*7c478bd9Sstevel@tonic-gate if (S_ISCHR(sb.st_mode)) { 103*7c478bd9Sstevel@tonic-gate res = strdup(fname); 104*7c478bd9Sstevel@tonic-gate goto dun; 105*7c478bd9Sstevel@tonic-gate } 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate /* raw part not found */ 109*7c478bd9Sstevel@tonic-gate res = NULL; 110*7c478bd9Sstevel@tonic-gate dun: 111*7c478bd9Sstevel@tonic-gate if (dirp != NULL) { 112*7c478bd9Sstevel@tonic-gate (void) closedir(dirp); 113*7c478bd9Sstevel@tonic-gate } 114*7c478bd9Sstevel@tonic-gate return (res); 115*7c478bd9Sstevel@tonic-gate } 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate /* 119*7c478bd9Sstevel@tonic-gate * fix the getfull{raw,blk}name problem for the fd and diskette case 120*7c478bd9Sstevel@tonic-gate * 121*7c478bd9Sstevel@tonic-gate * return value is malloc'ed, and must be free'd 122*7c478bd9Sstevel@tonic-gate * 123*7c478bd9Sstevel@tonic-gate * no match gets a malloc'ed null string 124*7c478bd9Sstevel@tonic-gate */ 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate char * 127*7c478bd9Sstevel@tonic-gate volmgt_getfullblkname(char *n) 128*7c478bd9Sstevel@tonic-gate { 129*7c478bd9Sstevel@tonic-gate extern char *getfullblkname(char *); 130*7c478bd9Sstevel@tonic-gate char *rval; 131*7c478bd9Sstevel@tonic-gate char namebuf[MAXPATHLEN+1]; 132*7c478bd9Sstevel@tonic-gate char *s; 133*7c478bd9Sstevel@tonic-gate char c; 134*7c478bd9Sstevel@tonic-gate char *res; 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate /* try to get full block-spcl device name */ 139*7c478bd9Sstevel@tonic-gate rval = getfullblkname(n); 140*7c478bd9Sstevel@tonic-gate if ((rval != NULL) && (*rval != NULLC)) { 141*7c478bd9Sstevel@tonic-gate /* found it */ 142*7c478bd9Sstevel@tonic-gate res = rval; 143*7c478bd9Sstevel@tonic-gate goto dun; 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate /* we have a null-string result */ 147*7c478bd9Sstevel@tonic-gate if (rval != NULL) { 148*7c478bd9Sstevel@tonic-gate /* free null string */ 149*7c478bd9Sstevel@tonic-gate free(rval); 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate /* ok, so we either have a bad device or a floppy */ 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate /* try the rfd# or rdiskette forms */ 155*7c478bd9Sstevel@tonic-gate if (((s = strstr(n, "/rfd")) != NULL) || 156*7c478bd9Sstevel@tonic-gate ((s = strstr(n, "/rdiskette")) != NULL) || 157*7c478bd9Sstevel@tonic-gate ((s = strstr(n, "/rdsk/")) != NULL)) { 158*7c478bd9Sstevel@tonic-gate /* 159*7c478bd9Sstevel@tonic-gate * we do not have to check for room here, since we will 160*7c478bd9Sstevel@tonic-gate * be making the string one shorter 161*7c478bd9Sstevel@tonic-gate */ 162*7c478bd9Sstevel@tonic-gate c = *++s; /* save the first char */ 163*7c478bd9Sstevel@tonic-gate *s = NULLC; /* replace it with a null */ 164*7c478bd9Sstevel@tonic-gate (void) strcpy(namebuf, n); /* save first part of it */ 165*7c478bd9Sstevel@tonic-gate *s++ = c; /* give the first char back */ 166*7c478bd9Sstevel@tonic-gate (void) strcat(namebuf, s); /* copy the rest */ 167*7c478bd9Sstevel@tonic-gate res = strdup(namebuf); 168*7c478bd9Sstevel@tonic-gate goto dun; 169*7c478bd9Sstevel@tonic-gate } 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate /* no match found */ 172*7c478bd9Sstevel@tonic-gate res = strdup(""); 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate dun: 175*7c478bd9Sstevel@tonic-gate return (res); 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate char * 180*7c478bd9Sstevel@tonic-gate volmgt_getfullrawname(char *n) 181*7c478bd9Sstevel@tonic-gate { 182*7c478bd9Sstevel@tonic-gate extern char *getfullrawname(char *); 183*7c478bd9Sstevel@tonic-gate char *rval; 184*7c478bd9Sstevel@tonic-gate char namebuf[MAXPATHLEN+1]; 185*7c478bd9Sstevel@tonic-gate char *s; 186*7c478bd9Sstevel@tonic-gate char c; 187*7c478bd9Sstevel@tonic-gate char *res; 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 191*7c478bd9Sstevel@tonic-gate denter("volmgt_getfullrawname(%s): entering\n", n); 192*7c478bd9Sstevel@tonic-gate #endif 193*7c478bd9Sstevel@tonic-gate /* try to get full char-spcl device name */ 194*7c478bd9Sstevel@tonic-gate rval = getfullrawname(n); 195*7c478bd9Sstevel@tonic-gate if ((rval != NULL) && (*rval != NULLC)) { 196*7c478bd9Sstevel@tonic-gate /* found it */ 197*7c478bd9Sstevel@tonic-gate res = rval; 198*7c478bd9Sstevel@tonic-gate goto dun; 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate /* we have a null-string result */ 202*7c478bd9Sstevel@tonic-gate if (rval != NULL) { 203*7c478bd9Sstevel@tonic-gate /* free null string */ 204*7c478bd9Sstevel@tonic-gate free(rval); 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate /* ok, so we either have a bad device or a floppy */ 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate /* try the "fd", "diskette", and the "dsk" form */ 210*7c478bd9Sstevel@tonic-gate if (((s = strstr(n, "/fd")) != NULL) || 211*7c478bd9Sstevel@tonic-gate ((s = strstr(n, "/diskette")) != NULL) || 212*7c478bd9Sstevel@tonic-gate ((s = strstr(n, "/dsk/")) != NULL)) { 213*7c478bd9Sstevel@tonic-gate /* 214*7c478bd9Sstevel@tonic-gate * ensure we have room to add one more char 215*7c478bd9Sstevel@tonic-gate */ 216*7c478bd9Sstevel@tonic-gate if (strlen(n) < (MAXPATHLEN - 1)) { 217*7c478bd9Sstevel@tonic-gate c = *++s; /* save the first char */ 218*7c478bd9Sstevel@tonic-gate *s = NULLC; /* replace it with a null */ 219*7c478bd9Sstevel@tonic-gate (void) strcpy(namebuf, n); /* save first part of str */ 220*7c478bd9Sstevel@tonic-gate *s = c; /* put first charback */ 221*7c478bd9Sstevel@tonic-gate (void) strcat(namebuf, "r"); /* insert an 'r' */ 222*7c478bd9Sstevel@tonic-gate (void) strcat(namebuf, s); /* copy rest of str */ 223*7c478bd9Sstevel@tonic-gate res = strdup(namebuf); 224*7c478bd9Sstevel@tonic-gate goto dun; 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate /* no match found */ 229*7c478bd9Sstevel@tonic-gate res = strdup(""); 230*7c478bd9Sstevel@tonic-gate dun: 231*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 232*7c478bd9Sstevel@tonic-gate dexit("volmgt_getfullrawname: returning %s\n", 233*7c478bd9Sstevel@tonic-gate res ? res : "<null ptr>"); 234*7c478bd9Sstevel@tonic-gate #endif 235*7c478bd9Sstevel@tonic-gate return (res); 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate /* 240*7c478bd9Sstevel@tonic-gate * volctl_name -- return name of volctl device 241*7c478bd9Sstevel@tonic-gate */ 242*7c478bd9Sstevel@tonic-gate const char * 243*7c478bd9Sstevel@tonic-gate volctl_name(void) 244*7c478bd9Sstevel@tonic-gate { 245*7c478bd9Sstevel@tonic-gate static char dev_name[] = "/dev/" VOLCTLNAME; 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate return (dev_name); 248*7c478bd9Sstevel@tonic-gate } 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate 251*7c478bd9Sstevel@tonic-gate /* 252*7c478bd9Sstevel@tonic-gate * concat_paths -- create a pathname from two (or three) components 253*7c478bd9Sstevel@tonic-gate * 254*7c478bd9Sstevel@tonic-gate * truncate the result if it is too large 255*7c478bd9Sstevel@tonic-gate * 256*7c478bd9Sstevel@tonic-gate * assume that res has a defined length of MAXPATHLEN+1 257*7c478bd9Sstevel@tonic-gate * 258*7c478bd9Sstevel@tonic-gate * ("head" and "tail" are required, but "tail2" is optional) 259*7c478bd9Sstevel@tonic-gate */ 260*7c478bd9Sstevel@tonic-gate char * 261*7c478bd9Sstevel@tonic-gate concat_paths(char *res, char *head, char *tail, char *tail2) 262*7c478bd9Sstevel@tonic-gate { 263*7c478bd9Sstevel@tonic-gate int head_len = strlen(head); 264*7c478bd9Sstevel@tonic-gate int len_avail = MAXPATHLEN; 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate 268*7c478bd9Sstevel@tonic-gate /* put in as much of the head as will fit */ 269*7c478bd9Sstevel@tonic-gate (void) strncpy(res, head, len_avail); 270*7c478bd9Sstevel@tonic-gate len_avail -= head_len; 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate /* see if there is room to proceed */ 273*7c478bd9Sstevel@tonic-gate if (len_avail > 0) { 274*7c478bd9Sstevel@tonic-gate char *cp = res + head_len; 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate /* there is room to append a slash */ 277*7c478bd9Sstevel@tonic-gate *cp++ = '/'; 278*7c478bd9Sstevel@tonic-gate len_avail--; 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate /* see if there is room to proceed */ 281*7c478bd9Sstevel@tonic-gate if (len_avail > 0) { 282*7c478bd9Sstevel@tonic-gate int tail_len = strlen(tail); 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate /* there is room to append the tail */ 285*7c478bd9Sstevel@tonic-gate (void) strncpy(cp, tail, len_avail); 286*7c478bd9Sstevel@tonic-gate cp += tail_len; 287*7c478bd9Sstevel@tonic-gate len_avail -= tail_len; 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate /* see if there is room to proceed */ 290*7c478bd9Sstevel@tonic-gate if ((len_avail > 0) && (tail2 != NULL)) { 291*7c478bd9Sstevel@tonic-gate 292*7c478bd9Sstevel@tonic-gate /* there is room to add tail2 (and need) */ 293*7c478bd9Sstevel@tonic-gate (void) strncpy(cp, tail2, len_avail); 294*7c478bd9Sstevel@tonic-gate } 295*7c478bd9Sstevel@tonic-gate } 296*7c478bd9Sstevel@tonic-gate } 297*7c478bd9Sstevel@tonic-gate 298*7c478bd9Sstevel@tonic-gate /* null terminate result (just in case) and return */ 299*7c478bd9Sstevel@tonic-gate res[MAXPATHLEN] = NULLC; 300*7c478bd9Sstevel@tonic-gate return (res); 301*7c478bd9Sstevel@tonic-gate } 302*7c478bd9Sstevel@tonic-gate 303*7c478bd9Sstevel@tonic-gate 304*7c478bd9Sstevel@tonic-gate 305*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 306*7c478bd9Sstevel@tonic-gate 307*7c478bd9Sstevel@tonic-gate /* 308*7c478bd9Sstevel@tonic-gate * debug print routines -- private to libvolmgt 309*7c478bd9Sstevel@tonic-gate */ 310*7c478bd9Sstevel@tonic-gate 311*7c478bd9Sstevel@tonic-gate #define DEBUG_INDENT_SPACES " " 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate int debug_level = 0; 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate 316*7c478bd9Sstevel@tonic-gate static void 317*7c478bd9Sstevel@tonic-gate derrprint(char *fmt, va_list ap) 318*7c478bd9Sstevel@tonic-gate { 319*7c478bd9Sstevel@tonic-gate int i; 320*7c478bd9Sstevel@tonic-gate int j; 321*7c478bd9Sstevel@tonic-gate char date_buf[256]; 322*7c478bd9Sstevel@tonic-gate time_t t; 323*7c478bd9Sstevel@tonic-gate struct tm *tm; 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate 326*7c478bd9Sstevel@tonic-gate (void) time(&t); 327*7c478bd9Sstevel@tonic-gate tm = localtime(&t); 328*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%02d/%02d/%02d %02d:%02d:%02d ", 329*7c478bd9Sstevel@tonic-gate tm->tm_mon+1, tm->tm_mday, tm->tm_year % 100, 330*7c478bd9Sstevel@tonic-gate tm->tm_hour, tm->tm_min, tm->tm_sec); 331*7c478bd9Sstevel@tonic-gate for (i = 0; i < debug_level; i++) { 332*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, DEBUG_INDENT_SPACES); 333*7c478bd9Sstevel@tonic-gate } 334*7c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, fmt, ap); 335*7c478bd9Sstevel@tonic-gate } 336*7c478bd9Sstevel@tonic-gate 337*7c478bd9Sstevel@tonic-gate /* 338*7c478bd9Sstevel@tonic-gate * denter -- do a derrprint(), then increment debug level 339*7c478bd9Sstevel@tonic-gate */ 340*7c478bd9Sstevel@tonic-gate void 341*7c478bd9Sstevel@tonic-gate denter(char *fmt, ...) 342*7c478bd9Sstevel@tonic-gate { 343*7c478bd9Sstevel@tonic-gate va_list ap; 344*7c478bd9Sstevel@tonic-gate 345*7c478bd9Sstevel@tonic-gate va_start(ap, fmt); 346*7c478bd9Sstevel@tonic-gate derrprint(fmt, ap); 347*7c478bd9Sstevel@tonic-gate va_end(ap); 348*7c478bd9Sstevel@tonic-gate debug_level++; 349*7c478bd9Sstevel@tonic-gate } 350*7c478bd9Sstevel@tonic-gate 351*7c478bd9Sstevel@tonic-gate /* 352*7c478bd9Sstevel@tonic-gate * dexit -- decrement debug level then do a derrprint() 353*7c478bd9Sstevel@tonic-gate */ 354*7c478bd9Sstevel@tonic-gate void 355*7c478bd9Sstevel@tonic-gate dexit(char *fmt, ...) 356*7c478bd9Sstevel@tonic-gate { 357*7c478bd9Sstevel@tonic-gate va_list ap; 358*7c478bd9Sstevel@tonic-gate 359*7c478bd9Sstevel@tonic-gate if (--debug_level < 0) { 360*7c478bd9Sstevel@tonic-gate debug_level = 0; 361*7c478bd9Sstevel@tonic-gate } 362*7c478bd9Sstevel@tonic-gate va_start(ap, fmt); 363*7c478bd9Sstevel@tonic-gate derrprint(fmt, ap); 364*7c478bd9Sstevel@tonic-gate va_end(ap); 365*7c478bd9Sstevel@tonic-gate } 366*7c478bd9Sstevel@tonic-gate 367*7c478bd9Sstevel@tonic-gate /* 368*7c478bd9Sstevel@tonic-gate * dprintf -- print debug info, indenting based on debug level 369*7c478bd9Sstevel@tonic-gate */ 370*7c478bd9Sstevel@tonic-gate void 371*7c478bd9Sstevel@tonic-gate dprintf(char *fmt, ...) 372*7c478bd9Sstevel@tonic-gate { 373*7c478bd9Sstevel@tonic-gate va_list ap; 374*7c478bd9Sstevel@tonic-gate 375*7c478bd9Sstevel@tonic-gate va_start(ap, fmt); 376*7c478bd9Sstevel@tonic-gate derrprint(fmt, ap); 377*7c478bd9Sstevel@tonic-gate va_end(ap); 378*7c478bd9Sstevel@tonic-gate } 379*7c478bd9Sstevel@tonic-gate 380*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 381