OSDN Git Service

Run all checks in check_node().
[android-x86/external-exfat.git] / libexfat / node.c
index 6a93277..4a3ee40 100644 (file)
@@ -3,7 +3,7 @@
        exFAT file system implementation library.
 
        Free exFAT implementation.
-       Copyright (C) 2010-2015  Andrew Nayenko
+       Copyright (C) 2010-2016  Andrew Nayenko
 
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
@@ -30,7 +30,6 @@ struct iterator
 {
        cluster_t cluster;
        off_t offset;
-       int contiguous;
        char* chunk;
 };
 
@@ -95,21 +94,28 @@ static off_t co2o(struct exfat* ef, cluster_t cluster, off_t offset)
 static int opendir(struct exfat* ef, const struct exfat_node* dir,
                struct iterator* it)
 {
+       char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
+
        if (!(dir->flags & EXFAT_ATTRIB_DIR))
-               exfat_bug("not a directory");
+       {
+               exfat_get_name(dir, buffer, sizeof(buffer) - 1);
+               exfat_bug("'%s' is not a directory", buffer);
+       }
        it->cluster = dir->start_cluster;
        it->offset = 0;
-       it->contiguous = IS_CONTIGUOUS(*dir);
        it->chunk = malloc(CLUSTER_SIZE(*ef->sb));
        if (it->chunk == NULL)
        {
-               exfat_error("out of memory");
+               exfat_error("failed to allocate memory for directory cluster");
                return -ENOMEM;
        }
        if (exfat_pread(ef->dev, it->chunk, CLUSTER_SIZE(*ef->sb),
                        exfat_c2o(ef, it->cluster)) < 0)
        {
-               exfat_error("failed to read directory cluster %#x", it->cluster);
+               free(it->chunk);
+               exfat_get_name(dir, buffer, sizeof(buffer) - 1);
+               exfat_error("failed to read '%s' directory cluster %#x", buffer,
+                               it->cluster);
                return -EIO;
        }
        return 0;
@@ -119,7 +125,6 @@ static void closedir(struct iterator* it)
 {
        it->cluster = 0;
        it->offset = 0;
-       it->contiguous = 0;
        free(it->chunk);
        it->chunk = NULL;
 }
@@ -197,6 +202,7 @@ static bool check_node(const struct exfat_node* node, uint16_t actual_checksum,
                uint16_t reference_checksum, uint64_t valid_size)
 {
        char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
+       bool ret = true;
 
        /*
           Validate checksum first. If it's invalid all other fields probably
@@ -207,7 +213,7 @@ static bool check_node(const struct exfat_node* node, uint16_t actual_checksum,
                exfat_get_name(node, buffer, sizeof(buffer) - 1);
                exfat_error("'%s' has invalid checksum (%#hx != %#hx)", buffer,
                                actual_checksum, reference_checksum);
-               return false;
+               ret = false;
        }
 
        /*
@@ -221,10 +227,10 @@ static bool check_node(const struct exfat_node* node, uint16_t actual_checksum,
                exfat_get_name(node, buffer, sizeof(buffer) - 1);
                exfat_error("'%s' has valid size (%"PRIu64") greater than size "
                                "(%"PRIu64")", buffer, valid_size, node->size);
-               return false;
+               ret = false;
        }
 
-       return true;
+       return ret;
 }
 
 static void decompress_upcase(uint16_t* output, const le16_t* source,