Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Dec 2004 12:34:33 +0200
From:      Peter Pentchev <roam@ringlet.net>
To:        Matteo Riondato <rionda@gufi.org>
Cc:        Maxim Sobolev <sobomax@FreeBSD.org>
Subject:   Re: Creating Compressed Loop FS from stdin
Message-ID:  <20041230103433.GB830@straylight.m.ringlet.net>
In-Reply-To: <1104358540.2895.10.camel@kaiser.sig11.org>
References:  <1104358540.2895.10.camel@kaiser.sig11.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--wq9mPyueHGvFACwf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Dec 29, 2004 at 11:15:40PM +0100, Matteo Riondato wrote:
> Hi folks!
>=20
> I think you know what FreeSBIE
> is and that we use compressed loop filesystems for /usr and /var
> directories on our LiveCD.=20
> At the moment, to create compressed filesystems, we rely on
> sysutils/cloop-utils, but I know /usr/bin/mkuzip is present in HEAD and
> in RELENG_5 and would like to switch to that. However, it seems that I
> cannot create valid cloopfs with mkuzip.
> To create the cloop image, I use:
>=20
> /usr/local/bin/mkisofs -lrJL $FREESBIEBASEDIR/usr | /usr/bin/mkuzip -v \
> -o $FREESBIEBASEDIR/cloop/usr.cloop -s 65536 /dev/stdin

Well, as you can see from the very first line output by mkuzip in that
case (if -v is indeed specified), it thinks that the input file is 0 bytes
long.  This is so because the first thing mkuzip does is a stat(2) on
the input file descriptor, and when you point it at /dev/stdin, stat()
returns a length of 0 bytes since it is impossible to determine beforehand
how much data will be produced by the pipe.

This could be fixed by the following patch.  I'm CC'ing Maxim Sobolev,
the author of mkuzip(8); Maxim, do you have any objections to this patch?

G'luck,
Peter

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 10:32:38 -0000
@@ -122,10 +122,23 @@
 	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() */
+	sb.st_size =3D lseek(fdr, 0, SEEK_END);
+	if (sb.st_size < 1 && fstat(fdr, &sb) !=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 */
+	}
+	lseek(fdr, 0, SEEK_SET);
 	hdr.nblocks =3D sb.st_size / hdr.blksz;
 	if ((sb.st_size % hdr.blksz) !=3D 0) {
 		if (verbose !=3D 0)
@@ -135,11 +148,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) {

--=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
This sentence claims to be an Epimenides paradox, but it is lying.

--wq9mPyueHGvFACwf
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)

iD8DBQFB09m57Ri2jRYZRVMRAlRcAKCH3qxE19Ay+kvmF0Ot6L/tlXzCEgCeJ7UL
bAPkDq8VR/D1OpkMkNEPGag=
=Zn97
-----END PGP SIGNATURE-----

--wq9mPyueHGvFACwf--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041230103433.GB830>