4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * routines in this module are meant to be called by other libvolmgt
41 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/varargs.h>
45 #include "volmgt_private.h"
49 * fix the getfull{raw,blk}name problem for the fd and diskette case
51 * return value is malloc'ed, and must be free'd
53 * no match gets a malloc'ed null string
57 volmgt_getfullblkname(char *n
)
59 extern char *getfullblkname(char *);
61 char namebuf
[MAXPATHLEN
+1];
68 /* try to get full block-spcl device name */
69 rval
= getfullblkname(n
);
70 if ((rval
!= NULL
) && (*rval
!= NULLC
)) {
76 /* we have a null-string result */
78 /* free null string */
82 /* ok, so we either have a bad device or a floppy */
84 /* try the rfd# or rdiskette forms */
85 if (((s
= strstr(n
, "/rfd")) != NULL
) ||
86 ((s
= strstr(n
, "/rdiskette")) != NULL
) ||
87 ((s
= strstr(n
, "/rdsk/")) != NULL
)) {
89 * we do not have to check for room here, since we will
90 * be making the string one shorter
92 c
= *++s
; /* save the first char */
93 *s
= NULLC
; /* replace it with a null */
94 (void) strcpy(namebuf
, n
); /* save first part of it */
95 *s
++ = c
; /* give the first char back */
96 (void) strcat(namebuf
, s
); /* copy the rest */
97 res
= strdup(namebuf
);
110 volmgt_getfullrawname(char *n
)
112 extern char *getfullrawname(char *);
114 char namebuf
[MAXPATHLEN
+1];
121 denter("volmgt_getfullrawname(%s): entering\n", n
);
123 /* try to get full char-spcl device name */
124 rval
= getfullrawname(n
);
125 if ((rval
!= NULL
) && (*rval
!= NULLC
)) {
131 /* we have a null-string result */
133 /* free null string */
137 /* ok, so we either have a bad device or a floppy */
139 /* try the "fd", "diskette", and the "dsk" form */
140 if (((s
= strstr(n
, "/fd")) != NULL
) ||
141 ((s
= strstr(n
, "/diskette")) != NULL
) ||
142 ((s
= strstr(n
, "/dsk/")) != NULL
)) {
144 * ensure we have room to add one more char
146 if (strlen(n
) < (MAXPATHLEN
- 1)) {
147 c
= *++s
; /* save the first char */
148 *s
= NULLC
; /* replace it with a null */
149 (void) strcpy(namebuf
, n
); /* save first part of str */
150 *s
= c
; /* put first charback */
151 (void) strcat(namebuf
, "r"); /* insert an 'r' */
152 (void) strcat(namebuf
, s
); /* copy rest of str */
153 res
= strdup(namebuf
);
162 dexit("volmgt_getfullrawname: returning %s\n",
163 res
? res
: "<null ptr>");
172 * debug print routines -- private to libvolmgt
175 #define DEBUG_INDENT_SPACES " "
181 derrprint(char *fmt
, va_list ap
)
192 (void) fprintf(stderr
, "%02d/%02d/%02d %02d:%02d:%02d ",
193 tm
->tm_mon
+1, tm
->tm_mday
, tm
->tm_year
% 100,
194 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
195 for (i
= 0; i
< debug_level
; i
++) {
196 (void) fprintf(stderr
, DEBUG_INDENT_SPACES
);
198 (void) vfprintf(stderr
, fmt
, ap
);
202 * denter -- do a derrprint(), then increment debug level
205 denter(char *fmt
, ...)
216 * dexit -- decrement debug level then do a derrprint()
219 dexit(char *fmt
, ...)
223 if (--debug_level
< 0) {
232 * dprintf -- print debug info, indenting based on debug level
235 dprintf(char *fmt
, ...)