OSDN Git Service

Fixed handling of long non-ASCII file names.
authorresver@gmail.com <resver@gmail.com@60bc1c72-a15a-11de-b98f-4500b42dc123>
Mon, 20 May 2013 16:33:27 +0000 (16:33 +0000)
committerresver@gmail.com <resver@gmail.com@60bc1c72-a15a-11de-b98f-4500b42dc123>
Mon, 20 May 2013 16:33:27 +0000 (16:33 +0000)
git-svn-id: http://exfat.googlecode.com/svn/trunk@355 60bc1c72-a15a-11de-b98f-4500b42dc123

fsck/main.c
fuse/main.c
libexfat/exfat.h
libexfat/node.c

index 421bd1d..e865641 100644 (file)
@@ -40,18 +40,18 @@ static int nodeck(struct exfat* ef, struct exfat_node* node)
        {
                if (CLUSTER_INVALID(c))
                {
-                       char name[EXFAT_NAME_MAX + 1];
+                       char name[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
 
-                       exfat_get_name(node, name, EXFAT_NAME_MAX);
+                       exfat_get_name(node, name, sizeof(name) - 1);
                        exfat_error("file `%s' has invalid cluster 0x%x", name, c);
                        rc = 1;
                        break;
                }
                if (BMAP_GET(ef->cmap.chunk, c - EXFAT_FIRST_DATA_CLUSTER) == 0)
                {
-                       char name[EXFAT_NAME_MAX + 1];
+                       char name[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
 
-                       exfat_get_name(node, name, EXFAT_NAME_MAX);
+                       exfat_get_name(node, name, sizeof(name) - 1);
                        exfat_error("cluster 0x%x of file `%s' is not allocated", c, name);
                        rc = 1;
                }
@@ -77,7 +77,7 @@ static void dirck(struct exfat* ef, const char* path)
                return;
 
        path_length = strlen(path);
-       entry_path = malloc(path_length + 1 + EXFAT_NAME_MAX);
+       entry_path = malloc(path_length + 1 + UTF8_BYTES(EXFAT_NAME_MAX) + 1);
        if (entry_path == NULL)
        {
                exfat_error("out of memory");
@@ -96,7 +96,8 @@ static void dirck(struct exfat* ef, const char* path)
        }
        while ((node = exfat_readdir(ef, &it)))
        {
-               exfat_get_name(node, entry_path + path_length + 1, EXFAT_NAME_MAX);
+               exfat_get_name(node, entry_path + path_length + 1,
+                               UTF8_BYTES(EXFAT_NAME_MAX));
                exfat_debug("%s: %s, %"PRIu64" bytes, cluster %u", entry_path,
                                IS_CONTIGUOUS(*node) ? "contiguous" : "fragmented",
                                node->size, node->start_cluster);
index 34b3ea6..6d91fb5 100644 (file)
@@ -92,7 +92,7 @@ static int fuse_exfat_readdir(const char* path, void* buffer,
        struct exfat_node* node;
        struct exfat_iterator it;
        int rc;
-       char name[EXFAT_NAME_MAX + 1];
+       char name[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
 
        exfat_debug("[%s] %s", __func__, path);
 
@@ -118,7 +118,7 @@ static int fuse_exfat_readdir(const char* path, void* buffer,
        }
        while ((node = exfat_readdir(&ef, &it)))
        {
-               exfat_get_name(node, name, EXFAT_NAME_MAX);
+               exfat_get_name(node, name, sizeof(name) - 1);
                exfat_debug("[%s] %s: %s, %"PRId64" bytes, cluster 0x%x", __func__,
                                name, IS_CONTIGUOUS(*node) ? "contiguous" : "fragmented",
                                node->size, node->start_cluster);
index 8596efd..704eece 100644 (file)
@@ -46,6 +46,7 @@
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #define DIV_ROUND_UP(x, d) (((x) + (d) - 1) / (d))
 #define ROUND_UP(x, d) (DIV_ROUND_UP(x, d) * (d))
+#define UTF8_BYTES(c) ((c) * 6) /* UTF-8 character can occupy up to 6 bytes */
 
 #define BMAP_GET(bitmap, index) \
        (((uint8_t*) bitmap)[(index) / 8] & (1u << ((index) % 8)))
@@ -98,8 +99,7 @@ struct exfat
                bool dirty;
        }
        cmap;
-       char label[EXFAT_ENAME_MAX * 6 + 1]; /* a character can occupy up to
-                                                                                       6 bytes in UTF-8 */
+       char label[UTF8_BYTES(EXFAT_ENAME_MAX) + 1];
        void* zero_cluster;
        int dmask, fmask;
        uid_t uid;
index 2a855dd..3295299 100644 (file)
@@ -44,8 +44,8 @@ void exfat_put_node(struct exfat* ef, struct exfat_node* node)
 {
        if (--node->references < 0)
        {
-               char buffer[EXFAT_NAME_MAX + 1];
-               exfat_get_name(node, buffer, EXFAT_NAME_MAX);
+               char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
+               exfat_get_name(node, buffer, sizeof(buffer) - 1);
                exfat_bug("reference counter of `%s' is below zero", buffer);
        }
 
@@ -293,9 +293,9 @@ static int readdir(struct exfat* ef, const struct exfat_node* parent,
                                */
                                if (real_size != (*node)->size)
                                {
-                                       char buffer[EXFAT_NAME_MAX + 1];
+                                       char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
 
-                                       exfat_get_name(*node, buffer, EXFAT_NAME_MAX);
+                                       exfat_get_name(*node, buffer, sizeof(buffer) - 1);
                                        exfat_error("`%s' real size does not equal to size "
                                                        "(%"PRIu64" != %"PRIu64")", buffer,
                                                        real_size, (*node)->size);
@@ -303,9 +303,9 @@ static int readdir(struct exfat* ef, const struct exfat_node* parent,
                                }
                                if (actual_checksum != reference_checksum)
                                {
-                                       char buffer[EXFAT_NAME_MAX + 1];
+                                       char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
 
-                                       exfat_get_name(*node, buffer, EXFAT_NAME_MAX);
+                                       exfat_get_name(*node, buffer, sizeof(buffer) - 1);
                                        exfat_error("`%s' has invalid checksum (0x%hx != 0x%hx)",
                                                        buffer, actual_checksum, reference_checksum);
                                        goto error;
@@ -493,8 +493,8 @@ static void reset_cache(struct exfat* ef, struct exfat_node* node)
        node->flags &= ~EXFAT_ATTRIB_CACHED;
        if (node->references != 0)
        {
-               char buffer[EXFAT_NAME_MAX + 1];
-               exfat_get_name(node, buffer, EXFAT_NAME_MAX);
+               char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
+               exfat_get_name(node, buffer, sizeof(buffer) - 1);
                exfat_warn("non-zero reference counter (%d) for `%s'",
                                node->references, buffer);
        }