AFFS never uses unicode.
* include/grub/charset.h (GRUB_MAX_UTF8_PER_LATIN1): New const. (grub_latin1_to_utf8): New inline function. * grub-core/fs/affs.c (grub_affs_iterate_dir): Convert latin1 to UTF8.
This commit is contained in:
parent
e7987e1b3b
commit
309e535231
3 changed files with 40 additions and 8 deletions
|
@ -1,3 +1,11 @@
|
|||
2011-12-14 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
AFFS never uses unicode.
|
||||
|
||||
* include/grub/charset.h (GRUB_MAX_UTF8_PER_LATIN1): New const.
|
||||
(grub_latin1_to_utf8): New inline function.
|
||||
* grub-core/fs/affs.c (grub_affs_iterate_dir): Convert latin1 to UTF8.
|
||||
|
||||
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
* grub-core/fs/romfs.c (grub_romfs_mount): Fix pointer comparison
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <grub/dl.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/fshelp.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
|
@ -292,15 +293,15 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
|
|||
struct grub_affs_data *data = dir->data;
|
||||
grub_uint32_t *hashtable;
|
||||
|
||||
auto int NESTED_FUNC_ATTR grub_affs_create_node (const char *name,
|
||||
grub_uint32_t block,
|
||||
auto int NESTED_FUNC_ATTR grub_affs_create_node (grub_uint32_t block,
|
||||
const struct grub_affs_file *fil);
|
||||
|
||||
int NESTED_FUNC_ATTR grub_affs_create_node (const char *name,
|
||||
grub_uint32_t block,
|
||||
int NESTED_FUNC_ATTR grub_affs_create_node (grub_uint32_t block,
|
||||
const struct grub_affs_file *fil)
|
||||
{
|
||||
int type;
|
||||
grub_uint8_t name_u8[sizeof (fil->name) * GRUB_MAX_UTF8_PER_LATIN1 + 1];
|
||||
|
||||
node = grub_zalloc (sizeof (*node));
|
||||
if (!node)
|
||||
{
|
||||
|
@ -322,7 +323,10 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
|
|||
node->di = *fil;
|
||||
node->parent = dir;
|
||||
|
||||
if (hook (name, type, node))
|
||||
*grub_latin1_to_utf8 (name_u8, fil->name,
|
||||
grub_min (fil->namelen, sizeof (fil->name))) = '\0';
|
||||
|
||||
if (hook ((char *) name_u8, type, node))
|
||||
{
|
||||
grub_free (hashtable);
|
||||
return 1;
|
||||
|
@ -377,9 +381,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
|
|||
if (grub_errno)
|
||||
goto fail;
|
||||
|
||||
file.name[file.namelen] = '\0';
|
||||
|
||||
if (grub_affs_create_node ((char *) (file.name), next, &file))
|
||||
if (grub_affs_create_node (next, &file))
|
||||
return 1;
|
||||
|
||||
next = grub_be_to_cpu32 (file.next);
|
||||
|
|
|
@ -118,6 +118,28 @@ grub_utf16_to_utf8 (grub_uint8_t *dest, grub_uint16_t *src,
|
|||
return dest;
|
||||
}
|
||||
|
||||
#define GRUB_MAX_UTF8_PER_LATIN1 2
|
||||
|
||||
/* Convert Latin1 to UTF-8. */
|
||||
static inline grub_uint8_t *
|
||||
grub_latin1_to_utf8 (grub_uint8_t *dest, const grub_uint8_t *src,
|
||||
grub_size_t size)
|
||||
{
|
||||
while (size--)
|
||||
{
|
||||
if (!(*src & 0x80))
|
||||
*dest++ = *src;
|
||||
else
|
||||
{
|
||||
*dest++ = (*src >> 6) | 0xC0;
|
||||
*dest++ = (*src & 0x3F) | 0x80;
|
||||
}
|
||||
src++;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* Convert UCS-4 to UTF-8. */
|
||||
char *grub_ucs4_to_utf8_alloc (grub_uint32_t *src, grub_size_t size);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue