void elfloader_arch_write_rom(int fd, unsigned short textoff, unsigned int size, char *mem) { #if ELFLOADER_CONF_TEXT_IN_ROM uint32_t ptr; int nbytes; cfs_seek(fd, textoff, CFS_SEEK_SET); cfs_seek(fd, textoff, CFS_SEEK_SET); /* Read data from file into RAM. */ nbytes = cfs_read(fd, (unsigned char *)datamemory, READSIZE); PRINTF("Bytes read: %d\n", nbytes); flash_erase_memory_page((uint32_t)mem); for(ptr = 0; ptr < size; ptr += 2) { uint16_t data; data = datamemory[ptr + 1]; data = data << 8; data |= datamemory[ptr]; /* Write data to flash. */ //PRINTF("Writing %x to %x\n", data, (uint32_t)mem + ptr); flash_write_memory_half_word((uint32_t) mem + ptr, data); } for(ptr = 0; ptr < size; ptr += 2) { uint16_t* data = (uint16_t*)(mem + ptr); /* Write data to flash. */ //PRINTF("Reading %x to %p\n", *data, data); } #else /* ELFLOADER_CONF_TEXT_IN_ROM */ PRINTF("Using serial flash\n"); cfs_seek(fd, textoff, CFS_SEEK_SET); cfs_read(fd, (unsigned char *)mem, size); #endif /* ELFLOADER_CONF_TEXT_IN_ROM */ }
/*---------------------------------------------------------------------------*/ static uint8_t read_byte(int fd) { #if DATA_AS_HEX uint8_t hex[2]; cfs_read(fd, hex, 2); if(hex[0] >= 'A' && hex[0] <= 'F') { hex[0] = (hex[0] - 'A' + 0xa); } else if(hex[0] >= 'a' && hex[0] <= 'f') { hex[0] = (hex[0] - 'a' + 0xa); } else { hex[0] = (hex[0] - '0'); } if(hex[1] >= 'A' && hex[1] <= 'F') { hex[1] = (hex[1] - 'A' + 0xa); } else if(hex[1] >= 'a' && hex[1] <= 'f') { hex[1] = (hex[1] - 'a' + 0xa); } else { hex[1] = (hex[1] - '0'); } return (uint8_t)((hex[0]<<4)&0xf0) | (hex[1]&0x0f); #else /* DATA_AS_HEX */ uint8_t c; cfs_read(fd, &c, 1); return c; #endif /* DATA_AS_HEX */ }
db_result_t storage_get_relation(relation_t *rel, char *name) { int fd; int r; int i; struct attribute_record record; db_result_t result; fd = cfs_open(name, CFS_READ); if(fd < 0) { return DB_STORAGE_ERROR; } r = cfs_read(fd, rel->name, sizeof(rel->name)); if(r != sizeof(rel->name)) { cfs_close(fd); PRINTF("DB: Failed to read name, got %d of %d bytes\n", r, sizeof(rel->name)); return DB_STORAGE_ERROR; } r = cfs_read(fd, rel->tuple_filename, sizeof(rel->tuple_filename)); if(r != sizeof(rel->name)) { cfs_close(fd); PRINTF("DB: Failed to read tuple filename\n"); return DB_STORAGE_ERROR; } rel->tuple_filename[sizeof(rel->tuple_filename) - 1] ^= ROW_XOR; /* Read attribute records. */ result = DB_OK; for(i = 0;; i++) { r = cfs_read(fd, &record, sizeof(record)); if(r == 0) { break; } if(r != sizeof(record)) { PRINTF("DB: Failed to read attribute record %d (r = %d)\n", i, r); result = DB_STORAGE_ERROR; break; } if(relation_attribute_add(rel, DB_MEMORY, record.name, record.domain, record.element_size) == NULL) { PRINTF("DB: Failed to add the attribute %s\n", record.name); result = DB_STORAGE_ERROR; break; } } PRINTF("DB: Read %d attributes\n", i); cfs_close(fd); return result; }
/** File read callback. * Responds to a SBP_MSG_FILEIO_READ_REQUEST message. * * Reads a certain length (up to 255 bytes) from a given offset. Returns the * data in a SBP_MSG_FILEIO_READ_RESPONSE message where the message length field * indicates how many bytes were succesfully read. */ static void read_cb(u16 sender_id, u8 len, u8 msg[], void* context) { (void)context; if (sender_id != SBP_SENDER_ID) { log_error("Invalid sender!\n"); return; } if ((len < 9) || (msg[len-1] != '\0')) { log_error("Invalid fileio read message!\n"); return; } u32 offset = ((u32)msg[3] << 24) | ((u32)msg[2] << 16) | (msg[1] << 8) | msg[0]; u8 readlen = MIN(msg[4], SBP_FRAMING_MAX_PAYLOAD_SIZE - len); u8 buf[256]; memcpy(buf, msg, len); int f = cfs_open((char*)&msg[5], CFS_READ); cfs_seek(f, offset, CFS_SEEK_SET); len += cfs_read(f, buf + len, readlen); cfs_close(f); sbp_send_msg(SBP_MSG_FILEIO_READ_RESPONSE, len, buf); }
/*-----------------------------------------------------------------------------------*/ static void apply_tcpipconfig(void) { int file = cfs_open("contiki.cfg", CFS_READ); int size = cfs_read(file, uip_buf, 100); cfs_close(file); nullterminate(ipaddr); uiplib_ipaddrconv(ipaddr, (uip_ipaddr_t *)&uip_buf[0]); nullterminate(netmask); uiplib_ipaddrconv(netmask, (uip_ipaddr_t *)&uip_buf[4]); nullterminate(gateway); uiplib_ipaddrconv(gateway, (uip_ipaddr_t *)&uip_buf[8]); #if WITH_DNS nullterminate(dnsserver); uiplib_ipaddrconv(dnsserver, (uip_ipaddr_t *)&uip_buf[12]); #endif /* WITH_DNS */ file = cfs_open("contiki.cfg", CFS_WRITE); cfs_write(file, uip_buf, size); cfs_close(file); }
ssize_t _read_r(struct _reent *r, int fd, void *ptr, size_t len) { if (fd < 0) { /* invalid file descriptor */ r->_errno = EBADF; return -1; } if (fd >= MAX_OPEN_DEVICES) { int ret; /* CFS file */ fd -= MAX_OPEN_DEVICES; /* Remap to CFS FD number */ /* this is not really reentrant */ ret = cfs_read(fd, ptr, len); if (ret < 0) { r->_errno = EBADF; } return ret; } if (devoptab_list[fd] == NULL) { /* nothing mapped on that FD */ r->_errno = EBADF; return -1; } if (devoptab_list[fd]->read_r == NULL) { /* Function not implemented */ r->_errno = ENOSYS; return -1; } /* Call method from device operations table */ return devoptab_list[fd]->read_r(r, fd, ptr, len); }
/*---------------------------------------------------------------------*/ static u16_t send_udpdata(struct codeprop_udphdr *uh) { u16_t len; uh->type = HTONS(TYPE_DATA); uh->addr = htons(s.addr); uh->id = htons(s.id); if(s.len - s.addr > UDPDATASIZE) { len = UDPDATASIZE; } else { len = s.len - s.addr; } cfs_seek(fd, s.addr, CFS_SEEK_SET); cfs_read(fd, &uh->data[0], len); /* eeprom_read(EEPROMFS_ADDR_CODEPROP + s.addr, &uh->data[0], len);*/ uh->len = htons(s.len); PRINTF(("codeprop: sending packet from address 0x%04x\n", s.addr)); uip_udp_send(len + UDPHEADERSIZE); return len; }
/*---------------------------------------------------------------------------*/ static uint8_t read_byte(int fd) { uint8_t c; cfs_read(fd, &c, 1); return c; }
char read_next_from_buffer() { char ret = '\0'; // need to load a new buffer if (b.nb_read_buf == b.buf_size && !b.eof) { int r = cfs_read(b.fd, b.ch_buf, INPUT_BUFFER_MAX_SIZE); if (r > 0) { b.buf_size = r; b.nb_read_buf = 0; } else b.eof = true; } if (!b.eof) { b.buf_pos = &b.ch_buf[b.nb_read_buf]; b.nb_read_buf++; ret = *b.buf_pos; } return ret; }
static void initscript(void) { char line[40], *lineptr; /* struct c64_fs_file f;*/ int f; if((f = cfs_open("config.cfg", 0)) == -1) { return; } line[0] = ' '; while(line[0] != '.' && line[0] != 0) { lineptr = line; do { if(cfs_read(f, lineptr, 1) != 1) { cfs_close(f); return; } ++lineptr; } while(*(lineptr - 1) != '\n' && *(lineptr - 1) != '\r'); *lineptr = 0; if(line[0] != '.' && line[0] != 0) { parse(line, initparsetab); } } cfs_close(f); return; }
db_result_t storage_read(db_storage_id_t fd, void *buffer, unsigned long offset, unsigned length) { char *ptr; int r; /* Extend the file if necessary, so that previously unwritten bytes will be read in as zeroes. */ if(cfs_seek(fd, offset + length, CFS_SEEK_SET) == (cfs_offset_t)-1) { return DB_STORAGE_ERROR; } if(cfs_seek(fd, offset, CFS_SEEK_SET) == (cfs_offset_t)-1) { return DB_STORAGE_ERROR; } ptr = buffer; while(length > 0) { r = cfs_read(fd, ptr, length); if(r <= 0) { return DB_STORAGE_ERROR; } ptr += r; length -= r; } return DB_OK; }
/* If the queuebuf is in CFS, load it to tmpdata */ static struct queuebuf_data * queuebuf_load_to_ram(struct queuebuf *b) { int fileid, fd, ret; cfs_offset_t offset; if(b->location == IN_RAM) { /* the qbuf is loacted in RAM */ return b->ram_ptr; } else { /* the qbuf is located in CFS */ if(tmpdata_qbuf && tmpdata_qbuf->swap_id == b->swap_id) { /* the qbuf is already in tmpdata */ return &tmpdata; } else { /* the qbuf needs to be loaded from CFS */ tmpdata_qbuf = b; /* read the qbuf from CFS */ fileid = b->swap_id / NQBUF_PER_FILE; offset = (b->swap_id % NQBUF_PER_FILE) * sizeof(struct queuebuf_data); fd = qbuf_files[fileid].fd; ret = cfs_seek(fd, offset, CFS_SEEK_SET); if(ret == -1) { PRINTF("queuebuf_load_to_ram: cfs seek error\n"); } ret = cfs_read(fd, &tmpdata, sizeof(struct queuebuf_data)); if(ret == -1) { PRINTF("queuebuf_load_to_ram: cfs read error\n"); } return &tmpdata; } } }
/*---------------------------------------------------------------------------*/ static void write_chunk(struct rudolph2_conn *c, int offset, int flag, uint8_t *data, int datalen) { int fd; #if CONTIKI_TARGET_NETSIM { char buf[100]; sprintf(buf, "%d%%", (100 * (offset + datalen)) / FILESIZE); ether_set_text(buf); } #endif /* CONTIKI_TARGET_NETSIM */ if(flag == RUDOLPH2_FLAG_NEWFILE) { printf("+++ rudolph2 new file incoming at %lu\n", clock_time()); leds_on(LEDS_RED); fd = cfs_open("codeprop.out", CFS_WRITE); } else { fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND); } if(datalen > 0) { int ret; cfs_seek(fd, offset, CFS_SEEK_SET); ret = cfs_write(fd, data, datalen); printf("+++ rudolph2 offset %d, length %d\n", offset, datalen); } cfs_close(fd); if(flag == RUDOLPH2_FLAG_LASTCHUNK) { int i; printf("+++ rudolph2 entire file received at %d, %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]); leds_off(LEDS_RED); leds_on(LEDS_YELLOW); fd = cfs_open("hej", CFS_READ); for(i = 0; i < FILESIZE; ++i) { unsigned char buf; int r = cfs_read(fd, &buf, 1); if (r != 1) { printf("%d.%d: error: read failed at %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], i); break; } else if(buf != (unsigned char)i) { printf("%d.%d: error: diff at %d, %d != %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], i, (unsigned char)i, buf); break; } } #if CONTIKI_TARGET_NETSIM ether_send_done(); #endif cfs_close(fd); } }
db_result_t storage_get_index(index_t *index, relation_t *rel, attribute_t *attr) { char filename[INDEX_NAME_LENGTH]; int fd; int r; struct index_record record; db_result_t result; merge_strings(filename, rel->name, INDEX_NAME_SUFFIX); fd = cfs_open(filename, CFS_READ); if(fd < 0) { return DB_STORAGE_ERROR; } for(result = DB_STORAGE_ERROR;;) { r = cfs_read(fd, &record, sizeof(record)); if(r < sizeof(record)) { break; } if(strcmp(attr->name, record.attribute_name) == 0) { PRINTF("DB: Found the index record for %s.%s: type %d, filename %s\n", rel->name, attr->name, record.type, record.file_name); index->type = record.type; memcpy(index->descriptor_file, record.file_name, sizeof(index->descriptor_file)); result = DB_OK; } } cfs_close(fd); return result; }
PROCESS_THREAD(cfs_write_test, ev, data) { PROCESS_BEGIN(); char str[20], str2[20]; strcpy(str, "Vot bl'a nahuj!"); int fd = cfs_open("a", CFS_WRITE); if (fd == -1) { cfs_close(fd); fd = cfs_open("a", CFS_WRITE); if (fd == -1) { alarma(5); } } cfs_write(fd, (void *)str, strlen(str)); cfs_close(fd); fd = cfs_open("a", CFS_READ); cfs_read(fd, (void *)str2, strlen(str)); cfs_close(fd); strcat(str2, " Da yopt!"); fd = cfs_open("a", CFS_WRITE); cfs_write(fd, (void *)str2, strlen(str2)); cfs_close(fd); ledd_on(PB5); PROCESS_END(); }
void manage_acq_setup() { for (u8 prn=0; prn<32; prn++) { acq_prn_param[prn].state = ACQ_PRN_UNTRIED; acq_prn_param[prn].score = 0; } int fd = cfs_open("almanac", CFS_READ); if (fd != -1) { cfs_read(fd, almanac, 32*sizeof(almanac_t)); log_info("Loaded almanac from flash\n"); cfs_close(fd); } else { log_info("No almanac file present in flash, create an empty one\n"); cfs_coffee_reserve("almanac", 32*sizeof(almanac_t)); cfs_coffee_configure_log("almanac", 256, sizeof(almanac_t)); for (u8 prn=0; prn<32; prn++) { almanac[prn].valid = 0; } } sbp_register_cbk( MSG_ALMANAC, &almanac_callback, &almanac_callback_node ); chThdCreateStatic( wa_manage_acq_thread, sizeof(wa_manage_acq_thread), MANAGE_ACQ_THREAD_PRIORITY, manage_acq_thread, NULL ); }
void urlconv_init(void) { int fd = cfs_open("wwwroot.cfg", CFS_READ); int rd = cfs_read(fd, wwwroot, sizeof(wwwroot)); cfs_close(fd); if(rd != -1) wwwrootlen = rd; }
char* getFromConfig(char* value){ int fd; fd = cfs_open("/config.xml",CFS_READ); memset(answer,0,100); int i = 0,j=0,k=0; uint8_t check = 1; if (fd!=-1){ char config[128]; int read; read = cfs_read(fd, config, 128); cfs_close(fd); while (config[i]!='\0'){ if (config[i]=='<'){ i++; for (j=0;j<strlen(value);j++){ if (config[i]!=value[j]){ check = 0; break; } i++; } if (check && config[i]=='>'){ i++; j=0; while (config[i]!='<' && j<100){ answer[j++]=config[i++]; } break; } } if (config[i]=='>'){ //if (config[i+1]=='\0') break; k+=i; cfs_open("/config.xml",CFS_READ); cfs_seek(fd,++k,CFS_SEEK_SET); memset(config,0,128); cfs_read(fd,config,128); cfs_close(fd); check = 1; i=-1; } i++; } return answer; } else return "-"; }
static void send_file_block(int para) { uint8_t buf[200]; cfs_seek(_f_reader.read_fd, _f_reader.read_cursor, CFS_SEEK_SET); _f_reader.sent_bytes = cfs_read(_f_reader.read_fd, buf, sizeof(buf)); send_file_data(para, buf, _f_reader.sent_bytes, send_file_callback, para); log_info("send_file_block(%d), %d, %d\n", para, _f_reader.sent_bytes, _f_reader.read_cursor); }
/*---------------------------------------------------------------------------*/ static int coffee_test_append(void) { int error; int afd; unsigned char buf[256], buf2[11]; int r, i, j, total_read; #define APPEND_BYTES 1000 #define BULK_SIZE 10 cfs_remove("T2"); /* Test 1 and 2: Append data to the same file many times. */ for(i = 0; i < APPEND_BYTES; i += BULK_SIZE) { afd = cfs_open("T3", CFS_WRITE | CFS_APPEND); if(afd < 0) { FAIL(1); } for(j = 0; j < BULK_SIZE; j++) { buf[j] = 1 + ((i + j) & 0x7f); } if((r = cfs_write(afd, buf, BULK_SIZE)) != BULK_SIZE) { printf("r=%d\n", r); FAIL(2); } cfs_close(afd); } /* Test 3-6: Read back the data written previously and verify that it is correct. */ afd = cfs_open("T3", CFS_READ); if(afd < 0) { FAIL(3); } total_read = 0; while((r = cfs_read(afd, buf2, sizeof(buf2))) > 0) { for(j = 0; j < r; j++) { if(buf2[j] != 1 + ((total_read + j) & 0x7f)) { FAIL(4); } } total_read += r; } if(r < 0) { FAIL(5); } if(total_read != APPEND_BYTES) { FAIL(6); } cfs_close(afd); error = 0; end: cfs_close(afd); return error; }
int main() { init(); printf("\n\nFirmware info - git: " GIT_VERSION ", built: " __DATE__ " " __TIME__ "\n"); printf("--- COFFEE TEST ---\n"); char buf[80] = "Hello, world\n"; int ret = cfs_coffee_format(); if (ret < 0) while(1); int fd = cfs_open("test", CFS_READ | CFS_WRITE); if(fd >= 0) { ret = cfs_write(fd, buf, strlen(buf)); if (ret < 0) while(1); ret = cfs_write(fd, "JELLO\n", 7); if (ret < 0) while(1); ret = cfs_seek(fd, 0, CFS_SEEK_SET); if (ret < 0) while(1); ret = cfs_read(fd, buf, sizeof(buf)); if (ret < 0) while(1); printf("Read message: %s\n", buf); ret = cfs_seek(fd, 0, CFS_SEEK_SET); if (ret < 0) while(1); ret = cfs_write(fd, "JELLO", 5); if (ret < 0) while(1); ret = cfs_seek(fd, 0, CFS_SEEK_SET); if (ret < 0) while(1); ret = cfs_read(fd, buf, sizeof(buf)); if (ret < 0) while(1); printf("Read message: %s\n", buf); cfs_close(fd); if (ret < 0) while(1); } while (1); return 0; }
static int send_data(int fd, int block){ int len; tftp_header *h = (tftp_header *)uip_appdata; h->op = uip_htons(TFTP_DATA); h->block_nr = uip_htons(block); cfs_seek(fd, (block-1)*config.blksize, CFS_SEEK_SET); len = cfs_read(fd, h->data, config.blksize); if(len>=0) send_packet(h, 4+len); PRINTF("> block %d (len %d)\n", block, len); return len; }
static int read_page(struct deluge_object *obj, unsigned pagenum, unsigned char *buf) { cfs_offset_t offset; offset = pagenum * S_PAGE; if(cfs_seek(obj->cfs_fd, offset, CFS_SEEK_SET) != offset) { return -1; } return cfs_read(obj->cfs_fd, (char *)buf, S_PAGE); }
/*-----------------------------------------------------------------------------------*/ struct ethernet_config * CC_FASTCALL config_read(char *filename) { static struct { uip_ipaddr_t hostaddr; uip_ipaddr_t netmask; uip_ipaddr_t draddr; uip_ipaddr_t resolvaddr; struct ethernet_config ethernetcfg; } config; int file; file = cfs_open(filename, CFS_READ); if(file < 0) { log_message(filename, ": File not found"); error_exit(); } if(cfs_read(file, &config, sizeof(config)) < sizeof(config) - sizeof(config.ethernetcfg.name)) { log_message(filename, ": No config file"); error_exit(); } cfs_close(file); log_message("IP Address: ", ipaddrtoa(&config.hostaddr, uip_buf)); log_message("Subnet Mask: ", ipaddrtoa(&config.netmask, uip_buf)); log_message("Def. Router: ", ipaddrtoa(&config.draddr, uip_buf)); log_message("DNS Server: ", ipaddrtoa(&config.resolvaddr, uip_buf)); #ifndef ETHERNET log_message("Eth. Driver: ", config.ethernetcfg.name); #else /* !ETHERNET */ #define _stringize(arg) #arg #define stringize(arg) _stringize(arg) log_message("Eth. Driver: ", stringize(ETHERNET)); #undef _stringize #undef stringize #endif /* !ETHERNET */ log_message("Driver Port: $", utoa(config.ethernetcfg.addr, uip_buf, 16)); uip_sethostaddr(&config.hostaddr); uip_setnetmask(&config.netmask); uip_setdraddr(&config.draddr); #if WITH_DNS resolv_conf(&config.resolvaddr); #endif /* WITH_DNS */ return &config.ethernetcfg; }
static int read_chunk(struct rudolph0_conn *c, int offset, uint8_t *to, int maxsize) { int ret; int fd; fd = cfs_open(filename, CFS_READ); cfs_seek(fd, offset, CFS_SEEK_SET); ret = cfs_read(fd, to, maxsize); /* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/ cfs_close(fd); return ret; }
/*-----------------------------------------------------------------------------------*/ void config_read(char *filename) { int file; file = cfs_open(filename, CFS_READ); if(file < 0) { log_message(filename, ": File not found"); error_exit(); } if(cfs_read(file, &config, sizeof(config)) < sizeof(uip_ipaddr_t) * 4 + sizeof(uint16_t)) { log_message(filename, ": No config file"); error_exit(); } cfs_close(file); log_message("IP Address: ", ipaddrtoa(&config.hostaddr, uip_buf)); log_message("Subnet Mask: ", ipaddrtoa(&config.netmask, uip_buf)); log_message("Def. Router: ", ipaddrtoa(&config.draddr, uip_buf)); log_message("DNS Server: ", ipaddrtoa(&config.resolvaddr, uip_buf)); #ifdef STATIC_DRIVER #define _stringize(arg) #arg #define stringize(arg) _stringize(arg) #if WITH_SLIP log_message("SLIP Driver: ", stringize(STATIC_DRIVER)); #else /* WITH_SLIP */ log_message("Eth. Driver: ", stringize(STATIC_DRIVER)); #endif /* WITH_SLIP */ #undef _stringize #undef stringize #else /* STATIC_DRIVER */ log_message("Eth. Driver: ", config.ethernet.name); #endif /* STATIC_DRIVER */ #if !WITH_SLIP log_message("Driver Port: $", utoa(config.ethernet.addr, uip_buf, 16)); #endif /* !WITH_SLIP */ uip_sethostaddr(&config.hostaddr); uip_setnetmask(&config.netmask); uip_setdraddr(&config.draddr); #if WITH_DNS uip_nameserver_update(&config.resolvaddr, UIP_NAMESERVER_INFINITE_LIFETIME); #endif /* WITH_DNS */ }
static int read_chunk(struct rudolph2_conn *c, int offset, uint8_t *to, int maxsize) { int fd; int ret; fd = cfs_open("hej", CFS_READ); cfs_seek(fd, offset, CFS_SEEK_SET); ret = cfs_read(fd, to, maxsize); /* printf("%d.%d: read_chunk %d bytes at %d, %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], ret, offset, (unsigned char)to[0]);*/ cfs_close(fd); return ret; }
/*---------------------------------------------------------------------------*/ static int read_chunk(struct rucb_conn *c, int offset, char *to, int maxsize) { int ret; if(fd < 0) { /* No file, send EOF */ leds_off(LEDS_GREEN); return 0; } cfs_seek(fd, offset, CFS_SEEK_SET); ret = cfs_read(fd, to, maxsize); if(ret < maxsize) { cfs_close(fd); fd = -1; } return ret; }
/*---------------------------------------------------------------------------*/ static void seek_read(int fd, unsigned int offset, char *buf, int len) { cfs_seek(fd, offset, CFS_SEEK_SET); cfs_read(fd, buf, len); #if DEBUG { int i; PRINTF("seek_read: Read len %d from offset %d\n", len, offset); for(i = 0; i < len; ++i ) { PRINTF("%02x ", buf[i]); } printf("\n"); } #endif /* DEBUG */ }
struct buffer create_buffer(int file) { b.fd = file; b.eof = false; int r = cfs_read(file, b.ch_buf, INPUT_BUFFER_MAX_SIZE); if (r > 0) { b.buf_size = r; b.buf_pos = &b.ch_buf[0]; } else printf("Error creating the buffer\n"); return b; }