From owner-freebsd-geom@FreeBSD.ORG Mon Sep 6 16:55:10 2010 Return-Path: Delivered-To: freebsd-geom@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E14F010656D3 for ; Mon, 6 Sep 2010 16:55:10 +0000 (UTC) (envelope-from jhellenthal@gmail.com) Received: from mail-qw0-f54.google.com (mail-qw0-f54.google.com [209.85.216.54]) by mx1.freebsd.org (Postfix) with ESMTP id 947B78FC1B for ; Mon, 6 Sep 2010 16:55:10 +0000 (UTC) Received: by qwg5 with SMTP id 5so4332202qwg.13 for ; Mon, 06 Sep 2010 09:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :x-enigmail-version:content-type:content-transfer-encoding; bh=znVU9Zxps0XO5F8KxKtOPILDEwPmXLfMISJ4vWOwYsw=; b=CHqNZvkHjeCGshdPpRCStawtroz2xi8aCqBwYIBVNmZsQ7WcEmgBd6RMX/4fNBsBq1 Msyrw9bvJY2YYXw1AvamRWObkdlVi8s37xCgl/w7i/gPeYq5I0YLc8CBkr0QbJNgy3yP iGem68ow49pNvygAbEFR52+BylfWl0GUFpcgI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; b=H52DfWOO+XZcvQ3iM7iRQHTgY8Kh/ID0+utqCcZVagk/ZEtqRBzKkcqx+N3fc07asc uNOXuwYDubZR44YblRUc4YjZ3Ie8rVf6aevUtAiZm89ImmvhKd6dkCLQKlogLuPYXgqE FR4uWzs8IlZ/PMzpQkp3P3tPdv0g0UV8OLbCI= Received: by 10.229.220.78 with SMTP id hx14mr1563093qcb.148.1283790265995; Mon, 06 Sep 2010 09:24:25 -0700 (PDT) Received: from centel.dataix.local (adsl-99-181-137-20.dsl.klmzmi.sbcglobal.net [99.181.137.20]) by mx.google.com with ESMTPS id r38sm5783468qcs.2.2010.09.06.09.24.23 (version=SSLv3 cipher=RC4-MD5); Mon, 06 Sep 2010 09:24:24 -0700 (PDT) Sender: "J. Hellenthal" Message-ID: <4C8515B6.4080304@DataIX.net> Date: Mon, 06 Sep 2010 12:24:22 -0400 From: jhell User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.9.2.8) Gecko/20100806 Lightning/1.0b1 Thunderbird MIME-Version: 1.0 To: Takanori Watanabe References: <201009051815.o85IFmsa024096@sana.init-main.com> In-Reply-To: <201009051815.o85IFmsa024096@sana.init-main.com> X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-geom@freebsd.org Subject: Re: UDF label function patch. X-BeenThere: freebsd-geom@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: GEOM-specific discussions and implementations List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Sep 2010 16:55:11 -0000 Can you file this here: http://www.freebsd.org/send-pr.html as a misc/change-request so it does not get lost ? Would be awesome! On 09/05/2010 14:15, Takanori Watanabe wrote: > I wrote a patch to add UDF support on geom label module. > How about it? > > Index: sys/conf/files > =================================================================== > --- sys/conf/files (revision 212175) > +++ sys/conf/files (working copy) > @@ -2023,6 +2023,7 @@ > geom/label/g_label_msdosfs.c optional geom_label > geom/label/g_label_ntfs.c optional geom_label > geom/label/g_label_reiserfs.c optional geom_label > +geom/label/g_label_udf.c optional geom_label > geom/label/g_label_ufs.c optional geom_label > geom/label/g_label_gpt.c optional geom_label > geom/linux_lvm/g_linux_lvm.c optional geom_linux_lvm > Index: sbin/geom/class/label/glabel.8 > =================================================================== > --- sbin/geom/class/label/glabel.8 (revision 212175) > +++ sbin/geom/class/label/glabel.8 (working copy) > @@ -109,6 +109,9 @@ > CD ISO9660 (directory > .Pa /dev/iso9660/ ) . > .It > +DVD UDF (directory > +.Pa /dev/udf/ ) . > +.It > EXT2FS (directory > .Pa /dev/ext2fs/ ) . > .It > Index: sys/geom/label/g_label_udf.c > =================================================================== > --- sys/geom/label/g_label_udf.c (revision 0) > +++ sys/geom/label/g_label_udf.c (revision 0) > @@ -0,0 +1,168 @@ > +/*- > + * Copyright (c) 2010 Takanori Watanabe > + * 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 AUTHORS 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 AUTHORS 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 > +__FBSDID("$FreeBSD$"); > + > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#define G_LABEL_UDF_DIR "udf" > +#define LOGICAL_SECTOR_SIZE 2048 > +#define UDF_OFFSET (256*LOGICAL_SECTOR_SIZE) > +#define VOLUME_LEN 16 > + > +static int > +g_label_udf_checktag(struct desc_tag *tag, uint16_t id) > +{ > + uint8_t *itag; > + uint8_t i, cksum = 0; > + > + itag = (uint8_t *)tag; > + > + if (le16toh(tag->id) != id) > + return (EINVAL); > + > + for (i = 0; i < 16; i++) > + cksum = cksum + itag[i]; > + cksum = cksum - itag[4]; > + > + if (cksum == tag->cksum) > + return (0); > + > + return (EINVAL); > +} > +static int > +g_label_udf_uncompress_unicode(unsigned char *dest,unsigned char *src, int size,int srcsize) > +{ > + int i,j; > + unsigned short unichar; > + if(src[0] == 8){ > + strlcpy(dest, src+1 , size); > + return 0; > + }else if(src[0] == 16){ > + /*Encode as UTF-8*/ > + for(j = 0,i = 1; i < srcsize; i+=2){ > + unichar = src[i]<<8|src[i+1]; > + if(unichar == 0){ > + *dest = 0; > + return 0; > + } > + if(unichar < 0x7f){ > + j++; > + if(j > size){ > + *dest = 0; > + return 0; > + } > + *dest++ = unichar; > + }else if(unichar < 0x7ff){ > + j += 2 ; > + if(j > size){ > + *dest = 0; > + return 0; > + } > + *dest++ = ((unichar>>6)&0x1f)|0xc0; > + *dest++ = (unichar &0x3f)|0x80; > + }else{ > + j+= 3; > + if(j > size){ > + *dest = 0; > + return 0; > + } > + *dest++ = ((unichar>>12)&0x0f)|0xe0; > + *dest++ = ((unichar>>6)&0x3f)|0x80; > + *dest++ = (unichar&0x3f)|0x80; > + } > + } > + } > + > + return 1; > +} > + > +static void > +g_label_udf_taste(struct g_consumer *cp, char *label, size_t size) > +{ > + struct g_provider *pp; > + unsigned char *sector = NULL; > + unsigned char *volume = NULL; > + int i; > + struct anchor_vdp *avdp; > + struct logvol_desc *logvol; > + > + g_topology_assert_not(); > + pp = cp->provider; > + label[0] = '\0'; > + > + if ((UDF_OFFSET % pp->sectorsize) != 0) > + return; > + sector = (unsigned char *)g_read_data(cp, UDF_OFFSET, pp->sectorsize, > + NULL); > + if (sector == NULL) > + return; > + > + if (g_label_udf_checktag((struct desc_tag *)sector, TAGID_ANCHOR) != 0) { > + goto end; > + } > + avdp = (struct anchor_vdp *) sector; > + for(i = 0; i < avdp->main_vds_ex.len; i+= LOGICAL_SECTOR_SIZE){ > + volume =(unsigned char *) > + g_read_data(cp, > + LOGICAL_SECTOR_SIZE > + *avdp->main_vds_ex.loc + i, > + LOGICAL_SECTOR_SIZE, > + NULL); > + if (g_label_udf_checktag((struct desc_tag *)volume, > + TAGID_LOGVOL) != 0) { > + g_free(volume); > + continue; > + } > + logvol = (struct logvol_desc *)volume; > + G_LABEL_DEBUG(1, "UDF file system detected on %s.", pp->name); > + if(g_label_udf_uncompress_unicode(label, logvol->logvol_id, size, sizeof(logvol->logvol_id))!= 0){ > + label[0] = '\0'; > + } > + break; > + } > +end: > + if(sector){ > + g_free(sector); > + } > + if(volume){ > + g_free(volume); > + } > +} > + > +struct g_label_desc g_label_udf = { > + .ld_taste = g_label_udf_taste, > + .ld_dir = G_LABEL_UDF_DIR, > + .ld_enabled = 1 > +}; > +G_LABEL_INIT(udf, g_label_udf, "Create device nodes for UDF volumes"); > Index: sys/geom/label/g_label.c > =================================================================== > --- sys/geom/label/g_label.c (revision 212175) > +++ sys/geom/label/g_label.c (working copy) > @@ -78,6 +78,7 @@ > const struct g_label_desc *g_labels[] = { > &g_label_ufs_id, > &g_label_ufs_volume, > + &g_label_udf, > &g_label_iso9660, > &g_label_msdosfs, > &g_label_ext2fs, > Index: sys/geom/label/g_label.h > =================================================================== > --- sys/geom/label/g_label.h (revision 212175) > +++ sys/geom/label/g_label.h (working copy) > @@ -80,6 +80,7 @@ > /* Supported labels. */ > extern struct g_label_desc g_label_ufs_id; > extern struct g_label_desc g_label_ufs_volume; > +extern struct g_label_desc g_label_udf; > extern struct g_label_desc g_label_iso9660; > extern struct g_label_desc g_label_msdosfs; > extern struct g_label_desc g_label_ext2fs; > Index: sys/modules/geom/geom_label/Makefile > =================================================================== > --- sys/modules/geom/geom_label/Makefile (revision 212175) > +++ sys/modules/geom/geom_label/Makefile (working copy) > @@ -10,6 +10,7 @@ > SRCS+= g_label_msdosfs.c > SRCS+= g_label_ntfs.c > SRCS+= g_label_reiserfs.c > +SRCS+= g_label_udf.c > SRCS+= g_label_ufs.c > > .include > _______________________________________________ > freebsd-geom@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-geom > To unsubscribe, send any mail to "freebsd-geom-unsubscribe@freebsd.org" -- jhell,v