X-Git-Url: http://git.sven.stormbind.net/?p=sven%2Fexfat-utils.git;a=blobdiff_plain;f=libexfat%2Fcluster.c;h=5a261336b6ed2812ba3881711048cb51a16d4cdb;hp=1d3923355534cfb371ed243bc219fdbdd51dc1d4;hb=3639f26edacd0198b1d3e4834000a88b6a43612c;hpb=2fa6c5654e0a345af10df5227b77d9f468759f20 diff --git a/libexfat/cluster.c b/libexfat/cluster.c index 1d39233..5a26133 100644 --- a/libexfat/cluster.c +++ b/libexfat/cluster.c @@ -103,7 +103,7 @@ cluster_t exfat_advance_cluster(const struct exfat* ef, for (i = node->fptr_index; i < count; i++) { node->fptr_cluster = exfat_next_cluster(ef, node, node->fptr_cluster); - if (CLUSTER_INVALID(node->fptr_cluster)) + if (CLUSTER_INVALID(*ef->sb, node->fptr_cluster)) break; /* the caller should handle this and print appropriate error message */ } @@ -214,10 +214,8 @@ static cluster_t allocate_cluster(struct exfat* ef, cluster_t hint) static void free_cluster(struct exfat* ef, cluster_t cluster) { - if (CLUSTER_INVALID(cluster)) - exfat_bug("freeing invalid cluster 0x%x", cluster); if (cluster - EXFAT_FIRST_DATA_CLUSTER >= ef->cmap.size) - exfat_bug("freeing non-existing cluster 0x%x (0x%x)", cluster, + exfat_bug("caller must check cluster validity (%#x, %#x)", cluster, ef->cmap.size); BMAP_CLR(ef->cmap.chunk, cluster - EXFAT_FIRST_DATA_CLUSTER); @@ -252,7 +250,7 @@ static int grow_file(struct exfat* ef, struct exfat_node* node, { /* get the last cluster of the file */ previous = exfat_advance_cluster(ef, node, current - 1); - if (CLUSTER_INVALID(previous)) + if (CLUSTER_INVALID(*ef->sb, previous)) { exfat_error("invalid cluster 0x%x while growing", previous); return -EIO; @@ -265,7 +263,7 @@ static int grow_file(struct exfat* ef, struct exfat_node* node, /* file does not have clusters (i.e. is empty), allocate the first one for it */ previous = allocate_cluster(ef, 0); - if (CLUSTER_INVALID(previous)) + if (CLUSTER_INVALID(*ef->sb, previous)) return -ENOSPC; node->fptr_cluster = node->start_cluster = previous; allocated = 1; @@ -276,7 +274,7 @@ static int grow_file(struct exfat* ef, struct exfat_node* node, while (allocated < difference) { next = allocate_cluster(ef, previous + 1); - if (CLUSTER_INVALID(next)) + if (CLUSTER_INVALID(*ef->sb, next)) { if (allocated != 0) shrink_file(ef, node, current + allocated, allocated); @@ -321,7 +319,7 @@ static int shrink_file(struct exfat* ef, struct exfat_node* node, { cluster_t last = exfat_advance_cluster(ef, node, current - difference - 1); - if (CLUSTER_INVALID(last)) + if (CLUSTER_INVALID(*ef->sb, last)) { exfat_error("invalid cluster 0x%x while shrinking", last); return -EIO; @@ -343,12 +341,13 @@ static int shrink_file(struct exfat* ef, struct exfat_node* node, /* free remaining clusters */ while (difference--) { - if (CLUSTER_INVALID(previous)) + if (CLUSTER_INVALID(*ef->sb, previous)) { exfat_error("invalid cluster 0x%x while freeing after shrink", previous); return -EIO; } + next = exfat_next_cluster(ef, node, previous); if (!set_next_cluster(ef, node->is_contiguous, previous, EXFAT_CLUSTER_FREE)) @@ -381,7 +380,7 @@ static int erase_range(struct exfat* ef, struct exfat_node* node, cluster_boundary = (begin | (CLUSTER_SIZE(*ef->sb) - 1)) + 1; cluster = exfat_advance_cluster(ef, node, begin / CLUSTER_SIZE(*ef->sb)); - if (CLUSTER_INVALID(cluster)) + if (CLUSTER_INVALID(*ef->sb, cluster)) { exfat_error("invalid cluster 0x%x while erasing", cluster); return -EIO; @@ -395,7 +394,7 @@ static int erase_range(struct exfat* ef, struct exfat_node* node, { cluster = exfat_next_cluster(ef, node, cluster); /* the cluster cannot be invalid because we have just allocated it */ - if (CLUSTER_INVALID(cluster)) + if (CLUSTER_INVALID(*ef->sb, cluster)) exfat_bug("invalid cluster 0x%x after allocation", cluster); if (!erase_raw(ef, CLUSTER_SIZE(*ef->sb), exfat_c2o(ef, cluster))) return -EIO;