summaryrefslogtreecommitdiffstats
path: root/exfat/libexfat/cluster.c
diff options
context:
space:
mode:
Diffstat (limited to 'exfat/libexfat/cluster.c')
-rw-r--r--exfat/libexfat/cluster.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/exfat/libexfat/cluster.c b/exfat/libexfat/cluster.c
index 2215636c6..fc3657b53 100644
--- a/exfat/libexfat/cluster.c
+++ b/exfat/libexfat/cluster.c
@@ -3,7 +3,7 @@
exFAT file system implementation library.
Free exFAT implementation.
- Copyright (C) 2010-2013 Andrew Nayenko
+ Copyright (C) 2010-2015 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
@@ -28,7 +28,7 @@
/*
* Sector to absolute offset.
*/
-static off64_t s2o(const struct exfat* ef, off64_t sector)
+static off_t s2o(const struct exfat* ef, off_t sector)
{
return sector << ef->sb->sector_bits;
}
@@ -36,18 +36,18 @@ static off64_t s2o(const struct exfat* ef, off64_t sector)
/*
* Cluster to sector.
*/
-static off64_t c2s(const struct exfat* ef, cluster_t cluster)
+static off_t c2s(const struct exfat* ef, cluster_t cluster)
{
if (cluster < EXFAT_FIRST_DATA_CLUSTER)
exfat_bug("invalid cluster number %u", cluster);
return le32_to_cpu(ef->sb->cluster_sector_start) +
- ((off64_t) (cluster - EXFAT_FIRST_DATA_CLUSTER) << ef->sb->spc_bits);
+ ((off_t) (cluster - EXFAT_FIRST_DATA_CLUSTER) << ef->sb->spc_bits);
}
/*
* Cluster to absolute offset.
*/
-off64_t exfat_c2o(const struct exfat* ef, cluster_t cluster)
+off_t exfat_c2o(const struct exfat* ef, cluster_t cluster)
{
return s2o(ef, c2s(ef, cluster));
}
@@ -55,7 +55,7 @@ off64_t exfat_c2o(const struct exfat* ef, cluster_t cluster)
/*
* Sector to cluster.
*/
-static cluster_t s2c(const struct exfat* ef, off64_t sector)
+static cluster_t s2c(const struct exfat* ef, off_t sector)
{
return ((sector - le32_to_cpu(ef->sb->cluster_sector_start)) >>
ef->sb->spc_bits) + EXFAT_FIRST_DATA_CLUSTER;
@@ -74,7 +74,7 @@ cluster_t exfat_next_cluster(const struct exfat* ef,
const struct exfat_node* node, cluster_t cluster)
{
le32_t next;
- off64_t fat_offset;
+ off_t fat_offset;
if (cluster < EXFAT_FIRST_DATA_CLUSTER)
exfat_bug("bad cluster 0x%x", cluster);
@@ -83,9 +83,9 @@ cluster_t exfat_next_cluster(const struct exfat* ef,
return cluster + 1;
fat_offset = s2o(ef, le32_to_cpu(ef->sb->fat_sector_start))
+ cluster * sizeof(cluster_t);
- /* FIXME handle I/O error */
if (exfat_pread(ef->dev, &next, sizeof(next), fat_offset) < 0)
- exfat_bug("failed to read the next cluster after %#x", cluster);
+ return EXFAT_CLUSTER_BAD; /* the caller should handle this and print
+ appropriate error message */
return le32_to_cpu(next);
}
@@ -136,6 +136,24 @@ static cluster_t find_bit_and_set(bitmap_t* bitmap, size_t start, size_t end)
return EXFAT_CLUSTER_END;
}
+static int flush_nodes(struct exfat* ef, struct exfat_node* node)
+{
+ struct exfat_node* p;
+
+ for (p = node->child; p != NULL; p = p->next)
+ {
+ int rc = flush_nodes(ef, p);
+ if (rc != 0)
+ return rc;
+ }
+ return exfat_flush_node(ef, node);
+}
+
+int exfat_flush_nodes(struct exfat* ef)
+{
+ return flush_nodes(ef, ef->root);
+}
+
int exfat_flush(struct exfat* ef)
{
if (ef->cmap.dirty)
@@ -149,13 +167,14 @@ int exfat_flush(struct exfat* ef)
}
ef->cmap.dirty = false;
}
+
return 0;
}
static bool set_next_cluster(const struct exfat* ef, bool contiguous,
cluster_t current, cluster_t next)
{
- off64_t fat_offset;
+ off_t fat_offset;
le32_t next_le32;
if (contiguous)
@@ -316,6 +335,7 @@ static int shrink_file(struct exfat* ef, struct exfat_node* node,
{
previous = node->start_cluster;
node->start_cluster = EXFAT_CLUSTER_FREE;
+ node->flags |= EXFAT_ATTRIB_DIRTY;
}
node->fptr_index = 0;
node->fptr_cluster = node->start_cluster;
@@ -339,7 +359,7 @@ static int shrink_file(struct exfat* ef, struct exfat_node* node,
return 0;
}
-static bool erase_raw(struct exfat* ef, size_t size, off64_t offset)
+static bool erase_raw(struct exfat* ef, size_t size, off_t offset)
{
if (exfat_pwrite(ef->dev, ef->zero_cluster, size, offset) < 0)
{
@@ -452,7 +472,7 @@ static int find_used_clusters(const struct exfat* ef,
return 0;
}
-int exfat_find_used_sectors(const struct exfat* ef, off64_t* a, off64_t* b)
+int exfat_find_used_sectors(const struct exfat* ef, off_t* a, off_t* b)
{
cluster_t ca, cb;