static void testit(const char *ser_fn_base) { char *ser_fn = test_filename(ser_fn_base); void *data = NULL; size_t data_len = 0; bool rc = bu_read_file(ser_fn, &data, &data_len, 10*1000*1000); assert(rc == true); struct const_buffer buf = { data, data_len }; struct mbuf_reader mbr; mbr_init(&mbr, &buf); rc = mbr_read(&mbr); assert(rc == true); assert(mbr.eof == false); assert(mbr.error == false); assert(!strncmp(mbr.msg.hdr.command, "block", 12)); rc = mbr_read(&mbr); assert(rc == false); assert(mbr.eof == true); assert(mbr.error == false); mbr_free(&mbr); free(data); free(ser_fn); }
int hdd_init(void) { if (ata_init()) return 1; if (mbr_init()) return 1; return 0; }
/*----------------------------------------------------------------------------*/ int diskio_detect_devices() { struct mbr mbr; int dev_num = 0; int i = 0, index = 0; memset(devices, 0, DISKIO_MAX_DEVICES * sizeof (struct diskio_device_info)); #ifdef FLASH_INIT if (FLASH_INIT() == 0) { devices[index].type = DISKIO_DEVICE_TYPE_GENERIC_FLASH; devices[index].number = dev_num; /* This Flash has 4096 Pages */ devices[index].num_sectors = 4096; /* A Page is 528 Bytes long, but for easier acces we use only 512 Byte*/ devices[index].sector_size = 512; devices[index].first_sector = 0; index += 1; } #endif #ifdef SD_INIT if (SD_INIT() == 0) { devices[index].type = DISKIO_DEVICE_TYPE_SD_CARD; devices[index].number = dev_num; devices[index].num_sectors = microSD_get_block_num(); devices[index].sector_size = microSD_get_block_size(); devices[index].first_sector = 0; if (devices[index].sector_size > DISKIO_MAX_SECTOR_SIZE) { goto end_of_function; } mbr_init(&mbr); mbr_read(&devices[index], &mbr); index += 1; for (i = 0; i < 4; ++i) { if (mbr_hasPartition(&mbr, i + 1) != 0) { devices[index].type = DISKIO_DEVICE_TYPE_SD_CARD | DISKIO_DEVICE_TYPE_PARTITION; devices[index].number = dev_num; devices[index].partition = i + 1; devices[index].num_sectors = mbr.partition[i].lba_num_sectors; devices[index].sector_size = devices[dev_num].sector_size; devices[index].first_sector = mbr.partition[i].lba_first_sector; index += 1; } } dev_num += 1; index += 1; } #endif end_of_function: if (index == 0) { return DISKIO_FAILURE; } return DISKIO_SUCCESS; }
/*----------------------------------------------------------------------------*/ int diskio_detect_devices() { struct mbr mbr; int dev_num = 0; int i = 0, index = 0; memset(devices, 0, DISKIO_MAX_DEVICES * sizeof (struct diskio_device_info)); /** @todo Place definitions at proper position */ #ifndef FLASH_ARCH_NUM_SECTORS /* This Flash has 4096 Pages */ #define FLASH_ARCH_NUM_SECTORS 4096 #endif #ifndef FLASH_ARCH_SECTOR_SIZE /* A Page is 528 Bytes long, but for easier access we use only 512 Byte*/ #define FLASH_ARCH_SECTOR_SIZE 512 #endif #ifdef FLASH_INIT if (FLASH_INIT() == 0) { devices[index].type = DISKIO_DEVICE_TYPE_GENERIC_FLASH; devices[index].number = dev_num; devices[index].num_sectors = FLASH_ARCH_NUM_SECTORS; devices[index].sector_size = FLASH_ARCH_SECTOR_SIZE; devices[index].first_sector = 0; index += 1; } #endif /* FLASH_INIT */ #ifdef SD_INIT if (SD_INIT() == 0) { devices[index].type = DISKIO_DEVICE_TYPE_SD_CARD; devices[index].number = dev_num; devices[index].num_sectors = SD_GET_BLOCK_NUM(); devices[index].sector_size = SD_GET_BLOCK_SIZE(); devices[index].first_sector = 0; if (devices[index].sector_size > DISKIO_MAX_SECTOR_SIZE) { goto end_of_function; } mbr_init(&mbr); mbr_read(&devices[index], &mbr); index += 1; // test for max 5 partitions for (i = 0; i < 4; ++i) { if (mbr_hasPartition(&mbr, i + 1) != 0) { devices[index].type = DISKIO_DEVICE_TYPE_SD_CARD | DISKIO_DEVICE_TYPE_PARTITION; devices[index].number = dev_num; devices[index].partition = i + 1; devices[index].num_sectors = mbr.partition[i].lba_num_sectors; devices[index].sector_size = devices[dev_num].sector_size; devices[index].first_sector = mbr.partition[i].lba_first_sector; index += 1; } } dev_num += 1; index += 1; } #endif /* SD_INIT */ end_of_function: if (index == 0) { return DISKIO_FAILURE; } return DISKIO_SUCCESS; }