X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=dump%2Fdump.c;h=8c9637616a6cbce1f7679ea02f675b7200be81bd;hb=HEAD;hp=1bd6ab23f6d904c317ba854469b5198909df6b70;hpb=a4f2404c58ad9a1134d98838617019286a680bef;p=sven%2Fexfatprogs.git diff --git a/dump/dump.c b/dump/dump.c index 1bd6ab2..8c96376 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -64,7 +64,7 @@ static unsigned int exfat_count_used_clusters(unsigned char *bitmap, return count; } -int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd) +static int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd) { struct pbr *ppbr; struct bsx64 *pbsx; @@ -76,17 +76,23 @@ int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd) unsigned char *bitmap; char *volume_label; - ppbr = malloc(bd->sector_size); + ppbr = malloc(EXFAT_MAX_SECTOR_SIZE); if (!ppbr) { exfat_err("Cannot allocate pbr: out of memory\n"); - return -1; + return -ENOMEM; } /* read main boot sector */ - ret = exfat_read_sector(bd, (char *)ppbr, BOOT_SEC_IDX); - if (ret < 0) { + if (exfat_read(bd->dev_fd, (char *)ppbr, EXFAT_MAX_SECTOR_SIZE, + 0) != (ssize_t)EXFAT_MAX_SECTOR_SIZE) { exfat_err("main boot sector read failed\n"); - ret = -1; + ret = -EIO; + goto free_ppbr; + } + + if (memcmp(ppbr->bpb.oem_name, "EXFAT ", 8) != 0) { + exfat_err("Bad fs_name in boot sector, which does not describe a valid exfat filesystem\n"); + ret = -EINVAL; goto free_ppbr; } @@ -96,20 +102,19 @@ int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd) pbsx->sect_size_bits > EXFAT_MAX_SECT_SIZE_BITS) { exfat_err("bogus sector size bits : %u\n", pbsx->sect_size_bits); - return -EINVAL; + ret = -EINVAL; + goto free_ppbr; } if (pbsx->sect_per_clus_bits > 25 - pbsx->sect_size_bits) { exfat_err("bogus sectors bits per cluster : %u\n", pbsx->sect_per_clus_bits); - return -EINVAL; + ret = -EINVAL; + goto free_ppbr; } - if (bd->sector_size != 1 << pbsx->sect_size_bits) { - exfat_err("bogus sectors size : %u(sector size bits : %u)\n", - bd->sector_size, pbsx->sect_size_bits); - - } + bd->sector_size_bits = pbsx->sect_size_bits; + bd->sector_size = 1 << pbsx->sect_size_bits; clu_offset = le32_to_cpu(pbsx->clu_offset); total_clus = le32_to_cpu(pbsx->clu_count); @@ -148,7 +153,7 @@ int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd) goto free_entry; } - volume_label = exfat_conv_volume_serial(&ed[0]); + volume_label = exfat_conv_volume_label(&ed[0]); if (!volume_label) { ret = -EINVAL; goto free_entry; @@ -177,6 +182,7 @@ int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd) bitmap = malloc(bitmap_len); if (!bitmap) { exfat_err("bitmap allocation failed\n"); + ret = -ENOMEM; goto free_volume_label; } @@ -195,6 +201,7 @@ int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd) exfat_info("Cluster size: \t\t\t\t%u\n", bd->cluster_size); exfat_info("Total Clusters: \t\t\t%u\n", total_clus); exfat_info("Free Clusters: \t\t\t\t%u\n", total_clus-used_clus); + ret = 0; free(bitmap); @@ -216,6 +223,7 @@ int main(int argc, char *argv[]) bool version_only = false; init_user_input(&ui); + ui.writeable = false; if (!setlocale(LC_CTYPE, "")) exfat_err("failed to init locale/codeset\n");