Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Jul 2005 21:31:43 +0200
From:      Dario Freni <saturnero@freesbie.org>
To:        current@freebsd.org
Subject:   CALL FOR TESTERS: geom_vol_cd9660 class
Message-ID:  <42E68F9F.8000407@freesbie.org>

next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigC0C18600241FC445A147098B
Content-Type: multipart/mixed; boundary="------------030702090004080306020809"

This is a multi-part message in MIME format.
--------------030702090004080306020809
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Hi everybody. I worked on a geom_vol_cd9660 class that acts like the
geom_vol_ffs one, with cd9660 image. Although the actual code doesn't
cover every possible type of images, this works fine for me.

Can anybody test it and report here the results? Inserting an ISO9660 CD
  or attaching and md vnode pointing to an ISO image should create a
/dev/vol/${LABEL} device, which can be used to mount it instead of
/dev/acd0 or whatever.

Hints and corrections are greatly appreciated, as this is my first
attempt with a geom class (and also with devices issues)

Bye and thanks in advance,
Dario

-- 
Dario Freni (saturnero@freesbie.org)
FreeSBIE developer (http://www.freesbie.org)
GPG Public key at http://www.saturnero.net/saturnero.asc

--------------030702090004080306020809
Content-Type: text/plain; x-mac-type="54455854"; x-mac-creator="74657874";
	name="geom_vol_cd9660.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="geom_vol_cd9660.c"

/*-
 * Copyright (c) 2005 Dario Freni
 * 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 AUTHOR 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 AUTHOR 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>
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/errno.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/bio.h>
#include <sys/lock.h>
#include <sys/mutex.h>

#include <isofs/cd9660/iso.h>

#include <geom/geom.h>
#include <geom/geom_slice.h>

#define VOL_CD9660_CLASS_NAME "VOL_CD9660"

struct g_vol_cd9660_softc {
	char *	vol;
};

static int
g_vol_cd9660_start(struct bio *bp __unused)
{
        return(0);
}

static struct g_geom *
g_vol_cd9660_taste(struct g_class *mp, struct g_provider *pp, int flags)
{
	void *buf;
	char volname[32];
	char *s;
	struct g_geom *gp;
	struct g_consumer *cp;
	struct g_vol_cd9660_softc *ms;
	int error, high_sierra=0;
	struct iso_volume_descriptor *vdp;
	struct iso_primary_descriptor *pri;
	struct iso_sierra_primary_descriptor *pri_sierra;

	g_trace(G_T_TOPOLOGY, "vol_taste(%s,%s)", mp->name, pp->name);
	g_topology_assert();

	/* Avoid recursion */
	if (flags == G_TF_NORMAL &&
		!strcmp(pp->geom->class->name, VOL_CD9660_CLASS_NAME))
		return NULL;

        gp = g_slice_new(mp, 1, pp, &cp, &ms, sizeof(*ms), g_vol_cd9660_start);
        if (gp == NULL)
                return (NULL);
        g_topology_unlock();

	buf = NULL;
	buf = g_read_data(cp, ((off_t) 16) <<11, ISO_DEFAULT_BLOCK_SIZE, 
	    &error);
	if (buf == NULL || error != 0)
		goto end;

	vdp = (struct iso_volume_descriptor *) buf;

	if (strncmp (vdp->id, ISO_STANDARD_ID, 
		sizeof(ISO_STANDARD_ID) - 1) != 0) {
		/* Untested with sierra images */
		if (strncmp (vdp->id_sierra, ISO_SIERRA_ID,
		    sizeof(ISO_SIERRA_ID) - 1) != 0) 
			goto end;
		else
			high_sierra = 1;
	}
	       
	switch (isonum_711 (high_sierra? vdp->type_sierra: vdp->type)) {
	case ISO_VD_PRIMARY:
		if (high_sierra) {
			pri_sierra = (struct iso_sierra_primary_descriptor *) vdp;
			s = pri_sierra->volume_id;
		} else {
			pri = (struct iso_primary_descriptor *) vdp;
			s = pri->volume_id;
		}
		bzero(volname,32);
		for (int i=0; i < 32 && *s; i++) {
			if (s[i] == ' ' || s[i] == '\0')
				break;
			volname[i] = s[i];
		}

		/* Check for volume name */
		if (volname[0] == '\0')
			goto end;

		break;
	/* XXX check for ISO_VD_SUPPLEMENTARY? */
	default:
		break;
	}

	g_topology_lock(); 
 	g_slice_config(gp, 0, G_SLICE_CONFIG_SET, (off_t) 0, 
 	    pp->mediasize, pp->sectorsize, "vol/%s", volname); 
	g_free(buf);
 	g_topology_unlock(); 

end:

        g_topology_lock();
        g_access(cp, -1, 0, 0);
        if (LIST_EMPTY(&gp->provider)) {
                g_slice_spoiled(cp);
                return (NULL);
        }

	return (gp);
}

static struct g_class g_vol_cd9660_class	= {
	.name = VOL_CD9660_CLASS_NAME,
	.version = G_VERSION,
	.taste = g_vol_cd9660_taste,
};

DECLARE_GEOM_CLASS(g_vol_cd9660_class, g_vol_cd9660);

--------------030702090004080306020809
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
 name="Makefile"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Makefile"

# $FreeBSD$

CFLAGS+=-g

KMOD=	geom_vol_cd9660
SRCS=	geom_vol_cd9660.c

.include <bsd.kmod.mk>

--------------030702090004080306020809--

--------------enigC0C18600241FC445A147098B
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)

iD8DBQFC5o+fymi72IiShysRAk73AKDxn+xslkc7/joEhdTwreUKPbEJywCeLPoT
AuVCIrTOgKyQShO87XUt1SA=
=72Y4
-----END PGP SIGNATURE-----

--------------enigC0C18600241FC445A147098B--



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