summaryrefslogtreecommitdiffstats
path: root/exfat/libexfat
diff options
context:
space:
mode:
Diffstat (limited to 'exfat/libexfat')
-rw-r--r--exfat/libexfat/exfat.h4
-rw-r--r--exfat/libexfat/node.c19
2 files changed, 12 insertions, 11 deletions
diff --git a/exfat/libexfat/exfat.h b/exfat/libexfat/exfat.h
index 3e4223e5d..a6a9f706d 100644
--- a/exfat/libexfat/exfat.h
+++ b/exfat/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/exfat/libexfat/node.c b/exfat/libexfat/node.c
index c2ee0da38..f89b5731d 100644
--- a/exfat/libexfat/node.c
+++ b/exfat/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;
@@ -389,7 +389,7 @@ static int readdir(struct exfat* ef, const struct exfat_node* parent,
goto error;
}
if (utf16_to_utf8(ef->label, label->name,
- sizeof(ef->label), EXFAT_ENAME_MAX) != 0)
+ sizeof(ef->label) - 1, EXFAT_ENAME_MAX) != 0)
goto error;
break;
@@ -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);
}
@@ -1051,5 +1051,6 @@ int exfat_set_label(struct exfat* ef, const char* label)
exfat_pwrite(ef->dev, &entry, sizeof(struct exfat_entry_label),
co2o(ef, cluster, offset));
+ strcpy(ef->label, label);
return 0;
}