Forum Rule: Always post complete source code & details to reproduce any issue!
Page 11 of 13 FirstFirst ... 9 10 11 12 13 LastLast
Results 251 to 275 of 305

Thread: USBHost_t36 USB Mass Storage Driver Experiments

  1. #251
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,681
    This will print the signature and number of partitions on the GPT disk:
    Code:
    #include "uSDFS.h"
    #include "diskio.h"
    
    #include <USBHost_t36.h>
    extern USBHost myusb;
    USBHub hub1(myusb);
    USBHub hub2(myusb);
    
    /*
    * for APL see http://elm-chan.org/fsw/ff/00index_e.html
    */
    #define TEST_DRV 2
    //
    #if TEST_DRV == 0
      const char *Dev = "0:/";  // SPI
    #elif TEST_DRV == 1
      const char *Dev = "1:/";  // SDHC
    #elif TEST_DRV == 2
      const char *Dev = "2:/";  // USB
    #endif
    
    struct partitionTable {
      uint8_t  boot;
      uint8_t  beginHead;
      unsigned beginSector : 6;
      unsigned beginCylinderHigh : 2;
      uint8_t  beginCylinderLow;
      uint8_t  type;
      uint8_t  endHead;
      unsigned endSector : 6;
      unsigned endCylinderHigh : 2;
      uint8_t  endCylinderLow;
      uint32_t firstSector;
      uint32_t totalSectors;
    } __attribute__((packed));
    typedef struct partitionTable part_t;
    
    struct masterBootRecord {
      uint8_t  codeArea[440];
      uint32_t diskSignature;
      uint16_t usuallyZero;
      part_t   part[4];
      uint8_t  mbrSig0;
      uint8_t  mbrSig1;
    } __attribute__((packed));
    typedef struct masterBootRecord mbr_t;
    
    struct guid {
      uint8_t signature[8];  //8 bytes
      uint8_t revision[4];  //pos 3
      uint8_t hdr_sz[4];    //pos 1
      uint32_t crc32;     //single 32bit val
      uint8_t reserved[4];
      uint8_t prim_lba[8];  //pos 1 always = 1
      uint8_t back_lba[8];  //Address of backup LBA
      uint8_t first_lba[8];
      uint8_t last_lba[8];
      uint8_t disk_guid[16];
      uint8_t part_entry_lba[8];
      uint8_t number_parts[4];
      uint8_t sz_parts[4];
      uint32_t part_entry_crc32;
      uint8_t temp1[420];
    }__attribute__((packed));
    typedef struct guid guid_t;
    
    struct fat32_boot {
      uint8_t jump[3];
      char    oemId[8];
      uint16_t bytesPerSector;
      uint8_t  sectorsPerCluster;
      uint16_t reservedSectorCount;
      uint8_t  fatCount;
      uint16_t rootDirEntryCount;
      uint16_t totalSectors16;
      uint8_t  mediaType;
      uint16_t sectorsPerFat16;
      uint16_t sectorsPerTrack;
      uint16_t headCount;
      uint32_t hidddenSectors;
      uint32_t totalSectors32;
      uint32_t sectorsPerFat32;
      uint16_t fat32Flags;
      uint16_t fat32Version;
      uint32_t fat32RootCluster;
      uint16_t fat32FSInfo;
      uint16_t fat32BackBootBlock;
      uint8_t  fat32Reserved[12];
      uint8_t  driveNumber;
      uint8_t  reserved1;
      uint8_t  bootSignature;
      uint32_t volumeSerialNumber;
      char     volumeLabel[11];
      char     fileSystemType[8];
      uint8_t  bootCode[420];
      uint8_t  bootSectorSig0;
      uint8_t  bootSectorSig1;
    }__attribute__((packed));
    typedef struct fat32_boot fat32_boot_t;
    
    typedef uint16_t  le16_t;
    typedef uint32_t  le32_t;
    typedef uint64_t  le64_t;
    
    struct exfat_super_block
    {
      uint8_t jump[3];        /* 0x00 jmp and nop instructions */
      uint8_t oem_name[8];      /* 0x03 "EXFAT   " */
      uint8_t __unused1[53];      /* 0x0B always 0 */
      le64_t sector_start;      /* 0x40 partition first sector */
      le64_t sector_count;      /* 0x48 partition sectors count */
      le32_t fat_sector_start;    /* 0x50 FAT first sector */
      le32_t fat_sector_count;    /* 0x54 FAT sectors count */
      le32_t cluster_sector_start;  /* 0x58 first cluster sector */
      le32_t cluster_count;     /* 0x5C total clusters count */
      le32_t rootdir_cluster;     /* 0x60 first cluster of the root dir */
      le32_t volume_serial;     /* 0x64 volume serial number */
      struct              /* 0x68 FS version */
      {
        uint8_t minor;
        uint8_t major;
      }
      version;
      le16_t volume_state;      /* 0x6A volume state flags */
      uint8_t sector_bits;      /* 0x6C sector size as (1 << n) */
      uint8_t spc_bits;       /* 0x6D sectors per cluster as (1 << n) */
      uint8_t fat_count;        /* 0x6E always 1 */
      uint8_t drive_no;       /* 0x6F always 0x80 */
      uint8_t allocated_percent;    /* 0x70 percentage of allocated space */
      uint8_t __unused2[397];     /* 0x71 always 0 */
      le16_t boot_signature;      /* the value of 0xAA55 */
    } __attribute__((packed));
    typedef struct exfat_super_block exfat_boot_t;
    
    
    uint32_t buffer[128];
    
    void setup() {
      // put your setup code here, to run once:
    
      while(!Serial);
      Serial.println("Test diskio");
      Serial.print("uSDFS_VER:"); Serial.println(uSDFS_VER);
      
      BYTE pdrv = TEST_DRV;
      
      DSTATUS stat = disk_initialize(TEST_DRV);
      Serial.print("Disk initialize Status: "); Serial.println(STAT_ERROR_STRING[stat]);
    
      BYTE* buff = (BYTE *) buffer;
      DWORD sector = 0;
      DWORD sector1 = 0;
      UINT count = 1;
      UINT count1 = 1;
      DRESULT res = disk_read (pdrv, buff, sector, count);
      Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
      for(int ii=0;ii<512; ii++)
      if((ii+1)%16) Serial.printf("%02x ",buff[ii]); else Serial.printf("%02x\n",buff[ii]);
    
      mbr_t *mbr = (mbr_t *) buffer;
      Serial.println("\nMaster Boot Record");
      for (int ii = 0; ii < 4; ii++)
      {
        Serial.print("  Partition: "); Serial.print(ii);
        Serial.print(" Type: "); 
        Serial.print(mbr->part[ii].type, HEX);
        Serial.print(" first Sector: ");
        Serial.print(mbr->part[ii].firstSector);
        Serial.print(" total Sectors: ");
        Serial.println(mbr->part[ii].totalSectors);
      }
    
      if(mbr->part[0].type == 0xee){
        // read now first partition sector
        Serial.println("\nFirst partition Sector");
        sector = mbr->part[0].firstSector;
        sector1 = mbr->part[1].firstSector;
        count = 1;
        res = disk_read (pdrv, buff, sector, count);
        Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
        for(int ii=0;ii<512; ii++)
        if((ii+1)%16) Serial.printf("%02x ",buff[ii]); else Serial.printf("%02x\n",buff[ii]);
      
        guid_t * ptr1=(guid_t *) buffer;
    
        Serial.println("====  GPT GUID HEADER ====");
        Serial.print("Signature: ");
        for(uint8_t ii = 0; ii<8; ii++){ 
          Serial.print(ptr1->signature[ii], HEX);
          Serial.print(", ");
        }
        Serial.println();
      
        Serial.print("Number of Partitions: ");
        Serial.println(ptr1->number_parts[0], HEX);
      } else {
        // read now first partition sector
        Serial.println("\nFirst partition Sector");
        sector = mbr->part[0].firstSector;
        sector1 = mbr->part[1].firstSector;
        count = 1;
        res = disk_read (pdrv, buff, sector, count);
        Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
        for(int ii=0;ii<512; ii++)
        if((ii+1)%16) Serial.printf("%02x ",buff[ii]); else Serial.printf("%02x\n",buff[ii]);
      
        fat32_boot_t * ptr1=(fat32_boot_t *) buffer;
        exfat_boot_t * ptr2=(exfat_boot_t *) buffer;
      
        if(strncmp(ptr1->fileSystemType,"FAT32",5)==0)
        {
          Serial.println("FAT32");
          Serial.print("bytes per sector :");Serial.println(ptr1->bytesPerSector);
          Serial.print("sectors per cluster :");Serial.println(ptr1->sectorsPerCluster);
        }
        else if(strncmp(ptr2->oem_name,"EXFAT",5)==0)
        {
          Serial.println("EXFAT");
          Serial.print("bytes per sector :");Serial.println(1<<ptr2->sector_bits);
          Serial.print("sectors per cluster :");Serial.println(1<<ptr2->spc_bits);
        }
        pinMode(13,OUTPUT);
      
        // read now Second partition sector
        Serial.println("\nSecond partition Sector");
        count = 1;
        res = disk_read (pdrv, buff, sector1, count);
        Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
        for(int ii=0;ii<512; ii++)
        if((ii+1)%16) Serial.printf("%02x ",buff[ii]); else Serial.printf("%02x\n",buff[ii]);
      
        if(strncmp(ptr1->fileSystemType,"FAT32",5)==0)
        {
          Serial.println("FAT32");
          Serial.print("bytes per sector :");Serial.println(ptr1->bytesPerSector);
          Serial.print("sectors per cluster :");Serial.println(ptr1->sectorsPerCluster);
        }
        else if(strncmp(ptr2->oem_name,"EXFAT",5)==0)
        {
          Serial.println("EXFAT");
          Serial.print("bytes per sector :");Serial.println(1<<ptr2->sector_bits);
          Serial.print("sectors per cluster :");Serial.println(1<<ptr2->spc_bits);
        }
      }
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      digitalWriteFast(13,!digitalReadFast(13));
      delay(1000);
    }
    EDIT: for my GPT disk I created 2 partitions both exFAT, so far I get this:
    Code:
    ====  GPT GUID HEADER ====
    Signature: 45, 46, 49, 20, 50, 41, 52, 54, 
    Number of Partitions: 2
    The signature is fixed according that reference web and it does match what was identified for the signature of the GPT disk
    Last edited by mjs513; 05-25-2019 at 05:53 PM. Reason: corrected Sketch

  2. #252
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    For the fun of it, I thought it might be nice to look at the sectors 1 and 2 of the UFI disk... so hacked up the test program to dump them, using the dump function for MSC library:
    Code:
    #include "uSDFS.h"
    #include "uSDFS.h"
    #include "diskio.h"
    
    #include <USBHost_t36.h>
    extern USBHost myusb;
    USBHub hub1(myusb);
    USBHub hub2(myusb);
    
    /*
      for APL see http://elm-chan.org/fsw/ff/00index_e.html
    */
    #define TEST_DRV 2
    //
    #if TEST_DRV == 0
    const char *Dev = "0:/";  // SPI
    #elif TEST_DRV == 1
    const char *Dev = "1:/";  // SDHC
    #elif TEST_DRV == 2
    const char *Dev = "2:/";  // USB
    #endif
    
    struct partitionTable {
      uint8_t  boot;
      uint8_t  beginHead;
      unsigned beginSector : 6;
      unsigned beginCylinderHigh : 2;
      uint8_t  beginCylinderLow;
      uint8_t  type;
      uint8_t  endHead;
      unsigned endSector : 6;
      unsigned endCylinderHigh : 2;
      uint8_t  endCylinderLow;
      uint32_t firstSector;
      uint32_t totalSectors;
    } __attribute__((packed));
    typedef struct partitionTable part_t;
    
    struct masterBootRecord {
      uint8_t  codeArea[440];
      uint32_t diskSignature;
      uint16_t usuallyZero;
      part_t   part[4];
      uint8_t  mbrSig0;
      uint8_t  mbrSig1;
    } __attribute__((packed));
    typedef struct masterBootRecord mbr_t;
    
    
    struct fat32_boot {
      uint8_t jump[3];
      char    oemId[8];
      uint16_t bytesPerSector;
      uint8_t  sectorsPerCluster;
      uint16_t reservedSectorCount;
      uint8_t  fatCount;
      uint16_t rootDirEntryCount;
      uint16_t totalSectors16;
      uint8_t  mediaType;
      uint16_t sectorsPerFat16;
      uint16_t sectorsPerTrack;
      uint16_t headCount;
      uint32_t hidddenSectors;
      uint32_t totalSectors32;
      uint32_t sectorsPerFat32;
      uint16_t fat32Flags;
      uint16_t fat32Version;
      uint32_t fat32RootCluster;
      uint16_t fat32FSInfo;
      uint16_t fat32BackBootBlock;
      uint8_t  fat32Reserved[12];
      uint8_t  driveNumber;
      uint8_t  reserved1;
      uint8_t  bootSignature;
      uint32_t volumeSerialNumber;
      char     volumeLabel[11];
      char     fileSystemType[8];
      uint8_t  bootCode[420];
      uint8_t  bootSectorSig0;
      uint8_t  bootSectorSig1;
    } __attribute__((packed));
    typedef struct fat32_boot fat32_boot_t;
    
    typedef uint16_t  le16_t;
    typedef uint32_t  le32_t;
    typedef uint64_t  le64_t;
    
    struct exfat_super_block
    {
      uint8_t jump[3];        /* 0x00 jmp and nop instructions */
      uint8_t oem_name[8];      /* 0x03 "EXFAT   " */
      uint8_t __unused1[53];      /* 0x0B always 0 */
      le64_t sector_start;      /* 0x40 partition first sector */
      le64_t sector_count;      /* 0x48 partition sectors count */
      le32_t fat_sector_start;    /* 0x50 FAT first sector */
      le32_t fat_sector_count;    /* 0x54 FAT sectors count */
      le32_t cluster_sector_start;  /* 0x58 first cluster sector */
      le32_t cluster_count;     /* 0x5C total clusters count */
      le32_t rootdir_cluster;     /* 0x60 first cluster of the root dir */
      le32_t volume_serial;     /* 0x64 volume serial number */
      struct              /* 0x68 FS version */
      {
        uint8_t minor;
        uint8_t major;
      }
      version;
      le16_t volume_state;      /* 0x6A volume state flags */
      uint8_t sector_bits;      /* 0x6C sector size as (1 << n) */
      uint8_t spc_bits;       /* 0x6D sectors per cluster as (1 << n) */
      uint8_t fat_count;        /* 0x6E always 1 */
      uint8_t drive_no;       /* 0x6F always 0x80 */
      uint8_t allocated_percent;    /* 0x70 percentage of allocated space */
      uint8_t __unused2[397];     /* 0x71 always 0 */
      le16_t boot_signature;      /* the value of 0xAA55 */
    } __attribute__((packed));
    typedef struct exfat_super_block exfat_boot_t;
    
    
    uint32_t buffer[128];
    
    uint8_t buffer2[512];
    
    void setup() {
      // put your setup code here, to run once:
    
      while (!Serial);
      Serial.println("Test diskio");
      Serial.print("uSDFS_VER:"); Serial.println(uSDFS_VER);
    
      BYTE pdrv = TEST_DRV;
    
      DSTATUS stat = disk_initialize(TEST_DRV);
      Serial.print("Disk initialize Status: "); Serial.println(STAT_ERROR_STRING[stat]);
    
      BYTE* buff = (BYTE *) buffer;
      DWORD sector = 0;
      DWORD sector1 = 0;
      UINT count = 1;
      UINT count1 = 1;
      DRESULT res = disk_read (pdrv, buff, sector, count);
      Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
      hexDump(buff, 512);
    
      mbr_t *mbr = (mbr_t *) buffer;
      Serial.println("\nMaster Boot Record");
      for (int ii = 0; ii < 4; ii++)
      {
        Serial.print("  Partition: "); Serial.print(ii);
        Serial.print(" Type: "); 
        Serial.print(mbr->part[ii].type, HEX);
        Serial.print(" first Sector: ");
        Serial.print(mbr->part[ii].firstSector);
        Serial.print(" total Sectors: ");
        Serial.println(mbr->part[ii].totalSectors);
      }
    
      // lets try reading a couple other sectors
      //---------------------
      res = disk_read (pdrv, buffer2, 1, 1);
      Serial.printf("\nSector 1: %x\n", res);
      hexDump(buffer2, 512);
    
      res = disk_read (pdrv, buffer2, 2, 1);
      Serial.printf("\nSector 2: %x\n", res);
      hexDump(buffer2, 512);
    
    
      // --------------------
      // read now first partition sector
      Serial.println("\nFirst partition Sector");
      sector = mbr->part[0].firstSector;
      sector1 = mbr->part[1].firstSector;
      count = 1;
      res = disk_read (pdrv, buff, sector, count);
      Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
      hexDump(buff, 512);
      fat32_boot_t * ptr1 = (fat32_boot_t *) buffer;
      exfat_boot_t * ptr2 = (exfat_boot_t *) buffer;
    
      if (strncmp(ptr1->fileSystemType, "FAT32", 5) == 0)
      {
        Serial.println("FAT32");
        Serial.print("bytes per sector :"); Serial.println(ptr1->bytesPerSector);
        Serial.print("sectors per cluster :"); Serial.println(ptr1->sectorsPerCluster);
      }
      else if (strncmp(ptr2->oem_name, "EXFAT", 5) == 0)
      {
        Serial.println("EXFAT");
        Serial.print("bytes per sector :"); Serial.println(1 << ptr2->sector_bits);
        Serial.print("sectors per cluster :"); Serial.println(1 << ptr2->spc_bits);
      }
      pinMode(13, OUTPUT);
    
      // read now Second partition sector
      Serial.println("\nSecond partition Sector");
      count = 1;
      res = disk_read (pdrv, buff, sector1, count);
      Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
      hexDump(buff, 512);
      if (strncmp(ptr1->fileSystemType, "FAT32", 5) == 0)
      {
        Serial.println("FAT32");
        Serial.print("bytes per sector :"); Serial.println(ptr1->bytesPerSector);
        Serial.print("sectors per cluster :"); Serial.println(ptr1->sectorsPerCluster);
      }
      else if (strncmp(ptr2->oem_name, "EXFAT", 5) == 0)
      {
        Serial.println("EXFAT");
        Serial.print("bytes per sector :"); Serial.println(1 << ptr2->sector_bits);
        Serial.print("sectors per cluster :"); Serial.println(1 << ptr2->spc_bits);
      }
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      digitalWriteFast(13, !digitalReadFast(13));
      delay(1000);
    }
    // A small hex dump funcion
    void hexDump(const void *ptr, uint32_t len)
    {
      uint32_t  i = 0, j = 0;
      uint8_t   c=0;
      const uint8_t *p = (const uint8_t *)ptr;
    
      Serial.printf("BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");
      Serial.printf("---------------------------------------------------------\n");
      for(i = 0; i <= (len-1); i+=16) {
       Serial.printf("%4.4x      ",i);
       for(j = 0; j < 16; j++) {
          c = p[i+j];
          Serial.printf("%2.2x ",c);
        }
        Serial.printf("  ");
        for(j = 0; j < 16; j++) {
          c = p[i+j];
          if(c > 31 && c < 127)
            Serial.printf("%c",c);
          else
            Serial.printf(".");
        }
        Serial.println();
      }
    
    }
    Output:
    Code:
    Test diskio
    uSDFS_VER:15_MAY_19_08_16
    Disk initialize Status: STA_OK
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0010      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0020      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0030      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0040      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0050      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 81 20 ce cb 00 00 00 00   ......... ......
    01c0      02 00 ee fe ff 00 01 00 00 00 ff ff ff ff 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa   ..............U.
    
    Master Boot Record
      Partition: 0 Type: EE first Sector: 1 total Sectors: 4294967295
      Partition: 1 Type: 0 first Sector: 0 total Sectors: 0
      Partition: 2 Type: 0 first Sector: 0 total Sectors: 0
      Partition: 3 Type: 0 first Sector: 0 total Sectors: 0
    
    Sector 1: 0
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      45 46 49 20 50 41 52 54 00 00 01 00 5c 00 00 00   EFI PART....\...
    0010      35 0b 97 16 00 00 00 00 01 00 00 00 00 00 00 00   5...............
    0020      af 6d 70 74 00 00 00 00 22 00 00 00 00 00 00 00   .mpt....".......
    0030      8e 6d 70 74 00 00 00 00 a3 c8 ca db a5 8e 76 45   .mpt..........vE
    0040      b8 16 56 8f d4 96 e4 25 02 00 00 00 00 00 00 00   ..V....%........
    0050      80 00 00 00 80 00 00 00 65 5a bf b1 00 00 00 00   ........eZ......
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    
    Sector 2: 0
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      16 e3 c9 e3 5c 0b b8 4d 81 7d f9 2d f0 02 15 ae   ....\..M.}.-....
    0010      5b 9b bc 04 f9 d8 33 46 94 b0 8a 3e aa 7f 5b e4   [.....3F...>..[.
    0020      22 00 00 00 00 00 00 00 ff 7f 00 00 00 00 00 00   "...............
    0030      00 00 00 00 00 00 00 00 4d 00 69 00 63 00 72 00   ........M.i.c.r.
    0040      6f 00 73 00 6f 00 66 00 74 00 20 00 72 00 65 00   o.s.o.f.t. .r.e.
    0050      73 00 65 00 72 00 76 00 65 00 64 00 20 00 70 00   s.e.r.v.e.d. .p.
    0060      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0090      64 c3 cb a7 0c a7 a8 4e 9f dc 6f e6 76 97 de 71   d......N..o.v..q
    00a0      00 80 00 00 00 00 00 00 ff 77 1c 1d 00 00 00 00   .........w......
    00b0      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    00c0      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    00d0      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0110      b5 15 aa 6f 94 d5 90 44 b6 7b 99 8f fd 7a 8f fd   ...o...D.{...z..
    0120      00 78 1c 1d 00 00 00 00 ff 5f 70 74 00 00 00 00   .x......._pt....
    0130      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    0140      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    0150      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    
    First partition Sector
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      45 46 49 20 50 41 52 54 00 00 01 00 5c 00 00 00   EFI PART....\...
    0010      35 0b 97 16 00 00 00 00 01 00 00 00 00 00 00 00   5...............
    0020      af 6d 70 74 00 00 00 00 22 00 00 00 00 00 00 00   .mpt....".......
    0030      8e 6d 70 74 00 00 00 00 a3 c8 ca db a5 8e 76 45   .mpt..........vE
    0040      b8 16 56 8f d4 96 e4 25 02 00 00 00 00 00 00 00   ..V....%........
    0050      80 00 00 00 80 00 00 00 65 5a bf b1 00 00 00 00   ........eZ......
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    
    Second partition Sector
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0010      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0020      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0030      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0040      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0050      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 81 20 ce cb 00 00 00 00   ......... ......
    01c0      02 00 ee fe ff 00 01 00 00 00 ff ff ff ff 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa   ..............U.
    Now off to store...
    Last edited by KurtE; 05-25-2019 at 06:01 PM. Reason: Updated Code and outputs

  3. #253
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,681
    We just can't resist can we - now I am off too - glad you are getting out.

    EDIT:
    Made a booboo with the structure - corrected in the sketch:
    Code:
    struct guid {
      uint8_t signature[8];  //8 bytes
      uint8_t revision[4];  //pos 3
      uint8_t hdr_sz[4];    //pos 1
      uint32_t crc32;     //single 32bit val
      uint8_t reserved[4];
      uint8_t prim_lba[8];  //pos 1 always = 1
      uint8_t back_lba[8];  //Address of backup LBA
      uint8_t first_lba[8];
      uint8_t last_lba[8];
      uint8_t disk_guid[16];
      uint8_t part_entry_lba[8];
      uint8_t number_parts[4];
      uint8_t sz_parts[4];
      uint32_t part_entry_crc32;
      uint8_t temp1[420];
    }__attribute__((packed));
    typedef struct guid guid_t;
    Last edited by mjs513; 05-25-2019 at 05:52 PM.

  4. #254
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    @mjs513 and others...

    Got back, decided to update all of the hex dumps to use the function...

    Also updated the hard disk with the guid stuff. To have two partitions, first Fat, second NTFS...

    I updated the program and output in previous post to this.

    Now probably need to look at what your updated program does

  5. #255
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,032
    I resisted - still didn't get enough sleep I only searched the page 'disk-sectors-on-gpt-disks' enough find that posted text.

    @KurtE - I was about 15 miles from your house yesterday - 5 hours of computer fun 45 min from home.

    Not sure why yet - but I'm seeing T$ not take new code without button to stop it - probably sketch issue.

    This is an elapsedMillis one second while in setup() - and the count of "cc" printed in setup is 37 Million
    Code:
    	while ( ems < 1000 ) {
    		cc++;
    		digitalWriteFast( LED_BUILTIN, !digitalReadFast( LED_BUILTIN ) );
    	}
    This for loop() drops to 21 Million - yield() not yet called in T$:
    Code:
    FASTRUN void loop() {
    	cc++;
    	if ( ems >= 1000 ) {
    		}
    		ems = 0;
    	}
    //	tPr( 0 );
    }
    As soon as another call is made uncommenting the "// tPr( 0 );" the count drops to 11 Million.

    Yikes - trying this sketch is turning into a T$ beta test issue: yield() not called between loop() with debug startup - no main() - but yield is called in other places - when Serial has wait on xfer. And any 'SerMon' send of multiple '\n' entries disconnects the USB - Mike - this is what we were seeing the other day using TyComm when we were doing CAN_TEST running two sketches at once and seeing T$ go offline/disconnect.

    So back to how I was trying to be on topic directly: it isn't done yet but test get 9.7M loop()'s with no busy_work or printing and then can add busy work with or without print and see the rate change, surge and block to the rate of USB's Serial.print() output. From 9M down to 71K when TyComm has empty buffer and 32K when TyComm has to garbage collect the buffer. The LED is toggling at the with each loop() - and when Serial USB blocks the light pulses from blocking when toggle is 32K times/sec. Now I want to try disk IO with 1K buffer ( 4K transfers ) ...

  6. #256
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    @mjs513 and @defragster...

    Ran your test (with old hex dumps ) Newer hex dumps back in #252... Output is:
    Code:
    ====  GPT GUID HEADER ====
    Signature: 45, 46, 49, 20, 50, 41, 52, 54, 
    Number of Partitions: 80
    Which is probably correct as Number of Partition entries I think is 80 hex...

  7. #257
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    @defragster - sounds like you were busy yesterday!

    Also sounds like your loop counting stuff is getting some strange results!

  8. #258
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,032
    Quote Originally Posted by KurtE View Post
    @defragster - sounds like you were busy yesterday!

    Also sounds like your loop counting stuff is getting some strange results!
    I felt busy … was supposed to hit Costco but it was 3:30 didn't feel like another hour diversion with added traffic. Maybe when T4 ships we should meet for a beer.

    Indeed the counting was simple to imagine being easy to do … and it will be in the end - and until then what wasn't pretty code is getting more twisted and tiring.

  9. #259
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,681
    Quote Originally Posted by KurtE View Post
    @mjs513 and @defragster...

    Ran your test (with old hex dumps ) Newer hex dumps back in #252... Output is:
    Code:
    ====  GPT GUID HEADER ====
    Signature: 45, 46, 49, 20, 50, 41, 52, 54, 
    Number of Partitions: 80
    Which is probably correct as Number of Partition entries I think is 80 hex...
    Still trying to decode everything - reading and rereading, but yeah 80 is correct based on the description on the web page. Everything for GPT is based on Logical block addressing (LBA), so I found this: https://gerardnico.com/io/drive/lba at least to start.

  10. #260
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    Hi @... again, @mjs513, I hacked some more on your last program, and have it dumping out some information about GUID partitions...
    Code:
    #include "uSDFS.h"
    #include "diskio.h"
    
    #include <USBHost_t36.h>
    extern USBHost myusb;
    USBHub hub1(myusb);
    USBHub hub2(myusb);
    
    /*
      for APL see http://elm-chan.org/fsw/ff/00index_e.html
    */
    #define TEST_DRV 2
    //
    #if TEST_DRV == 0
    const char *Dev = "0:/";  // SPI
    #elif TEST_DRV == 1
    const char *Dev = "1:/";  // SDHC
    #elif TEST_DRV == 2
    const char *Dev = "2:/";  // USB
    #endif
    
    struct partitionTable {
      uint8_t  boot;
      uint8_t  beginHead;
      unsigned beginSector : 6;
      unsigned beginCylinderHigh : 2;
      uint8_t  beginCylinderLow;
      uint8_t  type;
      uint8_t  endHead;
      unsigned endSector : 6;
      unsigned endCylinderHigh : 2;
      uint8_t  endCylinderLow;
      uint32_t firstSector;
      uint32_t totalSectors;
    } __attribute__((packed));
    typedef struct partitionTable part_t;
    
    struct masterBootRecord {
      uint8_t  codeArea[440];
      uint32_t diskSignature;
      uint16_t usuallyZero;
      part_t   part[4];
      uint8_t  mbrSig0;
      uint8_t  mbrSig1;
    } __attribute__((packed));
    typedef struct masterBootRecord mbr_t;
    
    struct guid {
      uint8_t signature[8];  //8 bytes
      uint8_t revision[4];  //pos 3
      uint8_t hdr_sz[4];    //pos 1
      uint32_t crc32;     //single 32bit val
      uint8_t reserved[4];
      uint8_t prim_lba[8];  //pos 1 always = 1
      uint8_t back_lba[8];  //Address of backup LBA
      uint8_t first_lba[8];
      uint8_t last_lba[8];
      uint8_t disk_guid[16];
      uint8_t part_entry_lba[8];
      uint8_t number_parts[4];
      uint8_t sz_parts[4];
      uint32_t part_entry_crc32;
      uint8_t temp1[420];
    } __attribute__((packed));
    typedef struct guid guid_t;
    
    struct guid_partition {
      uint8_t type_guid[16];  // Type of partition
      uint8_t id_guid[16];    // unique ID for partition
      uint8_t starting_lba[8];
      uint8_t ending_lba[8];
      uint8_t attribute_bits[8];
      uint8_t name[72];
    } __attribute__((packed));
    typedef struct guid_partition guid_partition_t; 
    
    struct fat32_boot {
      uint8_t jump[3];
      char    oemId[8];
      uint16_t bytesPerSector;
      uint8_t  sectorsPerCluster;
      uint16_t reservedSectorCount;
      uint8_t  fatCount;
      uint16_t rootDirEntryCount;
      uint16_t totalSectors16;
      uint8_t  mediaType;
      uint16_t sectorsPerFat16;
      uint16_t sectorsPerTrack;
      uint16_t headCount;
      uint32_t hidddenSectors;
      uint32_t totalSectors32;
      uint32_t sectorsPerFat32;
      uint16_t fat32Flags;
      uint16_t fat32Version;
      uint32_t fat32RootCluster;
      uint16_t fat32FSInfo;
      uint16_t fat32BackBootBlock;
      uint8_t  fat32Reserved[12];
      uint8_t  driveNumber;
      uint8_t  reserved1;
      uint8_t  bootSignature;
      uint32_t volumeSerialNumber;
      char     volumeLabel[11];
      char     fileSystemType[8];
      uint8_t  bootCode[420];
      uint8_t  bootSectorSig0;
      uint8_t  bootSectorSig1;
    } __attribute__((packed));
    typedef struct fat32_boot fat32_boot_t;
    
    typedef uint16_t  le16_t;
    typedef uint32_t  le32_t;
    typedef uint64_t  le64_t;
    
    struct exfat_super_block
    {
      uint8_t jump[3];        /* 0x00 jmp and nop instructions */
      uint8_t oem_name[8];      /* 0x03 "EXFAT   " */
      uint8_t __unused1[53];      /* 0x0B always 0 */
      le64_t sector_start;      /* 0x40 partition first sector */
      le64_t sector_count;      /* 0x48 partition sectors count */
      le32_t fat_sector_start;    /* 0x50 FAT first sector */
      le32_t fat_sector_count;    /* 0x54 FAT sectors count */
      le32_t cluster_sector_start;  /* 0x58 first cluster sector */
      le32_t cluster_count;     /* 0x5C total clusters count */
      le32_t rootdir_cluster;     /* 0x60 first cluster of the root dir */
      le32_t volume_serial;     /* 0x64 volume serial number */
      struct              /* 0x68 FS version */
      {
        uint8_t minor;
        uint8_t major;
      }
      version;
      le16_t volume_state;      /* 0x6A volume state flags */
      uint8_t sector_bits;      /* 0x6C sector size as (1 << n) */
      uint8_t spc_bits;       /* 0x6D sectors per cluster as (1 << n) */
      uint8_t fat_count;        /* 0x6E always 1 */
      uint8_t drive_no;       /* 0x6F always 0x80 */
      uint8_t allocated_percent;    /* 0x70 percentage of allocated space */
      uint8_t __unused2[397];     /* 0x71 always 0 */
      le16_t boot_signature;      /* the value of 0xAA55 */
    } __attribute__((packed));
    typedef struct exfat_super_block exfat_boot_t;
    
    
    uint32_t buffer[128];
    
    inline uint32_t convertNum(uint8_t *pnum) {
      return pnum[0] | ((uint32_t)pnum[1] << 8) | ((uint32_t)pnum[2] << 16) | ((uint32_t)pnum[3] << 24);
    }
    void setup() {
      // put your setup code here, to run once:
    
      while (!Serial);
      Serial.println("Test diskio");
      Serial.print("uSDFS_VER:"); Serial.println(uSDFS_VER);
    
      BYTE pdrv = TEST_DRV;
    
      DSTATUS stat = disk_initialize(TEST_DRV);
      Serial.print("Disk initialize Status: "); Serial.println(STAT_ERROR_STRING[stat]);
    
      BYTE* buff = (BYTE *) buffer;
      DWORD sector = 0;
      DWORD sector1 = 0;
      UINT count = 1;
      UINT count1 = 1;
      DRESULT res = disk_read (pdrv, buff, sector, count);
      Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
      hexDump(buff, 512);
      mbr_t *mbr = (mbr_t *) buffer;
      Serial.println("\nMaster Boot Record");
      for (int ii = 0; ii < 4; ii++)
      {
        Serial.print("  Partition: "); Serial.print(ii);
        Serial.print(" Type: ");
        Serial.print(mbr->part[ii].type, HEX);
        Serial.print(" first Sector: ");
        Serial.print(mbr->part[ii].firstSector);
        Serial.print(" total Sectors: ");
        Serial.println(mbr->part[ii].totalSectors);
      }
    
      if (mbr->part[0].type == 0xee) {
        // read now first partition sector
        Serial.println("\nFirst partition Sector");
        sector = mbr->part[0].firstSector;
        sector1 = mbr->part[1].firstSector;
        count = 1;
        res = disk_read (pdrv, buff, sector, count);
        Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
        hexDump(buff, 512);
    
        guid_t * ptr1 = (guid_t *) buffer;
    
        Serial.println("====  GPT GUID HEADER ====");
        Serial.print("Signature: ");
        for (uint8_t ii = 0; ii < 8; ii++) {
          Serial.print(ptr1->signature[ii], HEX);
          Serial.print(", ");
        }
        Serial.println();
    
        Serial.print("Number of Partitions: ");
        Serial.println(ptr1->number_parts[0], HEX);
    
        //-----------------------------------------------------------------
        // Hack for now, lets just read in first sector of table..
        //
        res = disk_read (pdrv, buff, 2, 1);
        Serial.print("Disk read Partition 2 Result: "); Serial.println(FR_ERROR_STRING[res]);
        hexDump(buff, 512);
        for (uint8_t i = 0; i < 3; i++) {
          guid_partition_t *gpt = (guid_partition_t*)((uint8_t*)&buff[i*0x80]);
          if (!gpt->type_guid[0] && !gpt->type_guid[1] && !gpt->type_guid[2]&& !gpt->type_guid[3]) break;
          Serial.printf("Part: %d Type: ", i);
          printGUID(gpt->type_guid);
          Serial.print(" id: ");
          printGUID(gpt->id_guid);
      
          Serial.printf(" starting: %d ending: %d", convertNum(gpt->starting_lba), convertNum(gpt->ending_lba));
          Serial.print(" Name: ");
          for (int j=0; j < 72; j+= 2) {
            if (!gpt->name[j]) break; // end of unicode string
            Serial.write(gpt->name[j]);
          }
          // 
          Serial.println();
        }
     
        //----------------------------------------------------------------------
      } else {
        // read now first partition sector
        Serial.println("\nFirst partition Sector");
        sector = mbr->part[0].firstSector;
        sector1 = mbr->part[1].firstSector;
        count = 1;
        res = disk_read (pdrv, buff, sector, count);
        Serial.print("Disk read Result: "); Serial.write(FR_ERROR_STRING[res]);
        Serial.println();
        hexDump(buff, 512);
    
        fat32_boot_t * ptr1 = (fat32_boot_t *) buffer;
        exfat_boot_t * ptr2 = (exfat_boot_t *) buffer;
    
        if (strncmp(ptr1->fileSystemType, "FAT32", 5) == 0)
        {
          Serial.println("FAT32");
          Serial.print("bytes per sector :"); Serial.println(ptr1->bytesPerSector);
          Serial.print("sectors per cluster :"); Serial.println(ptr1->sectorsPerCluster);
        }
        else if (strncmp(ptr2->oem_name, "EXFAT", 5) == 0)
        {
          Serial.println("EXFAT");
          Serial.print("bytes per sector :"); Serial.println(1 << ptr2->sector_bits);
          Serial.print("sectors per cluster :"); Serial.println(1 << ptr2->spc_bits);
        }
        pinMode(13, OUTPUT);
    
        // read now Second partition sector
        Serial.println("\nSecond partition Sector");
        count = 1;
        res = disk_read (pdrv, buff, sector1, count);
        Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
        hexDump(buff, 512);
    
        if (strncmp(ptr1->fileSystemType, "FAT32", 5) == 0)
        {
          Serial.println("FAT32");
          Serial.print("bytes per sector :"); Serial.println(ptr1->bytesPerSector);
          Serial.print("sectors per cluster :"); Serial.println(ptr1->sectorsPerCluster);
        }
        else if (strncmp(ptr2->oem_name, "EXFAT", 5) == 0)
        {
          Serial.println("EXFAT");
          Serial.print("bytes per sector :"); Serial.println(1 << ptr2->sector_bits);
          Serial.print("sectors per cluster :"); Serial.println(1 << ptr2->spc_bits);
        }
      }
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      digitalWriteFast(13, !digitalReadFast(13));
      delay(1000);
    }
    // A small hex dump funcion
    void hexDump(const void *ptr, uint32_t len)
    {
      uint32_t  i = 0, j = 0;
      uint8_t   c=0;
      const uint8_t *p = (const uint8_t *)ptr;
    
      Serial.printf("BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");
      Serial.printf("---------------------------------------------------------\n");
      for(i = 0; i <= (len-1); i+=16) {
       Serial.printf("%4.4x      ",i);
       for(j = 0; j < 16; j++) {
          c = p[i+j];
          Serial.printf("%2.2x ",c);
        }
        Serial.printf("  ");
        for(j = 0; j < 16; j++) {
          c = p[i+j];
          if(c > 31 && c < 127)
            Serial.printf("%c",c);
          else
            Serial.printf(".");
        }
        Serial.println();
      }
    }
    
    void printGUID(uint8_t *guid) {
    //EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
    // looks like strange order of bytes to print...
    //  0  1  2  3    4  5    6  7   8  9    10 11 12 13 4  15
    // a2 a0 d0 eb - e5 b9 - 33 44 - 87 c0 - 68 b6 b7 26 99 c7
      Serial.printf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
        guid[3],guid[2],guid[1],guid[0],
        guid[5],guid[4],guid[7],guid[6],
        guid[8],guid[9],
        guid[10],guid[11],guid[12],guid[13],guid[14],guid[15]);
    }
    Here is some of the additional printed out stuff...
    Code:
    ====  GPT GUID HEADER ====
    Signature: 45, 46, 49, 20, 50, 41, 52, 54, 
    Number of Partitions: 80
    Disk read Partition 2 Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      16 e3 c9 e3 5c 0b b8 4d 81 7d f9 2d f0 02 15 ae   ....\..M.}.-....
    0010      5b 9b bc 04 f9 d8 33 46 94 b0 8a 3e aa 7f 5b e4   [.....3F...>..[.
    0020      22 00 00 00 00 00 00 00 ff 7f 00 00 00 00 00 00   "...............
    0030      00 00 00 00 00 00 00 00 4d 00 69 00 63 00 72 00   ........M.i.c.r.
    0040      6f 00 73 00 6f 00 66 00 74 00 20 00 72 00 65 00   o.s.o.f.t. .r.e.
    0050      73 00 65 00 72 00 76 00 65 00 64 00 20 00 70 00   s.e.r.v.e.d. .p.
    0060      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0090      64 c3 cb a7 0c a7 a8 4e 9f dc 6f e6 76 97 de 71   d......N..o.v..q
    00a0      00 80 00 00 00 00 00 00 ff 77 1c 1d 00 00 00 00   .........w......
    00b0      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    00c0      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    00d0      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0110      b5 15 aa 6f 94 d5 90 44 b6 7b 99 8f fd 7a 8f fd   ...o...D.{...z..
    0120      00 78 1c 1d 00 00 00 00 ff 5f 70 74 00 00 00 00   .x......._pt....
    0130      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    0140      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    0150      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    Part: 0 Type: e3c9e316-0b5c-4db8-817d-f92df00215ae id: 04bc9b5b-d8f9-4633-94b0-8a3eaa7f5be4 starting: 34 ending: 32767 Name: Microsoft reserved partition
    Part: 1 Type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 id: a7cbc364-a70c-4ea8-9fdc-6fe67697de71 starting: 32768 ending: 488404991 Name: Basic data partition
    Part: 2 Type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 id: 6faa15b5-d594-4490-b67b-998ffd7a8ffd starting: 488404992 ending: 1953521663 Name: Basic data partition
    The print out stuff for guids is sort of strange, but these type ones match the partition type guids as mentioned in:
    https://en.wikipedia.org/wiki/GUID_P...ion_type_GUIDs

  11. #261
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,681
    @KurtE

    Cool.. Don't you just love hacking . I just gave it a try and am seeing pretty much the same data:
    Code:
    Test diskio
    uSDFS_VER:15_MAY_19_08_16
    Disk initialize Status: STA_OK
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0010      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0020      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0030      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0040      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0050      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 ae 7a ee f2 00 00 00 00   .........z......
    01c0      02 00 ee fe ff 00 01 00 00 00 ff ff ff ff 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa   ..............U.
    
    Master Boot Record
      Partition: 0 Type: EE first Sector: 1 total Sectors: 4294967295
      Partition: 1 Type: 0 first Sector: 0 total Sectors: 0
      Partition: 2 Type: 0 first Sector: 0 total Sectors: 0
      Partition: 3 Type: 0 first Sector: 0 total Sectors: 0
    
    First partition Sector
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      45 46 49 20 50 41 52 54 00 00 01 00 5c 00 00 00   EFI PART....\...
    0010      3e a8 c0 fc 00 00 00 00 01 00 00 00 00 00 00 00   >...............
    0020      af 6d 70 74 00 00 00 00 22 00 00 00 00 00 00 00   .mpt....".......
    0030      8e 6d 70 74 00 00 00 00 e2 34 12 ce 52 9c 0f 49   .mpt.....4..R..I
    0040      92 c4 c1 e5 20 ba fa 8c 02 00 00 00 00 00 00 00   .... ...........
    0050      80 00 00 00 80 00 00 00 94 f6 1f ae 00 00 00 00   ................
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    ====  GPT GUID HEADER ====
    Signature: 45, 46, 49, 20, 50, 41, 52, 54, 
    Number of Partitions: 80
    Disk read Partition 2 Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      16 e3 c9 e3 5c 0b b8 4d 81 7d f9 2d f0 02 15 ae   ....\..M.}.-....
    0010      41 61 c8 4a b0 43 f8 49 ab 41 9e b9 ec 06 8a 4e   Aa.J.C.I.A.....N
    0020      22 00 00 00 00 00 00 00 ff 7f 00 00 00 00 00 00   "...............
    0030      00 00 00 00 00 00 00 00 4d 00 69 00 63 00 72 00   ........M.i.c.r.
    0040      6f 00 73 00 6f 00 66 00 74 00 20 00 72 00 65 00   o.s.o.f.t. .r.e.
    0050      73 00 65 00 72 00 76 00 65 00 64 00 20 00 70 00   s.e.r.v.e.d. .p.
    0060      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0090      a5 26 06 f9 d1 ea 2b 4c 86 17 d7 8c 57 d3 38 88   .&....+L....W.8.
    00a0      00 80 00 00 00 00 00 00 ff 7f a8 61 00 00 00 00   ...........a....
    00b0      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    00c0      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    00d0      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0110      15 0d 81 ad f2 54 49 48 ae f8 b3 20 47 e6 dd 47   .....TIH... G..G
    0120      00 80 a8 61 00 00 00 00 ff 5f 70 74 00 00 00 00   ...a....._pt....
    0130      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    0140      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    0150      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    Part: 0 Type: e3c9e316-0b5c-4db8-817d-f92df00215ae id: 4ac86141-43b0-49f8-ab41-9eb9ec068a4e starting: 34 ending: 32767 Name: Microsoft reserved partition
    Part: 1 Type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 id: f90626a5-ead1-4c2b-8617-d78c57d33888 starting: 32768 ending: 1638432767 Name: Basic data partition
    Part: 2 Type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 id: ad810d15-54f2-4849-aef8-b32047e6dd47 starting: 1638432768 ending: 1953521663 Name: Basic data partition
    EDIT: Don't know how much farther we want to take this. Don't know how much work it would be to incorporate it into the library.
    Last edited by mjs513; 05-25-2019 at 09:42 PM.

  12. #262
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    @mjs513, @WMXZ... My guess more for someone who knows more... But may look if no one else does. Now full support may be beyond what is easily doable, like 8 byte sector numbers... probably would have to change many things including which SCSI calls...

  13. #263
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,681
    Quote Originally Posted by KurtE View Post
    @mjs513, @WMXZ... My guess more for someone who knows more... But may look if no one else does. Now full support may be beyond what is easily doable, like 8 byte sector numbers... probably would have to change many things including which SCSI calls...
    I agree know it is beyond me - my gut feel is that it would require a lot of changes or probably a separate class to make it easier. At least now we have a way to identify that its a GPT disk.

  14. #264
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,032
    Just Identify it as GPT and return the appropriate error was my expectation. Given the needed utility it is easy enough to start with a fresh drive or redo an old one to function. ExFat or FAT32 are wasteful of space on larger drives - but then again it reduces FAT structure updates with fewer added allocation units on growing a file or following a file chain to read.

    Not sure what is really involved - but my EASEUS Partition master program did do a conversion to MBR on the drive(s) I had so afflicted with data in place conversion. So it of course maps - but would take another layer and overhead.

  15. #265
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    Good morning @mjs513, @defragster, @WMXZ and ...

    As mentioned Hacking is fun!

    So I went a little farther and now identify the file system type...

    Also broke off the printing of file system type and read/hexdump to function to call...

    Current program:

    Code:
    #include "uSDFS.h"
    #include "diskio.h"
    
    #include <USBHost_t36.h>
    extern USBHost myusb;
    USBHub hub1(myusb);
    USBHub hub2(myusb);
    
    /*
      for APL see http://elm-chan.org/fsw/ff/00index_e.html
    */
    #define TEST_DRV 2
    //
    #if TEST_DRV == 0
    const char *Dev = "0:/";  // SPI
    #elif TEST_DRV == 1
    const char *Dev = "1:/";  // SDHC
    #elif TEST_DRV == 2
    const char *Dev = "2:/";  // USB
    #endif
    
    struct partitionTable {
      uint8_t  boot;
      uint8_t  beginHead;
      unsigned beginSector : 6;
      unsigned beginCylinderHigh : 2;
      uint8_t  beginCylinderLow;
      uint8_t  type;
      uint8_t  endHead;
      unsigned endSector : 6;
      unsigned endCylinderHigh : 2;
      uint8_t  endCylinderLow;
      uint32_t firstSector;
      uint32_t totalSectors;
    } __attribute__((packed));
    typedef struct partitionTable part_t;
    
    struct masterBootRecord {
      uint8_t  codeArea[440];
      uint32_t diskSignature;
      uint16_t usuallyZero;
      part_t   part[4];
      uint8_t  mbrSig0;
      uint8_t  mbrSig1;
    } __attribute__((packed));
    typedef struct masterBootRecord mbr_t;
    
    struct guid {
      uint8_t signature[8];  //8 bytes
      uint8_t revision[4];  //pos 3
      uint8_t hdr_sz[4];    //pos 1
      uint32_t crc32;     //single 32bit val
      uint8_t reserved[4];
      uint8_t prim_lba[8];  //pos 1 always = 1
      uint8_t back_lba[8];  //Address of backup LBA
      uint8_t first_lba[8];
      uint8_t last_lba[8];
      uint8_t disk_guid[16];
      uint8_t part_entry_lba[8];
      uint8_t number_parts[4];
      uint8_t sz_parts[4];
      uint32_t part_entry_crc32;
      uint8_t temp1[420];
    } __attribute__((packed));
    typedef struct guid guid_t;
    
    struct guid_partition {
      uint8_t type_guid[16];  // Type of partition
      uint8_t id_guid[16];    // unique ID for partition
      uint8_t starting_lba[8];
      uint8_t ending_lba[8];
      uint8_t attribute_bits[8];
      uint8_t name[72];
    } __attribute__((packed));
    typedef struct guid_partition guid_partition_t;
    
    struct fat32_boot {
      uint8_t jump[3];
      char    oemId[8];
      uint16_t bytesPerSector;
      uint8_t  sectorsPerCluster;
      uint16_t reservedSectorCount;
      uint8_t  fatCount;
      uint16_t rootDirEntryCount;
      uint16_t totalSectors16;
      uint8_t  mediaType;
      uint16_t sectorsPerFat16;
      uint16_t sectorsPerTrack;
      uint16_t headCount;
      uint32_t hidddenSectors;
      uint32_t totalSectors32;
      uint32_t sectorsPerFat32;
      uint16_t fat32Flags;
      uint16_t fat32Version;
      uint32_t fat32RootCluster;
      uint16_t fat32FSInfo;
      uint16_t fat32BackBootBlock;
      uint8_t  fat32Reserved[12];
      uint8_t  driveNumber;
      uint8_t  reserved1;
      uint8_t  bootSignature;
      uint32_t volumeSerialNumber;
      char     volumeLabel[11];
      char     fileSystemType[8];
      uint8_t  bootCode[420];
      uint8_t  bootSectorSig0;
      uint8_t  bootSectorSig1;
    } __attribute__((packed));
    typedef struct fat32_boot fat32_boot_t;
    
    typedef uint16_t  le16_t;
    typedef uint32_t  le32_t;
    typedef uint64_t  le64_t;
    
    struct exfat_super_block
    {
      uint8_t jump[3];        /* 0x00 jmp and nop instructions */
      uint8_t oem_name[8];      /* 0x03 "EXFAT   " */
      uint8_t __unused1[53];      /* 0x0B always 0 */
      le64_t sector_start;      /* 0x40 partition first sector */
      le64_t sector_count;      /* 0x48 partition sectors count */
      le32_t fat_sector_start;    /* 0x50 FAT first sector */
      le32_t fat_sector_count;    /* 0x54 FAT sectors count */
      le32_t cluster_sector_start;  /* 0x58 first cluster sector */
      le32_t cluster_count;     /* 0x5C total clusters count */
      le32_t rootdir_cluster;     /* 0x60 first cluster of the root dir */
      le32_t volume_serial;     /* 0x64 volume serial number */
      struct              /* 0x68 FS version */
      {
        uint8_t minor;
        uint8_t major;
      }
      version;
      le16_t volume_state;      /* 0x6A volume state flags */
      uint8_t sector_bits;      /* 0x6C sector size as (1 << n) */
      uint8_t spc_bits;       /* 0x6D sectors per cluster as (1 << n) */
      uint8_t fat_count;        /* 0x6E always 1 */
      uint8_t drive_no;       /* 0x6F always 0x80 */
      uint8_t allocated_percent;    /* 0x70 percentage of allocated space */
      uint8_t __unused2[397];     /* 0x71 always 0 */
      le16_t boot_signature;      /* the value of 0xAA55 */
    } __attribute__((packed));
    typedef struct exfat_super_block exfat_boot_t;
    
    
    uint32_t buffer[128];
    
    inline uint32_t convertNum(uint8_t *pnum) {
      return pnum[0] | ((uint32_t)pnum[1] << 8) | ((uint32_t)pnum[2] << 16) | ((uint32_t)pnum[3] << 24);
    }
    void setup() {
      // put your setup code here, to run once:
    
      while (!Serial);
      Serial.println("Test diskio");
      Serial.print("uSDFS_VER:"); Serial.println(uSDFS_VER);
      pinMode(13, OUTPUT);
    
      BYTE pdrv = TEST_DRV;
    
      DSTATUS stat = disk_initialize(TEST_DRV);
      Serial.print("Disk initialize Status: "); Serial.println(STAT_ERROR_STRING[stat]);
    
      BYTE* buff = (BYTE *) buffer;
      DWORD sector = 0;
      DWORD sector1 = 0;
      UINT count = 1;
      UINT count1 = 1;
      DRESULT res = disk_read (pdrv, buff, sector, count);
      Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
      hexDump(buff, 512);
      mbr_t *mbr = (mbr_t *) buffer;
      Serial.println("\nMaster Boot Record");
      for (int ii = 0; ii < 4; ii++)
      {
        Serial.print("  Partition: "); Serial.print(ii);
        Serial.print(" Type: ");
        Serial.print(mbr->part[ii].type, HEX);
        Serial.print(" first Sector: ");
        Serial.print(mbr->part[ii].firstSector);
        Serial.print(" total Sectors: ");
        Serial.println(mbr->part[ii].totalSectors);
      }
    
      if (mbr->part[0].type == 0xee) {
        // read now first partition sector
        Serial.println("\nFirst partition Sector");
        sector = mbr->part[0].firstSector;
        sector1 = mbr->part[1].firstSector;
        count = 1;
        res = disk_read (pdrv, buff, sector, count);
        Serial.print("Disk read Result: "); Serial.println(FR_ERROR_STRING[res]);
        hexDump(buff, 512);
    
        guid_t * ptr1 = (guid_t *) buffer;
    
        Serial.println("====  GPT GUID HEADER ====");
        Serial.print("Signature: ");
        for (uint8_t ii = 0; ii < 8; ii++) {
          Serial.print(ptr1->signature[ii], HEX);
          Serial.print(", ");
        }
        Serial.println();
    
        Serial.print("Number of Partitions: ");
        Serial.println(ptr1->number_parts[0], HEX);
    
        //-----------------------------------------------------------------
        // Hack for now, lets just read in first sector of table..
        //
        res = disk_read (pdrv, buff, 2, 1);
        Serial.print("Disk read Partition 2 Result: "); Serial.println(FR_ERROR_STRING[res]);
        hexDump(buff, 512);
        for (uint8_t i = 0; i < 3; i++) {
          guid_partition_t *gpt = (guid_partition_t*)((uint8_t*)&buff[i * 0x80]);
          if (!gpt->type_guid[0] && !gpt->type_guid[1] && !gpt->type_guid[2] && !gpt->type_guid[3]) break;
          Serial.printf("Part: %d Type: ", i);
          printGUID(gpt->type_guid);
          Serial.print(" id: ");
          printGUID(gpt->id_guid);
          uint32_t start_lba = convertNum(gpt->starting_lba);
          Serial.printf(" starting: %d ending: %d", start_lba, convertNum(gpt->ending_lba));
          Serial.print(" Name: ");
          for (int j = 0; j < 72; j += 2) {
            if (!gpt->name[j]) break; // end of unicode string
            Serial.write(gpt->name[j]);
          }
          Serial.println();
          if (IsBasicDataPartition(gpt)) {
            printFileSystemInfo(pdrv, start_lba);
          } else {
            Serial.println("\nNot Basic Data Partition\n===============================\n");
          }
        }
    
        //----------------------------------------------------------------------
      } else {
        for (uint8_t i = 0; i < 3; i++) {
          // read now first partition sector
          if (mbr->part[i].firstSector == 0) break;
    
          Serial.printf("\nFirst Sector for partition: %d\n", i);
          printFileSystemInfo(pdrv, mbr->part[i].firstSector);
        }
      }
    }
    void loop() {
      // put your main code here, to run repeatedly:
      digitalWriteFast(13, !digitalReadFast(13));
      delay(1000);
    }
    // A small hex dump funcion
    void hexDump(const void *ptr, uint32_t len)
    {
      uint32_t  i = 0, j = 0;
      uint8_t   c = 0;
      const uint8_t *p = (const uint8_t *)ptr;
    
      Serial.printf("BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");
      Serial.printf("---------------------------------------------------------\n");
      for (i = 0; i <= (len - 1); i += 16) {
        Serial.printf("%4.4x      ", i);
        for (j = 0; j < 16; j++) {
          c = p[i + j];
          Serial.printf("%2.2x ", c);
        }
        Serial.printf("  ");
        for (j = 0; j < 16; j++) {
          c = p[i + j];
          if (c > 31 && c < 127)
            Serial.printf("%c", c);
          else
            Serial.printf(".");
        }
        Serial.println();
      }
    }
    
    void printGUID(uint8_t *guid) {
      //EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
      // looks like strange order of bytes to print...
      //  0  1  2  3    4  5    6  7   8  9    10 11 12 13 4  15
      // a2 a0 d0 eb - e5 b9 - 33 44 - 87 c0 - 68 b6 b7 26 99 c7
      Serial.printf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
                    guid[3], guid[2], guid[1], guid[0],
                    guid[5], guid[4], guid[7], guid[6],
                    guid[8], guid[9],
                    guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]);
    }
    
    //---------------------------------------------------------------
    uint8_t buffer_fsi[512];
    
    void printFileSystemInfo(BYTE pdrv, uint32_t first_sector) {
      DWORD res = disk_read (pdrv, buffer_fsi, first_sector, 1);
      Serial.print("Disk read Result: "); Serial.write(FR_ERROR_STRING[res]);
      Serial.println();
      hexDump(buffer_fsi, 512);
    
      fat32_boot_t * ptr1 = (fat32_boot_t *) buffer_fsi;
      exfat_boot_t * ptr2 = (exfat_boot_t *) buffer_fsi;
    
      if (strncmp(ptr1->fileSystemType, "FAT32", 5) == 0)
      {
        Serial.println("FAT32");
        Serial.print("bytes per sector :"); Serial.println(ptr1->bytesPerSector);
        Serial.print("sectors per cluster :"); Serial.println(ptr1->sectorsPerCluster);
      }
      else if (strncmp(ptr2->oem_name, "EXFAT", 5) == 0)
      {
        Serial.println("EXFAT");
        Serial.print("bytes per sector :"); Serial.println(1 << ptr2->sector_bits);
        Serial.print("sectors per cluster :"); Serial.println(1 << ptr2->spc_bits);
      }
      else
      {
        Serial.println("Other");
      }
      Serial.println("\n===========================================\n");
    }
    
    bool IsBasicDataPartition(guid_partition_t *gpt) {
      const static uint8_t basicDataPartition_guid[] = {0xa2, 0xa0, 0xd0, 0xeb, 0xe5, 0xb9, 0x33, 0x44,
                                                        0x87, 0xc0, 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7
                                                       };
      for (uint8_t i = 0; i < 16; i++) {
        if (gpt->type_guid[i] != basicDataPartition_guid[i]) return false;
      }
      return true;
    }
    Current long output:
    Code:
    Test diskio
    uSDFS_VER:15_MAY_19_08_16
    ## mscInit before msgGetMaxLun: 1
    ## mscInit after msgGetMaxLun: 1
    ## mscInit after msDeviceInquiry LUN(0): Device Type: 0 result:0
    ## mscInit after msReadDeviceCapacity: 0
    Disk initialize Status: STA_OK
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0010      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0020      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0030      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0040      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0050      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 81 20 ce cb 00 00 00 00   ......... ......
    01c0      02 00 ee fe ff 00 01 00 00 00 ff ff ff ff 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa   ..............U.
    
    Master Boot Record
      Partition: 0 Type: EE first Sector: 1 total Sectors: 4294967295
      Partition: 1 Type: 0 first Sector: 0 total Sectors: 0
      Partition: 2 Type: 0 first Sector: 0 total Sectors: 0
      Partition: 3 Type: 0 first Sector: 0 total Sectors: 0
    
    First partition Sector
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      45 46 49 20 50 41 52 54 00 00 01 00 5c 00 00 00   EFI PART....\...
    0010      35 0b 97 16 00 00 00 00 01 00 00 00 00 00 00 00   5...............
    0020      af 6d 70 74 00 00 00 00 22 00 00 00 00 00 00 00   .mpt....".......
    0030      8e 6d 70 74 00 00 00 00 a3 c8 ca db a5 8e 76 45   .mpt..........vE
    0040      b8 16 56 8f d4 96 e4 25 02 00 00 00 00 00 00 00   ..V....%........
    0050      80 00 00 00 80 00 00 00 65 5a bf b1 00 00 00 00   ........eZ......
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    ====  GPT GUID HEADER ====
    Signature: 45, 46, 49, 20, 50, 41, 52, 54, 
    Number of Partitions: 80
    Disk read Partition 2 Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      16 e3 c9 e3 5c 0b b8 4d 81 7d f9 2d f0 02 15 ae   ....\..M.}.-....
    0010      5b 9b bc 04 f9 d8 33 46 94 b0 8a 3e aa 7f 5b e4   [.....3F...>..[.
    0020      22 00 00 00 00 00 00 00 ff 7f 00 00 00 00 00 00   "...............
    0030      00 00 00 00 00 00 00 00 4d 00 69 00 63 00 72 00   ........M.i.c.r.
    0040      6f 00 73 00 6f 00 66 00 74 00 20 00 72 00 65 00   o.s.o.f.t. .r.e.
    0050      73 00 65 00 72 00 76 00 65 00 64 00 20 00 70 00   s.e.r.v.e.d. .p.
    0060      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0090      64 c3 cb a7 0c a7 a8 4e 9f dc 6f e6 76 97 de 71   d......N..o.v..q
    00a0      00 80 00 00 00 00 00 00 ff 77 1c 1d 00 00 00 00   .........w......
    00b0      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    00c0      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    00d0      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0110      b5 15 aa 6f 94 d5 90 44 b6 7b 99 8f fd 7a 8f fd   ...o...D.{...z..
    0120      00 78 1c 1d 00 00 00 00 ff 5f 70 74 00 00 00 00   .x......._pt....
    0130      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    0140      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    0150      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    Part: 0 Type: e3c9e316-0b5c-4db8-817d-f92df00215ae id: 04bc9b5b-d8f9-4633-94b0-8a3eaa7f5be4 starting: 34 ending: 32767 Name: Microsoft reserved partition
    
    Not Basic Data Partition
    ===============================
    
    Part: 1 Type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 id: a7cbc364-a70c-4ea8-9fdc-6fe67697de71 starting: 32768 ending: 488404991 Name: Basic data partition
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      eb 76 90 45 58 46 41 54 20 20 20 00 00 00 00 00   .v.EXFAT   .....
    0010      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0020      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0030      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0040      00 80 00 00 00 00 00 00 00 f8 1b 1d 00 00 00 00   ................
    0050      00 08 00 00 00 3b 00 00 00 48 00 00 b0 1b 1d 00   .....;...H......
    0060      05 00 00 00 66 11 45 e0 00 01 00 00 09 08 01 80   ....f.E.........
    0070      00 00 00 00 00 00 00 00 33 c9 8e d1 8e c1 8e d9   ........3.......
    0080      bc d0 7b bd 00 7c 88 16 6f 7c b4 41 bb aa 55 cd   ..{..|..o|.A..U.
    0090      13 72 69 81 fb 55 aa 75 63 f6 c1 01 74 5e fe 06   .ri..U.uc...t^..
    00a0      02 7c 66 50 b0 65 e8 a6 00 66 58 66 b8 01 00 00   .|fP.e...fXf....
    00b0      00 8a 0e 6d 7c 66 d3 e0 66 89 46 e8 66 b8 01 00   ...m|f..f.F.f...
    00c0      00 00 8a 0e 6c 7c 66 d3 e0 66 89 46 d8 66 a1 40   ....l|f..f.F.f.@
    00d0      7c 66 40 bb 00 7e b9 01 00 66 50 e8 41 00 66 58   |f@..~...fP.A.fX
    00e0      66 40 bb 00 80 b9 01 00 e8 34 00 66 50 b0 78 e8   f@.......4.fP.x.
    00f0      5d 00 66 58 e9 09 01 a0 fc 7d eb 05 a0 fb 7d eb   ].fX.....}....}.
    0100      00 b4 7d 8b f0 ac 98 40 74 0c 48 74 0e b4 0e bb   ..}....@t.Ht....
    0110      07 00 cd 10 eb ef a0 fd 7d eb e6 cd 16 cd 19 66   ........}......f
    0120      60 66 6a 00 66 50 06 53 66 68 10 00 01 00 b4 42   `fj.fP.Sfh.....B
    0130      b2 80 8a 16 6f 7c 8b f4 cd 13 66 58 66 58 66 58   ....o|....fXfXfX
    0140      66 58 66 61 72 b1 03 5e d8 66 40 49 75 d1 c3 66   fXfar..^.f@Iu..f
    0150      60 b4 0e bb 07 00 b9 01 00 cd 10 66 61 c3 42 00   `..........fa.B.
    0160      4f 00 4f 00 54 00 4d 00 47 00 52 00 0d 0a 52 65   O.O.T.M.G.R...Re
    0170      6d 6f 76 65 20 64 69 73 6b 73 20 6f 72 20 6f 74   move disks or ot
    0180      68 65 72 20 6d 65 64 69 61 2e ff 0d 0a 44 69 73   her media....Dis
    0190      6b 20 65 72 72 6f 72 ff 0d 0a 50 72 65 73 73 20   k error...Press 
    01a0      61 6e 79 20 6b 65 79 20 74 6f 20 72 65 73 74 61   any key to resta
    01b0      72 74 0d 0a 00 00 00 00 00 00 00 00 00 00 ff ff   rt..............
    01c0      ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff   ................
    01d0      ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff   ................
    01e0      ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff   ................
    01f0      ff ff ff ff ff ff ff ff ff ff ff 6c 8b 98 55 aa   ...........l..U.
    EXFAT
    bytes per sector :512
    sectors per cluster :256
    
    ===========================================
    
    Part: 2 Type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 id: 6faa15b5-d594-4490-b67b-998ffd7a8ffd starting: 488404992 ending: 1953521663 Name: Basic data partition
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      eb 52 90 4e 54 46 53 20 20 20 20 00 02 08 00 00   .R.NTFS    .....
    0010      00 00 00 00 00 f8 00 00 3f 00 ff 00 00 78 1c 1d   ........?....x..
    0020      00 00 00 00 80 00 80 00 ff e7 53 57 00 00 00 00   ..........SW....
    0030      00 00 0c 00 00 00 00 00 02 00 00 00 00 00 00 00   ................
    0040      f6 00 00 00 01 00 00 00 53 4a 55 cc 96 55 cc fe   ........SJU..U..
    0050      00 00 00 00 fa 33 c0 8e d0 bc 00 7c fb 68 c0 07   .....3.....|.h..
    0060      1f 1e 68 66 00 cb 88 16 0e 00 66 81 3e 03 00 4e   ..hf......f.>..N
    0070      54 46 53 75 15 b4 41 bb aa 55 cd 13 72 0c 81 fb   TFSu..A..U..r...
    0080      55 aa 75 06 f7 c1 01 00 75 03 e9 dd 00 1e 83 ec   U.u.....u.......
    0090      18 68 1a 00 b4 48 8a 16 0e 00 8b f4 16 1f cd 13   .h...H..........
    00a0      9f 83 c4 18 9e 58 1f 72 e1 3b 06 0b 00 75 db a3   .....X.r.;...u..
    00b0      0f 00 c1 2e 0f 00 04 1e 5a 33 db b9 00 20 2b c8   ........Z3... +.
    00c0      66 ff 06 11 00 03 16 0f 00 8e c2 ff 06 16 00 e8   f...............
    00d0      4b 00 2b c8 77 ef b8 00 bb cd 1a 66 23 c0 75 2d   K.+.w......f#.u-
    00e0      66 81 fb 54 43 50 41 75 24 81 f9 02 01 72 1e 16   f..TCPAu$....r..
    00f0      68 07 bb 16 68 52 11 16 68 09 00 66 53 66 53 66   h...hR..h..fSfSf
    0100      55 16 16 16 68 b8 01 66 61 0e 07 cd 1a 33 c0 bf   U...h..fa....3..
    0110      0a 13 b9 f6 0c fc f3 aa e9 fe 01 90 90 66 60 1e   .............f`.
    0120      06 66 a1 11 00 66 03 06 1c 00 1e 66 68 00 00 00   .f...f.....fh...
    0130      00 66 50 06 53 68 01 00 68 10 00 b4 42 8a 16 0e   .fP.Sh..h...B...
    0140      00 16 1f 8b f4 cd 13 66 59 5b 5a 66 59 66 59 1f   .......fY[ZfYfY.
    0150      0f 82 16 00 66 ff 06 11 00 03 16 0f 00 8e c2 ff   ....f...........
    0160      0e 16 00 75 bc 07 1f 66 61 c3 a1 f6 01 e8 09 00   ...u...fa.......
    0170      a1 fa 01 e8 03 00 f4 eb fd 8b f0 ac 3c 00 74 09   ............<.t.
    0180      b4 0e bb 07 00 cd 10 eb f2 c3 0d 0a 41 20 64 69   ............A di
    0190      73 6b 20 72 65 61 64 20 65 72 72 6f 72 20 6f 63   sk read error oc
    01a0      63 75 72 72 65 64 00 0d 0a 42 4f 4f 54 4d 47 52   curred...BOOTMGR
    01b0      20 69 73 20 63 6f 6d 70 72 65 73 73 65 64 00 0d    is compressed..
    01c0      0a 50 72 65 73 73 20 43 74 72 6c 2b 41 6c 74 2b   .Press Ctrl+Alt+
    01d0      44 65 6c 20 74 6f 20 72 65 73 74 61 72 74 0d 0a   Del to restart..
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 8a 01 a7 01 bf 01 00 00 55 aa   ..............U.
    Other
    
    ===========================================
    Last edited by KurtE; 05-26-2019 at 02:43 PM. Reason: Updated code for MBR disks to only read first sectors of defined partitions

  16. #266
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,681
    @KurtE - @wwatson - @WMXZ - @defragster - @....

    Nice Kurt. Just can't resisting hacking and having fun. Anyway, you got the LBA sorted out I see and even printing out the partition format Since I can't resist trying it for my disk here is what I get for the Seagate with 2 exFATs:
    Code:
    Test diskio
    uSDFS_VER:15_MAY_19_08_16
    Disk initialize Status: STA_OK
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0010      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0020      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0030      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0040      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0050      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 ae 7a ee f2 00 00 00 00   .........z......
    01c0      02 00 ee fe ff 00 01 00 00 00 ff ff ff ff 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa   ..............U.
    
    Master Boot Record
      Partition: 0 Type: EE first Sector: 1 total Sectors: 4294967295
      Partition: 1 Type: 0 first Sector: 0 total Sectors: 0
      Partition: 2 Type: 0 first Sector: 0 total Sectors: 0
      Partition: 3 Type: 0 first Sector: 0 total Sectors: 0
    
    First partition Sector
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      45 46 49 20 50 41 52 54 00 00 01 00 5c 00 00 00   EFI PART....\...
    0010      3e a8 c0 fc 00 00 00 00 01 00 00 00 00 00 00 00   >...............
    0020      af 6d 70 74 00 00 00 00 22 00 00 00 00 00 00 00   .mpt....".......
    0030      8e 6d 70 74 00 00 00 00 e2 34 12 ce 52 9c 0f 49   .mpt.....4..R..I
    0040      92 c4 c1 e5 20 ba fa 8c 02 00 00 00 00 00 00 00   .... ...........
    0050      80 00 00 00 80 00 00 00 94 f6 1f ae 00 00 00 00   ................
    0060      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0090      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0110      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0120      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0130      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0140      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0150      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    ====  GPT GUID HEADER ====
    Signature: 45, 46, 49, 20, 50, 41, 52, 54, 
    Number of Partitions: 80
    Disk read Partition 2 Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      16 e3 c9 e3 5c 0b b8 4d 81 7d f9 2d f0 02 15 ae   ....\..M.}.-....
    0010      41 61 c8 4a b0 43 f8 49 ab 41 9e b9 ec 06 8a 4e   Aa.J.C.I.A.....N
    0020      22 00 00 00 00 00 00 00 ff 7f 00 00 00 00 00 00   "...............
    0030      00 00 00 00 00 00 00 00 4d 00 69 00 63 00 72 00   ........M.i.c.r.
    0040      6f 00 73 00 6f 00 66 00 74 00 20 00 72 00 65 00   o.s.o.f.t. .r.e.
    0050      73 00 65 00 72 00 76 00 65 00 64 00 20 00 70 00   s.e.r.v.e.d. .p.
    0060      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0070      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0080      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0090      a5 26 06 f9 d1 ea 2b 4c 86 17 d7 8c 57 d3 38 88   .&....+L....W.8.
    00a0      00 80 00 00 00 00 00 00 ff 7f a8 61 00 00 00 00   ...........a....
    00b0      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    00c0      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    00d0      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    00e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    00f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0100      a2 a0 d0 eb e5 b9 33 44 87 c0 68 b6 b7 26 99 c7   ......3D..h..&..
    0110      15 0d 81 ad f2 54 49 48 ae f8 b3 20 47 e6 dd 47   .....TIH... G..G
    0120      00 80 a8 61 00 00 00 00 ff 5f 70 74 00 00 00 00   ...a....._pt....
    0130      00 00 00 00 00 00 00 00 42 00 61 00 73 00 69 00   ........B.a.s.i.
    0140      63 00 20 00 64 00 61 00 74 00 61 00 20 00 70 00   c. .d.a.t.a. .p.
    0150      61 00 72 00 74 00 69 00 74 00 69 00 6f 00 6e 00   a.r.t.i.t.i.o.n.
    0160      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0170      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0180      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0190      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01a0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01b0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01c0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01d0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01e0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    01f0      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    Part: 0 Type: e3c9e316-0b5c-4db8-817d-f92df00215ae id: 4ac86141-43b0-49f8-ab41-9eb9ec068a4e starting: 34 ending: 32767 Name: Microsoft reserved partition
    
    Not Basic Data Partition
    ===============================
    
    Part: 1 Type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 id: f90626a5-ead1-4c2b-8617-d78c57d33888 starting: 32768 ending: 1638432767 Name: Basic data partition
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      eb 76 90 45 58 46 41 54 20 20 20 00 00 00 00 00   .v.EXFAT   .....
    0010      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0020      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0030      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0040      00 80 00 00 00 00 00 00 00 00 a8 61 00 00 00 00   ...........a....
    0050      00 08 00 00 00 62 00 00 00 70 00 00 c8 d3 30 00   .....b...p....0.
    0060      05 00 00 00 72 8e 2a 4c 00 01 00 00 09 09 01 80   ....r.*L........
    0070      00 00 00 00 00 00 00 00 33 c9 8e d1 8e c1 8e d9   ........3.......
    0080      bc d0 7b bd 00 7c 88 16 6f 7c b4 41 bb aa 55 cd   ..{..|..o|.A..U.
    0090      13 72 69 81 fb 55 aa 75 63 f6 c1 01 74 5e fe 06   .ri..U.uc...t^..
    00a0      02 7c 66 50 b0 65 e8 a6 00 66 58 66 b8 01 00 00   .|fP.e...fXf....
    00b0      00 8a 0e 6d 7c 66 d3 e0 66 89 46 e8 66 b8 01 00   ...m|f..f.F.f...
    00c0      00 00 8a 0e 6c 7c 66 d3 e0 66 89 46 d8 66 a1 40   ....l|f..f.F.f.@
    00d0      7c 66 40 bb 00 7e b9 01 00 66 50 e8 41 00 66 58   |f@..~...fP.A.fX
    00e0      66 40 bb 00 80 b9 01 00 e8 34 00 66 50 b0 78 e8   f@.......4.fP.x.
    00f0      5d 00 66 58 e9 09 01 a0 fc 7d eb 05 a0 fb 7d eb   ].fX.....}....}.
    0100      00 b4 7d 8b f0 ac 98 40 74 0c 48 74 0e b4 0e bb   ..}....@t.Ht....
    0110      07 00 cd 10 eb ef a0 fd 7d eb e6 cd 16 cd 19 66   ........}......f
    0120      60 66 6a 00 66 50 06 53 66 68 10 00 01 00 b4 42   `fj.fP.Sfh.....B
    0130      b2 80 8a 16 6f 7c 8b f4 cd 13 66 58 66 58 66 58   ....o|....fXfXfX
    0140      66 58 66 61 72 b1 03 5e d8 66 40 49 75 d1 c3 66   fXfar..^.f@Iu..f
    0150      60 b4 0e bb 07 00 b9 01 00 cd 10 66 61 c3 42 00   `..........fa.B.
    0160      4f 00 4f 00 54 00 4d 00 47 00 52 00 0d 0a 52 65   O.O.T.M.G.R...Re
    0170      6d 6f 76 65 20 64 69 73 6b 73 20 6f 72 20 6f 74   move disks or ot
    0180      68 65 72 20 6d 65 64 69 61 2e ff 0d 0a 44 69 73   her media....Dis
    0190      6b 20 65 72 72 6f 72 ff 0d 0a 50 72 65 73 73 20   k error...Press 
    01a0      61 6e 79 20 6b 65 79 20 74 6f 20 72 65 73 74 61   any key to resta
    01b0      72 74 0d 0a 00 00 00 00 00 00 00 00 00 00 ff ff   rt..............
    01c0      ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff   ................
    01d0      ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff   ................
    01e0      ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff   ................
    01f0      ff ff ff ff ff ff ff ff ff ff ff 6c 8b 98 55 aa   ...........l..U.
    EXFAT
    bytes per sector :512
    sectors per cluster :512
    
    ===========================================
    
    Part: 2 Type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 id: ad810d15-54f2-4849-aef8-b32047e6dd47 starting: 1638432768 ending: 1953521663 Name: Basic data partition
    Disk read Result: FR_OK
    BYTE      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    ---------------------------------------------------------
    0000      eb 76 90 45 58 46 41 54 20 20 20 00 00 00 00 00   .v.EXFAT   .....
    0010      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0020      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0030      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    0040      00 80 a8 61 00 00 00 00 00 e0 c7 12 00 00 00 00   ...a............
    0050      00 08 00 00 00 26 00 00 00 30 00 00 b0 c7 12 00   .....&...0......
    0060      05 00 00 00 fa 52 33 8c 00 01 00 00 09 08 01 80   .....R3.........
    0070      00 00 00 00 00 00 00 00 33 c9 8e d1 8e c1 8e d9   ........3.......
    0080      bc d0 7b bd 00 7c 88 16 6f 7c b4 41 bb aa 55 cd   ..{..|..o|.A..U.
    0090      13 72 69 81 fb 55 aa 75 63 f6 c1 01 74 5e fe 06   .ri..U.uc...t^..
    00a0      02 7c 66 50 b0 65 e8 a6 00 66 58 66 b8 01 00 00   .|fP.e...fXf....
    00b0      00 8a 0e 6d 7c 66 d3 e0 66 89 46 e8 66 b8 01 00   ...m|f..f.F.f...
    00c0      00 00 8a 0e 6c 7c 66 d3 e0 66 89 46 d8 66 a1 40   ....l|f..f.F.f.@
    00d0      7c 66 40 bb 00 7e b9 01 00 66 50 e8 41 00 66 58   |f@..~...fP.A.fX
    00e0      66 40 bb 00 80 b9 01 00 e8 34 00 66 50 b0 78 e8   f@.......4.fP.x.
    00f0      5d 00 66 58 e9 09 01 a0 fc 7d eb 05 a0 fb 7d eb   ].fX.....}....}.
    0100      00 b4 7d 8b f0 ac 98 40 74 0c 48 74 0e b4 0e bb   ..}....@t.Ht....
    0110      07 00 cd 10 eb ef a0 fd 7d eb e6 cd 16 cd 19 66   ........}......f
    0120      60 66 6a 00 66 50 06 53 66 68 10 00 01 00 b4 42   `fj.fP.Sfh.....B
    0130      b2 80 8a 16 6f 7c 8b f4 cd 13 66 58 66 58 66 58   ....o|....fXfXfX
    0140      66 58 66 61 72 b1 03 5e d8 66 40 49 75 d1 c3 66   fXfar..^.f@Iu..f
    0150      60 b4 0e bb 07 00 b9 01 00 cd 10 66 61 c3 42 00   `..........fa.B.
    0160      4f 00 4f 00 54 00 4d 00 47 00 52 00 0d 0a 52 65   O.O.T.M.G.R...Re
    0170      6d 6f 76 65 20 64 69 73 6b 73 20 6f 72 20 6f 74   move disks or ot
    0180      68 65 72 20 6d 65 64 69 61 2e ff 0d 0a 44 69 73   her media....Dis
    0190      6b 20 65 72 72 6f 72 ff 0d 0a 50 72 65 73 73 20   k error...Press 
    01a0      61 6e 79 20 6b 65 79 20 74 6f 20 72 65 73 74 61   any key to resta
    01b0      72 74 0d 0a 00 00 00 00 00 00 00 00 00 00 ff ff   rt..............
    01c0      ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff   ................
    01d0      ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff   ................
    01e0      ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff   ................
    01f0      ff ff ff ff ff ff ff ff ff ff ff 6c 8b 98 55 aa   ...........l..U.
    EXFAT
    bytes per sector :512
    sectors per cluster :256
    
    ===========================================

  17. #267
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    @mjs513 - Yep having fun hacking...

    Also looking through the uSDFS code to see how hard to implement...

    Most of the changes can be handled in: ff.c find_volume

    In the code at about 3272-3284...
    It calls off to check_fs which is the one that looks at the first sector of the partition and sees if it is fat, exfat...

    Will see how hard it will be to detect the GPT after the first check_fs, then change that loop that fills in the br array, to get the offsets
    from the sector 2... For now probably be sufficient to only look at first page of these, even though could have up to 128...

    After the br array is setup, it might just work...

  18. #268
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,681
    @KurtE

    Just took a quick well maybe not a quick look , looks like it might work. Agree don't need to do all 128.

  19. #269
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,250
    Good evening @KurtE, @mjs513, @defragster and ...
    Quote Originally Posted by KurtE View Post
    As mentioned Hacking is fun!
    Agree, but have to take me a little bit back, to deliver for day job commitments (less fun, but nevertheless important)

    concerning this thread, if handling of GPT could be added uSDFS, that would be great.

  20. #270
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,032
    @KurtE - @wwatson - @WMXZ - @mjs513 - @....

    @wwatson - welcome back and to having a T$ to test with! - hopefully your crash didn't lose you anything but time.

    Just scanned prior messages - gotta go solder my lone spare POGO pin to finish another test I started - being able to manage/select multiple MBR parts would be nice - but 4 seems enough? These large drives are so cheap. GPT doesn't allow any new OS format type support - just to reach onto same partitions on a drive that is GPT ordered and extended? For me I'd expect tp zap any drive I got to use MBR.

  21. #271
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    Good Afternoon ....

    I just pushed up a new fork/branch: https://github.com/KurtE/uSDFS/tree/Support_gpt

    Which appeared to work on the GPT disk I tried it on... Only works currently on the first partition as second is NTFS...

    Also has some debug stuff printing out...

    But here is a run of the logging program...

    Code:
    Test logger_RawWrite
    2019-05-26 12:27:48
    BUFFSIZE :8192
    Dev Type :2
    Using uSDFS
    uSDFS_VER:15_MAY_19_08_16
    ## f_mount path=2:/ vol=2
    ## mscInit before msgGetMaxLun: 1
    ## mscInit after msgGetMaxLun: 1
    ## mscInit after msDeviceInquiry LUN(0): Device Type: 0 result:0
    ## mscInit after msReadDeviceCapacity: 0
    ## check_GPT_disk - Maybe
    ## After read sector 1
    ## Looks like valid GPT table lets get indexes...
    ## Found Basic User Partition: 1 (0) starting at 32768
    ## Found Basic User Partition: 2 (1) starting at 488404992
    File System FS_EXFAT
    Free Disk Size -1 clusters
    Cluster Size 256 sectors
    Sector Size 512 bytes
    
    Change drive
    A_00001.dat
    stat FR_OK 0
     opened FR_OK 0
    
    ................................................................
    .................................... (4008992 - 8.173626 MB/s)
     (open: 16020 us; close: 8979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1014, Reads: 9, 9 1, Writes:1003 64003 63
    A_00002.dat
    stat FR_OK 9
     opened FR_OK 0
    
    ................................................................
    .................................... (4017992 - 8.155317 MB/s)
     (open: 5986 us; close: 17979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1005, Reads: 2, 2 1, Writes:1003 64003 63
    A_00003.dat
    stat FR_OK 103
     opened FR_OK 0
    
    ................................................................
    .................................... (4018992 - 8.153288 MB/s)
     (open: 5987 us; close: 18979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1005, Reads: 2, 2 1, Writes:1003 64003 63
    A_00004.dat
    stat FR_OK 1fd
     opened FR_OK 0
    
    ................................................................
    .................................... (4017992 - 8.155317 MB/s)
     (open: 14987 us; close: 17979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1008, Reads: 5, 5 1, Writes:1003 64003 63
    A_00005.dat
    stat FR_OK 2f7
     opened FR_OK 0
    
    ................................................................
    .................................... (4014992 - 8.161411 MB/s)
     (open: 17987 us; close: 14979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1009, Reads: 6, 6 1, Writes:1003 64003 63
    A_00006.dat
    stat FR_OK 3f1
     opened FR_OK 0
    
    ................................................................
    .................................... (4013992 - 8.163445 MB/s)
     (open: 17987 us; close: 13979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1009, Reads: 6, 6 1, Writes:1003 64003 63
    A_00007.dat
    stat FR_OK 4eb
     opened FR_OK 0
    
    ................................................................
    .................................... (4014992 - 8.161411 MB/s)
     (open: 17987 us; close: 14979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1009, Reads: 6, 6 1, Writes:1003 64003 63
    A_00008.dat
    stat FR_OK 5e5
     opened FR_OK 0
    
    ................................................................
    .................................... (4014992 - 8.161411 MB/s)
     (open: 17987 us; close: 14979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1009, Reads: 6, 6 1, Writes:1003 64003 63
    A_00009.dat
    stat FR_OK 6df
     opened FR_OK 0
    
    ................................................................
    .................................... (4024992 - 8.141134 MB/s)
     (open: 32987 us; close: 24979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1018, Reads: 13, 13 1, Writes:1005 64005 63
    A_00010.dat
    stat FR_OK 7d9
     opened FR_OK 0
    
    ................................................................
    .................................... (4017992 - 8.155317 MB/s)
     (open: 23985 us; close: 17979 us; write: min,max: 3977 3991 us)
    
    MSC Call data: Cmds: 1011, Reads: 8, 8 1, Writes:1003 64003 63
    ## f_mount path=2:/ vol=2
    unmount FR_OK
    And I plugged the disk into PC and the new files exist...

    Others might try and see if it works for disk 3... Which in my version of the logger which was also checked in here is defined to talk to the 2nd partition... Which fails on my disk as 2nd one defined as NTFS.

  22. #272
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,681
    Hi All
    You know me - just can't resist trying things out. I have two partitions both exFAT that show up as Disks H: and I: on my windows machine. I made a change to vol2part if defines:
    Code:
    #define TEST_DRV 3
    //
    #if TEST_DRV == 0
      const char *Dev = "0:/";  // SPI
    #elif TEST_DRV == 1
      const char *Dev = "1:/";  // SDHC
    #elif TEST_DRV == 2
      const char *Dev = "2:/";  // USB
    #elif TEST_DRV == 3
      const char *Dev = "3:/";  // USB 2nd partition
    #elif TEST_DRV == 4
      const char *Dev = "4:/";  // USB 3rd partition
    #endif
    PARTITION VolToPart[] = {{0,0}, {1,0}, {2,0}, {2,1}, {2,2}};  /* Volume - Partition resolution table */
    Where TEST_DRV=3 is my H-Drive and TEST_DRV=4 is the I-Drive. After the running the logger sketch (Not the FS one) and checking the drive on the PC the files are written and show up on both drives (partitions )

    So bottom line, Kurt, looks like it works. Nice job.

  23. #273
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,250
    Quote Originally Posted by KurtE View Post
    Good Afternoon ....

    I just pushed up a new fork/branch: https://github.com/KurtE/uSDFS/tree/Support_gpt

    Which appeared to work on the GPT disk I tried it on... Only works currently on the first partition as second is NTFS...

    Also has some debug stuff printing out...

    But here is a run of the logging program...
    That is really great.
    please make a PR if you are happy with testing.
    Walter

  24. #274
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,052
    Hi @WMXZ - Issued a PR: https://github.com/WMXZ-EU/uSDFS/pull/7

    You might want to check it out and see if I screwed up anything obvious...

    I also now tried it where I redid the 2 partition disk on Ubuntu 18.04 using gparted and had it format as Fat32... And test app still worked.

  25. #275
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,250
    Quote Originally Posted by KurtE View Post
    Merged, pushed version to 1.1.1 and will update readme

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •