static imgtoolerr_t process_bml3_file(struct bml3_dirent *ent, imgtool_image *img, imgtool_stream *destf, size_t *size) { imgtoolerr_t err; size_t remaining_size, granule_size; bml3_diskinfo *info = bml3_get_diskinfo(img); struct granule_list_t granule_list; granule_list.granule_count = 0; err = list_granules(ent, img, &granule_list); if (err) return err; err = get_file_size(ent, img, &granule_list, size); if (err) return err; if (destf) { remaining_size = *size; granule_size = info->granule_sectors * info->sector_size; for (int c = 0; c < granule_list.granule_count; c++) { if (granule_size >= remaining_size) granule_size = remaining_size; transfer_from_granule(img, granule_list.granules[c], granule_size, destf); remaining_size -= granule_size; } } return IMGTOOLERR_SUCCESS; }
static imgtoolerr_t process_rsdos_file(struct rsdos_dirent *ent, imgtool_image *img, imgtool_stream *destf, size_t *size) { floperr_t ferr; size_t s, lastgransize; UINT8 granule_count; unsigned char i = 0, granule; UINT8 usedmap[MAX_GRANULEMAP_SIZE]; /* Used to detect infinite loops */ UINT8 granule_map[MAX_GRANULEMAP_SIZE]; ferr = get_granule_map(img, granule_map, &granule_count); if (ferr) return imgtool_floppy_error(ferr); memset(usedmap, 0, granule_count); lastgransize = ent->lastsectorbytes_lsb + (((int) ent->lastsectorbytes_msb) << 8); s = 0; granule = ent->first_granule; while(!usedmap[granule] && ((i = granule_map[granule]) < granule_count)) { usedmap[granule] = 1; if (destf) transfer_from_granule(img, granule, 9*256, destf); /* i is the next granule */ s += (256 * 9); granule = i; } if ((i < 0xc0) || (i > 0xc9)) return IMGTOOLERR_CORRUPTIMAGE; if (lastgransize) i--; lastgransize += (256 * (i - 0xc0)); if (destf) transfer_from_granule(img, granule, lastgransize, destf); if (size) *size = s + lastgransize; return IMGTOOLERR_SUCCESS; }