Module Name:    src
Committed By:   pooka
Date:           Tue Sep  8 21:36:35 UTC 2009

Modified Files:
        src/sbin/cgdconfig: Makefile cgdconfig.c
Added Files:
        src/sbin/cgdconfig: Makefile.cgdconfig cgd_kernelops.c cgd_kernelops.h

Log Message:
* allow specification of kernel operations vector
* make it possible to build cgdconfig as a library


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sbin/cgdconfig/Makefile
cvs rdiff -u -r0 -r1.1 src/sbin/cgdconfig/Makefile.cgdconfig \
    src/sbin/cgdconfig/cgd_kernelops.c src/sbin/cgdconfig/cgd_kernelops.h
cvs rdiff -u -r1.27 -r1.28 src/sbin/cgdconfig/cgdconfig.c

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

Modified files:

Index: src/sbin/cgdconfig/Makefile
diff -u src/sbin/cgdconfig/Makefile:1.11 src/sbin/cgdconfig/Makefile:1.12
--- src/sbin/cgdconfig/Makefile:1.11	Mon Apr 20 16:05:30 2009
+++ src/sbin/cgdconfig/Makefile	Tue Sep  8 21:36:35 2009
@@ -1,20 +1,10 @@
-# $NetBSD: Makefile,v 1.11 2009/04/20 16:05:30 drochner Exp $
+# $NetBSD: Makefile,v 1.12 2009/09/08 21:36:35 pooka Exp $
 
 PROG=	cgdconfig
 MAN=	cgdconfig.8
 
-SRCS=	cgdconfig.c		\
-	cgdlex.l		\
-	cgdparse.y		\
-	pkcs5_pbkdf2.c		\
-	params.c		\
-	utils.c
+SRCS+=	cgd_kernelops.c
 
-CPPFLAGS+= -I${.CURDIR} -I. -DYY_NO_INPUT
-
-YHEADER=1
-
-DPADD=  ${LIBUTIL} ${LIBCRYPTO} ${LIBCRYPT} ${LIBY} ${LIBL}
-LDADD=  -lutil -lcrypto -lcrypt -ly -ll
+.include "${.CURDIR}/Makefile.cgdconfig"
 
 .include <bsd.prog.mk>

Index: src/sbin/cgdconfig/cgdconfig.c
diff -u src/sbin/cgdconfig/cgdconfig.c:1.27 src/sbin/cgdconfig/cgdconfig.c:1.28
--- src/sbin/cgdconfig/cgdconfig.c:1.27	Thu Jul 24 19:07:36 2008
+++ src/sbin/cgdconfig/cgdconfig.c	Tue Sep  8 21:36:35 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdconfig.c,v 1.27 2008/07/24 19:07:36 christos Exp $ */
+/* $NetBSD: cgdconfig.c,v 1.28 2009/09/08 21:36:35 pooka Exp $ */
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 2002, 2003\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: cgdconfig.c,v 1.27 2008/07/24 19:07:36 christos Exp $");
+__RCSID("$NetBSD: cgdconfig.c,v 1.28 2009/09/08 21:36:35 pooka Exp $");
 #endif
 
 #include <err.h>
@@ -59,6 +59,8 @@
 #include "params.h"
 #include "pkcs5_pbkdf2.h"
 #include "utils.h"
+#include "cgd_kernelops.h"
+#include "cgdconfig.h"
 
 #define CGDCONFIG_DIR		"/etc/cgd"
 #define CGDCONFIG_CFILE		CGDCONFIG_DIR "/cgd.conf"
@@ -168,9 +170,18 @@
 	*action = value;
 }
 
+#ifndef CGDCONFIG_AS_LIB
 int
 main(int argc, char **argv)
 {
+
+	return cgdconfig(argc, argv);
+}
+#endif
+
+int
+cgdconfig(int argc, char *argv[])
+{
 	struct params *p;
 	struct params *tp;
 	struct keygen *kg;
@@ -447,7 +458,7 @@
 	if (flags == CONFIG_FLAGS_FROMALL && (argc < 2 || argc > 3))
 		return -1;
 
-	fd = opendisk(*argv, O_RDWR, buf, sizeof(buf), 1);
+	fd = opendisk1(*argv, O_RDWR, buf, sizeof(buf), 1, cgd_kops.ko_open);
 	if (fd == -1) {
 		int saved_errno = errno;
 
@@ -464,7 +475,7 @@
 		return 0;
 
 	ret = unconfigure_fd(fd);
-	(void)close(fd);
+	(void)cgd_kops.ko_close(fd);
 	return ret;
 }
 
@@ -473,7 +484,7 @@
 {
 	struct	cgd_ioctl ci;
 
-	if (ioctl(fd, CGDIOCCLR, &ci) == -1) {
+	if (cgd_kops.ko_ioctl(fd, CGDIOCCLR, &ci) == -1) {
 		warn("ioctl");
 		return -1;
 	}
@@ -572,7 +583,7 @@
 			break;
 
 		(void)unconfigure_fd(fd);
-		(void)close(fd);
+		(void)cgd_kops.ko_close(fd);
 
 		if (!loop) {
 			warnx("verification failed permanently");
@@ -583,11 +594,11 @@
 	}
 
 	params_free(p);
-	(void)close(fd);
+	(void)cgd_kops.ko_close(fd);
 	return 0;
 bail_err:
 	params_free(p);
-	(void)close(fd);
+	(void)cgd_kops.ko_close(fd);
 	return -1;
 }
 
@@ -646,7 +657,7 @@
 		return 0;
 	}
 
-	fd = opendisk(cgd, O_RDWR, buf, buflen, 0);
+	fd = opendisk1(cgd, O_RDWR, buf, buflen, 0, cgd_kops.ko_open);
 	if (fd == -1)
 		warnx("can't open cgd \"%s\", \"%s\"", cgd, buf);
 
@@ -680,7 +691,7 @@
 	if (nflag)
 		return 0;
 
-	if (ioctl(fd, CGDIOCSET, &ci) == -1) {
+	if (cgd_kops.ko_ioctl(fd, CGDIOCSET, &ci) == -1) {
 		int saved_errno = errno;
 		warn("ioctl");
 		return saved_errno;
@@ -728,7 +739,7 @@
 	 * partition information.
 	 */
 
-	ret = pread(fd, buf, 8192, 0);
+	ret = cgd_kops.ko_pread(fd, buf, 8192, 0);
 	if (ret < 0) {
 		warn("can't read disklabel area");
 		return -1;
@@ -753,7 +764,7 @@
 		} u;
 		ssize_t ret;
 
-		ret = pread(fd, &u, sizeof(u), sblock_try[i]);
+		ret = cgd_kops.ko_pread(fd, &u, sizeof(u), sblock_try[i]);
 		if (ret < 0) {
 			warn("pread");
 			break;

Added files:

Index: src/sbin/cgdconfig/Makefile.cgdconfig
diff -u /dev/null src/sbin/cgdconfig/Makefile.cgdconfig:1.1
--- /dev/null	Tue Sep  8 21:36:35 2009
+++ src/sbin/cgdconfig/Makefile.cgdconfig	Tue Sep  8 21:36:35 2009
@@ -0,0 +1,24 @@
+#	$NetBSD: Makefile.cgdconfig,v 1.1 2009/09/08 21:36:35 pooka Exp $
+#
+
+SRCS+=	cgdconfig.c		\
+	cgdlex.l		\
+	cgdparse.y		\
+	pkcs5_pbkdf2.c		\
+	params.c		\
+	utils.c
+
+CPPFLAGS+= -I${.CURDIR} -I. -DYY_NO_INPUT
+
+YHEADER=1
+
+DPADD=  ${LIBUTIL} ${LIBCRYPTO} ${LIBCRYPT} ${LIBY} ${LIBL}
+LDADD=  -lutil -lcrypto -lcrypt -ly -ll
+
+.include <bsd.own.mk>
+
+CGDCONFIGDIR=	${NETBSDSRCDIR}/sbin/cgdconfig
+
+.PATH:	${CGDCONFIGDIR}
+
+CPPFLAGS+=	-I${CGDCONFIGDIR}
Index: src/sbin/cgdconfig/cgd_kernelops.c
diff -u /dev/null src/sbin/cgdconfig/cgd_kernelops.c:1.1
--- /dev/null	Tue Sep  8 21:36:35 2009
+++ src/sbin/cgdconfig/cgd_kernelops.c	Tue Sep  8 21:36:35 2009
@@ -0,0 +1,47 @@
+/*	$NetBSD: cgd_kernelops.c,v 1.1 2009/09/08 21:36:35 pooka Exp $	*/
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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>
+#ifndef lint
+__RCSID("$NetBSD: cgd_kernelops.c,v 1.1 2009/09/08 21:36:35 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "cgd_kernelops.h"
+
+const struct cgd_kernelops cgd_kops = {
+	.ko_open = (void *)open, /* XXX: rump_syscalls prototype */
+	.ko_ioctl = (void *)ioctl,
+	.ko_pread = pread,
+	.ko_close = close,
+};
Index: src/sbin/cgdconfig/cgd_kernelops.h
diff -u /dev/null src/sbin/cgdconfig/cgd_kernelops.h:1.1
--- /dev/null	Tue Sep  8 21:36:35 2009
+++ src/sbin/cgdconfig/cgd_kernelops.h	Tue Sep  8 21:36:35 2009
@@ -0,0 +1,45 @@
+/*      $NetBSD: cgd_kernelops.h,v 1.1 2009/09/08 21:36:35 pooka Exp $	*/
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef _CGD_KERNEL_OPS_H_
+#define _CGD_KERNEL_OPS_H_
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <fcntl.h>
+
+struct cgd_kernelops {
+	int (*ko_open)(const char *, int, mode_t);
+	int (*ko_ioctl)(int, unsigned long, void *);
+	int (*ko_close)(int);
+	int (*ko_pread)(int, void *, size_t, off_t);
+};
+extern const struct cgd_kernelops cgd_kops;
+
+#endif /* _CGD_KERNEL_OPS_H_ */

Reply via email to