1*45916cd2Sjpk /*
2*45916cd2Sjpk * CDDL HEADER START
3*45916cd2Sjpk *
4*45916cd2Sjpk * The contents of this file are subject to the terms of the
5*45916cd2Sjpk * Common Development and Distribution License (the "License").
6*45916cd2Sjpk * You may not use this file except in compliance with the License.
7*45916cd2Sjpk *
8*45916cd2Sjpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*45916cd2Sjpk * or http://www.opensolaris.org/os/licensing.
10*45916cd2Sjpk * See the License for the specific language governing permissions
11*45916cd2Sjpk * and limitations under the License.
12*45916cd2Sjpk *
13*45916cd2Sjpk * When distributing Covered Code, include this CDDL HEADER in each
14*45916cd2Sjpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*45916cd2Sjpk * If applicable, add the following below this CDDL HEADER, with the
16*45916cd2Sjpk * fields enclosed by brackets "[]" replaced with your own identifying
17*45916cd2Sjpk * information: Portions Copyright [yyyy] [name of copyright owner]
18*45916cd2Sjpk *
19*45916cd2Sjpk * CDDL HEADER END
20*45916cd2Sjpk */
21*45916cd2Sjpk
22*45916cd2Sjpk /*
23*45916cd2Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24*45916cd2Sjpk * Use is subject to license terms.
25*45916cd2Sjpk */
26*45916cd2Sjpk
27*45916cd2Sjpk #pragma ident "%Z%%M% %I% %E% SMI"
28*45916cd2Sjpk
29*45916cd2Sjpk #include <stdlib.h>
30*45916cd2Sjpk #include <errno.h>
31*45916cd2Sjpk #include <tsol/label.h>
32*45916cd2Sjpk #include <bsm/devices.h>
33*45916cd2Sjpk
34*45916cd2Sjpk
35*45916cd2Sjpk /*
36*45916cd2Sjpk * getdevicerange
37*45916cd2Sjpk * Gets the minimum and maximum labels within which the device can
38*45916cd2Sjpk * be used. If label range is not specified for the device in
39*45916cd2Sjpk * device_allocate, defaults to admin_low and admin_high.
40*45916cd2Sjpk * Returns malloc'ed blrange pointer, or NULL on any error.
41*45916cd2Sjpk */
42*45916cd2Sjpk blrange_t *
getdevicerange(const char * dev)43*45916cd2Sjpk getdevicerange(const char *dev)
44*45916cd2Sjpk {
45*45916cd2Sjpk int err;
46*45916cd2Sjpk char *lstr;
47*45916cd2Sjpk devalloc_t *da;
48*45916cd2Sjpk devmap_t *dm;
49*45916cd2Sjpk blrange_t *range;
50*45916cd2Sjpk
51*45916cd2Sjpk errno = 0;
52*45916cd2Sjpk if ((range = malloc(sizeof (blrange_t))) == NULL)
53*45916cd2Sjpk return (NULL);
54*45916cd2Sjpk if ((range->lower_bound = blabel_alloc()) == NULL) {
55*45916cd2Sjpk free(range);
56*45916cd2Sjpk return (NULL);
57*45916cd2Sjpk }
58*45916cd2Sjpk if ((range->upper_bound = blabel_alloc()) == NULL) {
59*45916cd2Sjpk blabel_free(range->lower_bound);
60*45916cd2Sjpk free(range);
61*45916cd2Sjpk return (NULL);
62*45916cd2Sjpk }
63*45916cd2Sjpk
64*45916cd2Sjpk /*
65*45916cd2Sjpk * If an entry is found for the named device,
66*45916cd2Sjpk * return its label range.
67*45916cd2Sjpk */
68*45916cd2Sjpk setdaent();
69*45916cd2Sjpk if ((da = getdanam((char *)dev)) == NULL) {
70*45916cd2Sjpk setdmapent();
71*45916cd2Sjpk /* check for an actual device file */
72*45916cd2Sjpk if ((dm = getdmapdev((char *)dev)) != NULL) {
73*45916cd2Sjpk da = getdanam(dm->dmap_devname);
74*45916cd2Sjpk freedmapent(dm);
75*45916cd2Sjpk }
76*45916cd2Sjpk enddmapent();
77*45916cd2Sjpk }
78*45916cd2Sjpk enddaent();
79*45916cd2Sjpk if (da == NULL) {
80*45916cd2Sjpk bsllow(range->lower_bound);
81*45916cd2Sjpk bslhigh(range->upper_bound);
82*45916cd2Sjpk } else {
83*45916cd2Sjpk lstr = kva_match(da->da_devopts, DAOPT_MINLABEL);
84*45916cd2Sjpk if (lstr == NULL) {
85*45916cd2Sjpk bsllow(range->lower_bound);
86*45916cd2Sjpk } else if (stobsl(lstr, range->lower_bound, NO_CORRECTION,
87*45916cd2Sjpk &err) == 0) {
88*45916cd2Sjpk blabel_free(range->lower_bound);
89*45916cd2Sjpk blabel_free(range->upper_bound);
90*45916cd2Sjpk free(range);
91*45916cd2Sjpk errno = ENOTSUP;
92*45916cd2Sjpk return (NULL);
93*45916cd2Sjpk }
94*45916cd2Sjpk lstr = kva_match(da->da_devopts, DAOPT_MAXLABEL);
95*45916cd2Sjpk if (lstr == NULL) {
96*45916cd2Sjpk bslhigh(range->upper_bound);
97*45916cd2Sjpk } else if (stobsl(lstr, range->upper_bound, NO_CORRECTION,
98*45916cd2Sjpk &err) == 0) {
99*45916cd2Sjpk blabel_free(range->lower_bound);
100*45916cd2Sjpk blabel_free(range->upper_bound);
101*45916cd2Sjpk free(range);
102*45916cd2Sjpk errno = ENOTSUP;
103*45916cd2Sjpk return (NULL);
104*45916cd2Sjpk }
105*45916cd2Sjpk freedaent(da);
106*45916cd2Sjpk }
107*45916cd2Sjpk
108*45916cd2Sjpk return (range);
109*45916cd2Sjpk }
110