/* This function scans tables for contiguous clusters. A contiguous run of clusters may be allocated, unallocated, or zero.  */
static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s, QEDTable *table, unsigned int index, unsigned int n, uint64_t *offset)
/* This function scans tables for contiguous clusters. A contiguous run of clusters may be allocated, unallocated, or zero.  */
static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s, QEDTable *table, unsigned int index, unsigned int n, uint64_t *offset)
{
    unsigned int end = MIN(index + n, s->table_nelems);
    uint64_t last = table->offsets[index];
    unsigned int i;
    *offset = last;
    for (i = index + 1; i < end; i++) {
        if (qed_offset_is_unalloc_cluster(last)) {
            if (!qed_offset_is_unalloc_cluster(table->offsets[i])) {
                break;
            }
        } else if (qed_offset_is_zero_cluster(last)) {
            if (!qed_offset_is_zero_cluster(table->offsets[i])) {
                break;
            }
        } else {
            if (table->offsets[i] != last + s->header.cluster_size) {
                break;
            }
            last = table->offsets[i];
        }
    }
    return i - index;
}