aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorresver@gmail.com <resver@gmail.com@60bc1c72-a15a-11de-b98f-4500b42dc123>2013-05-20 16:33:27 +0000
committerresver@gmail.com <resver@gmail.com@60bc1c72-a15a-11de-b98f-4500b42dc123>2013-05-20 16:33:27 +0000
commit6b83efb2ddde97658a5d71596cb73afa7c44442a (patch)
tree559a2280ec3bf1435ba3ddd66bc9725050f28115
parentc79ca50bc9bb5e58ecb5e47fd3adad6d0bd5815d (diff)
downloadandroid_external_exfat-6b83efb2ddde97658a5d71596cb73afa7c44442a.tar.gz
android_external_exfat-6b83efb2ddde97658a5d71596cb73afa7c44442a.tar.bz2
android_external_exfat-6b83efb2ddde97658a5d71596cb73afa7c44442a.zip
Fixed handling of long non-ASCII file names.
git-svn-id: http://exfat.googlecode.com/svn/trunk@355 60bc1c72-a15a-11de-b98f-4500b42dc123
-rw-r--r--fsck/main.c13
-rw-r--r--fuse/main.c4
-rw-r--r--libexfat/exfat.h4
-rw-r--r--libexfat/node.c16
4 files changed, 19 insertions, 18 deletions
diff --git a/fsck/main.c b/fsck/main.c
index 421bd1d..e865641 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -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);
diff --git a/fuse/main.c b/fuse/main.c
index 34b3ea6..6d91fb5 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -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);
diff --git a/libexfat/exfat.h b/libexfat/exfat.h
index 8596efd..704eece 100644
--- a/libexfat/exfat.h
+++ b/libexfat/exfat.h
@@ -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;
diff --git a/libexfat/node.c b/libexfat/node.c
index 2a855dd..3295299 100644
--- a/libexfat/node.c
+++ b/libexfat/node.c
@@ -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);
}