Beispiel #1
0
static void
boot_sector_init( Bytes  boot, Bytes  info, Wide   disk_size, const char*  label )
{
    int   sectors_per_cluster = get_sectors_per_cluster(disk_size);
    int   sectors_per_fat    = get_sectors_per_fat(disk_size, sectors_per_cluster);
    int   sectors_per_disk   = (int)(disk_size / BYTES_PER_SECTOR);
    int   serial_id          = get_serial_id();
    int   free_count;

    if (label == NULL)
        label = "SDCARD";

    POKEB(boot, 0xeb);
    POKEB(boot+1, 0x5a);
    POKEB(boot+2, 0x90);
    strcpy( (char*)boot + 3, "MSWIN4.1" );
    POKES( boot + 0x0b, BYTES_PER_SECTOR );    /* sector size */
    POKEB( boot + 0xd, sectors_per_cluster );  /* sectors per cluster */
    POKES( boot + 0xe, RESERVED_SECTORS );     /* reserved sectors before first FAT */
    POKEB( boot + 0x10, NUM_FATS );            /* number of FATs */
    POKES( boot + 0x11, 0 );                   /* max root directory entries for FAT12/FAT16, 0 for FAT32 */
    POKES( boot + 0x13, 0 );                   /* total sectors, 0 to use 32-bit value at offset 0x20 */
    POKEB( boot + 0x15, 0xF8 );                /* media descriptor, 0xF8 == hard disk */
    POKES( boot + 0x16, 0 );                   /* Sectors per FAT for FAT12/16, 0 for FAT32 */
    POKES( boot + 0x18, 9 );                   /* Sectors per track (whatever) */
    POKES( boot + 0x1a, 2 );                   /* Number of heads (whatever) */
    POKEW( boot + 0x1c, 0 );                   /* Hidden sectors */
    POKEW( boot + 0x20, sectors_per_disk );    /* Total sectors */

    /* extension */
    POKEW( boot + 0x24, sectors_per_fat );       /* Sectors per FAT */
    POKES( boot + 0x28, 0 );         /* FAT flags */
    POKES( boot + 0x2a, 0 );         /* version */
    POKEW( boot + 0x2c, 2 );         /* cluster number of root directory start */
    POKES( boot + 0x30, 1 );         /* sector number of FS information sector */
    POKES( boot + 0x32, BACKUP_BOOT_SECTOR );         /* sector number of a copy of this boot sector */
    POKEB( boot + 0x40, 0x80 );      /* physical drive number */
    POKEB( boot + 0x42, 0x29 );      /* extended boot signature ?? */
    POKEW( boot + 0x43, serial_id ); /* serial ID */
    strncpy( (char*)boot + 0x47, label, 11 );  /* Volume Label */
    memcpy( boot + 0x52, "FAT32   ", 8 );  /* FAT system type, padded with 0x20 */

    POKEB( boot + BYTES_PER_SECTOR-2, 0x55 );    /* boot sector signature */
    POKEB( boot + BYTES_PER_SECTOR-1, 0xAA );

    /* FSInfo sector */
    free_count = sectors_per_disk - 32 - 2*sectors_per_fat;

    POKEW( info + 0,   0x41615252 );
    POKEW( info + 484, 0x61417272 );
    POKEW( info + 488, free_count );   /* number of free clusters */
    POKEW( info + 492, 3 );            /* next free clusters, 0-1 reserved, 2 is used for the root dir */
    POKEW( info + 508, 0xAA550000 );
}
Beispiel #2
0
 /**
  * @param [out] serial_id serial number of ftdi device
  * @return 0 on success<br>-1 on failure
  * @sa get_serial_id(unsigned int, std::string&), get_serial_id(std::string&)
  * , get_manufacturer(unsigned int, std::string&), get_manufacturer(std::string&)
  * , get_product(unsigned int, std::string&), get_product(std::string&)
  **/
 int get_serial_id(std::string &serial_id) { return get_serial_id(0, serial_id); }