mingw32: Make NTFS sparse file on --file-allocation=trunc

pull/43/head
Tatsuhiro Tsujikawa 2013-01-11 18:35:54 +09:00
parent 357e4b1a77
commit e0ea88ebcf
6 changed files with 20 additions and 7 deletions

View File

@ -463,11 +463,23 @@ void AbstractDiskWriter::truncate(int64_t length)
}
}
void AbstractDiskWriter::allocate(int64_t offset, int64_t length)
void AbstractDiskWriter::allocate(int64_t offset, int64_t length, bool sparse)
{
if(fd_ == A2_BAD_FD) {
throw DL_ABORT_EX("File not yet opened.");
}
if(sparse) {
#ifdef __MINGW32__
DWORD bytesReturned;
if(!DeviceIoControl(fd_, FSCTL_SET_SPARSE, 0, 0, 0, 0,
&bytesReturned, 0)) {
A2_LOG_WARN(fmt("Making file sparse failed or pending: %s",
fileStrerror(GetLastError()).c_str()));
}
#endif // __MINGW32__
truncate(offset+length);
return;
}
#ifdef HAVE_SOME_FALLOCATE
# ifdef __MINGW32__
truncate(offset+length);

View File

@ -84,7 +84,7 @@ public:
virtual void truncate(int64_t length);
// File must be opened before calling this function.
virtual void allocate(int64_t offset, int64_t length);
virtual void allocate(int64_t offset, int64_t length, bool sparse);
virtual int64_t size();

View File

@ -62,7 +62,7 @@ void AdaptiveFileAllocationIterator::allocateChunk()
if(offset_ < totalLength_) {
int64_t len = std::min(totalLength_-offset_,
static_cast<int64_t>(4096));
stream_->allocate(offset_, len);
stream_->allocate(offset_, len, false);
offset_ += len;
}
A2_LOG_DEBUG("File system supports fallocate.");

View File

@ -55,8 +55,9 @@ public:
virtual void truncate(int64_t length) {}
// Allocates given length bytes of disk space from given offset. The
// default implementation does nothing.
virtual void allocate(int64_t offset, int64_t length) {}
// default implementation does nothing. If sparse is true, the
// implementation may create sparse file (with holes).
virtual void allocate(int64_t offset, int64_t length, bool sparse) {}
};
} // namespace aria2

View File

@ -44,7 +44,7 @@ FallocFileAllocationIterator::FallocFileAllocationIterator
void FallocFileAllocationIterator::allocateChunk()
{
if(offset_ < totalLength_) {
stream_->allocate(offset_, totalLength_-offset_);
stream_->allocate(offset_, totalLength_-offset_, false);
offset_ = totalLength_;
} else {
stream_->truncate(totalLength_);

View File

@ -46,7 +46,7 @@ TruncFileAllocationIterator::TruncFileAllocationIterator
void TruncFileAllocationIterator::allocateChunk()
{
stream_->truncate(totalLength_);
stream_->allocate(0, totalLength_, true);
offset_ = totalLength_;
}