+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
#include <grub/dl.h>
#include <grub/types.h>
#include <grub/fshelp.h>
+#include <grub/charset.h>
GRUB_MOD_LICENSE ("GPLv3+");
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)
{
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;
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);
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);