xref: /netbsd-src/lib/libutil/getlabelsector.c (revision a02f89094ff757f4057d509fd22096b7ac853418)
1*a02f8909Sjmcneill /*	$NetBSD: getlabelsector.c,v 1.5 2011/09/04 12:34:49 jmcneill Exp $	*/
20c83fd49Sscw 
30c83fd49Sscw /*
40c83fd49Sscw  * Copyright 2002 Wasabi Systems, Inc.
50c83fd49Sscw  * All rights reserved.
60c83fd49Sscw  *
70c83fd49Sscw  * Written by Steve C. Woodford for Wasabi Systems, Inc.
80c83fd49Sscw  *
90c83fd49Sscw  * Redistribution and use in source and binary forms, with or without
100c83fd49Sscw  * modification, are permitted provided that the following conditions
110c83fd49Sscw  * are met:
120c83fd49Sscw  * 1. Redistributions of source code must retain the above copyright
130c83fd49Sscw  *    notice, this list of conditions and the following disclaimer.
140c83fd49Sscw  * 2. Redistributions in binary form must reproduce the above copyright
150c83fd49Sscw  *    notice, this list of conditions and the following disclaimer in the
160c83fd49Sscw  *    documentation and/or other materials provided with the distribution.
170c83fd49Sscw  * 3. All advertising materials mentioning features or use of this software
180c83fd49Sscw  *    must display the following acknowledgement:
190c83fd49Sscw  *      This product includes software developed for the NetBSD Project by
200c83fd49Sscw  *      Wasabi Systems, Inc.
210c83fd49Sscw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
220c83fd49Sscw  *    or promote products derived from this software without specific prior
230c83fd49Sscw  *    written permission.
240c83fd49Sscw  *
250c83fd49Sscw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
260c83fd49Sscw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
270c83fd49Sscw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
280c83fd49Sscw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
290c83fd49Sscw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
300c83fd49Sscw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
310c83fd49Sscw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
320c83fd49Sscw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
330c83fd49Sscw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
340c83fd49Sscw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
350c83fd49Sscw  * POSSIBILITY OF SUCH DAMAGE.
360c83fd49Sscw  */
370c83fd49Sscw 
380c83fd49Sscw #include <sys/cdefs.h>
390c83fd49Sscw #if defined(LIBC_SCCS) && !defined(lint)
40*a02f8909Sjmcneill __RCSID("$NetBSD: getlabelsector.c,v 1.5 2011/09/04 12:34:49 jmcneill Exp $");
410c83fd49Sscw #endif
420c83fd49Sscw 
430c83fd49Sscw #include <sys/param.h>
440c83fd49Sscw #include <sys/sysctl.h>
450c83fd49Sscw #include <util.h>
460c83fd49Sscw 
47a3ff3a30Sfvdl int
getlabelsector(void)480c83fd49Sscw getlabelsector(void)
490c83fd49Sscw {
500c83fd49Sscw 	int sector, mib[2];
510c83fd49Sscw 	size_t varlen;
520c83fd49Sscw 
530c83fd49Sscw 	mib[0] = CTL_KERN;
540c83fd49Sscw 	mib[1] = KERN_LABELSECTOR;
550c83fd49Sscw 	varlen = sizeof(sector);
5602197be1Selad 	if (sysctl(mib, 2, &sector, &varlen, NULL, (size_t)0) < 0)
570c83fd49Sscw 		return (-1);
580c83fd49Sscw 
59a3ff3a30Sfvdl 	return sector;
600c83fd49Sscw }
610c83fd49Sscw 
620c83fd49Sscw off_t
getlabeloffset(void)630c83fd49Sscw getlabeloffset(void)
640c83fd49Sscw {
650c83fd49Sscw 	int offset, mib[2];
660c83fd49Sscw 	size_t varlen;
670c83fd49Sscw 
680c83fd49Sscw 	mib[0] = CTL_KERN;
690c83fd49Sscw 	mib[1] = KERN_LABELOFFSET;
700c83fd49Sscw 	varlen = sizeof(offset);
7102197be1Selad 	if (sysctl(mib, 2, &offset, &varlen, NULL, (size_t)0) < 0)
720c83fd49Sscw 		return (-1);
730c83fd49Sscw 
740c83fd49Sscw 	return ((off_t)offset);
750c83fd49Sscw }
76a47e2eb7Sbouyer 
77a47e2eb7Sbouyer int
getlabelusesmbr(void)78a47e2eb7Sbouyer getlabelusesmbr(void)
79a47e2eb7Sbouyer {
80a47e2eb7Sbouyer 	int use;
81a47e2eb7Sbouyer 	size_t uselen;
82a47e2eb7Sbouyer 
83*a02f8909Sjmcneill 	uselen = sizeof(use);
84a47e2eb7Sbouyer 	if (sysctlbyname("kern.labelusesmbr", &use, &uselen,
85a47e2eb7Sbouyer 	    NULL, (size_t)0) < 0)
86a47e2eb7Sbouyer 		return (-1);
87a47e2eb7Sbouyer 
88a47e2eb7Sbouyer 	return use;
89a47e2eb7Sbouyer }
90