Add getlabelsector() and getlabeloffset() as wrappers around the

KERN_LABELSECTOR and KERN_LABELOFFSET sysctls.
This commit is contained in:
scw 2002-12-12 09:45:32 +00:00
parent f4fe3fda21
commit 0c83fd4944
5 changed files with 159 additions and 5 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.504 2002/12/05 03:59:19 explorer Exp $
# $NetBSD: mi,v 1.505 2002/12/12 09:45:34 scw Exp $
./sys comp-sysutil-root
./usr/bin/addr2line comp-debug-bin
./usr/bin/ar comp-util-bin
@ -2010,6 +2010,8 @@
./usr/share/man/cat3/gethostid.0 comp-c-catman
./usr/share/man/cat3/gethostname.0 comp-c-catman
./usr/share/man/cat3/getifaddrs.0 comp-c-catman
./usr/share/man/cat3/getlabeloffset.0 comp-c-catman
./usr/share/man/cat3/getlabelsector.0 comp-c-catman
./usr/share/man/cat3/getloadavg.0 comp-c-catman
./usr/share/man/cat3/getmaxpartitions.0 comp-c-catman
./usr/share/man/cat3/getmaxx.0 comp-c-catman
@ -4993,6 +4995,8 @@
./usr/share/man/man3/gethostid.3 comp-c-man
./usr/share/man/man3/gethostname.3 comp-c-man
./usr/share/man/man3/getifaddrs.3 comp-c-man
./usr/share/man/man3/getlabeloffset.3 comp-c-man
./usr/share/man/man3/getlabelsector.3 comp-c-man
./usr/share/man/man3/getloadavg.3 comp-c-man
./usr/share/man/man3/getmaxpartitions.3 comp-c-man
./usr/share/man/man3/getmaxx.3 comp-c-man

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.h,v 1.28 2002/11/30 03:04:45 lukem Exp $ */
/* $NetBSD: util.h,v 1.29 2002/12/12 09:45:32 scw Exp $ */
/*-
* Copyright (c) 1995
@ -66,6 +66,8 @@ struct winsize;
pid_t forkpty(int *, char *, struct termios *, struct winsize *);
const char *getbootfile(void);
off_t getlabeloffset(void);
daddr_t getlabelsector(void);
int getmaxpartitions(void);
int getrawpartition(void);
int humanize_number(char *, size_t, int64_t, const char *, int,

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.41 2002/11/30 03:04:46 lukem Exp $
# $NetBSD: Makefile,v 1.42 2002/12/12 09:45:33 scw Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
@ -7,14 +7,14 @@ USE_SHLIBDIR= yes
LIB= util
CPPFLAGS+=-DLIBC_SCCS
SRCS= getbootfile.c getmaxpartitions.c getrawpartition.c \
SRCS= getbootfile.c getlabelsector.c getmaxpartitions.c getrawpartition.c \
disklabel_dkcksum.c disklabel_scan.c \
login.c loginx.c login_cap.c login_tty.c logout.c logoutx.c \
logwtmp.c logwtmpx.c opendisk.c \
passwd.c pw_scan.c pidfile.c pidlock.c pty.c secure_path.c \
snprintb.c ttyaction.c ttymsg.c
MAN= getbootfile.3 getmaxpartitions.3 getrawpartition.3 \
MAN= getbootfile.3 getlabelsector.3 getmaxpartitions.3 getrawpartition.3 \
login.3 login_cap.3 loginx.3 \
disklabel_dkcksum.3 disklabel_scan.3 \
opendisk.3 openpty.3 pidfile.3 pidlock.3 \
@ -23,6 +23,7 @@ MAN= getbootfile.3 getmaxpartitions.3 getrawpartition.3 \
.PATH: ${NETBSDSRCDIR}/lib/libc/gen
MLINKS+=getlabelsector.3 getlabeloffset.3
MLINKS+=login.3 logout.3
MLINKS+=login.3 logwtmp.3
MLINKS+=login_cap.3 login_getclass.3

View File

@ -0,0 +1,72 @@
.\" $NetBSD: getlabelsector.3,v 1.1 2002/12/12 09:45:33 scw Exp $
.\"
.\"
.\" Copyright 2002 Wasabi Systems, Inc.
.\" All rights reserved.
.\"
.\" Written by Steve C. Woodford for Wasabi Systems, Inc.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed for the NetBSD Project by
.\" Wasabi Systems, Inc.
.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse
.\" or promote products derived from this software without specific prior
.\" written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd Dec 11, 2002
.Dt GETLABELSECTOR 3
.Os
.Sh NAME
.Nm getlabelsector
.Nm getlabeloffset
.Nd get the sector number and offset of the disklabel
.Sh LIBRARY
.Lb libutil
.Sh SYNOPSIS
.Fd #include \*[Lt]util.h\*[Gt]
.Ft daddr_t
.Fn getlabelsector void
.Ft off_t
.Fn getlabeloffset void
.Sh DESCRIPTION
The
.Fn getlabelsector
and
.Fn getlabeloffset
functions return values which describe the exact on-disk location of the
.Xr disklabel 5
on the current system, or -1 on error.
These functions supercede the hardcoded LABELSECTOR and LABELOFFSET
definitions previously used to derive the location of the
.Xr disklabel 5 .
.Sh SEE ALSO
.Xr disklabel 5 ,
.Xr sysctl 3
.Sh HISTORY
The
.Fn getlabelsector
and
.Fn getlabeloffset
function calls appeared in
.Nx 1.7 .

View File

@ -0,0 +1,75 @@
/* $NetBSD: getlabelsector.c,v 1.1 2002/12/12 09:45:33 scw Exp $ */
/*
* Copyright 2002 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Steve C. Woodford for Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: getlabelsector.c,v 1.1 2002/12/12 09:45:33 scw Exp $");
#endif
#include <sys/param.h>
#include <sys/sysctl.h>
#include <util.h>
daddr_t
getlabelsector(void)
{
int sector, mib[2];
size_t varlen;
mib[0] = CTL_KERN;
mib[1] = KERN_LABELSECTOR;
varlen = sizeof(sector);
if (sysctl(mib, 2, &sector, &varlen, NULL, 0) < 0)
return (-1);
return ((daddr_t)sector);
}
off_t
getlabeloffset(void)
{
int offset, mib[2];
size_t varlen;
mib[0] = CTL_KERN;
mib[1] = KERN_LABELOFFSET;
varlen = sizeof(offset);
if (sysctl(mib, 2, &offset, &varlen, NULL, 0) < 0)
return (-1);
return ((off_t)offset);
}