7712 mandoc -Tlint does always exit with error code 0
[unleashed.git] / usr / src / lib / lvm / libsvm / common / check_svm.c
blob5c92ac27889f8dcce5627879bf5c0391e0e93b2a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <errno.h>
32 #include <string.h>
33 #include <meta.h>
34 #include <sys/types.h>
35 #include <sys/mkdev.h>
36 #include <sys/stat.h>
37 #include <limits.h>
38 #include <svm.h>
41 * FUNCTION: valid_bootlist
43 * INPUT: file pointer, line buffer, line_length
45 * RETURN VALUES:
46 * 0 - SUCCESS
47 * -1 - FAIL
51 int
52 valid_bootlist(FILE *fp, int line_len)
54 char *bp = NULL;
55 char *line;
58 * errno may not be cleared by callee routines and we
59 * we want to catch fgets failures hence errno is reset.
61 errno = 0;
62 if ((line = malloc(line_len)) == NULL)
63 return (RET_ERROR);
65 while (fgets(line, line_len, fp) != NULL) {
66 bp = strstr(line, "mddb_bootlist");
67 if (bp != NULL) {
68 /* if not commented out then breakout */
69 if (*line != '*' && *line != '#') {
70 break;
75 free(line);
76 if (bp == NULL || errno != 0)
77 return (RET_ERROR);
79 return (RET_SUCCESS);
83 * FUNCTION: svm_check
84 * Check the existance of DiskSuite or SVM
86 * INPUT: rootpath
88 * RETURN VALUES:
89 * 0 - SUCCESS
90 * -1 - FAIL
93 int
94 svm_check(char *path)
96 FILE *fp;
97 char tmppath[PATH_MAX];
98 int rval;
100 (void) strcat(strcpy(tmppath, path), MD_CONF);
102 if ((fp = fopen(tmppath, "r")) == NULL) {
103 rval = errno;
104 goto free_exit;
107 rval = valid_bootlist(fp, MDDB_BOOTLIST_MAX_LEN);
109 debug_printf("svm_check(): valid bootlist in %s. status %d\n",
110 tmppath, rval);
112 if (rval == RET_SUCCESS) {
113 goto free_exit;
115 (void) fclose(fp);
117 /* not found in md.conf try etc/system */
118 (void) strcat(strcpy(tmppath, path), SYSTEM_FILE);
120 if ((fp = fopen(tmppath, "r")) == NULL) {
121 rval = errno;
122 goto free_exit;
125 rval = valid_bootlist(fp, MDDB_BOOTLIST_MAX_LEN);
127 debug_printf("svm_check(): valid bootlist in %s. status %d\n",
128 tmppath, rval);
129 free_exit:
130 (void) fclose(fp);
131 if (rval > 0)
132 rval = RET_ERROR;
133 return (rval);
137 * FUNCTION: svm_is_md
138 * Check if the the given device name has an md driver.
139 * INPUT: special device name (/dev/dsk/c0t0d0s0 or /dev/md/dsk/d10)
141 * RETURN:
142 * 1 - if it is a metadevice.
143 * 0 - if it is not a metadevice.
147 svm_is_md(char *device_name)
149 char buf[30];
150 struct stat sbuf;
151 int rval = 0;
153 (void) memset(buf, 0, 30);
155 debug_printf("svm_is_md(): device %s\n", device_name);
156 if (stat(device_name, &sbuf) != 0)
157 return (RET_ERROR);
159 if (get_drv_name(major(sbuf.st_rdev), "/", buf) == RET_ERROR) {
160 debug_printf("svm_is_md(): device get_drv_name failed: %s\n",
161 device_name);
162 return (0);
164 if (strcmp(buf, MD_MODULE) == 0) {
165 debug_printf("svm_is_md(): device %s succeed\n", device_name);
166 rval = 1;
168 return (rval);