Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libutil - add getdiskrawname.



details:   https://anonhg.NetBSD.org/src/rev/48c1622a9fd4
branches:  trunk
changeset: 778661:48c1622a9fd4
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Apr 07 16:44:39 2012 +0000

description:
- add getdiskrawname.
- exit on error for lint.

diffstat:

 lib/libutil/Makefile         |   8 ++-
 lib/libutil/getdiskrawname.3 |  71 +++++++++++++++++++++++++++++++++++
 lib/libutil/getdiskrawname.c |  89 ++++++++++++++++++++++++++++++++++++++++++++
 lib/libutil/shlib_version    |   4 +-
 4 files changed, 167 insertions(+), 5 deletions(-)

diffs (216 lines):

diff -r bbdc919c7b42 -r 48c1622a9fd4 lib/libutil/Makefile
--- a/lib/libutil/Makefile      Sat Apr 07 16:44:10 2012 +0000
+++ b/lib/libutil/Makefile      Sat Apr 07 16:44:39 2012 +0000
@@ -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 @@
 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 @@
 
 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 @@
 
 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
diff -r bbdc919c7b42 -r 48c1622a9fd4 lib/libutil/getdiskrawname.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libutil/getdiskrawname.3      Sat Apr 07 16:44:39 2012 +0000
@@ -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
diff -r bbdc919c7b42 -r 48c1622a9fd4 lib/libutil/getdiskrawname.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libutil/getdiskrawname.c      Sat Apr 07 16:44:39 2012 +0000
@@ -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;
+}
diff -r bbdc919c7b42 -r 48c1622a9fd4 lib/libutil/shlib_version
--- a/lib/libutil/shlib_version Sat Apr 07 16:44:10 2012 +0000
+++ b/lib/libutil/shlib_version Sat Apr 07 16:44:39 2012 +0000
@@ -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



Home | Main Index | Thread Index | Old Index