]> git.sven.stormbind.net Git - sven/exfatprogs.git/blobdiff - dump/dump.c
releasing package exfatprogs version 1.2.3-1
[sven/exfatprogs.git] / dump / dump.c
index 85d5101f40e8653d193d32e4304390aa5902c9f5..73a231ab2c9e367837ae49b87833f098819c44f9 100644 (file)
@@ -76,20 +76,26 @@ static int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd)
        unsigned char *bitmap;
        char *volume_label;
 
        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 -ENOMEM;
        }
 
        /* read main boot sector */
        if (!ppbr) {
                exfat_err("Cannot allocate pbr: out of memory\n");
                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 = -EIO;
                goto free_ppbr;
        }
 
                exfat_err("main boot sector read failed\n");
                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;
+       }
+
        pbsx = &ppbr->bsx;
 
        if (pbsx->sect_size_bits < EXFAT_MIN_SECT_SIZE_BITS ||
        pbsx = &ppbr->bsx;
 
        if (pbsx->sect_size_bits < EXFAT_MIN_SECT_SIZE_BITS ||
@@ -107,12 +113,8 @@ static int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd)
                goto free_ppbr;
        }
 
                goto free_ppbr;
        }
 
-       if (bd->sector_size != 1 << pbsx->sect_size_bits) {
-               exfat_err("bogus sector size : %u (sector size bits : %u)\n",
-                               bd->sector_size, pbsx->sect_size_bits);
-               ret = -EINVAL;
-               goto free_ppbr;
-       }
+       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);
 
        clu_offset = le32_to_cpu(pbsx->clu_offset);
        total_clus = le32_to_cpu(pbsx->clu_count);
@@ -129,8 +131,8 @@ static int exfat_show_ondisk_all_info(struct exfat_blk_dev *bd)
        exfat_info("Cluster Count: \t\t\t\t%u\n", total_clus);
        exfat_info("Root Cluster (cluster offset): \t\t%u\n", root_clu);
        exfat_info("Volume Serial: \t\t\t\t0x%x\n", le32_to_cpu(pbsx->vol_serial));
        exfat_info("Cluster Count: \t\t\t\t%u\n", total_clus);
        exfat_info("Root Cluster (cluster offset): \t\t%u\n", root_clu);
        exfat_info("Volume Serial: \t\t\t\t0x%x\n", le32_to_cpu(pbsx->vol_serial));
-       exfat_info("Sector Size Bits: \t\t\t%u\n", pbsx->sect_size_bits);
-       exfat_info("Sector per Cluster bits: \t\t%u\n\n", pbsx->sect_per_clus_bits);
+       exfat_info("Bytes per Sector: \t\t\t%u\n", 1 << pbsx->sect_size_bits);
+       exfat_info("Sectors per Cluster: \t\t\t%u\n\n", 1 << pbsx->sect_per_clus_bits);
 
        bd->cluster_size =
                1 << (pbsx->sect_per_clus_bits + pbsx->sect_size_bits);
 
        bd->cluster_size =
                1 << (pbsx->sect_per_clus_bits + pbsx->sect_size_bits);
@@ -221,6 +223,7 @@ int main(int argc, char *argv[])
        bool version_only = false;
 
        init_user_input(&ui);
        bool version_only = false;
 
        init_user_input(&ui);
+       ui.writeable = false;
 
        if (!setlocale(LC_CTYPE, ""))
                exfat_err("failed to init locale/codeset\n");
 
        if (!setlocale(LC_CTYPE, ""))
                exfat_err("failed to init locale/codeset\n");