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
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 * miscellaneous utilities
37 static int meta_fd
= -1;
38 static major_t meta_major
;
41 * open administrative device
50 /* if not already open */
54 /* try read/write fall back to readonly */
55 if ((meta_fd
= open(ADMSPECIAL
, O_RDWR
, 0)) < 0) {
56 if (errno
== ENOENT
&& getzoneid() != GLOBAL_ZONEID
)
57 return (mderror(ep
, MDE_ZONE_ADMIN
, NULL
));
59 return (mdsyserror(ep
, errno
, ADMSPECIAL
));
60 if ((meta_fd
= open(ADMSPECIAL
, O_RDONLY
, 0)) < 0)
61 return (mdsyserror(ep
, errno
, ADMSPECIAL
));
65 if (fstat(meta_fd
, &buf
) != 0)
66 return (mdsyserror(ep
, errno
, ADMSPECIAL
));
67 meta_major
= major(buf
.st_rdev
);
69 /* check driver version */
70 if (metaioctl(MD_IOCGVERSION
, &dversion
, ep
, NULL
) != 0)
72 if (dversion
!= MD_DVERSION
)
73 return (mderror(ep
, MDE_DVERSION
, NULL
));
86 if (close(meta_fd
) == -1)
87 return (mdsyserror(ep
, errno
, ADMSPECIAL
));
95 * Returns True if the md_dev64_t passed in is a metadevice.
96 * Else it returns False.
104 md_error_t status
= mdnullerror
;
106 fd
= open_admin(&status
);
108 return (meta_getmajor(dev
) == meta_major
);
113 meta_get_nunits(md_error_t
*ep
)
116 static set_t max_nunits
= 0;
119 if (metaioctl(MD_IOCGETNUNITS
, &max_nunits
, ep
, NULL
) != 0)
126 metamakedev(minor_t mnum
)
129 md_error_t status
= mdnullerror
;
131 fd
= open_admin(&status
);
135 return (((md_dev64_t
)meta_major
<< NBITSMINOR64
) | mnum
);