sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libvolmgt / common / volprivate.c
blob9ef56f329e8ed6eee15c017dc3f31275bdf4082d
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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
30 * routines only
33 #include <stdio.h>
34 #include <string.h>
35 #include <dirent.h>
36 #include <string.h>
37 #include <libintl.h>
38 #include <limits.h>
39 #include <unistd.h>
40 #include <stdlib.h>
41 #include <sys/types.h>
42 #include <sys/stat.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
56 char *
57 volmgt_getfullblkname(char *n)
59 extern char *getfullblkname(char *);
60 char *rval;
61 char namebuf[MAXPATHLEN+1];
62 char *s;
63 char c;
64 char *res;
68 /* try to get full block-spcl device name */
69 rval = getfullblkname(n);
70 if ((rval != NULL) && (*rval != NULLC)) {
71 /* found it */
72 res = rval;
73 goto dun;
76 /* we have a null-string result */
77 if (rval != NULL) {
78 /* free null string */
79 free(rval);
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);
98 goto dun;
101 /* no match found */
102 res = strdup("");
104 dun:
105 return (res);
109 char *
110 volmgt_getfullrawname(char *n)
112 extern char *getfullrawname(char *);
113 char *rval;
114 char namebuf[MAXPATHLEN+1];
115 char *s;
116 char c;
117 char *res;
120 #ifdef DEBUG
121 denter("volmgt_getfullrawname(%s): entering\n", n);
122 #endif
123 /* try to get full char-spcl device name */
124 rval = getfullrawname(n);
125 if ((rval != NULL) && (*rval != NULLC)) {
126 /* found it */
127 res = rval;
128 goto dun;
131 /* we have a null-string result */
132 if (rval != NULL) {
133 /* free null string */
134 free(rval);
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);
154 goto dun;
158 /* no match found */
159 res = strdup("");
160 dun:
161 #ifdef DEBUG
162 dexit("volmgt_getfullrawname: returning %s\n",
163 res ? res : "<null ptr>");
164 #endif
165 return (res);
169 #ifdef DEBUG
172 * debug print routines -- private to libvolmgt
175 #define DEBUG_INDENT_SPACES " "
177 int debug_level = 0;
180 static void
181 derrprint(char *fmt, va_list ap)
183 int i;
184 int j;
185 char date_buf[256];
186 time_t t;
187 struct tm *tm;
190 (void) time(&t);
191 tm = localtime(&t);
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
204 void
205 denter(char *fmt, ...)
207 va_list ap;
209 va_start(ap, fmt);
210 derrprint(fmt, ap);
211 va_end(ap);
212 debug_level++;
216 * dexit -- decrement debug level then do a derrprint()
218 void
219 dexit(char *fmt, ...)
221 va_list ap;
223 if (--debug_level < 0) {
224 debug_level = 0;
226 va_start(ap, fmt);
227 derrprint(fmt, ap);
228 va_end(ap);
232 * dprintf -- print debug info, indenting based on debug level
234 void
235 dprintf(char *fmt, ...)
237 va_list ap;
239 va_start(ap, fmt);
240 derrprint(fmt, ap);
241 va_end(ap);
244 #endif /* DEBUG */