1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2021 LG Electronics.
5 * Author(s): Hyunchul Lee <hyc.lee@gmail.com>
19 #include "exfat_ondisk.h"
22 #include "exfat_dir.h"
24 #define EXFAT_MAX_UPCASE_CHARS 0x10000
26 struct exfat2img_hdr {
31 __le32 heap_clus_offset;
37 #define EI_MAGIC 0xB67598DB
38 #define EI_CC_PAYLOAD_LEN 4
43 EI_CC_COPY_2, /* followed by cluster count(4-byte) */
45 EI_CC_SKIP_2, /* followed by cluster count(4-byte) */
53 struct exfat_blk_dev bdev;
56 struct buffer_desc *scan_bdesc;
57 struct exfat_de_iter de_iter;
64 uint64_t written_bytes;
67 static struct exfat2img_hdr ei_hdr;
68 static struct exfat2img ei;
69 static struct exfat_stat exfat_stat;
70 static struct path_resolve_ctx path_resolve_ctx;
72 static struct option opts[] = {
73 {"output", required_argument, NULL, 'o' },
74 {"version", no_argument, NULL, 'V' },
75 {"help", no_argument, NULL, 'h' },
79 static void usage(const char *name)
81 fprintf(stderr, "Usage: %s <device> [image-file]\n", name);
82 fprintf(stderr, "\t-o | --output <image-file> Specify destination file\n");
83 fprintf(stderr, "\t-V | --version Show version\n");
84 fprintf(stderr, "\t-h | --help Show help\n");
88 #define ei_err(parent, inode, fmt, ...) \
90 exfat_resolve_path_parent(&path_resolve_ctx, \
92 exfat_err("ERROR: %s: " fmt, \
93 path_resolve_ctx.local_path, \
97 static void free_exfat2img(struct exfat2img *ei)
100 exfat_free_buffer(ei->exfat, ei->scan_bdesc);
102 exfat_free_exfat(ei->exfat);
103 if (ei->dump_cluster)
104 free(ei->dump_cluster);
108 close(ei->bdev.dev_fd);
111 static int create_exfat2img(struct exfat2img *ei,
113 const char *out_path)
117 ei->exfat = exfat_alloc_exfat(&ei->bdev, bs);
121 ei->dump_cluster = malloc(ei->exfat->clus_size);
122 if (!ei->dump_cluster) {
127 ei->scan_bdesc = exfat_alloc_buffer(ei->exfat);
128 if (!ei->scan_bdesc) {
133 if (strcmp(out_path, "-")) {
134 ei->out_fd = open(out_path, O_CREAT | O_TRUNC | O_RDWR, 0664);
136 ei->is_stdout = true;
137 ei->out_fd = fileno(stdout);
140 if (ei->out_fd < 0) {
141 exfat_err("failed to open %s: %s\n", out_path,
156 static ssize_t dump_range(struct exfat2img *ei, off_t start, off_t end)
158 struct exfat *exfat = ei->exfat;
159 size_t len, total_len = 0;
163 unsigned int sc, sc_offset;
164 unsigned int ec, ec_offset;
166 if (exfat_o2c(ei->exfat, start, &sc, &sc_offset) < 0)
168 if (exfat_o2c(ei->exfat, end - 1, &ec, &ec_offset) < 0)
170 exfat_bitmap_set_range(ei->exfat, exfat->alloc_bitmap,
175 while (start < end) {
176 len = (size_t)MIN(end - start, exfat->clus_size);
178 ret = exfat_read(exfat->blk_dev->dev_fd,
179 ei->dump_cluster, len, start);
180 if (ret != (ssize_t)len) {
181 exfat_err("failed to read %llu bytes at %llu\n",
182 (unsigned long long)len,
183 (unsigned long long)start);
187 ret = pwrite(ei->out_fd, ei->dump_cluster, len, start);
188 if (ret != (ssize_t)len) {
189 exfat_err("failed to write %llu bytes at %llu\n",
190 (unsigned long long)len,
191 (unsigned long long)start);
197 exfat_stat.written_bytes += len;
202 static int dump_sectors(struct exfat2img *ei,
206 struct exfat *exfat = ei->exfat;
209 s = exfat_s2o(exfat, start_sect);
210 e = exfat_s2o(exfat, end_sect_excl);
211 return dump_range(ei, s, e) <= 0 ? -EIO : 0;
214 static int dump_clusters(struct exfat2img *ei,
216 clus_t end_clus_excl)
218 struct exfat *exfat = ei->exfat;
221 s = exfat_c2o(exfat, start_clus);
222 e = exfat_c2o(exfat, end_clus_excl);
223 return dump_range(ei, s, e) <= 0 ? -EIO : 0;
226 static int dump_directory(struct exfat2img *ei,
227 struct exfat_inode *inode, size_t size,
228 clus_t *out_clus_count)
230 struct exfat *exfat = ei->exfat;
231 clus_t clus, possible_count;
234 off_t start_off, end_off;
239 if (!(inode->attr & ATTR_SUBDIR))
242 clus = inode->first_clus;
244 max_count = DIV_ROUND_UP(inode->size, exfat->clus_size);
246 possible_count = (256 * MB) >> (exfat->bs->bsx.sect_per_clus_bits +
247 exfat->bs->bsx.sect_size_bits);
248 possible_count = MIN(possible_count, exfat->clus_count);
250 while (exfat_heap_clus(exfat, clus) && *out_clus_count < possible_count) {
251 dump_size = MIN(size, exfat->clus_size);
252 start_off = exfat_c2o(exfat, clus);
253 end_off = start_off + DIV_ROUND_UP(dump_size, 512) * 512;
255 if (dump_range(ei, start_off, end_off) < 0)
258 *out_clus_count += 1;
263 if (inode->is_contiguous) {
264 if (*out_clus_count >= max_count)
267 if (exfat_get_inode_next_clus(exfat, inode, clus, &clus))
273 static int dump_root(struct exfat2img *ei)
275 struct exfat *exfat = ei->exfat;
276 struct exfat_inode *root;
277 clus_t clus_count = 0;
279 root = exfat_alloc_inode(ATTR_SUBDIR);
283 root->first_clus = le32_to_cpu(exfat->bs->bsx.root_cluster);
284 dump_directory(ei, root, (size_t)-1, &clus_count);
285 root->size = clus_count * exfat->clus_size;
287 ei->exfat->root = root;
291 static int read_file_dentry_set(struct exfat_de_iter *iter,
292 struct exfat_inode **new_node, int *skip_dentries)
294 struct exfat_dentry *file_de, *stream_de, *dentry;
295 struct exfat_inode *node = NULL;
298 ret = exfat_de_iter_get(iter, 0, &file_de);
299 if (ret || file_de->type != EXFAT_FILE) {
300 exfat_debug("failed to get file dentry\n");
304 ret = exfat_de_iter_get(iter, 1, &stream_de);
305 if (ret || stream_de->type != EXFAT_STREAM) {
306 exfat_debug("failed to get stream dentry\n");
312 node = exfat_alloc_inode(le16_to_cpu(file_de->file_attr));
316 for (i = 2; i <= MIN(file_de->file_num_ext, 1 + MAX_NAME_DENTRIES); i++) {
317 ret = exfat_de_iter_get(iter, i, &dentry);
318 if (ret || dentry->type != EXFAT_NAME)
321 (i - 2) * ENTRY_NAME_MAX, dentry->name_unicode,
322 sizeof(dentry->name_unicode));
325 node->first_clus = le32_to_cpu(stream_de->stream_start_clu);
326 node->is_contiguous =
327 ((stream_de->stream_flags & EXFAT_SF_CONTIGUOUS) != 0);
328 node->size = le64_to_cpu(stream_de->stream_size);
335 exfat_free_inode(node);
339 static int read_file(struct exfat_de_iter *de_iter,
340 struct exfat_inode **new_node, int *dentry_count)
342 struct exfat_inode *node;
347 ret = read_file_dentry_set(de_iter, &node, dentry_count);
351 if (node->attr & ATTR_SUBDIR)
352 exfat_stat.dir_count++;
354 exfat_stat.file_count++;
359 static int read_bitmap(struct exfat2img *ei, struct exfat_de_iter *iter)
361 struct exfat *exfat = ei->exfat;
362 struct exfat_dentry *dentry;
365 ret = exfat_de_iter_get(iter, 0, &dentry);
366 if (ret || dentry->type != EXFAT_BITMAP) {
367 exfat_debug("failed to get bimtap dentry\n");
371 exfat_debug("start cluster %#x, size %#" PRIx64 "\n",
372 le32_to_cpu(dentry->bitmap_start_clu),
373 le64_to_cpu(dentry->bitmap_size));
375 if (!exfat_heap_clus(exfat, le32_to_cpu(dentry->bitmap_start_clu))) {
376 exfat_err("invalid start cluster of allocate bitmap. 0x%x\n",
377 le32_to_cpu(dentry->bitmap_start_clu));
381 exfat->disk_bitmap_clus = le32_to_cpu(dentry->bitmap_start_clu);
382 exfat->disk_bitmap_size = DIV_ROUND_UP(exfat->clus_count, 8);
384 return dump_clusters(ei,
385 exfat->disk_bitmap_clus,
386 exfat->disk_bitmap_clus +
387 DIV_ROUND_UP(exfat->disk_bitmap_size,
391 static int read_upcase_table(struct exfat2img *ei,
392 struct exfat_de_iter *iter)
394 struct exfat *exfat = ei->exfat;
395 struct exfat_dentry *dentry = NULL;
399 retval = exfat_de_iter_get(iter, 0, &dentry);
400 if (retval || dentry->type != EXFAT_UPCASE) {
401 exfat_debug("failed to get upcase dentry\n");
405 if (!exfat_heap_clus(exfat, le32_to_cpu(dentry->upcase_start_clu))) {
406 exfat_err("invalid start cluster of upcase table. 0x%x\n",
407 le32_to_cpu(dentry->upcase_start_clu));
411 size = EXFAT_MAX_UPCASE_CHARS * sizeof(__le16);
412 return dump_clusters(ei, le32_to_cpu(dentry->upcase_start_clu),
413 le32_to_cpu(dentry->upcase_start_clu) +
414 DIV_ROUND_UP(size, exfat->clus_size));
417 static int read_children(struct exfat2img *ei, struct exfat_inode *dir,
418 off_t *end_file_offset)
420 struct exfat *exfat = ei->exfat;
421 struct exfat_inode *node = NULL;
422 struct exfat_dentry *dentry;
423 struct exfat_de_iter *de_iter;
427 *end_file_offset = 0;
428 de_iter = &ei->de_iter;
429 ret = exfat_de_iter_init(de_iter, exfat, dir, ei->scan_bdesc);
436 ret = exfat_de_iter_get(de_iter, 0, &dentry);
440 ei_err(dir->parent, dir,
441 "failed to get a dentry. %d\n", ret);
446 switch (dentry->type) {
448 ret = read_file(de_iter, &node, &dentry_count);
450 exfat_stat.error_count++;
455 if ((node->attr & ATTR_SUBDIR) && node->size) {
457 list_add_tail(&node->sibling,
459 list_add_tail(&node->list,
462 exfat_free_inode(node);
469 if (dir == exfat->root) {
470 ret = read_bitmap(ei, de_iter);
472 exfat_debug("failed to read bitmap\n");
476 if (dir == exfat->root) {
477 ret = read_upcase_table(ei, de_iter);
479 exfat_debug("failed to upcase table\n");
487 ret = exfat_de_iter_advance(de_iter, dentry_count);
490 *end_file_offset = exfat_de_iter_file_offset(de_iter);
491 exfat_de_iter_flush(de_iter);
494 exfat_free_children(dir, false);
495 INIT_LIST_HEAD(&dir->children);
496 exfat_de_iter_flush(de_iter);
500 static int dump_filesystem(struct exfat2img *ei)
502 struct exfat *exfat = ei->exfat;
503 struct exfat_inode *dir;
504 int ret = 0, dir_errors;
506 off_t end_file_offset;
509 exfat_err("root is NULL\n");
513 list_add(&exfat->root->list, &exfat->dir_list);
515 while (!list_empty(&exfat->dir_list)) {
516 dir = list_entry(exfat->dir_list.next,
517 struct exfat_inode, list);
520 if (!(dir->attr & ATTR_SUBDIR)) {
521 ei_err(dir->parent, dir,
522 "failed to travel directories. the node is not directory\n");
527 dir_errors = read_children(ei, dir, &end_file_offset);
529 dump_directory(ei, dir, (size_t)end_file_offset,
531 } else if (dir_errors) {
532 dump_directory(ei, dir, (size_t)-1,
534 exfat_resolve_path(&path_resolve_ctx, dir);
535 exfat_debug("failed to check dentries: %s\n",
536 path_resolve_ctx.local_path);
540 list_del(&dir->list);
541 exfat_free_ancestors(dir);
544 exfat_free_dir_list(exfat);
548 static int dump_bytes_to_stdout(struct exfat2img *ei,
549 off_t start, off_t end_excl)
551 struct exfat *exfat = ei->exfat;
555 if (start != ei->stdout_offset) {
556 exfat_err("try to skip for stdout at %llu, expected: %llu\n",
557 (unsigned long long)start,
558 (unsigned long long)ei->stdout_offset);
562 while (start < end_excl) {
563 len = (size_t)MIN(end_excl - start, exfat->clus_size);
564 ret = exfat_read(exfat->blk_dev->dev_fd, ei->dump_cluster,
566 if (ret != (ssize_t)len) {
567 exfat_err("failed to read %llu bytes at %llu\n",
568 (unsigned long long)len,
569 (unsigned long long)start);
573 ret = write(ei->out_fd, ei->dump_cluster, len);
574 if (ret != (ssize_t)len) {
575 exfat_err("failed to write %llu bytes at %llu\n",
576 (unsigned long long)len,
577 (unsigned long long)start);
582 ei->stdout_offset += len;
583 exfat_stat.written_bytes += len;
588 static int dump_clusters_to_stdout(struct exfat2img *ei,
589 unsigned int start_clu, unsigned int end_clu,
592 unsigned int clu, clu_count;
594 unsigned int cc_clu_count, cc_len;
595 off_t start_off, end_off_excl;
596 char buf[1 + EI_CC_PAYLOAD_LEN];
599 clu_count = end_clu - start_clu + 1;
602 /* if the count of clusters is less than 5, use SKIP_1 or COPY_2 */
603 cc_clu_count = clu_count < 5 ? 1 : clu_count;
604 cc_len = cc_clu_count == 1 ? 1 : 1 + EI_CC_PAYLOAD_LEN;
606 cc = cc_clu_count == 1 ? EI_CC_SKIP_1 : EI_CC_SKIP_2;
608 cc = cc_clu_count == 1 ? EI_CC_COPY_1 : EI_CC_COPY_2;
611 cc_clu_count = clu_count;
614 while (clu <= end_clu) {
615 if (cc != EI_CC_INVALID) {
617 *((__le32 *)&buf[1]) =
618 cpu_to_le32(cc_clu_count);
619 if (write(ei->out_fd, buf, cc_len) != (ssize_t)cc_len) {
620 exfat_err("failed to write cc %d : %u\n for %u ~ %u clusters\n",
622 start_clu, start_clu + cc_clu_count - 1);
626 if (cc == EI_CC_COPY_1 || cc == EI_CC_COPY_2) {
627 start_off = exfat_c2o(ei->exfat, clu);
628 end_off_excl = exfat_c2o(ei->exfat, clu + cc_clu_count);
630 if (dump_bytes_to_stdout(ei, start_off, end_off_excl) < 0)
633 ei->stdout_offset += (off_t)cc_clu_count * ei->exfat->clus_size;
641 static int dump_to_stdout(struct exfat2img *ei)
643 struct exfat *exfat = ei->exfat;
644 off_t start_off, end_off;
645 unsigned int clu, last_clu, next_clu;
646 unsigned int start_clu, end_clu;
649 end_off = exfat_s2o(exfat, le32_to_cpu(exfat->bs->bsx.clu_offset));
650 if (dump_bytes_to_stdout(ei, start_off, end_off) < 0) {
651 exfat_err("failed to dump boot sectors and FAT tables\n");
655 clu = EXFAT_FIRST_CLUSTER;
656 last_clu = clu + exfat->clus_count;
657 while (clu < last_clu) {
658 /* read and write clusters for allocated ones */
660 while (clu < last_clu &&
661 exfat_bitmap_get(exfat->alloc_bitmap, clu)) {
669 if (dump_clusters_to_stdout(ei, start_clu, end_clu, false) < 0) {
670 start_off = exfat_c2o(exfat, start_clu);
671 end_off = exfat_c2o(exfat, end_clu);
672 exfat_err("failed to dump range from %llx to %llx\n",
673 (unsigned long long)start_off,
674 (unsigned long long)end_off);
679 /* exit if all of the remaining clusters are free */
682 if (exfat_bitmap_find_one(exfat, exfat->alloc_bitmap,
684 next_clu = EXFAT_FIRST_CLUSTER + exfat->clus_count;
686 /* write zeroes for free clusters */
688 end_clu = next_clu - 1;
689 if (dump_clusters_to_stdout(ei, start_clu, end_clu, true) < 0) {
690 start_off = exfat_c2o(exfat, start_clu);
691 end_off = exfat_c2o(exfat, end_clu);
692 exfat_err("failed to dump zero range from %llx to %llx\n",
693 (unsigned long long)start_off,
694 (unsigned long long)end_off);
704 static int dump_header(struct exfat2img *ei)
706 struct exfat *exfat = ei->exfat;
708 ei_hdr.magic = cpu_to_le32(EI_MAGIC);
709 ei_hdr.major_version = cpu_to_le32(1);
710 ei_hdr.minor_version = cpu_to_le32(0);
711 ei_hdr.data_offset = cpu_to_le32(sizeof(struct exfat2img_hdr));
712 ei_hdr.heap_clus_offset =
713 cpu_to_le32(le32_to_cpu(exfat->bs->bsx.clu_offset) *
715 ei_hdr.cluster_size = cpu_to_le32(exfat->clus_size);
716 ei_hdr.cluster_count = cpu_to_le32(exfat->clus_count);
718 if (write(ei->out_fd, &ei_hdr, sizeof(ei_hdr)) != (ssize_t)sizeof(ei_hdr)) {
719 exfat_err("failed to write exfat2img header\n");
725 static ssize_t read_stream(int fd, void *buf, size_t len)
730 while (read_len < len) {
731 ret = read(fd, buf, len - read_len);
733 if (errno != -EAGAIN && errno != -EINTR)
736 } else if (ret == 0) {
739 buf = (char *)buf + (size_t)ret;
740 read_len += (size_t)ret;
745 static int restore_from_stdin(struct exfat2img *ei)
749 unsigned int clu, end_clu;
750 unsigned int cc_clu_count;
751 unsigned int clus_size;
752 __le32 t_cc_clu_count;
753 off_t out_start_off, out_end_off_excl;
757 in_fd = fileno(stdin);
759 exfat_err("failed to get fd from stdin\n");
763 if (read_stream(in_fd, &ei_hdr, sizeof(ei_hdr)) != (ssize_t)sizeof(ei_hdr)) {
764 exfat_err("failed to read a header\n");
768 if (le32_to_cpu(ei_hdr.magic) != EI_MAGIC) {
769 exfat_err("header has invalid magic %#x, expected %#x\n",
770 le32_to_cpu(ei_hdr.magic), EI_MAGIC);
774 clus_size = le32_to_cpu(ei_hdr.cluster_size);
776 ei->out_fd = ei->bdev.dev_fd;
777 ei->dump_cluster = malloc(clus_size);
778 if (!ei->dump_cluster)
781 /* restore boot regions, and FAT tables */
782 in_start_off = le32_to_cpu(ei_hdr.data_offset);
784 out_end_off_excl = le32_to_cpu(ei_hdr.heap_clus_offset);
785 while (out_start_off < out_end_off_excl) {
786 len = MIN(out_end_off_excl - out_start_off, clus_size);
787 if (read_stream(in_fd, ei->dump_cluster, len) != (ssize_t)len) {
788 exfat_err("failed to read first meta region. %llu ~ %llu\n",
789 (unsigned long long)in_start_off,
790 (unsigned long long)in_start_off + len);
795 if (pwrite(ei->out_fd, ei->dump_cluster, len, out_start_off)
797 exfat_err("failed to write first meta region. %llu ~ %llu\n",
798 (unsigned long long)out_start_off,
799 (unsigned long long)out_start_off + len);
804 out_start_off += len;
808 /* restore heap clusters */
810 while (clu < le32_to_cpu(ei_hdr.cluster_count)) {
811 if (read_stream(in_fd, &cc, sizeof(cc)) != (ssize_t)sizeof(cc)) {
812 exfat_err("failed to read cc at %llu\n",
813 (unsigned long long)in_start_off);
819 if (cc == EI_CC_COPY_2 || cc == EI_CC_SKIP_2) {
820 if (read_stream(in_fd, &t_cc_clu_count, EI_CC_PAYLOAD_LEN) !=
821 (ssize_t)EI_CC_PAYLOAD_LEN) {
822 exfat_err("failed to read cc cluster count at %llu\n",
823 (unsigned long long)in_start_off);
827 cc_clu_count = le32_to_cpu(t_cc_clu_count);
828 in_start_off += EI_CC_PAYLOAD_LEN;
829 } else if (cc == EI_CC_COPY_1 || cc == EI_CC_SKIP_1) {
832 exfat_err("unexpected cc %d at %llu\n",
833 cc, (unsigned long long)in_start_off);
838 if (cc == EI_CC_COPY_1 || cc == EI_CC_COPY_2) {
839 end_clu = clu + cc_clu_count;
840 while (clu < end_clu) {
841 if (read_stream(in_fd, ei->dump_cluster,
842 clus_size) != (ssize_t)clus_size) {
843 exfat_err("failed to read range %llu ~ %llu\n",
844 (unsigned long long)in_start_off,
845 (unsigned long long)in_start_off + clus_size);
849 if (pwrite(ei->out_fd, ei->dump_cluster,
850 clus_size, out_start_off) != (ssize_t)clus_size) {
851 exfat_err("failed to write range %llu ~ %llu\n",
852 (unsigned long long)out_start_off,
853 (unsigned long long)out_start_off + clus_size);
858 out_start_off += clus_size;
859 in_start_off += clus_size;
863 out_start_off += (off_t)cc_clu_count * clus_size;
864 in_start_off += (off_t)cc_clu_count * clus_size;
865 if (lseek(ei->out_fd, out_start_off, SEEK_SET) == (off_t)-1) {
866 exfat_err("failed to seek to %llu\n",
867 (unsigned long long)out_start_off);
875 if (fsync(ei->out_fd)) {
876 exfat_err("failed to fsync: %d\n", errno);
879 free(ei->dump_cluster);
883 int main(int argc, char * const argv[])
886 const char *in_path, *out_path = NULL, *blkdev_path;
888 struct exfat_user_input ui;
892 print_level = EXFAT_ERROR;
895 while ((c = getopt_long(argc, argv, "o:Vh", opts, NULL)) != EOF) {
912 if (!(optind == argc - 1 && out_path) &&
913 !(optind == argc - 2 && !out_path))
916 in_path = argv[optind++];
918 out_path = argv[optind++];
920 if (!strcmp(in_path, "-")) {
922 blkdev_path = out_path;
925 blkdev_path = in_path;
928 memset(&ui, 0, sizeof(ui));
929 snprintf(ui.dev_name, sizeof(ui.dev_name), "%s", blkdev_path);
933 ui.writeable = false;
935 if (exfat_get_blk_dev_info(&ui, &ei.bdev)) {
936 exfat_err("failed to open %s\n", ui.dev_name);
941 return restore_from_stdin(&ei);
943 err = read_boot_sect(&ei.bdev, &bs);
945 close(ei.bdev.dev_fd);
949 err = create_exfat2img(&ei, bs, out_path);
954 err = dump_sectors(&ei, 0, le32_to_cpu(ei.exfat->bs->bsx.clu_offset));
956 exfat_err("failed to dump boot sectors, fat\n");
960 last_sect = (off_t)le32_to_cpu(ei.exfat->bs->bsx.clu_offset) +
961 (le32_to_cpu(ei.exfat->bs->bsx.clu_count) <<
962 ei.exfat->bs->bsx.sect_per_clus_bits) - 1;
963 err = dump_sectors(&ei, last_sect, last_sect + 1);
965 exfat_err("failed to dump last sector\n");
970 err = dump_root(&ei);
972 exfat_err("failed to dump root\n");
976 dump_filesystem(&ei);
979 err = dump_header(&ei);
982 err = dump_to_stdout(&ei);
986 err = fsync(ei.out_fd);
988 exfat_err("failed to fsync %s. %d\n", out_path, errno);
994 printf("%ld files found, %ld directories dumped, %llu kbytes written\n",
995 exfat_stat.file_count,
996 exfat_stat.dir_count,
997 (unsigned long long)DIV_ROUND_UP(exfat_stat.written_bytes, 1024));
1000 free_exfat2img(&ei);
1001 return err == 0 ? EXIT_SUCCESS : EXIT_FAILURE;