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 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 #include <sys/types.h>
29 #include <sys/mkdev.h>
41 #define DISK_DIR "/dev/rdsk"
43 extern int _map_to_effective_dev();
45 static int is_blank(char *);
48 * is_blank() returns 1 (true) if a line specified is composed of
49 * whitespace characters only. otherwise, it returns 0 (false).
51 * Note. the argument (line) must be null-terminated.
56 for (/* nothing */; *line
!= '\0'; line
++)
63 * FUNCTION: write_targ_nm_table
64 * creates a tuple table of <driver name, major number > in md.conf
73 write_targ_nm_table(char *path
)
77 char buf
[PATH_MAX
], *cp
;
78 int retval
= RET_SUCCESS
;
81 if ((mdfp
= fopen(MD_CONF
, "a")) == NULL
)
84 (void) snprintf(buf
, sizeof (buf
), "%s%s", path
, NAME_TO_MAJOR
);
86 if ((targfp
= fopen(buf
, "r")) == NULL
) {
91 while (fgets(buf
, PATH_MAX
, targfp
) != NULL
&&
92 (retval
== RET_SUCCESS
)) {
93 /* remove a new-line character for md_targ_nm_table */
94 if ((cp
= strchr(buf
, '\n')) != NULL
)
96 /* cut off comments starting with '#' */
97 if ((cp
= strchr(buf
, '#')) != NULL
)
99 /* ignore comment or blank lines */
103 if (fprintf(mdfp
, "md_targ_nm_table=\"%s\"", buf
) < 0)
107 if (fprintf(mdfp
, ",\"%s\"", buf
) < 0)
112 if (fprintf(mdfp
, ";\n") < 0)
115 (void) fclose(targfp
);
120 * FUNCTION: write_xlate_to_mdconf
121 * creates a tuple table of <miniroot devt, target devt> in md.conf
130 write_xlate_to_mdconf(char *path
)
135 struct stat statb_dev
;
136 struct stat statb_edev
;
138 char edevname
[PATH_MAX
];
139 char targname
[PATH_MAX
];
140 char diskdir
[PATH_MAX
];
141 char linkpath
[PATH_MAX
];
143 int ret
= RET_SUCCESS
;
145 if ((fptr
= fopen(MD_CONF
, "a")) == NULL
) {
150 (void) snprintf(diskdir
, sizeof (diskdir
), "%s%s", path
, DISK_DIR
);
151 if ((dirp
= opendir(diskdir
)) == NULL
) {
156 /* special case to write the first tuple in the table */
157 while (((dp
= readdir(dirp
)) != (struct dirent
*)0) &&
158 (ret
!= RET_ERROR
)) {
159 if ((strcmp(dp
->d_name
, ".") == 0) ||
160 (strcmp(dp
->d_name
, "..") == 0))
163 if ((strlen(diskdir
) + strlen(dp
->d_name
) + 2) > PATH_MAX
) {
167 (void) snprintf(targname
, sizeof (targname
), "%s/%s",
168 diskdir
, dp
->d_name
);
171 * stat /devices to see if it's a devfs based file system
172 * On Solaris 10 and up, the devfs has been built on the
173 * fly for the mini-root. We need to adjust the path
175 * If it's not devfs, just use the targname as it is.
178 if (stat("/devices", &statb_dev
) != 0) {
182 if (strncmp("devfs", statb_dev
.st_fstype
, 5) == 0) {
183 if (readlink(targname
, linkpath
,
184 sizeof (linkpath
)) == -1) {
188 * turn ../../devices/<path> into /devices/<path>
189 * and stat that into statb_dev
191 if (stat(strstr(linkpath
, "/devices"),
196 if (stat(targname
, &statb_dev
) != 0) {
201 if ((devname
= strstr(targname
, DISK_DIR
)) == NULL
) {
205 if (_map_to_effective_dev((char *)devname
, (char *)&edevname
)
210 if (stat(edevname
, &statb_edev
) != 0) {
215 if (fprintf(fptr
, "md_xlate_ver=\"%s\";\n"
216 "md_xlate=%lu,%lu", VERSION
,
217 statb_edev
.st_rdev
, statb_dev
.st_rdev
) < 0)
221 if (fprintf(fptr
, ",%lu,%lu", statb_edev
.st_rdev
,
222 statb_dev
.st_rdev
) < 0)
227 if (fprintf(fptr
, ";\n") < 0)
230 (void) closedir(dirp
);