void pred_read_2013(FILE *fd, pred *pred) { uint64_t k = read_uint64(fd); assert(k == K); pred->arity = read_uint64(fd); pred->data = read_uint64(fd); }
bool LZOCompressedReaderAdapter::fill_buffer() { size_t buffer_size; if (read_uint64(m_file, buffer_size) == 0) return false; ensure_minimum_size(m_buffer, buffer_size); lzo_uint compressed_buffer_size; read_uint64(m_file, compressed_buffer_size); ensure_minimum_size(m_compressed_buffer, compressed_buffer_size); m_file.read(&m_compressed_buffer[0], compressed_buffer_size); lzo_uint new_buffer_end; lzo1x_decompress( &m_compressed_buffer[0], compressed_buffer_size, &m_buffer[0], &new_buffer_end, &m_working_memory[0]); m_buffer_index = 0; m_buffer_end = static_cast<size_t>(new_buffer_end); return true; }
void read_trailer(unsigned char* data, int length, int* offsetSize, int* objectRefSize, uint64_t* numObjects, uint64_t* topObject, uint64_t* offsetTableOffset) { unsigned char* trailer = &data[length-32]; *offsetSize = trailer[6]; *objectRefSize = trailer[7]; *numObjects = read_uint64(&trailer[8]); *topObject = read_uint64(&trailer[16]); *offsetTableOffset = read_uint64(&trailer[24]); }
static uint64_t SPICE_GNUC_UNUSED consume_uint64(uint8_t **ptr) { uint64_t val; val = read_uint64(*ptr); *ptr += 8; return val; }
// shows the use of the pipeHandler. int main(int argc, char* argv[]) { // must be initialized before doing anything init_pipe_handler(); // register a FIFO pipe test_pipe with // depth 32, word-width 32. register_pipe("test_pipe",32,32,0); register_pipe("test_pipe_64",1,64,0); // write a integer to test_pipe. write_uint32("test_pipe",1); uint64_t tmp = 1; tmp = tmp | (tmp << 32); write_uint64("test_pipe_64",tmp); // read back and print integer. uint32_t v = read_uint32("test_pipe"); fprintf(stderr,"TEST: received uint32_t %d\n", v); uint64_t v64 = read_uint64("test_pipe_64"); fprintf(stderr,"TEST: received uint64_t %llu\n", v64); // write another integer write_uint32("test_pipe",1); // read back and print integer. v = read_uint32("test_pipe"); fprintf(stderr,"TEST: received %d\n", v); // close the handler. close_pipe_handler(); return(0); }
/** * Reads a variable length integer. */ std::uint64_t read_var_int() { std::uint64_t ret = 0; std::uint8_t size = read_uint8(); if (size < 253) { ret = size; } else if (size == 253) { ret = read_uint16(); } else if (size == 254) { ret = read_uint32(); } else if (size == 255) { ret = read_uint64(); } else { assert(0); } return ret; }
// burst read/write.. void read_uint64_n(const char *id, uint64_t* buf, int buf_len) { int i; for(i = 0; i < buf_len; i++) { buf[i] = read_uint64((char*) id); } }
struct log_entry_t *read_log_entry(const char *filename) { int fd = open(filename, O_RDONLY); if(fd == -1) { return NULL; } uint64_t term; uint64_t index; uint64_t req_id; uint32_t bufsize; if(!read_uint64(fd, &term) || !read_uint64(fd, &index) || !read_uint64(fd, &req_id) || !read_uint32(fd, &bufsize)) { close(fd); return NULL; } int i = 0; unsigned char *buffer = (unsigned char *)malloc(bufsize); while(i < bufsize) { int nread = read(fd, buffer + i, bufsize - i); if(nread == -1) { close(fd); free(buffer); return NULL; } i += nread; } close(fd); struct log_entry_t *le = (struct log_entry_t *)malloc( sizeof(struct log_entry_t)); if(le) { le->term = term; le->index = index; le->req_id = req_id; le->bufsize = bufsize; le->buffer = buffer; return le; } free(buffer); return NULL; }
void Squeezer_chunk_header_t::read_from_file(FILE * in) { chunk_mark[0] = read_uint8(in); chunk_mark[1] = read_uint8(in); chunk_mark[2] = read_uint8(in); chunk_mark[3] = read_uint8(in); number_of_bytes = read_uint64(in); number_of_samples = read_uint32(in); chunk_type = read_uint32(in); compression_error.read_from_file(in); }
bool LZ4CompressedReaderAdapter::fill_buffer() { size_t buffer_size; if (read_uint64(m_file, buffer_size) == 0) return false; ensure_minimum_size(m_buffer, buffer_size); size_t compressed_buffer_size; read_uint64(m_file, compressed_buffer_size); ensure_minimum_size(m_compressed_buffer, compressed_buffer_size); m_file.read(&m_compressed_buffer[0], compressed_buffer_size); LZ4_decompress_fast( reinterpret_cast<const char*>(&m_compressed_buffer[0]), reinterpret_cast<char*>(&m_buffer[0]), static_cast<int>(buffer_size)); m_buffer_index = 0; m_buffer_end = buffer_size; return true; }
static void load_state(struct server_context_t *s) { DBG_LOG(LOG_INFO, "[%s][%d] Loading state from disk", ss[s->state], s->current_term); char *raftstate = path_join(s->basedir, RAFT_STATE); if(raftstate) { int fd = open(raftstate, O_RDONLY); if(fd == -1) { return; } if(!read_uint64(fd, &s->current_term) || !read_uint32(fd, (uint32_t *)&s->current_leader)) { DBG_LOG(LOG_FATAL, "error in reading state from file"); exit(1); } close(fd); free(raftstate); } }
/** * Reads a network address. * @param prefix_timestamp If false the timestamp will be omitted. */ protocol::network_address_t read_network_address( const bool & prefix_version, const bool & prefix_timestamp ) { protocol::network_address_t ret; if (prefix_version) { /** * Read the version. */ ret.version = read_uint32(); } if (prefix_timestamp) { /** * Read the timestamp. */ ret.timestamp = read_uint32(); } /** * Read the services. */ ret.services = read_uint64(); /** * Read the address. */ read_bytes( reinterpret_cast<char *>(&ret.address[0]), ret.address.size() ); /** * Read the port. */ ret.port = ntohs(read_uint16()); return ret; }
void Receiver() { int count = 0; FILE* fout = fopen("characterized_data.txt", "w"); while(1) { count++; int64_t best_sigma_index = read_uint64("bsi_output_pipe"); double p0 = read_float64("dotP_output_pipe"); double p1 = read_float64("dotP_output_pipe"); double p2 = read_float64("dotP_output_pipe"); double p3 = read_float64("dotP_output_pipe"); double p4 = read_float64("dotP_output_pipe"); double p5 = read_float64("dotP_output_pipe"); fprintf(fout, " Best sigma= %f, (index = %"PRId64").\n", (MIN_SIGMA + (((float)(best_sigma_index))*(MAX_SIGMA - MIN_SIGMA)/NSIGMAS)), best_sigma_index); fprintf(fout, "best fit coeffs are = %le,%le,%le,%le,%le,%le\n\n\n", p0, p1, p2, p3, p4, p5); printf("characterized %d number of beats\n", count); } fclose(fout); }
static enum dlep_status_code parse_session_init_resp_message(const uint8_t* data_items, uint16_t len, uint32_t* heartbeat_interval, enum dlep_status_code* sc) { const uint8_t* data_item = data_items; printf("Valid Session Initialization Response message from modem:\n"); /* The message has been validated so just scan for the relevant data_items */ while (data_item < data_items + len) { /* Octets 0 and 1 are the data item type */ enum dlep_data_item item_id = read_uint16(data_item); /* Octets 2 and 3 are the data item length */ uint16_t item_len = read_uint16(data_item + 2); /* Increment data_item to point to the data */ data_item += 4; switch (item_id) { case DLEP_HEARTBEAT_INTERVAL_DATA_ITEM: *heartbeat_interval = read_uint32(data_item); printf(" Heartbeat Interval: %ums\n",*heartbeat_interval); break; case DLEP_PEER_TYPE_DATA_ITEM: printf(" Peer Type: '%.*s'%s\n",(int)item_len-1,data_item + 1,data_item[0] ? " - Secured Medium" : ""); break; case DLEP_STATUS_DATA_ITEM: *sc = data_item[0]; printf_status(*sc); break; case DLEP_MDRR_DATA_ITEM: printf(" Default MDDR: %"PRIu64"bps\n",read_uint64(data_item)); break; case DLEP_MDRT_DATA_ITEM: printf(" Default MDDT: %"PRIu64"bps\n",read_uint64(data_item)); break; case DLEP_CDRR_DATA_ITEM: printf(" Default CDDR: %"PRIu64"bps\n",read_uint64(data_item)); break; case DLEP_CDRT_DATA_ITEM: printf(" Default CDDT: %"PRIu64"bps\n",read_uint64(data_item)); break; case DLEP_LATENCY_DATA_ITEM: printf(" Default Latency: %"PRIu64"\x03\xBCs\n",read_uint64(data_item)); break; case DLEP_RESOURCES_DATA_ITEM: printf(" Default Resources: %u%%\n",data_item[0]); break; case DLEP_RLQR_DATA_ITEM: printf(" Default RLQR: %u\n",data_item[0]); break; case DLEP_RLQT_DATA_ITEM: printf(" Default RLQT: %u\n",data_item[0]); break; case DLEP_MTU_DATA_ITEM: printf(" Default MTU: %"PRIu32"\n",read_uint32(data_item)); break; case DLEP_EXTS_SUPP_DATA_ITEM: if (item_len > 0) { size_t i = 0; printf(" Extensions advertised by peer:\n"); for (; i < item_len; i += 2) { printf(" Unknown DLEP extension %u (which we don't support)\n",read_uint16(data_item + i)); } } break; case DLEP_IPV4_ADDRESS_DATA_ITEM: case DLEP_IPV6_ADDRESS_DATA_ITEM: printf(" Modem "); parse_address(data_item,item_len,0); break; case DLEP_IPV4_ATT_SUBNET_DATA_ITEM: case DLEP_IPV6_ATT_SUBNET_DATA_ITEM: printf(" Modem "); parse_attached_subnet(data_item,item_len,0); break; default: /* Others will be caught by the check function */ break; } /* Increment data_item to point to the next data item */ data_item += item_len; } return DLEP_SC_SUCCESS; }
void *read_pipe_(void *args) { int i = 0, j = 0, len = 0; uint8_t *buf = (uint8_t *)(((FnArgs *)args)->buf); ioq_t ioq; ioq.v = 0; word_t w; w.v = 0; while (1) { // Read data and ctrl from wrapper_output. uint8_t inctrl = read_uint8("out_ctrl"); uint64_t indata = read_uint64("out_data"); uint16_t word_count; switch (inctrl) { case 0xff: word_count = 0; ioq.v = indata; printf("Read the IOQ:\n"); printf("srcp: %04x\n", ntohs(ioq.f.srcp)); printf("wlen: %04x\n", ntohs(ioq.f.wlen)); printf("dstp: %04x\n", ntohs(ioq.f.dstp)); printf("blen: %04x\n", ntohs(ioq.f.blen)); break; case 0x00: printf("Read a data word (%d): %llx \n", word_count, indata); word_count++; w.v = indata; for (j = 0; j < 8; ++j) buf[i * 8 + j] = w.s.b[j]; i++; break; case 0x01: // Last word, 8 bytes case 0x02: // Last word, 7 bytes case 0x04: // Last word, 6 bytes case 0x08: // Last word, 5 bytes case 0x10: // Last word, 4 bytes case 0x20: // Last word, 3 bytes case 0x40: // Last word, 2 bytes case 0x80: // Last word, 1 byte printf("Read the last data word (%d): %llx.\n", word_count,indata); w.v = indata; for (j = 0; j < 8; ++j) buf[i * 8 + j] = w.s.b[j]; i++; goto done; break; default: printf("Unknown control bus signal.\n"); break; } if(word_count == 255) { printf("whoops! read 256 words, end-of-packet not seen.\n"); goto done; } } done: printf("Read %d bytes from netfpga wrapper:", ntohs(ioq.f.blen)); for (i = 0; i < ntohs(ioq.f.blen); i++) { if (i % 8 == 0) printf("\n"); printf("%02x ", buf[i]); } printf("\n"); }
void *read_pipe_2_(void* a) { *((uint64_t*)a) = read_uint64("dest2_pipe"); }
value read_value(unsigned char *p) { return (value)read_uint64(p); }
((char *)&u)[7-i] = c[i]; } return u; } void pred_read_2013(FILE *fd, pred *pred) { uint64_t k = read_uint64(fd); assert(k == K); pred->arity = read_uint64(fd); pred->data = read_uint64(fd); } int majclass_read_2013(FILE *fd, majclass *class) { /* the size of the basis */ uint64_t size = read_uint64(fd); for(int64_t i = size; i > 0; --i) { pred pred; pred_read_2013(fd, &pred); clone_insert_pred(&class->basis, &pred); } clone_read(fd, &class->clone); class->num_subclasses = -1; class->subclasses = NULL; return 1; }
static int dmg_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVDMGState *s = bs->opaque; DmgHeaderState ds; uint64_t rsrc_fork_offset, rsrc_fork_length; uint64_t plist_xml_offset, plist_xml_length; int64_t offset; int ret; block_module_load_one("dmg-bz2"); bs->read_only = true; s->n_chunks = 0; s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; /* used by dmg_read_mish_block to keep track of the current I/O position */ ds.data_fork_offset = 0; ds.max_compressed_size = 1; ds.max_sectors_per_chunk = 1; /* locate the UDIF trailer */ offset = dmg_find_koly_offset(bs->file, errp); if (offset < 0) { ret = offset; goto fail; } /* offset of data fork (DataForkOffset) */ ret = read_uint64(bs, offset + 0x18, &ds.data_fork_offset); if (ret < 0) { goto fail; } else if (ds.data_fork_offset > offset) { ret = -EINVAL; goto fail; } /* offset of resource fork (RsrcForkOffset) */ ret = read_uint64(bs, offset + 0x28, &rsrc_fork_offset); if (ret < 0) { goto fail; } ret = read_uint64(bs, offset + 0x30, &rsrc_fork_length); if (ret < 0) { goto fail; } if (rsrc_fork_offset >= offset || rsrc_fork_length > offset - rsrc_fork_offset) { ret = -EINVAL; goto fail; } /* offset of property list (XMLOffset) */ ret = read_uint64(bs, offset + 0xd8, &plist_xml_offset); if (ret < 0) { goto fail; } ret = read_uint64(bs, offset + 0xe0, &plist_xml_length); if (ret < 0) { goto fail; } if (plist_xml_offset >= offset || plist_xml_length > offset - plist_xml_offset) { ret = -EINVAL; goto fail; } ret = read_uint64(bs, offset + 0x1ec, (uint64_t *)&bs->total_sectors); if (ret < 0) { goto fail; } if (bs->total_sectors < 0) { ret = -EINVAL; goto fail; } if (rsrc_fork_length != 0) { ret = dmg_read_resource_fork(bs, &ds, rsrc_fork_offset, rsrc_fork_length); if (ret < 0) { goto fail; } } else if (plist_xml_length != 0) { ret = dmg_read_plist_xml(bs, &ds, plist_xml_offset, plist_xml_length); if (ret < 0) { goto fail; } } else { ret = -EINVAL; goto fail; } /* initialize zlib engine */ s->compressed_chunk = qemu_try_blockalign(bs->file->bs, ds.max_compressed_size + 1); s->uncompressed_chunk = qemu_try_blockalign(bs->file->bs, 512 * ds.max_sectors_per_chunk); if (s->compressed_chunk == NULL || s->uncompressed_chunk == NULL) { ret = -ENOMEM; goto fail; } if (inflateInit(&s->zstream) != Z_OK) { ret = -EINVAL; goto fail; } s->current_chunk = s->n_chunks; qemu_co_mutex_init(&s->lock); return 0; fail: g_free(s->types); g_free(s->offsets); g_free(s->lengths); g_free(s->sectors); g_free(s->sectorcounts); qemu_vfree(s->compressed_chunk); qemu_vfree(s->uncompressed_chunk); return ret; }
static int reader_uint64(lua_State* L) { reader_t* reader = lua_touserdata(L, 1); lua_pushinteger(L, (lua_Integer)read_uint64(reader)); return 1; }
int start(void) #endif { int i; uint32_t apl; float ong; uint64_t apl64; uint16_t apl16; uint8_t apl8; void* ptr; double ong64; for (i = 0; i < 10; ++i) { apl64 = read_uint64("apples64"); #ifdef RUN fprintf(stderr, "\n(%d.a) got a 64 bit apple: %llu..", i, apl64); #endif ong64 = (double)apl64; write_float64("oranges64", ong64); #ifdef RUN fprintf(stderr, "\nsent a (double) orange: %le.", ong64); #endif apl = read_uint32("apples32"); #ifdef RUN fprintf(stderr, "\n(%d.b) got a 32-bit apple: %d.", i, apl); #endif ong = (float)apl; write_float32("oranges32", ong); #ifdef RUN fprintf(stderr, "\nsent a (float) orange: %f.", ong); #endif apl16 = read_uint16("apples16"); #ifdef RUN fprintf(stderr, "\n(%d.c) got a 16-bit apple: %d.", i, apl16); #endif apl8 = (uint8_t)apl; write_uint8("oranges8", apl8); #ifdef RUN fprintf(stderr, "\nsent an 8-bit orange: %d.", apl8); #endif ptr = read_pointer("apples32"); #ifdef RUN fprintf(stderr, "\n(%d.d) got a pointer apple: %d.", i, (unsigned int) ptr); #endif write_pointer("oranges32", ptr); #ifdef RUN fprintf(stderr, "\nsent a pointer orange: %d.", (unsigned int) ptr); #endif } #ifdef RUN fprintf(stderr, "\n"); #endif return 0; }
static int dmg_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVDMGState *s = bs->opaque; uint64_t info_begin, info_end, last_in_offset, last_out_offset; uint32_t count, tmp; uint32_t max_compressed_size = 1, max_sectors_per_chunk = 1, i; int64_t offset; int ret; bs->read_only = 1; s->n_chunks = 0; s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; /* read offset of info blocks */ offset = bdrv_getlength(bs->file); if (offset < 0) { ret = offset; goto fail; } offset -= 0x1d8; ret = read_uint64(bs, offset, &info_begin); if (ret < 0) { goto fail; } else if (info_begin == 0) { ret = -EINVAL; goto fail; } ret = read_uint32(bs, info_begin, &tmp); if (ret < 0) { goto fail; } else if (tmp != 0x100) { ret = -EINVAL; goto fail; } ret = read_uint32(bs, info_begin + 4, &count); if (ret < 0) { goto fail; } else if (count == 0) { ret = -EINVAL; goto fail; } info_end = info_begin + count; offset = info_begin + 0x100; /* read offsets */ last_in_offset = last_out_offset = 0; while (offset < info_end) { uint32_t type; ret = read_uint32(bs, offset, &count); if (ret < 0) { goto fail; } else if (count == 0) { ret = -EINVAL; goto fail; } offset += 4; ret = read_uint32(bs, offset, &type); if (ret < 0) { goto fail; } if (type == 0x6d697368 && count >= 244) { size_t new_size; uint32_t chunk_count; offset += 4; offset += 200; chunk_count = (count - 204) / 40; new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count); s->types = g_realloc(s->types, new_size / 2); s->offsets = g_realloc(s->offsets, new_size); s->lengths = g_realloc(s->lengths, new_size); s->sectors = g_realloc(s->sectors, new_size); s->sectorcounts = g_realloc(s->sectorcounts, new_size); for (i = s->n_chunks; i < s->n_chunks + chunk_count; i++) { ret = read_uint32(bs, offset, &s->types[i]); if (ret < 0) { goto fail; } offset += 4; if (s->types[i] != 0x80000005 && s->types[i] != 1 && s->types[i] != 2) { if (s->types[i] == 0xffffffff && i > 0) { last_in_offset = s->offsets[i - 1] + s->lengths[i - 1]; last_out_offset = s->sectors[i - 1] + s->sectorcounts[i - 1]; } chunk_count--; i--; offset += 36; continue; } offset += 4; ret = read_uint64(bs, offset, &s->sectors[i]); if (ret < 0) { goto fail; } s->sectors[i] += last_out_offset; offset += 8; ret = read_uint64(bs, offset, &s->sectorcounts[i]); if (ret < 0) { goto fail; } offset += 8; if (s->sectorcounts[i] > DMG_SECTORCOUNTS_MAX) { error_report("sector count %" PRIu64 " for chunk %" PRIu32 " is larger than max (%u)", s->sectorcounts[i], i, DMG_SECTORCOUNTS_MAX); ret = -EINVAL; goto fail; } ret = read_uint64(bs, offset, &s->offsets[i]); if (ret < 0) { goto fail; } s->offsets[i] += last_in_offset; offset += 8; ret = read_uint64(bs, offset, &s->lengths[i]); if (ret < 0) { goto fail; } offset += 8; if (s->lengths[i] > DMG_LENGTHS_MAX) { error_report("length %" PRIu64 " for chunk %" PRIu32 " is larger than max (%u)", s->lengths[i], i, DMG_LENGTHS_MAX); ret = -EINVAL; goto fail; } update_max_chunk_size(s, i, &max_compressed_size, &max_sectors_per_chunk); } s->n_chunks += chunk_count; } } /* initialize zlib engine */ s->compressed_chunk = qemu_try_blockalign(bs->file, max_compressed_size + 1); s->uncompressed_chunk = qemu_try_blockalign(bs->file, 512 * max_sectors_per_chunk); if (s->compressed_chunk == NULL || s->uncompressed_chunk == NULL) { ret = -ENOMEM; goto fail; } if (inflateInit(&s->zstream) != Z_OK) { ret = -EINVAL; goto fail; } s->current_chunk = s->n_chunks; qemu_co_mutex_init(&s->lock); return 0; fail: g_free(s->types); g_free(s->offsets); g_free(s->lengths); g_free(s->sectors); g_free(s->sectorcounts); qemu_vfree(s->compressed_chunk); qemu_vfree(s->uncompressed_chunk); return ret; }
chd_error chdcd_parse_nero(const char *tocfname, cdrom_toc &outtoc, chdcd_track_input_info &outinfo) { FILE *infile; unsigned char buffer[12]; UINT32 chain_offs, chunk_size; int done = 0; astring path = astring(tocfname); infile = fopen(tocfname, "rb"); path = get_file_path(path); if (infile == (FILE *)NULL) { return CHDERR_FILE_NOT_FOUND; } /* clear structures */ memset(&outtoc, 0, sizeof(outtoc)); outinfo.reset(); // seek to 12 bytes before the end fseek(infile, -12, SEEK_END); fread(buffer, 12, 1, infile); if (memcmp(buffer, "NER5", 4)) { printf("ERROR: Not a Nero 5.5 or later image!\n"); fclose(infile); return CHDERR_UNSUPPORTED_VERSION; } chain_offs = buffer[11] | (buffer[10]<<8) | (buffer[9]<<16) | (buffer[8]<<24); if ((buffer[7] != 0) || (buffer[6] != 0) || (buffer[5] != 0) || (buffer[4] != 0)) { printf("ERROR: File size is > 4GB, this version of CHDMAN cannot handle it."); fclose(infile); return CHDERR_UNSUPPORTED_FORMAT; } // printf("NER5 detected, chain offset: %x\n", chain_offs); while (!done) { UINT32 offset; UINT8 start, end; int track; fseek(infile, chain_offs, SEEK_SET); fread(buffer, 8, 1, infile); chunk_size = (buffer[7] | buffer[6]<<8 | buffer[5]<<16 | buffer[4]<<24); // printf("Chunk type: %c%c%c%c, size %x\n", buffer[0], buffer[1], buffer[2], buffer[3], chunk_size); // we want the DAOX chunk, which has the TOC information if (!memcmp(buffer, "DAOX", 4)) { // skip second chunk size and UPC code fseek(infile, 20, SEEK_CUR); fread(&start, 1, 1, infile); fread(&end, 1, 1, infile); // printf("Start track %d End track: %d\n", start, end); outtoc.numtrks = (end-start) + 1; offset = 0; for (track = start; track <= end; track++) { UINT32 size, mode; UINT64 index0, index1, track_end; fseek(infile, 12, SEEK_CUR); // skip ISRC code size = read_uint16(infile); mode = read_uint16(infile); fseek(infile, 2, SEEK_CUR); index0 = read_uint64(infile); index1 = read_uint64(infile); track_end = read_uint64(infile); // printf("Track %d: sector size %d mode %x index0 %llx index1 %llx track_end %llx (pregap %d sectors, length %d sectors)\n", track, size, mode, index0, index1, track_end, (UINT32)(index1-index0)/size, (UINT32)(track_end-index1)/size); outinfo.track[track-1].fname.cpy(tocfname); outinfo.track[track-1].offset = offset + (UINT32)(index1-index0); outinfo.track[track-1].idx0offs = 0; outinfo.track[track-1].idx1offs = 0; switch (mode) { case 0x0000: // 2048 byte data outtoc.tracks[track-1].trktype = CD_TRACK_MODE1; outinfo.track[track-1].swap = false; break; case 0x0300: // Mode 2 Form 1 printf("ERROR: Mode 2 Form 1 tracks not supported\n"); fclose(infile); return CHDERR_UNSUPPORTED_FORMAT; case 0x0500: // raw data printf("ERROR: Raw data tracks not supported\n"); fclose(infile); return CHDERR_UNSUPPORTED_FORMAT; case 0x0600: // 2352 byte mode 2 raw outtoc.tracks[track-1].trktype = CD_TRACK_MODE2_RAW; outinfo.track[track-1].swap = false; break; case 0x0700: // 2352 byte audio outtoc.tracks[track-1].trktype = CD_TRACK_AUDIO; outinfo.track[track-1].swap = true; break; case 0x0f00: // raw data with sub-channel printf("ERROR: Raw data tracks with sub-channel not supported\n"); fclose(infile); return CHDERR_UNSUPPORTED_FORMAT; case 0x1000: // audio with sub-channel printf("ERROR: Audio tracks with sub-channel not supported\n"); fclose(infile); return CHDERR_UNSUPPORTED_FORMAT; case 0x1100: // raw Mode 2 Form 1 with sub-channel printf("ERROR: Raw Mode 2 Form 1 tracks with sub-channel not supported\n"); fclose(infile); return CHDERR_UNSUPPORTED_FORMAT; default: printf("ERROR: Unknown track type %x, contact MAMEDEV!\n", mode); fclose(infile); return CHDERR_UNSUPPORTED_FORMAT; } outtoc.tracks[track-1].datasize = size; outtoc.tracks[track-1].subtype = CD_SUB_NONE; outtoc.tracks[track-1].subsize = 0; outtoc.tracks[track-1].pregap = (UINT32)(index1-index0)/size; outtoc.tracks[track-1].frames = (UINT32)(track_end-index1)/size; outtoc.tracks[track-1].postgap = 0; outtoc.tracks[track-1].pgtype = 0; outtoc.tracks[track-1].pgsub = CD_SUB_NONE; outtoc.tracks[track-1].pgdatasize = 0; outtoc.tracks[track-1].pgsubsize = 0; outtoc.tracks[track-1].padframes = 0; offset += (UINT32)track_end-index1; } } if (!memcmp(buffer, "END!", 4)) { done = 1; } else { chain_offs += chunk_size + 8; } } fclose(infile); return CHDERR_NONE; }
void *read_pipe_(void* a) { *((uint64_t*)a) = read_uint64("foo_out"); }
static int dmg_open(BlockDriverState *bs, int flags) { BDRVDMGState *s = bs->opaque; uint64_t info_begin,info_end,last_in_offset,last_out_offset; uint32_t count, tmp; uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i; int64_t offset; int ret; bs->read_only = 1; s->n_chunks = 0; s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; /* read offset of info blocks */ offset = bdrv_getlength(bs->file); if (offset < 0) { ret = offset; goto fail; } offset -= 0x1d8; ret = read_uint64(bs, offset, &info_begin); if (ret < 0) { goto fail; } else if (info_begin == 0) { ret = -EINVAL; goto fail; } ret = read_uint32(bs, info_begin, &tmp); if (ret < 0) { goto fail; } else if (tmp != 0x100) { ret = -EINVAL; goto fail; } ret = read_uint32(bs, info_begin + 4, &count); if (ret < 0) { goto fail; } else if (count == 0) { ret = -EINVAL; goto fail; } info_end = info_begin + count; offset = info_begin + 0x100; /* read offsets */ last_in_offset = last_out_offset = 0; while (offset < info_end) { uint32_t type; ret = read_uint32(bs, offset, &count); if (ret < 0) { goto fail; } else if (count == 0) { ret = -EINVAL; goto fail; } offset += 4; ret = read_uint32(bs, offset, &type); if (ret < 0) { goto fail; } if (type == 0x6d697368 && count >= 244) { int new_size, chunk_count; offset += 4; offset += 200; chunk_count = (count-204)/40; new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count); s->types = g_realloc(s->types, new_size/2); s->offsets = g_realloc(s->offsets, new_size); s->lengths = g_realloc(s->lengths, new_size); s->sectors = g_realloc(s->sectors, new_size); s->sectorcounts = g_realloc(s->sectorcounts, new_size); for (i = s->n_chunks; i < s->n_chunks + chunk_count; i++) { ret = read_uint32(bs, offset, &s->types[i]); if (ret < 0) { goto fail; } offset += 4; if(s->types[i]!=0x80000005 && s->types[i]!=1 && s->types[i]!=2) { if(s->types[i]==0xffffffff) { last_in_offset = s->offsets[i-1]+s->lengths[i-1]; last_out_offset = s->sectors[i-1]+s->sectorcounts[i-1]; } chunk_count--; i--; offset += 36; continue; } offset += 4; ret = read_uint64(bs, offset, &s->sectors[i]); if (ret < 0) { goto fail; } s->sectors[i] += last_out_offset; offset += 8; ret = read_uint64(bs, offset, &s->sectorcounts[i]); if (ret < 0) { goto fail; } offset += 8; ret = read_uint64(bs, offset, &s->offsets[i]); if (ret < 0) { goto fail; } s->offsets[i] += last_in_offset; offset += 8; ret = read_uint64(bs, offset, &s->lengths[i]); if (ret < 0) { goto fail; } offset += 8; if(s->lengths[i]>max_compressed_size) max_compressed_size = s->lengths[i]; if(s->sectorcounts[i]>max_sectors_per_chunk) max_sectors_per_chunk = s->sectorcounts[i]; } s->n_chunks+=chunk_count; } } /* initialize zlib engine */ s->compressed_chunk = g_malloc(max_compressed_size+1); s->uncompressed_chunk = g_malloc(512*max_sectors_per_chunk); if(inflateInit(&s->zstream) != Z_OK) { ret = -EINVAL; goto fail; } s->current_chunk = s->n_chunks; qemu_co_mutex_init(&s->lock); return 0; fail: g_free(s->types); g_free(s->offsets); g_free(s->lengths); g_free(s->sectors); g_free(s->sectorcounts); g_free(s->compressed_chunk); g_free(s->uncompressed_chunk); return ret; }
static void parse_destination_update_message(const uint8_t* data_items, uint16_t len) { const uint8_t* data_item = data_items; printf("Received Destination Update message from modem:\n"); /* The message has been validated so just scan for the relevant data_items */ while (data_item < data_items + len) { /* Octets 0 and 1 are the data item type */ enum dlep_data_item item_id = read_uint16(data_item); /* Octets 2 and 3 are the data item length */ uint16_t item_len = read_uint16(data_item + 2); /* Increment data_item to point to the data */ data_item += 4; switch (item_id) { case DLEP_MAC_ADDRESS_DATA_ITEM: printf(" MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\n",data_item[0],data_item[1],data_item[2],data_item[3],data_item[4],data_item[5]); break; case DLEP_IPV4_ADDRESS_DATA_ITEM: case DLEP_IPV6_ADDRESS_DATA_ITEM: printf(" "); parse_address(data_item,item_len,1); break; case DLEP_IPV4_ATT_SUBNET_DATA_ITEM: case DLEP_IPV6_ATT_SUBNET_DATA_ITEM: printf(" "); parse_attached_subnet(data_item,item_len,1); break; case DLEP_MDRR_DATA_ITEM: printf(" MDDR: %"PRIu64"bps\n",read_uint64(data_item)); break; case DLEP_MDRT_DATA_ITEM: printf(" MDDT: %"PRIu64"bps\n",read_uint64(data_item)); break; case DLEP_CDRR_DATA_ITEM: printf(" CDDR: %"PRIu64"bps\n",read_uint64(data_item)); break; case DLEP_CDRT_DATA_ITEM: printf(" CDDT: %"PRIu64"bps\n",read_uint64(data_item)); break; case DLEP_LATENCY_DATA_ITEM: printf(" Latency: %"PRIu64"\x03\xBCs\n",read_uint64(data_item)); break; case DLEP_RESOURCES_DATA_ITEM: printf(" Resources (Receive): %u%%\n",data_item[0]); break; case DLEP_RLQR_DATA_ITEM: printf(" RLQR: %u\n",data_item[0]); break; case DLEP_RLQT_DATA_ITEM: printf(" RLQT: %u\n",data_item[0]); break; case DLEP_MTU_DATA_ITEM: printf(" MTU: %"PRIu32"\n",read_uint32(data_item)); break; default: /* Others will be caught by the check function */ break; } /* Increment data_item to point to the next data item */ data_item += item_len; } }