Improve error messages in opendir().

This commit is contained in:
relan
2016-11-12 10:22:51 +03:00
parent c80517b50d
commit 1a2f610852

View File

@@ -94,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->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)
{
free(it->chunk);
exfat_error("failed to read directory cluster %#x", it->cluster);
exfat_get_name(dir, buffer, sizeof(buffer) - 1);
exfat_error("failed to read '%s' directory cluster %#x", buffer,
it->cluster);
return -EIO;
}
return 0;