1*87afc19eSderaadt /* $OpenBSD: getrawpartition.c,v 1.11 2020/10/12 22:08:34 deraadt Exp $ */
24b826ba8Sderaadt /* $NetBSD: getrawpartition.c,v 1.1 1996/05/16 07:03:33 thorpej Exp $ */
34b826ba8Sderaadt
44b826ba8Sderaadt /*-
54b826ba8Sderaadt * Copyright (c) 1996 The NetBSD Foundation, Inc.
64b826ba8Sderaadt * All rights reserved.
74b826ba8Sderaadt *
84b826ba8Sderaadt * This code is derived from software contributed to The NetBSD Foundation
94b826ba8Sderaadt * by Jason R. Thorpe.
104b826ba8Sderaadt *
114b826ba8Sderaadt * Redistribution and use in source and binary forms, with or without
124b826ba8Sderaadt * modification, are permitted provided that the following conditions
134b826ba8Sderaadt * are met:
144b826ba8Sderaadt * 1. Redistributions of source code must retain the above copyright
154b826ba8Sderaadt * notice, this list of conditions and the following disclaimer.
164b826ba8Sderaadt * 2. Redistributions in binary form must reproduce the above copyright
174b826ba8Sderaadt * notice, this list of conditions and the following disclaimer in the
184b826ba8Sderaadt * documentation and/or other materials provided with the distribution.
194b826ba8Sderaadt *
204b826ba8Sderaadt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
214b826ba8Sderaadt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
224b826ba8Sderaadt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
234b826ba8Sderaadt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
244b826ba8Sderaadt * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
254b826ba8Sderaadt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
264b826ba8Sderaadt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
274b826ba8Sderaadt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
284b826ba8Sderaadt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
294b826ba8Sderaadt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
304b826ba8Sderaadt * POSSIBILITY OF SUCH DAMAGE.
314b826ba8Sderaadt */
324b826ba8Sderaadt
33429b3653Sderaadt #include <sys/types.h>
344b826ba8Sderaadt #include <sys/sysctl.h>
3507c8d458Sguenther #include <stdio.h> /* for NULL */
36ad69070aSdownsj
37ad69070aSdownsj #include "util.h"
384b826ba8Sderaadt
394b826ba8Sderaadt int
getrawpartition(void)401477552aSderaadt getrawpartition(void)
414b826ba8Sderaadt {
42*87afc19eSderaadt const int mib[2] = { CTL_KERN, KERN_RAWPARTITION };
43*87afc19eSderaadt int rawpart;
444b826ba8Sderaadt size_t varlen;
454b826ba8Sderaadt
464b826ba8Sderaadt varlen = sizeof(rawpart);
47df69c215Sderaadt if (sysctl(mib, 2, &rawpart, &varlen, NULL, (size_t)0) == -1)
484b826ba8Sderaadt return (-1);
494b826ba8Sderaadt
504b826ba8Sderaadt return (rawpart);
514b826ba8Sderaadt }
52