From nobody Wed Apr 16 07:38:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499447510050784.5579158694048; Fri, 7 Jul 2017 10:11:50 -0700 (PDT) Received: from localhost ([::1]:57696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWnB-0006x9-JK for importer@patchew.org; Fri, 07 Jul 2017 13:11:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWky-0004ju-44 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkx-0007gE-2v for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56150) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWku-0007dd-FS; Fri, 07 Jul 2017 13:09:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 841B17D0DC; Fri, 7 Jul 2017 17:09:23 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A38561F23; Fri, 7 Jul 2017 17:09:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 841B17D0DC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 841B17D0DC From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:27 +0200 Message-Id: <1499447335-6125-13-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:09:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 012/100] vvfat: correctly create long names for non-ASCII filenames X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau Assume that input filename is encoded as UTF-8, so correctly create UTF-16 = encoding. Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 0c6d0f4..c52c9ba 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -424,28 +424,19 @@ static void init_mbr(BDRVVVFATState *s, int cyls, int= heads, int secs) =20 /* direntry functions */ =20 -/* dest is assumed to hold 258 bytes, and pads with 0xffff up to next mult= iple of 26 */ -static inline int short2long_name(char* dest,const char* src) +static direntry_t *create_long_filename(BDRVVVFATState *s, const char *fil= ename) { - int i; - int len; - for(i=3D0;i<129 && src[i];i++) { - dest[2*i]=3Dsrc[i]; - dest[2*i+1]=3D0; + int number_of_entries, i; + glong length; + direntry_t *entry; + + gunichar2 *longname =3D g_utf8_to_utf16(filename, -1, NULL, &length, N= ULL); + if (!longname) { + fprintf(stderr, "vvfat: invalid UTF-8 name: %s\n", filename); + return NULL; } - len=3D2*i; - dest[2*i]=3Ddest[2*i+1]=3D0; - for(i=3D2*i+2;(i%26);i++) - dest[i]=3D0xff; - return len; -} =20 -static inline direntry_t* create_long_filename(BDRVVVFATState* s,const cha= r* filename) -{ - char buffer[258]; - int length=3Dshort2long_name(buffer,filename), - number_of_entries=3D(length+25)/26,i; - direntry_t* entry; + number_of_entries =3D (length * 2 + 25) / 26; =20 for(i=3D0;idirectory)); @@ -460,8 +451,15 @@ static inline direntry_t* create_long_filename(BDRVVVF= ATState* s,const char* fil else if(offset<22) offset=3D14+offset-10; else offset=3D28+offset-22; entry=3Darray_get(&(s->directory),s->directory.next-1-(i/26)); - entry->name[offset]=3Dbuffer[i]; + if (i >=3D 2 * length + 2) { + entry->name[offset] =3D 0xff; + } else if (i % 2 =3D=3D 0) { + entry->name[offset] =3D longname[i / 2] & 0xff; + } else { + entry->name[offset] =3D longname[i / 2] >> 8; + } } + g_free(longname); return array_get(&(s->directory),s->directory.next-number_of_entries); } =20 --=20 1.8.3.1