Module Name:    src
Committed By:   christos
Date:           Sat Apr  7 16:44:39 UTC 2012

Modified Files:
        src/lib/libutil: Makefile shlib_version
Added Files:
        src/lib/libutil: getdiskrawname.3 getdiskrawname.c

Log Message:
- add getdiskrawname.
- exit on error for lint.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/lib/libutil/Makefile
cvs rdiff -u -r0 -r1.1 src/lib/libutil/getdiskrawname.3 \
    src/lib/libutil/getdiskrawname.c
cvs rdiff -u -r1.50 -r1.51 src/lib/libutil/shlib_version

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/Makefile
diff -u src/lib/libutil/Makefile:1.72 src/lib/libutil/Makefile:1.73
--- src/lib/libutil/Makefile:1.72	Sat Apr  7 00:04:45 2012
+++ src/lib/libutil/Makefile	Sat Apr  7 12:44:39 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.72 2012/04/07 04:04:45 christos Exp $
+#	$NetBSD: Makefile,v 1.73 2012/04/07 16:44:39 christos Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 
 USE_SHLIBDIR=	yes
@@ -10,8 +10,9 @@ USE_SHLIBDIR=	yes
 WARNS?=	5
 LIB=	util
 CPPFLAGS+=-DLIBC_SCCS -I${.CURDIR}
+LINTFLAGS+=-w
 SRCS+=	efun.c getbootfile.c getlabelsector.c getmaxpartitions.c \
-	getfsspecname.c getmntopts.c getrawpartition.c \
+	getfsspecname.c getmntopts.c getrawpartition.c getdiskrawname.c \
 	disklabel_dkcksum.c disklabel_scan.c \
 	if_media.c \
 	login.c loginx.c login_cap.c login_tty.c logout.c logoutx.c \
@@ -23,7 +24,7 @@ SRCS+=	efun.c getbootfile.c getlabelsect
 
 MAN=	efun.3 getbootfile.3 getfstypename.3 getlabelsector.3 \
 	getmaxpartitions.3 getmntopts.3 getrawpartition.3 \
-	getfsspecname.3 \
+	getdiskrawname.3 getfsspecname.3 \
 	login.3 login_cap.3 loginx.3 \
 	disklabel_dkcksum.3 disklabel_scan.3 \
 	opendisk.3 openpty.3 parsedate.3 pidfile.3 pidlock.3 \
@@ -39,6 +40,7 @@ YPREFIX=__pd
 
 MLINKS+=getlabelsector.3 getlabeloffset.3
 MLINKS+=getlabelsector.3 getlabelusesmbr.3
+MLINKS+=getdiskrawname.3 getdiskcookedname.3
 MLINKS+=login.3 logout.3
 MLINKS+=login.3 logwtmp.3
 MLINKS+=login_cap.3 login_getclass.3

Index: src/lib/libutil/shlib_version
diff -u src/lib/libutil/shlib_version:1.50 src/lib/libutil/shlib_version:1.51
--- src/lib/libutil/shlib_version:1.50	Sat Apr  7 00:04:45 2012
+++ src/lib/libutil/shlib_version	Sat Apr  7 12:44:39 2012
@@ -1,5 +1,5 @@
-#	$NetBSD: shlib_version,v 1.50 2012/04/07 04:04:45 christos Exp $
+#	$NetBSD: shlib_version,v 1.51 2012/04/07 16:44:39 christos Exp $
 #	Remember to update distrib/sets/lists/base/shl.* when changing
 #
 major=7
-minor=20
+minor=21

Added files:

Index: src/lib/libutil/getdiskrawname.3
diff -u /dev/null src/lib/libutil/getdiskrawname.3:1.1
--- /dev/null	Sat Apr  7 12:44:40 2012
+++ src/lib/libutil/getdiskrawname.3	Sat Apr  7 12:44:39 2012
@@ -0,0 +1,71 @@
+.\"	$NetBSD: getdiskrawname.3,v 1.1 2012/04/07 16:44:39 christos Exp $
+.\"
+.\" Copyright (c) 2012 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Christos Zoulas.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``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 THE FOUNDATION OR CONTRIBUTORS
+.\" 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 March 7, 2012
+.Dt GETDISKRAWNAME 3
+.Os
+.Sh NAME
+.Nm getdiskrawname
+.Nd get the the block/character device name for a disk
+.Sh LIBRARY
+.Lb libutil
+.Sh SYNOPSIS
+.In util.h
+.Ft const char *
+.Fn getdiskrawname "char *buf" "size_t buflen" "const char *name"
+.Ft const char *
+.Fn getdiskcookedname "char *buf" "size_t buflen" "const char *name"
+.Sh DESCRIPTION
+The
+.Fn getdiskrawname
+function converts the
+.Fa name
+argument thar contains a path to a disk block device node to the
+path that contains the corresponding character device node.
+The
+.Fn getdiskcookedname
+function converts the
+.Fa name
+argument thar contains a path to a disk character device node to the
+path that contains the corresponding block device node.
+.Sh RETURN VALUES
+On success the absolute pathname of the underlying device node is returned.
+On failure
+.Dv NULL
+is returned and
+.Va errno
+contains the reason for the error.
+.Sh HISTORY
+The
+.Fn getdiskrawname
+and
+.Fn getdiskcookedname
+functions appeared in
+.Nx 7.0
Index: src/lib/libutil/getdiskrawname.c
diff -u /dev/null src/lib/libutil/getdiskrawname.c:1.1
--- /dev/null	Sat Apr  7 12:44:40 2012
+++ src/lib/libutil/getdiskrawname.c	Sat Apr  7 12:44:39 2012
@@ -0,0 +1,89 @@
+/*	$NetBSD: getdiskrawname.c,v 1.1 2012/04/07 16:44:39 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 THE FOUNDATION OR CONTRIBUTORS
+ * 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>
+__RCSID("$NetBSD: getdiskrawname.c,v 1.1 2012/04/07 16:44:39 christos Exp $");
+
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <util.h>
+
+const char *
+getdiskrawname(char *buf, size_t bufsiz, const char *name)
+{
+	const char *dp = strrchr(name, '/');
+	struct stat st;
+
+	if (dp == NULL) {
+		errno = EINVAL;
+		return NULL;
+	}
+
+	if (stat(name, &st) == -1)
+		return NULL;
+
+	if (!S_ISBLK(st.st_mode)) {
+		errno = EFTYPE;
+		return NULL;
+	}
+
+	(void)snprintf(buf, bufsiz, "%.*s/r%s", (int)(dp - name), name, dp + 1);
+
+	return buf;
+}
+
+const char *
+getdiskcookedname(char *buf, size_t bufsiz, const char *name)
+{
+	const char *dp;
+	struct stat st;
+
+	if ((dp = strrchr(name, '/')) == NULL) {
+		errno = EINVAL;
+		return NULL;
+	}
+	if (stat(name, &st) == -1)
+		return NULL;
+
+	if (!S_ISCHR(st.st_mode)) {
+		errno = EFTYPE;
+		return NULL;
+	}
+	if (dp[1] != 'r') {
+		errno = EINVAL;
+		return NULL;
+	}
+	(void)snprintf(buf, bufsiz, "%.*s/%s", (int)(dp - name), name, dp + 2);
+
+	return buf;
+}

Reply via email to