int32_t mfso::vread(int32_t fd, void *buff, uint32_t size) { fdinfo* fi; uint64_t realsize; int32_t bytesread; FileMapping* fm = NULL; try { fi = this->__fdmanager->get(fd); if (fi->node != NULL) fm = this->mapFile(fi->node); if (fm != NULL) { uint64_t fileSize = fm->maxOffset(); if (fi->node->size() <= fileSize) { if (size <= (fi->node->size() - fi->offset)) realsize = size; else realsize = fi->node->size() - fi->offset; } else { if (size <= (fileSize - fi->offset)) realsize = size; else realsize = fileSize - fi->offset; } bytesread = this->readFromMapping(fm, fi, buff, realsize); fm->delref(); return bytesread; } else { return (0); } } catch(...) { //throw(vfsError("problem while reading file")); } if (fm) fm->delref(); return (0); }
uint64_t mfso::vseek(int32_t fd, uint64_t offset, int32_t whence) { fdinfo* fi; FileMapping* fm; try { fi = this->__fdmanager->get(fd); fm = this->mapFile(fi->node); if (fm == NULL) throw std::string("can't allocate fm"); if (whence == 0) { if (offset > fm->maxOffset()) { fm->delref(); return ((uint64_t)-1); } else fi->offset = offset; } else if (whence == 1) { if ((fi->offset + offset) > fm->maxOffset()) { fm->delref(); return ((uint64_t)-1); } else fi->offset += offset; } else if (whence == 2) fi->offset = fm->maxOffset(); fm->delref(); return (fi->offset); } catch(...) { std::cout << "problem while getting fd information" << std::endl; } if (fm != NULL) fm->delref(); return ((uint64_t)-1); }