From nobody Sun Feb 8 10:49:40 2026 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.zoho.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 1495487708994165.47384829024384; Mon, 22 May 2017 14:15:08 -0700 (PDT) Received: from localhost ([::1]:44929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dCufS-0001KH-HJ for importer@patchew.org; Mon, 22 May 2017 17:15:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dCuco-0007dP-Lk for qemu-devel@nongnu.org; Mon, 22 May 2017 17:12:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dCucn-00007Y-Ie for qemu-devel@nongnu.org; Mon, 22 May 2017 17:12:22 -0400 Received: from smtp2-g21.free.fr ([212.27.42.2]:36938) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dCucj-0008WH-Uz; Mon, 22 May 2017 17:12:18 -0400 Received: from localhost.localdomain (unknown [82.227.227.196]) by smtp2-g21.free.fr (Postfix) with ESMTP id CE1B12003F2; Mon, 22 May 2017 23:12:16 +0200 (CEST) From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= To: qemu-devel@nongnu.org Date: Mon, 22 May 2017 23:12:00 +0200 Message-Id: <20170522211205.14265-9-hpoussin@reactos.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170522211205.14265-1-hpoussin@reactos.org> References: <20170522211205.14265-1-hpoussin@reactos.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 212.27.42.2 Subject: [Qemu-devel] [PATCH v2 08/13] 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: Kevin Wolf , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , qemu-block@nongnu.org, Max Reitz 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" Assume that input filename is encoded as UTF-8, so correctly create UTF-16 = encoding. Signed-off-by: Herv=C3=A9 Poussineau --- block/vvfat.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index d4664c531b..d34241da17 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -425,28 +425,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)); @@ -461,8 +452,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 2.11.0