]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
AFFS never uses unicode.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 14 Dec 2011 08:52:00 +0000 (09:52 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 14 Dec 2011 08:52:00 +0000 (09:52 +0100)
* 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.

ChangeLog
grub-core/fs/affs.c
include/grub/charset.h

index d3d7f0ea7f342d2735497453adbdf419eab17959..2d811e710f1cd56e3ffeff133b1649731651141e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index 06f41c4c34ad03c5b2282de01b5c960778baa785..0ad5e6672e9e62198f01a7929037111547be9a56 100644 (file)
@@ -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);
index c7f86a1ef64bda07e6c11748ab47377bd95a99ac..2b1f54fe8b261abb563db390e50aa9b6c41b0836 100644 (file)
@@ -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);