2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * get root device
2N/A */
2N/A
2N/A#include <meta.h>
2N/A#include "meta_lib_prv.h"
2N/A
2N/A#include <sys/mnttab.h>
2N/A
2N/A/*
2N/A * Return the current root filesystem block device name
2N/A */
2N/Avoid *
2N/Ameta_get_current_root(
2N/A md_error_t *ep
2N/A)
2N/A{
2N/A FILE *fp;
2N/A struct mnttab mp;
2N/A
2N/A if ((fp = open_mnttab()) == NULL) {
2N/A (void) mdsyserror(ep, errno, MNTTAB);
2N/A return (NULL);
2N/A }
2N/A
2N/A while (getmntent(fp, &mp) == 0) {
2N/A if (strcmp(mp.mnt_mountp, "/") == 0)
2N/A return (mp.mnt_special);
2N/A }
2N/A (void) mderror(ep, MDE_NOROOT, NULL);
2N/A return (NULL);
2N/A}
2N/A
2N/A/*
2N/A * Return the current root filesystem block device name. This is only valid
2N/A * when root is either a slice, a stripe or a mirror.
2N/A */
2N/Amdname_t *
2N/Ameta_get_current_root_dev(
2N/A mdsetname_t *sp,
2N/A md_error_t *ep
2N/A)
2N/A{
2N/A md_stripe_t *stripep;
2N/A md_mirror_t *mirrorp;
2N/A md_row_t *rp;
2N/A md_comp_t *cp;
2N/A mdname_t *rootnp;
2N/A void *curroot;
2N/A char *miscname;
2N/A int smi;
2N/A
2N/A if ((curroot = meta_get_current_root(ep)) == NULL)
2N/A return (NULL);
2N/A if ((rootnp = metaname(&sp, curroot, UNKNOWN, ep)) == NULL)
2N/A return (NULL);
2N/A if (metaismeta(rootnp)) {
2N/A if ((miscname = metagetmiscname(rootnp, ep)) == NULL)
2N/A return (NULL);
2N/A if ((strcmp(miscname, MD_MIRROR) == 0) &&
2N/A ((mirrorp = meta_get_mirror(sp, rootnp, ep)) != NULL)) {
2N/A for (smi = 0; smi < NMIRROR; smi++) {
2N/A md_submirror_t *mdsp =
2N/A &mirrorp->submirrors[smi];
2N/A rootnp = mdsp->submirnamep;
2N/A /* skip unused submirrors */
2N/A if (rootnp == NULL) {
2N/A assert(mdsp->state == SMS_UNUSED);
2N/A continue;
2N/A }
2N/A if ((miscname = metagetmiscname(rootnp, ep))
2N/A == NULL) {
2N/A (void) mdmderror(ep, MDE_UNKNOWN_TYPE,
2N/A meta_getminor(rootnp->dev),
2N/A rootnp->cname);
2N/A return (NULL);
2N/A }
2N/A break;
2N/A }
2N/A }
2N/A if ((strcmp(miscname, MD_STRIPE) == 0) &&
2N/A ((stripep = meta_get_stripe(sp, rootnp, ep)) != NULL)) {
2N/A rp = &stripep->rows.rows_val[0];
2N/A cp = &rp->comps.comps_val[0];
2N/A if (metachkcomp(cp->compnamep, ep) == 0)
2N/A return (cp->compnamep);
2N/A }
2N/A /* Root is not a single stripe metadevice */
2N/A (void) mddeverror(ep, MDE_INV_ROOT, rootnp->dev, rootnp->cname);
2N/A return (NULL);
2N/A } else return (rootnp);
2N/A}