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