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 * patch /etc/system file for the root device
37 * set root device name in md.conf and vfstab, patch in mddb locations
41 mdname_t
*rootnp
, /* root device */
42 char *sname
, /* system file name */
43 char *vname
, /* vfstab file name */
44 char *cname
, /* mddb.cf file name */
45 char *dbname
, /* md.conf file name */
46 int doit
, /* really patch files */
47 int verbose
, /* show what we're doing */
48 md_error_t
*ep
/* returned error */
52 int ismeta
= metaismeta(rootnp
);
62 sname
= "/etc/system";
64 vname
= "/etc/vfstab";
68 dbname
= "/kernel/drv/md.conf";
70 /* make sure we have a local name */
71 if ((sp
= metagetset(rootnp
, TRUE
, ep
)) == NULL
)
74 if (! metaislocalset(sp
)) {
75 return (mddeverror(ep
, MDE_NOT_LOCAL
, rootnp
->dev
,
79 /* replace forceload and rootdev lines in system */
80 if (meta_systemfile_copy(sname
, 1, 0, doit
, verbose
, &tsname
, &tsfp
,
84 if (meta_systemfile_append_mdroot(rootnp
, sname
,
85 tsname
, tsfp
, ismeta
, doit
, verbose
, ep
) != 0) {
89 /* replace bootlist lines in /kernel/drv/md.conf */
90 if (meta_systemfile_copy(dbname
, 0, 1, doit
, verbose
, &dbtname
,
94 if (meta_systemfile_append_mddb(cname
, dbname
, dbtname
, dbtfp
, doit
,
95 verbose
, 1, ep
) != 0) {
99 /* force the file contents out to disk */
101 if ((fflush(tsfp
) != 0) ||
102 (fsync(fileno(tsfp
)) != 0) ||
103 (fclose(tsfp
) != 0)) {
104 (void) mdsyserror(ep
, errno
, tsname
);
108 if ((fflush(dbtfp
) != 0) ||
109 (fsync(fileno(dbtfp
)) != 0) ||
110 (fclose(dbtfp
) != 0)) {
111 (void) mdsyserror(ep
, errno
, dbtname
);
117 /* replace lines in vfstab */
118 if (meta_patch_vfstab("/", rootnp
, vname
, NULL
, doit
, verbose
, &tvname
,
123 /* rename files, better hope both work */
125 if (rename(tsname
, sname
) != 0) {
126 (void) mdsyserror(ep
, errno
, sname
);
131 if (rename(dbtname
, dbname
) != 0) {
132 (void) mdsyserror(ep
, errno
, dbname
);
137 if (rename(tvname
, vname
) != 0) {
138 (void) mdsyserror(ep
, errno
, vname
);
146 /* cleanup, return error */
150 if (tsname
!= NULL
) {
152 (void) unlink(tsname
);
155 if (tvname
!= NULL
) {
157 (void) unlink(tvname
);
161 /* free the temporary files for md.conf */
163 (void) fclose(dbtfp
);
164 if (dbtname
!= NULL
) {
166 (void) unlink(dbtname
);