+static int dump_file_fragments(const char* spec, const char* path)
+{
+ struct exfat ef;
+ struct exfat_node* node;
+ cluster_t cluster;
+ cluster_t next_cluster;
+ cluster_t fragment_start_cluster;
+ off_t remainder;
+ off_t fragment_size = 0;
+ int rc = 0;
+
+ if (exfat_mount(&ef, spec, "ro") != 0)
+ return 1;
+
+ rc = exfat_lookup(&ef, &node, path);
+ if (rc != 0)
+ {
+ exfat_unmount(&ef);
+ exfat_error("'%s': %s", path, strerror(-rc));
+ return 1;
+ }
+
+ cluster = fragment_start_cluster = node->start_cluster;
+ remainder = node->size;
+ while (remainder > 0)
+ {
+ off_t lsize;
+
+ if (CLUSTER_INVALID(*ef.sb, cluster))
+ {
+ exfat_error("'%s' has invalid cluster %#x", path, cluster);
+ rc = 1;
+ break;
+ }
+
+ lsize = MIN(CLUSTER_SIZE(*ef.sb), remainder);
+ fragment_size += lsize;
+ remainder -= lsize;
+
+ next_cluster = exfat_next_cluster(&ef, node, cluster);
+ if (next_cluster != cluster + 1 || remainder == 0)
+ {
+ /* next cluster is not contiguous or this is EOF */
+ printf("%"PRIu64" %"PRIu64"\n",
+ exfat_c2o(&ef, fragment_start_cluster), fragment_size);
+ /* start a new fragment */
+ fragment_start_cluster = next_cluster;
+ fragment_size = 0;
+ }
+ cluster = next_cluster;
+ }
+
+ exfat_put_node(&ef, node);
+ exfat_unmount(&ef);
+ return rc;
+}
+