diskfs / go-diskfs

MIT License
515 stars 113 forks source link

Can't seem to read fat32 partition #165

Closed rmb938 closed 1 year ago

rmb938 commented 1 year ago

Trying to read the server image for raspberry pi found here https://ubuntu.com/download/raspberry-pi Direct download link https://cdimage.ubuntu.com/releases/22.04.1/release/ubuntu-22.04.1-preinstalled-server-arm64+raspi.img.xz

time="2023-01-16T23:31:23Z" level=debug msg="trying fat32"
time="2023-01-16T23:31:23Z" level=debug msg="fat32 failed: error reading MS-DOS Boot Sector: could not read FAT32 BIOS Parameter Block from boot sector: could not read embedded DOS 3.31 BPB: error reading embedded DOS 2.0 BPB: invalid sector size 0 provided in DOS 2.0 BPB. Must be 512"
time="2023-01-16T23:31:23Z" level=debug msg="trying iso9660 with physical block size 512"
time="2023-01-16T23:31:23Z" level=debug msg="iso9660 failed: blocksize for ISO9660 must be one of 2048, 4096, 8192"
2023/01/16 23:31:23 Error getting filesystem for partition 0: unknown filesystem on partition 0

fdisk says it is a fat32

%  fdisk -l images/ubuntu-22.04.1-preinstalled-server-arm64+raspi.img
Disk images/ubuntu-22.04.1-preinstalled-server-arm64+raspi.img: 3.7 GiB, 3969908736 bytes, 7753728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb0a6845e

Device                                                     Boot  Start     End Sectors  Size Id Type
images/ubuntu-22.04.1-preinstalled-server-arm64+raspi.img1 *      2048  526335  524288  256M  c W95 FAT32 (LBA)
images/ubuntu-22.04.1-preinstalled-server-arm64+raspi.img2      526336 7720267 7193932  3.4G 83 Linux

So I am unsure what is wrong. This is the code I am using

    log.Printf("Reading disk partitions %s", diskPath)
    destDisk, err := diskfs.Open(diskPath)
    if err != nil {
        log.Fatalf("Error opening disk %s: %v", diskPath, err)
    }

    rawTable, err := destDisk.GetPartitionTable()
    if err != nil {
        log.Fatalf("Error getting partition table for disk %s: %v", diskPath, err)
    }

    log.Printf("Found partition table %s", rawTable.Type())

    if rawTable.Type() != "mbr" {
        log.Fatalf("GPT partition tables are not supported")
    }

    for _, part := range rawTable.GetPartitions() {
        log.Printf("%#vn", part)
    }

    // system-boot filesystem is always the first one
    systemBootFs, err := destDisk.GetFilesystem(0)
    if err != nil {
        log.Fatalf("Error getting filesystem for partition %d: %v", 0, err)
    }
rmb938 commented 1 year ago

Oh actually. I am dumb and didn't read the documentation that GetFilesystem indexes from 1 not from 0.