Subject: savecore compression
To: None <tech-userlevel@netbsd.org>
From: Johan Danielsson <joda@pdc.kth.se>
List: tech-userlevel
Date: 12/29/2000 17:26:08
Any reason for it to still use compress? Gzip gives about 30% size
reduction (on my test crash-dump) with the same running time.
Executable size is a bit larger though (~40k on i386).

/Johan

Index: savecore.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/savecore/savecore.c,v
retrieving revision 1.47
diff -w -u -r1.47 savecore.c
--- savecore.c	2000/12/11 14:33:51	1.47
+++ savecore.c	2000/12/29 16:04:04
@@ -67,7 +67,7 @@
 #include <limits.h>
 #include <kvm.h>
 
-extern FILE *zopen(const char *fname, const char *mode, int bits);
+extern FILE *zopen(const char *fname, const char *mode);
 
 #define KREAD(kd, addr, p)\
 	(kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p)))
@@ -427,9 +427,9 @@
 
 	/* Create the core file. */
 	(void)snprintf(path, sizeof(path), "%s/netbsd.%d.core%s",
-	    dirname, bounds, compress ? ".Z" : "");
+	    dirname, bounds, compress ? ".gz" : "");
 	if (compress) {
-		if ((fp = zopen(path, "w", 0)) == NULL) {
+		if ((fp = zopen(path, "w")) == NULL) {
 			syslog(LOG_ERR, "%s: %m", path);
 			exit(1);
 		}
@@ -489,9 +489,9 @@
 	/* Copy the kernel. */
 	ifd = Open(kernel ? kernel : _PATH_UNIX, O_RDONLY);
 	(void)snprintf(path, sizeof(path), "%s/netbsd.%d%s",
-	    dirname, bounds, compress ? ".Z" : "");
+	    dirname, bounds, compress ? ".gz" : "");
 	if (compress) {
-		if ((fp = zopen(path, "w", 0)) == NULL) {
+		if ((fp = zopen(path, "w")) == NULL) {
 			syslog(LOG_ERR, "%s: %m", path);
 			exit(1);
 		}
Index: zopen.c
===================================================================
RCS file: zopen.c
diff -N zopen.c
--- /dev/null	Fri Dec 29 04:52:43 2000
+++ zopen.c	Fri Dec 29 18:04:04 2000
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <zlib.h>
+#include <errno.h>
+
+FILE *zopen(const char *fname, const char *mode);
+
+/* convert arguments */
+static int xgzread(void *cookie, char *data, int size)
+{
+    return gzread(cookie, data, size);
+}
+
+static int xgzwrite(void *cookie, const char *data, int size)
+{
+    return gzwrite(cookie, (void*)data, size);
+}
+
+FILE *
+zopen(const char *fname, const char *mode)
+{
+    gzFile gz = gzopen(fname, mode);
+    if(gz == NULL)
+	return NULL;
+
+    if(*mode == 'r')
+	return (funopen(gz, xgzread, NULL, NULL, gzclose));
+    else
+	return (funopen(gz, NULL, xgzwrite, NULL, gzclose));
+}
Index: savecore.8
===================================================================
RCS file: /cvsroot/basesrc/sbin/savecore/savecore.8,v
retrieving revision 1.17
diff -w -u -r1.17 savecore.8
--- savecore.8	2000/12/07 03:18:03	1.17
+++ savecore.8	2000/12/29 16:04:04
@@ -106,7 +106,7 @@
 Prints out some additional debugging information.
 .It Fl z
 Compresses the core dump and kernel (see
-.Xr compress 1 ).
+.Xr gzip 1 ).
 .El
 .Pp
 .Nm
@@ -117,9 +117,9 @@
 and the system in
 .Ar directory Ns Pa /netbsd.#
 (or in
-.Ar directory Ns Pa /netbsd.#.core.Z
+.Ar directory Ns Pa /netbsd.#.core.gz
 and
-.Ar directory Ns Pa /netbsd.#.Z ,
+.Ar directory Ns Pa /netbsd.#.gz ,
 respectively, if the
 .Fl z
 option is used).
@@ -154,10 +154,10 @@
 .Sh BUGS
 The minfree code does not consider the effect of compression.
 .Sh SEE ALSO
-.Xr compress 1 ,
 .Xr dmesg 8 ,
 .Xr fstat 1 ,
 .Xr gdb 1 ,
+.Xr gzip 1 ,
 .Xr iostat 8 ,
 .Xr netstat 1 ,
 .Xr ps 1 , 
Index: Makefile
===================================================================
RCS file: /cvsroot/basesrc/sbin/savecore/Makefile,v
retrieving revision 1.23
diff -w -u -r1.23 Makefile
--- Makefile	1998/02/19 23:43:37	1.23
+++ Makefile	2000/12/29 16:04:04
@@ -6,8 +6,7 @@
 
 MAN=	savecore.8
 
-LDADD=	-lkvm
+LDADD=	-lkvm -lz
 DPADD=	${LIBKVM}
-.PATH:	${.CURDIR}/../../usr.bin/compress
 
 .include <bsd.prog.mk>