mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
vvfat: correctly create long names for non-ASCII filenames
Assume that input filename is encoded as UTF-8, so correctly create UTF-16 encoding. Signed-off-by: Hervé Poussineau <hpoussin@reactos.org> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
f82d92bb02
commit
09ec4119fb
1 changed files with 19 additions and 21 deletions
|
@ -424,28 +424,19 @@ static void init_mbr(BDRVVVFATState *s, int cyls, int heads, int secs)
|
||||||
|
|
||||||
/* direntry functions */
|
/* direntry functions */
|
||||||
|
|
||||||
/* dest is assumed to hold 258 bytes, and pads with 0xffff up to next multiple of 26 */
|
static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename)
|
||||||
static inline int short2long_name(char* dest,const char* src)
|
|
||||||
{
|
{
|
||||||
int i;
|
int number_of_entries, i;
|
||||||
int len;
|
glong length;
|
||||||
for(i=0;i<129 && src[i];i++) {
|
direntry_t *entry;
|
||||||
dest[2*i]=src[i];
|
|
||||||
dest[2*i+1]=0;
|
|
||||||
}
|
|
||||||
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)
|
gunichar2 *longname = g_utf8_to_utf16(filename, -1, NULL, &length, NULL);
|
||||||
{
|
if (!longname) {
|
||||||
char buffer[258];
|
fprintf(stderr, "vvfat: invalid UTF-8 name: %s\n", filename);
|
||||||
int length=short2long_name(buffer,filename),
|
return NULL;
|
||||||
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++) {
|
for(i=0;i<number_of_entries;i++) {
|
||||||
entry=array_get_next(&(s->directory));
|
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 if(offset<22) offset=14+offset-10;
|
||||||
else offset=28+offset-22;
|
else offset=28+offset-22;
|
||||||
entry=array_get(&(s->directory),s->directory.next-1-(i/26));
|
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);
|
return array_get(&(s->directory),s->directory.next-number_of_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue