mirror of https://github.com/aria2/aria2
Use enum to select file allocation method
parent
27e44439ea
commit
e2fcd6d72c
|
@ -98,20 +98,22 @@ void AbstractSingleDiskAdaptor::truncate(int64_t length)
|
|||
SharedHandle<FileAllocationIterator>
|
||||
AbstractSingleDiskAdaptor::fileAllocationIterator()
|
||||
{
|
||||
switch(getFileAllocationMethod()) {
|
||||
#ifdef HAVE_SOME_FALLOCATE
|
||||
if(doesFallocate()) {
|
||||
case(DiskAdaptor::FILE_ALLOC_FALLOC): {
|
||||
SharedHandle<FallocFileAllocationIterator> h
|
||||
(new FallocFileAllocationIterator
|
||||
(diskWriter_.get(), size() ,totalLength_));
|
||||
return h;
|
||||
} else
|
||||
}
|
||||
#endif // HAVE_SOME_FALLOCATE
|
||||
{
|
||||
SharedHandle<AdaptiveFileAllocationIterator> h
|
||||
(new AdaptiveFileAllocationIterator
|
||||
(diskWriter_.get(), size(), totalLength_));
|
||||
return h;
|
||||
}
|
||||
default: {
|
||||
SharedHandle<AdaptiveFileAllocationIterator> h
|
||||
(new AdaptiveFileAllocationIterator
|
||||
(diskWriter_.get(), size(), totalLength_));
|
||||
return h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractSingleDiskAdaptor::enableReadOnly()
|
||||
|
|
|
@ -634,7 +634,7 @@ void DefaultPieceStorage::initStorage()
|
|||
diskAdaptor_ = multiDiskAdaptor;
|
||||
}
|
||||
if(option_->get(PREF_FILE_ALLOCATION) == V_FALLOC) {
|
||||
diskAdaptor_->enableFallocate();
|
||||
diskAdaptor_->setFileAllocationMethod(DiskAdaptor::FILE_ALLOC_FALLOC);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
namespace aria2 {
|
||||
|
||||
DiskAdaptor::DiskAdaptor()
|
||||
: fallocate_(false)
|
||||
: fileAllocationMethod_(FILE_ALLOC_ADAPTIVE)
|
||||
{}
|
||||
|
||||
DiskAdaptor::~DiskAdaptor() {}
|
||||
|
|
|
@ -48,11 +48,12 @@ class FileEntry;
|
|||
class FileAllocationIterator;
|
||||
|
||||
class DiskAdaptor:public BinaryStream {
|
||||
private:
|
||||
std::vector<SharedHandle<FileEntry> > fileEntries_;
|
||||
|
||||
bool fallocate_;
|
||||
public:
|
||||
enum FileAllocationMethod {
|
||||
FILE_ALLOC_ADAPTIVE,
|
||||
FILE_ALLOC_FALLOC
|
||||
};
|
||||
|
||||
DiskAdaptor();
|
||||
virtual ~DiskAdaptor();
|
||||
|
||||
|
@ -100,20 +101,20 @@ public:
|
|||
// successfully changed.
|
||||
virtual size_t utime(const Time& actime, const Time& modtime) = 0;
|
||||
|
||||
void enableFallocate()
|
||||
void setFileAllocationMethod(FileAllocationMethod method)
|
||||
{
|
||||
fallocate_ = true;
|
||||
fileAllocationMethod_ = method;
|
||||
}
|
||||
|
||||
void disableFallocate()
|
||||
int getFileAllocationMethod() const
|
||||
{
|
||||
fallocate_ = false;
|
||||
return fileAllocationMethod_;
|
||||
}
|
||||
|
||||
bool doesFallocate() const
|
||||
{
|
||||
return fallocate_;
|
||||
}
|
||||
private:
|
||||
std::vector<SharedHandle<FileEntry> > fileEntries_;
|
||||
|
||||
FileAllocationMethod fileAllocationMethod_;
|
||||
};
|
||||
|
||||
typedef SharedHandle<DiskAdaptor> DiskAdaptorHandle;
|
||||
|
|
|
@ -67,20 +67,22 @@ void MultiFileAllocationIterator::allocateChunk()
|
|||
diskAdaptor_->openIfNot(entry, &DiskWriterEntry::openFile);
|
||||
if(entry->needsFileAllocation() && entry->size() < fileEntry->getLength()) {
|
||||
// Calling private function of MultiDiskAdaptor.
|
||||
switch(diskAdaptor_->getFileAllocationMethod()) {
|
||||
#ifdef HAVE_SOME_FALLOCATE
|
||||
if(diskAdaptor_->doesFallocate()) {
|
||||
case(DiskAdaptor::FILE_ALLOC_FALLOC):
|
||||
fileAllocationIterator_.reset
|
||||
(new FallocFileAllocationIterator(entry->getDiskWriter().get(),
|
||||
entry->size(),
|
||||
fileEntry->getLength()));
|
||||
} else
|
||||
break;
|
||||
#endif // HAVE_SOME_FALLOCATE
|
||||
{
|
||||
fileAllocationIterator_.reset
|
||||
(new AdaptiveFileAllocationIterator(entry->getDiskWriter().get(),
|
||||
entry->size(),
|
||||
fileEntry->getLength()));
|
||||
}
|
||||
default:
|
||||
fileAllocationIterator_.reset
|
||||
(new AdaptiveFileAllocationIterator(entry->getDiskWriter().get(),
|
||||
entry->size(),
|
||||
fileEntry->getLength()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(finished()) {
|
||||
|
|
Loading…
Reference in New Issue