/* */ #include "AbstractSingleDiskAdaptor.h" #include "File.h" #include "SingleFileAllocationIterator.h" #ifdef HAVE_POSIX_FALLOCATE # include "FallocFileAllocationIterator.h" #endif // HAVE_POSIX_FALLOCATE #include "DiskWriter.h" namespace aria2 { AbstractSingleDiskAdaptor::AbstractSingleDiskAdaptor(): totalLength(0), _readOnly(false) {} AbstractSingleDiskAdaptor::~AbstractSingleDiskAdaptor() {} void AbstractSingleDiskAdaptor::initAndOpenFile() { diskWriter->initAndOpenFile(totalLength); } void AbstractSingleDiskAdaptor::openFile() { diskWriter->openFile(totalLength); } void AbstractSingleDiskAdaptor::closeFile() { diskWriter->closeFile(); } void AbstractSingleDiskAdaptor::openExistingFile() { diskWriter->openExistingFile(totalLength); } void AbstractSingleDiskAdaptor::writeData(const unsigned char* data, size_t len, off_t offset) { diskWriter->writeData(data, len, offset); } ssize_t AbstractSingleDiskAdaptor::readData(unsigned char* data, size_t len, off_t offset) { return diskWriter->readData(data, len, offset); } bool AbstractSingleDiskAdaptor::fileExists() { return File(getFilePath()).exists(); } uint64_t AbstractSingleDiskAdaptor::size() { return File(getFilePath()).size(); } void AbstractSingleDiskAdaptor::truncate(uint64_t length) { diskWriter->truncate(length); } FileAllocationIteratorHandle AbstractSingleDiskAdaptor::fileAllocationIterator() { #ifdef HAVE_POSIX_FALLOCATE if(_fallocate) { SharedHandle h (new FallocFileAllocationIterator(this, size(), totalLength)); return h; } else #endif // HAVE_POSIX_FALLOCATE { SingleFileAllocationIteratorHandle h (new SingleFileAllocationIterator(this, size(), totalLength)); h->init(); return h; } } void AbstractSingleDiskAdaptor::enableDirectIO() { diskWriter->enableDirectIO(); } void AbstractSingleDiskAdaptor::disableDirectIO() { diskWriter->disableDirectIO(); } void AbstractSingleDiskAdaptor::enableReadOnly() { diskWriter->enableReadOnly(); _readOnly = true; } void AbstractSingleDiskAdaptor::disableReadOnly() { diskWriter->disableReadOnly(); _readOnly = false; } void AbstractSingleDiskAdaptor::cutTrailingGarbage() { if(File(getFilePath()).size() > totalLength) { diskWriter->truncate(totalLength); } } void AbstractSingleDiskAdaptor::setDiskWriter(const DiskWriterHandle& diskWriter) { this->diskWriter = diskWriter; } void AbstractSingleDiskAdaptor::setTotalLength(const uint64_t& totalLength) { this->totalLength = totalLength; } } // namespace aria2