[Glibc-bsd-commits] r3189 - in trunk/freebsd-utils/debian: . patches

Robert Millan rmh at alioth.debian.org
Sun Sep 19 20:13:29 UTC 2010


Author: rmh
Date: 2010-09-19 20:13:17 +0000 (Sun, 19 Sep 2010)
New Revision: 3189

Added:
   trunk/freebsd-utils/debian/patches/000_mkuzip.diff
Modified:
   trunk/freebsd-utils/debian/patches/series
   trunk/freebsd-utils/debian/rules
Log:
Add mkuzip as a patch.

Added: trunk/freebsd-utils/debian/patches/000_mkuzip.diff
===================================================================
--- trunk/freebsd-utils/debian/patches/000_mkuzip.diff	                        (rev 0)
+++ trunk/freebsd-utils/debian/patches/000_mkuzip.diff	2010-09-19 20:13:17 UTC (rev 3189)
@@ -0,0 +1,403 @@
+diff -Nur a/usr.bin/mkuzip/Makefile b/usr.bin/mkuzip/Makefile
+--- a/usr.bin/mkuzip/Makefile	1970-01-01 01:00:00.000000000 +0100
++++ b/usr.bin/mkuzip/Makefile	2005-05-02 19:38:49.000000000 +0200
+@@ -0,0 +1,11 @@
++# $FreeBSD$
++
++PROG=	mkuzip
++MAN=	mkuzip.8
++
++DPADD=	${LIBZ}
++LDADD=	-lz
++
++WARNS?=	6
++
++.include <bsd.prog.mk>
+diff -Nur a/usr.bin/mkuzip/mkuzip.8 b/usr.bin/mkuzip/mkuzip.8
+--- a/usr.bin/mkuzip/mkuzip.8	1970-01-01 01:00:00.000000000 +0100
++++ b/usr.bin/mkuzip/mkuzip.8	2006-09-29 17:20:48.000000000 +0200
+@@ -0,0 +1,106 @@
++.\" ----------------------------------------------------------------------------
++.\" "THE BEER-WARE LICENSE" (Revision 42):
++.\" <sobomax at FreeBSD.ORG> wrote this file. As long as you retain this notice you
++.\" can do whatever you want with this stuff. If we meet some day, and you think
++.\" this stuff is worth it, you can buy me a beer in return.       Maxim Sobolev
++.\" ----------------------------------------------------------------------------
++.\"
++.\" $FreeBSD$
++.\"
++.Dd March 17, 2006
++.Dt MKUZIP 8
++.Os
++.Sh NAME
++.Nm mkuzip
++.Nd compress disk image for use with
++.Xr geom_uzip 4
++class
++.Sh SYNOPSIS
++.Nm
++.Op Fl v
++.Op Fl o Ar outfile
++.Op Fl s Ar cluster_size
++.Ar infile
++.Sh DESCRIPTION
++The
++.Nm
++utility compresses a disk image file so that the
++.Xr geom_uzip 4
++class will be able to decompress the resulting image at run-time.
++This allows for a significant reduction of size of disk image at
++the expense of some CPU time required to decompress the data each
++time it is read.
++The
++.Nm
++utility
++works in two phases:
++.Bl -enum
++.It
++An
++.Ar infile
++image is split into clusters; each cluster is compressed using
++.Xr zlib 3 .
++.It
++The resulting set of compressed clusters along with headers that allow
++locating each individual cluster is written to the output file.
++.El
++.Pp
++The options are:
++.Bl -tag -width indent
++.It Fl o Ar outfile
++Name of the output file
++.Ar outfile .
++The default is to use the input name with the suffix
++.Pa .uzip .
++.It Fl s Ar cluster_size
++Split the image into clusters of
++.Ar cluster_size
++bytes, 16384 bytes by default.
++The
++.Ar cluster_size
++should be a multiple of 512 bytes.
++.It Fl v
++Display verbose messages.
++.El
++.Sh NOTES
++The compression ratio largely depends on the cluster size used.
++.\" The following two sentences are unclear: how can gzip(1) be
++.\" used in a comparable fashion, and wouldn't a gzip-compressed
++.\" image suffer from larger cluster sizes as well?
++For large cluster sizes (16K and higher), typical compression ratios
++are only 1-2% less than those achieved with
++.Xr gzip 1 .
++However, it should be kept in mind that larger cluster
++sizes lead to higher overhead in the
++.Xr geom_uzip 4
++class, as the class has to decompress the whole cluster even if
++only a few bytes from that cluster have to be read.
++.Pp
++The
++.Nm
++utility
++inserts a short shell script at the beginning of the generated image,
++which makes it possible to
++.Dq run
++the image just like any other shell script.
++The script tries to load the
++.Xr geom_uzip 4
++class if it is not loaded, configure the image as an
++.Xr md 4
++disk device using
++.Xr mdconfig 8 ,
++and automatically mount it using
++.Xr mount_cd9660 8
++on the mount point provided as the first argument to the script.
++.Sh EXIT STATUS
++.Ex -std
++.Sh SEE ALSO
++.Xr gzip 1 ,
++.Xr zlib 3 ,
++.Xr geom 4 ,
++.Xr geom_uzip 4 ,
++.Xr md 4 ,
++.Xr mdconfig 8 ,
++.Xr mount_cd9660 8
++.Sh AUTHORS
++.An Maxim Sobolev Aq sobomax at FreeBSD.org
+diff -Nur a/usr.bin/mkuzip/mkuzip.c b/usr.bin/mkuzip/mkuzip.c
+--- a/usr.bin/mkuzip/mkuzip.c	1970-01-01 01:00:00.000000000 +0100
++++ b/usr.bin/mkuzip/mkuzip.c	2007-03-06 18:04:15.000000000 +0100
+@@ -0,0 +1,274 @@
++/*
++ * ----------------------------------------------------------------------------
++ * "THE BEER-WARE LICENSE" (Revision 42):
++ * <sobomax at FreeBSD.ORG> wrote this file. As long as you retain this notice you
++ * can do whatever you want with this stuff. If we meet some day, and you think
++ * this stuff is worth it, you can buy me a beer in return.       Maxim Sobolev
++ * ----------------------------------------------------------------------------
++ *
++ * $FreeBSD$
++ *
++ */
++
++#include <sys/types.h>
++#include <sys/disk.h>
++#include <sys/endian.h>
++#include <sys/param.h>
++#include <sys/stat.h>
++#include <sys/uio.h>
++#include <netinet/in.h>
++#include <zlib.h>
++#include <err.h>
++#include <fcntl.h>
++#include <signal.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <unistd.h>
++
++#define CLSTSIZE	16384
++#define DEFAULT_SUFX	".uzip"
++
++#define CLOOP_MAGIC_LEN 128
++static char CLOOP_MAGIC_START[] = "#!/bin/sh\n#V2.0 Format\n"
++    "m=geom_uzip\n(kldstat -m $m 2>&-||kldload $m)>&-&&"
++    "mount_cd9660 /dev/`mdconfig -af $0`.uzip $1\nexit $?\n";
++
++static char *readblock(int, char *, u_int32_t);
++static void usage(void);
++static void *safe_malloc(size_t);
++static void cleanup(void);
++
++static char *cleanfile = NULL;
++
++int main(int argc, char **argv)
++{
++	char *iname, *oname, *obuf, *ibuf;
++	uint64_t *toc;
++	int fdr, fdw, i, opt, verbose, tmp;
++	struct iovec iov[2];
++	struct stat sb;
++	uLongf destlen;
++	uint64_t offset;
++	struct cloop_header {
++		char magic[CLOOP_MAGIC_LEN];    /* cloop magic */
++		uint32_t blksz;                 /* block size */
++		uint32_t nblocks;               /* number of blocks */
++	} hdr;
++
++	memset(&hdr, 0, sizeof(hdr));
++	hdr.blksz = CLSTSIZE;
++	strcpy(hdr.magic, CLOOP_MAGIC_START);
++	oname = NULL;
++	verbose = 0;
++
++	while((opt = getopt(argc, argv, "o:s:v")) != -1) {
++		switch(opt) {
++		case 'o':
++			oname = optarg;
++			break;
++
++		case 's':
++			tmp = atoi(optarg);
++			if (tmp <= 0) {
++				errx(1, "invalid cluster size specified: %s",
++				    optarg);
++				/* Not reached */
++			}
++			if (tmp % DEV_BSIZE != 0) {
++				errx(1, "cluster size should be multiple of %d",
++				    DEV_BSIZE);
++				/* Not reached */
++			}
++			if (compressBound(tmp) > MAXPHYS) {
++				errx(1, "cluster size is too large");
++				    /* Not reached */
++			}
++			hdr.blksz = tmp;
++			break;
++
++		case 'v':
++			verbose = 1;
++			break;
++
++		default:
++			usage();
++			/* Not reached */
++		}
++	}
++	argc -= optind;
++	argv += optind;
++
++	if (argc != 1) {
++		usage();
++		/* Not reached */
++	}
++
++	iname = argv[0];
++	if (oname == NULL) {
++		asprintf(&oname, "%s%s", iname, DEFAULT_SUFX);
++		if (oname == NULL) {
++			err(1, "can't allocate memory");
++			/* Not reached */
++		}
++	}
++
++	obuf = safe_malloc(compressBound(hdr.blksz));
++	ibuf = safe_malloc(hdr.blksz);
++
++	signal(SIGHUP, exit);
++	signal(SIGINT, exit);
++	signal(SIGTERM, exit);
++	signal(SIGXCPU, exit);
++	signal(SIGXFSZ, exit);
++	atexit(cleanup);
++
++	fdr = open(iname, O_RDONLY);
++	if (fdr < 0) {
++		err(1, "open(%s)", iname);
++		/* Not reached */
++	}
++	if (fstat(fdr, &sb) != 0) {
++		err(1, "fstat(%s)", iname);
++		/* Not reached */
++	}
++	if (S_ISCHR(sb.st_mode)) {
++		off_t ms;
++
++		if (ioctl(fdr, DIOCGMEDIASIZE, &ms) < 0) {
++			err(1, "ioctl(DIOCGMEDIASIZE)");
++			/* Not reached */
++		}
++		sb.st_size = ms;
++	} else if (!S_ISREG(sb.st_mode)) {
++		fprintf(stderr, "%s: not a character device or regular file\n",
++			iname);
++		exit(1);
++	}
++	hdr.nblocks = sb.st_size / hdr.blksz;
++	if ((sb.st_size % hdr.blksz) != 0) {
++		if (verbose != 0)
++			fprintf(stderr, "file size is not multiple "
++			"of %d, padding data\n", hdr.blksz);
++		hdr.nblocks++;
++	}
++	toc = safe_malloc((hdr.nblocks + 1) * sizeof(*toc));
++
++	fdw = open(oname, O_WRONLY | O_TRUNC | O_CREAT,
++		   S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
++	if (fdw < 0) {
++		err(1, "open(%s)", oname);
++		/* Not reached */
++	}
++	cleanfile = oname;
++
++	/* Prepare header that we will write later when we have index ready. */
++	iov[0].iov_base = (char *)&hdr;
++	iov[0].iov_len = sizeof(hdr);
++	iov[1].iov_base = (char *)toc;
++	iov[1].iov_len = (hdr.nblocks + 1) * sizeof(*toc);
++	offset = iov[0].iov_len + iov[1].iov_len;
++
++	/* Reserve space for header */
++	lseek(fdw, offset, SEEK_SET);
++
++	if (verbose != 0)
++		fprintf(stderr, "data size %ju bytes, number of clusters "
++		    "%u, index length %zu bytes\n", sb.st_size,
++		    hdr.nblocks, iov[1].iov_len);
++
++	for(i = 0; i == 0 || ibuf != NULL; i++) {
++		ibuf = readblock(fdr, ibuf, hdr.blksz);
++		if (ibuf != NULL) {
++			destlen = compressBound(hdr.blksz);
++			if (compress2(obuf, &destlen, ibuf, hdr.blksz,
++			    Z_BEST_COMPRESSION) != Z_OK) {
++				errx(1, "can't compress data: compress2() "
++				    "failed");
++				/* Not reached */
++			}
++			if (verbose != 0)
++				fprintf(stderr, "cluster #%d, in %u bytes, "
++				    "out %lu bytes\n", i, hdr.blksz, destlen);
++		} else {
++			destlen = DEV_BSIZE - (offset % DEV_BSIZE);
++			memset(obuf, 0, destlen);
++			if (verbose != 0)
++				fprintf(stderr, "padding data with %lu bytes so "
++				    "that file size is multiple of %d\n", destlen,
++				    DEV_BSIZE);
++		}
++		if (write(fdw, obuf, destlen) < 0) {
++			err(1, "write(%s)", oname);
++			/* Not reached */
++		}
++		toc[i] = htobe64(offset);
++		offset += destlen;
++	}
++	close(fdr);
++
++	if (verbose != 0)
++		fprintf(stderr, "compressed data to %ju bytes, saved %lld "
++		    "bytes, %.2f%% decrease.\n", offset, (long long)(sb.st_size - offset),
++		    100.0 * (long long)(sb.st_size - offset) / (float)sb.st_size);
++
++	/* Convert to big endian */
++	hdr.blksz = htonl(hdr.blksz);
++	hdr.nblocks = htonl(hdr.nblocks);
++	/* Write headers into pre-allocated space */
++	lseek(fdw, 0, SEEK_SET);
++	if (writev(fdw, iov, 2) < 0) {
++		err(1, "writev(%s)", oname);
++		/* Not reached */
++	}
++	cleanfile = NULL;
++	close(fdw);
++
++	exit(0);
++}
++
++static char *
++readblock(int fd, char *ibuf, u_int32_t clstsize)
++{
++	int numread;
++
++	bzero(ibuf, clstsize);
++	numread = read(fd, ibuf, clstsize);
++	if (numread < 0) {
++		err(1, "read() failed");
++		/* Not reached */
++	}
++	if (numread == 0) {
++		return NULL;
++	}
++	return ibuf;
++}
++
++static void
++usage(void)
++{
++
++	fprintf(stderr, "usage: mkuzip [-v] [-o outfile] [-s cluster_size] infile\n");
++	exit(1);
++}
++
++static void *
++safe_malloc(size_t size)
++{
++	void *retval;
++
++	retval = malloc(size);
++	if (retval == NULL) {
++		err(1, "can't allocate memory");
++		/* Not reached */
++	}
++	return retval;
++}
++
++static void
++cleanup(void)
++{
++
++	if (cleanfile != NULL)
++		unlink(cleanfile);
++}

Modified: trunk/freebsd-utils/debian/patches/series
===================================================================
--- trunk/freebsd-utils/debian/patches/series	2010-09-19 19:34:22 UTC (rev 3188)
+++ trunk/freebsd-utils/debian/patches/series	2010-09-19 20:13:17 UTC (rev 3189)
@@ -1,3 +1,4 @@
+000_mkuzip.diff
 001_dmesg.diff
 002_ifconfig.diff
 003_kbdcontrol.diff

Modified: trunk/freebsd-utils/debian/rules
===================================================================
--- trunk/freebsd-utils/debian/rules	2010-09-19 19:34:22 UTC (rev 3188)
+++ trunk/freebsd-utils/debian/rules	2010-09-19 20:13:17 UTC (rev 3189)
@@ -30,7 +30,6 @@
 	rm -rf $(ORIGDIR)
 	mkdir -p $(ORIGDIR)/sys/kern $(ORIGDIR)/etc
 	for i in sbin/dmesg sbin/sysctl usr.bin/kdump usr.bin/ktrace \
-		 usr.bin/mkuzip \
 		 usr.sbin/jail bin/chflags sbin/devd usr.sbin/acpi/acpiconf \
 		 sbin/kldconfig sbin/kldload sbin/kldstat sbin/kldunload \
 		 usr.bin/ktrdump usr.bin/vmstat sbin/devfs sbin/fdisk \
@@ -180,7 +179,7 @@
 	$(PMAKE) -C sbin/umount clean
 	$(PMAKE) -C usr.bin/kdump clean
 	$(PMAKE) -C usr.bin/ktrace clean
-	$(PMAKE) -C usr.bin/mkuzip clean
+	-$(PMAKE) -C usr.bin/mkuzip clean
 	$(PMAKE) -C usr.sbin/acpi/acpiconf clean
 	$(PMAKE) -C usr.sbin/rpc.umntall clean
 




More information about the Glibc-bsd-commits mailing list