xref: /netbsd-src/lib/libutil/getrawpartition.c (revision 9e66e6d75e9910b3de5f4ef031995955f69a7dd1)
1*9e66e6d7Sabs /*	$NetBSD: getrawpartition.c,v 1.7 2012/06/25 22:32:47 abs Exp $	*/
27795b411Sthorpej 
37795b411Sthorpej /*-
47795b411Sthorpej  * Copyright (c) 1996 The NetBSD Foundation, Inc.
57795b411Sthorpej  * All rights reserved.
67795b411Sthorpej  *
77795b411Sthorpej  * This code is derived from software contributed to The NetBSD Foundation
87795b411Sthorpej  * by Jason R. Thorpe.
97795b411Sthorpej  *
107795b411Sthorpej  * Redistribution and use in source and binary forms, with or without
117795b411Sthorpej  * modification, are permitted provided that the following conditions
127795b411Sthorpej  * are met:
137795b411Sthorpej  * 1. Redistributions of source code must retain the above copyright
147795b411Sthorpej  *    notice, this list of conditions and the following disclaimer.
157795b411Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
167795b411Sthorpej  *    notice, this list of conditions and the following disclaimer in the
177795b411Sthorpej  *    documentation and/or other materials provided with the distribution.
187795b411Sthorpej  *
197795b411Sthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
207795b411Sthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
217795b411Sthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2223bee85aSjtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2323bee85aSjtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
247795b411Sthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
257795b411Sthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
267795b411Sthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
277795b411Sthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
287795b411Sthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
297795b411Sthorpej  * POSSIBILITY OF SUCH DAMAGE.
307795b411Sthorpej  */
317795b411Sthorpej 
32f5646a08Schristos #include <sys/cdefs.h>
337795b411Sthorpej #if defined(LIBC_SCCS) && !defined(lint)
34*9e66e6d7Sabs __RCSID("$NetBSD: getrawpartition.c,v 1.7 2012/06/25 22:32:47 abs Exp $");
357795b411Sthorpej #endif
367795b411Sthorpej 
377795b411Sthorpej #include <sys/param.h>
387795b411Sthorpej #include <sys/sysctl.h>
397795b411Sthorpej #include <util.h>
407795b411Sthorpej 
417795b411Sthorpej int
getrawpartition(void)42*9e66e6d7Sabs getrawpartition(void)
437795b411Sthorpej {
447795b411Sthorpej 	int rawpart, mib[2];
457795b411Sthorpej 	size_t varlen;
467795b411Sthorpej 
477795b411Sthorpej 	mib[0] = CTL_KERN;
487795b411Sthorpej 	mib[1] = KERN_RAWPARTITION;
497795b411Sthorpej 	varlen = sizeof(rawpart);
50232f61faSelad 	if (sysctl(mib, 2, &rawpart, &varlen, NULL, (size_t)0) < 0)
517795b411Sthorpej 		return (-1);
527795b411Sthorpej 
537795b411Sthorpej 	return (rawpart);
547795b411Sthorpej }
55