xref: /minix/lib/libutil/getrawpartition.c (revision dba3562d)
1*dba3562dSLionel Sambuc /*	$NetBSD: getrawpartition.c,v 1.7 2012/06/25 22:32:47 abs Exp $	*/
20c3983b2SBen Gras 
30c3983b2SBen Gras /*-
40c3983b2SBen Gras  * Copyright (c) 1996 The NetBSD Foundation, Inc.
50c3983b2SBen Gras  * All rights reserved.
60c3983b2SBen Gras  *
70c3983b2SBen Gras  * This code is derived from software contributed to The NetBSD Foundation
80c3983b2SBen Gras  * by Jason R. Thorpe.
90c3983b2SBen Gras  *
100c3983b2SBen Gras  * Redistribution and use in source and binary forms, with or without
110c3983b2SBen Gras  * modification, are permitted provided that the following conditions
120c3983b2SBen Gras  * are met:
130c3983b2SBen Gras  * 1. Redistributions of source code must retain the above copyright
140c3983b2SBen Gras  *    notice, this list of conditions and the following disclaimer.
150c3983b2SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
160c3983b2SBen Gras  *    notice, this list of conditions and the following disclaimer in the
170c3983b2SBen Gras  *    documentation and/or other materials provided with the distribution.
180c3983b2SBen Gras  *
190c3983b2SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
200c3983b2SBen Gras  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
210c3983b2SBen Gras  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
220c3983b2SBen Gras  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
230c3983b2SBen Gras  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
240c3983b2SBen Gras  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
250c3983b2SBen Gras  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
260c3983b2SBen Gras  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
270c3983b2SBen Gras  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
280c3983b2SBen Gras  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
290c3983b2SBen Gras  * POSSIBILITY OF SUCH DAMAGE.
300c3983b2SBen Gras  */
310c3983b2SBen Gras 
320c3983b2SBen Gras #include <sys/cdefs.h>
330c3983b2SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
34*dba3562dSLionel Sambuc __RCSID("$NetBSD: getrawpartition.c,v 1.7 2012/06/25 22:32:47 abs Exp $");
350c3983b2SBen Gras #endif
360c3983b2SBen Gras 
370c3983b2SBen Gras #include <sys/param.h>
380c3983b2SBen Gras #include <sys/sysctl.h>
390c3983b2SBen Gras #include <util.h>
400c3983b2SBen Gras 
410c3983b2SBen Gras int
getrawpartition(void)42*dba3562dSLionel Sambuc getrawpartition(void)
430c3983b2SBen Gras {
440c3983b2SBen Gras 	int rawpart, mib[2];
450c3983b2SBen Gras 	size_t varlen;
460c3983b2SBen Gras 
470c3983b2SBen Gras 	mib[0] = CTL_KERN;
480c3983b2SBen Gras 	mib[1] = KERN_RAWPARTITION;
490c3983b2SBen Gras 	varlen = sizeof(rawpart);
500c3983b2SBen Gras 	if (sysctl(mib, 2, &rawpart, &varlen, NULL, (size_t)0) < 0)
510c3983b2SBen Gras 		return (-1);
520c3983b2SBen Gras 
530c3983b2SBen Gras 	return (rawpart);
540c3983b2SBen Gras }
55