From 29c5ef9215be004b31cd53ef8841680c3f015d57 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 25 Mar 2009 05:43:07 +0000 Subject: 2009-03-25 Tatsuhiro Tsujikawa Added 'falloc' parameter for --file-allocation option. 'falloc' allocation mode uses posix_fallocate() system call to allocate file on disk. If you are using newer file systems such as ext4 (with extents support), btrfs or xfs, 'falloc' is your best choice. It allocates large(few GiB) files almost instantly. Don't use 'falloc' with legacy file systems such as ext3 because it takes almost same time as 'prealloc' and it blocks aria2 entirely until allocation finishes. 'falloc' may not be available if your system doesn't have posix_fallocate() system call. * configure.ac * src/AbstractDiskWriter.cc * src/AbstractDiskWriter.h * src/AbstractSingleDiskAdaptor.cc * src/BinaryStream.h * src/BtCheckIntegrityEntry.cc * src/ByteArrayDiskWriter.h * src/CheckIntegrityEntry.cc * src/CheckIntegrityEntry.h * src/DefaultPieceStorage.cc * src/DiskAdaptor.cc * src/DiskAdaptor.h * src/DiskWriter.h * src/FallocFileAllocationIterator.cc * src/FallocFileAllocationIterator.h * src/FileAllocationEntry.cc * src/FileAllocationEntry.h * src/Makefile.am * src/MultiFileAllocationIterator.cc * src/MultiFileAllocationIterator.h * src/OptionHandlerFactory.cc * src/RequestGroup.cc * src/StreamCheckIntegrityEntry.cc * src/prefs.cc * src/prefs.h * src/usage_text.h * test/FallocFileAllocationIteratorTest.cc * test/Makefile.am --- src/FallocFileAllocationIterator.cc | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/FallocFileAllocationIterator.cc (limited to 'src/FallocFileAllocationIterator.cc') diff --git a/src/FallocFileAllocationIterator.cc b/src/FallocFileAllocationIterator.cc new file mode 100644 index 00000000..ca0a0161 --- /dev/null +++ b/src/FallocFileAllocationIterator.cc @@ -0,0 +1,69 @@ +/* */ +#include "FallocFileAllocationIterator.h" +#include "DlAbortEx.h" + +namespace aria2 { + +FallocFileAllocationIterator::FallocFileAllocationIterator +(BinaryStream* stream, off_t offset, uint64_t totalLength): + _stream(stream), _offset(offset), _totalLength(totalLength) {} + +void FallocFileAllocationIterator::allocateChunk() +{ + if(static_cast(_offset) > _totalLength) { + throw DlAbortEx("FallocFileAllocationIterator: offset is larger than" + " totalLength"); + } + _stream->allocate(_offset, _totalLength-_offset); + _offset = _totalLength; +} + +bool FallocFileAllocationIterator::finished() +{ + return static_cast(_offset) == _totalLength; +} + +off_t FallocFileAllocationIterator::getCurrentLength() +{ + return _offset; +} + +uint64_t FallocFileAllocationIterator::getTotalLength() +{ + return _totalLength; +} + +} // namespace aria2 -- cgit