From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 30 14:55:46 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D518B16A4D1 for ; Thu, 30 Dec 2004 14:55:46 +0000 (GMT) Received: from gandalf.online.bg (gandalf.online.bg [217.75.128.9]) by mx1.FreeBSD.org (Postfix) with SMTP id 58F0243D48 for ; Thu, 30 Dec 2004 14:55:45 +0000 (GMT) (envelope-from roam@ringlet.net) Received: (qmail 23854 invoked from network); 30 Dec 2004 14:55:40 -0000 Received: from unknown (HELO straylight.ringlet.net) (213.16.36.84) by gandalf.online.bg with SMTP; 30 Dec 2004 14:55:40 -0000 Received: (qmail 10554 invoked by uid 1000); 30 Dec 2004 14:55:43 -0000 Date: Thu, 30 Dec 2004 16:55:43 +0200 From: Peter Pentchev To: Maxim Sobolev Message-ID: <20041230145543.GJ830@straylight.m.ringlet.net> Mail-Followup-To: Maxim Sobolev , Matteo Riondato , freebsd-hackers@FreeBSD.ORG References: <1104358540.2895.10.camel@kaiser.sig11.org> <20041230103433.GB830@straylight.m.ringlet.net> <1104409708.6657.1.camel@kaiser.sig11.org> <20041230123116.GE830@straylight.m.ringlet.net> <41D4036B.1060600@portaone.com> <20041230140007.GH830@straylight.m.ringlet.net> <41D40EA0.2060009@portaone.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="x+RZeZVNR8VILNfK" Content-Disposition: inline In-Reply-To: <41D40EA0.2060009@portaone.com> User-Agent: Mutt/1.5.6i cc: freebsd-hackers@FreeBSD.ORG cc: Matteo Riondato Subject: Re: Creating Compressed Loop FS from stdin X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Dec 2004 14:55:47 -0000 --x+RZeZVNR8VILNfK Content-Type: multipart/mixed; boundary="BEa57a89OpeoUzGD" Content-Disposition: inline --BEa57a89OpeoUzGD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Dec 30, 2004 at 04:20:16PM +0200, Maxim Sobolev wrote: > You don't check return code of the second lseek - I bet it fails. This=20 > probably leads to creation of seemingly valid loop fs (i.e. with valid=20 > header), but filled with zeroes or some random junk. I said I'd tested it before posting it the first time. It works. It creates a valid loop fs, containing exactly the files that are in the input ISO image. However, your point is valid; here's another patch which returns to the start only if the original lseek() did not move away (or failed), and checks the return value, too. This version of mkuzip works on today's RELENG_5, as can be seen from the attached mkuzip.script sequence of commands. G'luck, Peter --=20 Peter Pentchev roam@ringlet.net roam@cnsys.bg roam@FreeBSD.org PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 Nostalgia ain't what it used to be. --BEa57a89OpeoUzGD Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="mkuzip.script" Content-Transfer-Encoding: quoted-printable Script started on Thu Dec 30 16:50:57 2004 Starting interactive C shell [roam@straylight ~/fbsd/r/src/usr.bin/mkuzip]> `make -V .OBJDIR`/`make -V P= ROG` -v -s 65536 -o dns-stdin.uz /dev/stdin < ~/dns.iso data size 5505024 bytes, number of clusters 84, index lengh 680 bytes cluster #0, in 65536 bytes, out 2263 bytes cluster #1, in 65536 bytes, out 11581 bytes [snip more of the same] cluster #82, in 65536 bytes, out 11684 bytes cluster #83, in 65536 bytes, out 752 bytes padding data with 161 bytes so that file size is multiple of 512 compressed data to 1361920 bytes, saved 4143104 bytes, 75.26% decrease. [roam@straylight ~/fbsd/r/src/usr.bin/mkuzip]> sudo mdconfig -a -f dns-stdi= n.uz otp-md5 455 st1434 ext Password:=20 md0 [roam@straylight ~/fbsd/r/src/usr.bin/mkuzip]> sudo mount_cd9660 /dev/md0.u= zip /mnt [roam@straylight ~/fbsd/r/src/usr.bin/mkuzip]> sudo find /mnt | wc -l 604 [roam@straylight ~/fbsd/r/src/usr.bin/mkuzip]> sudo md5 /mnt/djbdns-1.05/ti= nydns MD5 (/mnt/djbdns-1.05/tinydns) =3D d16c2fe610c19148ff005fb35242561c [roam@straylight ~/fbsd/r/src/usr.bin/mkuzip]> sudo md5 /home/roam/fbsd/r/p= orts/dns/djbdns/work/djbdns-1.05/tinydns MD5 (/home/roam/fbsd/r/ports/dns/djbdns/work/djbdns-1.05/tinydns) =3D d16c2= fe610c19148ff005fb35242561c [roam@straylight ~/fbsd/r/src/usr.bin/mkuzip]> sudo umount /mnt [roam@straylight ~/fbsd/r/src/usr.bin/mkuzip]> sudo mdconfig -d -u 0 [roam@straylight ~/fbsd/r/src/usr.bin/mkuzip]> exit exit Script done on Thu Dec 30 16:52:53 2004 --BEa57a89OpeoUzGD Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="mkuzip-size.patch" Content-Transfer-Encoding: quoted-printable Index: src/usr.bin/mkuzip/mkuzip.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/usr.bin/mkuzip/mkuzip.c,v retrieving revision 1.2 diff -u -r1.2 mkuzip.c --- src/usr.bin/mkuzip/mkuzip.c 10 Sep 2004 23:16:05 -0000 1.2 +++ src/usr.bin/mkuzip/mkuzip.c 30 Dec 2004 14:47:35 -0000 @@ -122,10 +122,28 @@ signal(SIGXFSZ, exit); atexit(cleanup); =20 - if (stat(iname, &sb) !=3D 0) { + fdr =3D open(iname, O_RDONLY); + if (fdr < 0) { + err(1, "%s", iname); + /* Not reached */ + } + + /* Try seeking to the end; if that fails, fall back to fstat() */ + memset(&sb, 0, sizeof(sb)); + sb.st_size =3D lseek(fdr, 0, SEEK_END); + if (sb.st_size < 1) { + if (fstat(fdr, &sb) !=3D 0) { + err(1, "%s", iname); + /* Not reached */ + } + } else if (lseek(fdr, 0, SEEK_SET) !=3D 0) { err(1, "%s", iname); /* Not reached */ } + if (sb.st_size < 1) { + errx(1, "Could not determine the size of %s", iname); + /* Not reached */ + } hdr.nblocks =3D sb.st_size / hdr.blksz; if ((sb.st_size % hdr.blksz) !=3D 0) { if (verbose !=3D 0) @@ -135,11 +153,6 @@ } toc =3D safe_malloc((hdr.nblocks + 1) * sizeof(*toc)); =20 - fdr =3D open(iname, O_RDONLY); - if (fdr < 0) { - err(1, "%s", iname); - /* Not reached */ - } fdw =3D open(oname, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fdw < 0) { --BEa57a89OpeoUzGD-- --x+RZeZVNR8VILNfK Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (FreeBSD) iD8DBQFB1Bbv7Ri2jRYZRVMRAlo2AKCZZwJH/yWQOk4jZqXUsuQwAsKPIQCfRQ0p T+mowuggWUd5tIox/i//QZc= =eg9L -----END PGP SIGNATURE----- --x+RZeZVNR8VILNfK--