[patch] combine mount_udf(8) with kiconv(3)

Scott Long scottl at freebsd.org
Tue Nov 4 08:43:21 PST 2003


Ok, looks good.  Please send me a full diff and I'll commit it.

Thanks!

Scott

On Wed, 5 Nov 2003, R. Imura wrote:

> Hi,
>
> On Tue, Nov 04, 2003 at 03:26:20AM -0700, Scott Long wrote:
> > Hi,
> >
> > This looks very good.  I have one question, however,  Why do you
> > copy transname into unibuf?  Is it because of endian problems?
> > If so, feel free to modify the OSTA code to produce the correct
> > format.  Doing a second zalloc() and copy for every single
> > filename gets expensive and should be avoided.
>
> Ah, yes, you're right. I now modified the OSTA code and add
> udf_UncompressUnicodeByte() to it.  When iconv is available
> udf_UncompressUnicodeByte() is used, and when not udf_UncompressUnicode()
> is used.  New patch is
>
>   http://www.ryu16.org/FreeBSD/kiconv/udf_5_current_20031104.diff
>
> Difference from previous version's udf_vnops.c is as follows.
>
> diff -u -r1.1.2.6 udf_vnops.c
> --- udf_vnops.c	4 Nov 2003 15:17:48 -0000	1.1.2.6
> +++ udf_vnops.c	4 Nov 2003 15:45:41 -0000
> @@ -459,42 +459,43 @@
>  	unicode_t *transname;
>  	char *unibuf, *unip;
>  	int i, unilen = 0, destlen;
> -	size_t unileft, destleft = MAXNAMLEN;
> -
> -	/* allocate a buffer big enough to hold an 8->16 bit expansion */
> -	transname = uma_zalloc(udf_zone_trans, M_WAITOK);
> -
> -	if ((unilen = udf_UncompressUnicode(len, cs0string, transname)) == -1) {
> -		printf("udf: Unicode translation failed\n");
> -		uma_zfree(udf_zone_trans, transname);
> -		return 0;
> -	}
> +	size_t destleft = MAXNAMLEN;
>
>  	/* Convert 16-bit Unicode to destname */
>  	if (udfmp->im_flags & UDFMNT_KICONV && udf_iconv) {
> +		/* allocate a buffer big enough to hold an 8->16 bit expansion */
>  		unibuf = uma_zalloc(udf_zone_trans, M_WAITOK);
>  		unip = unibuf;
> -		for (i = 0; i < unilen ; i++) {
> -			*unibuf++ = (char)(transname[i] >> 8);
> -			*unibuf++ = (char)transname[i];
> +		if ((unilen = udf_UncompressUnicodeByte(len, cs0string, unibuf)) == -1) {
> +			printf("udf: Unicode translation failed\n");
> +			uma_zfree(udf_zone_trans, unibuf);
> +			return 0;
>  		}
> -		unibuf = unip;
> -		unileft = (size_t)unilen * 2;
> -		while (unileft > 0 && destleft > 0) {
> +
> +		while (unilen > 0 && destleft > 0) {
>  			udf_iconv->conv(udfmp->im_d2l, (const char **)&unibuf,
> -				&unileft, (char **)&destname, &destleft);
> +				(size_t *)&unilen, (char **)&destname, &destleft);
>  			/* Unconverted character found */
> -			if (unileft > 0 && destleft > 0) {
> +			if (unilen > 0 && destleft > 0) {
>  				*destname++ = '?';
>  				destleft--;
>  				unibuf += 2;
> -				unileft -= 2;
> +				unilen -= 2;
>  			}
>  		}
>  		uma_zfree(udf_zone_trans, unip);
>  		*destname = '\0';
>  		destlen = MAXNAMLEN - (int)destleft;
>  	} else {
> +		/* allocate a buffer big enough to hold an 8->16 bit expansion */
> +		transname = uma_zalloc(udf_zone_trans, M_WAITOK);
> +
> +		if ((unilen = udf_UncompressUnicode(len, cs0string, transname)) == -1) {
> +			printf("udf: Unicode translation failed\n");
> +			uma_zfree(udf_zone_trans, transname);
> +			return 0;
> +		}
> +
>  		for (i = 0; i < unilen ; i++) {
>  			if (transname[i] & 0xff00) {
>  				destname[i] = '.';	/* Fudge the 16bit chars */
> @@ -502,11 +503,10 @@
>  				destname[i] = transname[i] & 0xff;
>  			}
>  		}
> +		uma_zfree(udf_zone_trans, transname);
>  		destname[unilen] = 0;
>  		destlen = unilen;
>  	}
> -
> -	uma_zfree(udf_zone_trans, transname);
>
>  	return (destlen);
>  }
>
>
> - R. Imura
>
>


More information about the freebsd-fs mailing list