[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 012/100] vvfat: correctly create long names for non-A
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 012/100] vvfat: correctly create long names for non-ASCII filenames |
Date: |
Fri, 7 Jul 2017 19:07:27 +0200 |
From: Hervé Poussineau <address@hidden>
Assume that input filename is encoded as UTF-8, so correctly create UTF-16
encoding.
Signed-off-by: Hervé Poussineau <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
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)
/* direntry functions */
-/* dest is assumed to hold 258 bytes, and pads with 0xffff up to next multiple
of 26 */
-static inline int short2long_name(char* dest,const char* src)
+static direntry_t *create_long_filename(BDRVVVFATState *s, const char
*filename)
{
- int i;
- int len;
- for(i=0;i<129 && src[i];i++) {
- dest[2*i]=src[i];
- dest[2*i+1]=0;
+ int number_of_entries, i;
+ glong length;
+ direntry_t *entry;
+
+ gunichar2 *longname = g_utf8_to_utf16(filename, -1, NULL, &length, NULL);
+ if (!longname) {
+ fprintf(stderr, "vvfat: invalid UTF-8 name: %s\n", filename);
+ return NULL;
}
- len=2*i;
- dest[2*i]=dest[2*i+1]=0;
- for(i=2*i+2;(i%26);i++)
- dest[i]=0xff;
- return len;
-}
-static inline direntry_t* create_long_filename(BDRVVVFATState* s,const char*
filename)
-{
- char buffer[258];
- int length=short2long_name(buffer,filename),
- number_of_entries=(length+25)/26,i;
- direntry_t* entry;
+ number_of_entries = (length * 2 + 25) / 26;
for(i=0;i<number_of_entries;i++) {
entry=array_get_next(&(s->directory));
@@ -460,8 +451,15 @@ static inline direntry_t*
create_long_filename(BDRVVVFATState* s,const char* fil
else if(offset<22) offset=14+offset-10;
else offset=28+offset-22;
entry=array_get(&(s->directory),s->directory.next-1-(i/26));
- entry->name[offset]=buffer[i];
+ if (i >= 2 * length + 2) {
+ entry->name[offset] = 0xff;
+ } else if (i % 2 == 0) {
+ entry->name[offset] = longname[i / 2] & 0xff;
+ } else {
+ entry->name[offset] = longname[i / 2] >> 8;
+ }
}
+ g_free(longname);
return array_get(&(s->directory),s->directory.next-number_of_entries);
}
--
1.8.3.1
- [Qemu-block] [PULL 000/100] Block layer patches, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 003/100] block: Simplify use of BDRV_BLOCK_RAW, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 004/100] blkdebug: Support .bdrv_co_get_block_status, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 002/100] block: Guarantee that *file is set on bdrv_get_block_status(), Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 001/100] qemu-io: Don't die on second open, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 005/100] vvfat: fix qemu-img map and qemu-img convert, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 007/100] vvfat: fix typos, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 008/100] vvfat: rename useless enumeration values, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 010/100] vvfat: fix field names in FAT12/FAT16 and FAT32 boot sectors, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 011/100] vvfat: always create . and .. entries at first and in that order, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 012/100] vvfat: correctly create long names for non-ASCII filenames,
Kevin Wolf <=
- [Qemu-block] [PULL 009/100] vvfat: introduce offset_to_bootsector, offset_to_fat and offset_to_root_dir, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 013/100] vvfat: correctly create base short names for non-ASCII filenames, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 014/100] vvfat: correctly generate numeric-tail of short file names, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 015/100] vvfat: limit number of entries in root directory in FAT12/FAT16, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 016/100] vvfat: handle KANJI lead byte 0xe5, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 006/100] vvfat: replace tabs by 8 spaces, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 018/100] qemu-img: drop -e and -6 options from the 'create' & 'convert' commands, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 020/100] blockjob: Track job ratelimits via bytes, not sectors, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 017/100] vvfat: change OEM name to 'MSWIN4.1', Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 019/100] blockdev: Print a warning for legacy drive options that belong to -device, Kevin Wolf, 2017/07/07