mirror of https://github.com/aria2/aria2
Use int64_t instead of off_t
Using off_t, at least, in DiskAdaptor layer is problematic because torrent can contain under 2GiB files but total sum of those files may exceed 2GiB limit, which makes off_t overflow in 32 bit system without large file support. So we use int64_t in API. We'll check the file length before download so that it does not exceed max off_t.pull/25/merge
parent
f56743b083
commit
860f4dd06a
|
@ -69,7 +69,7 @@ AbstractDiskWriter::~AbstractDiskWriter()
|
||||||
closeFile();
|
closeFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::openFile(off_t totalLength)
|
void AbstractDiskWriter::openFile(int64_t totalLength)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
openExistingFile(totalLength);
|
openExistingFile(totalLength);
|
||||||
|
@ -104,7 +104,7 @@ void AbstractDiskWriter::closeFile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::openExistingFile(off_t totalLength)
|
void AbstractDiskWriter::openExistingFile(int64_t totalLength)
|
||||||
{
|
{
|
||||||
int flags = O_BINARY;
|
int flags = O_BINARY;
|
||||||
if(readOnly_) {
|
if(readOnly_) {
|
||||||
|
@ -146,7 +146,7 @@ void AbstractDiskWriter::createFile(int addFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t AbstractDiskWriter::writeDataInternal(const unsigned char* data,
|
ssize_t AbstractDiskWriter::writeDataInternal(const unsigned char* data,
|
||||||
size_t len, off_t offset)
|
size_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
if(mapaddr_) {
|
if(mapaddr_) {
|
||||||
memcpy(mapaddr_ + offset, data, len);
|
memcpy(mapaddr_ + offset, data, len);
|
||||||
|
@ -168,7 +168,7 @@ ssize_t AbstractDiskWriter::writeDataInternal(const unsigned char* data,
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len,
|
ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len,
|
||||||
off_t offset)
|
int64_t offset)
|
||||||
{
|
{
|
||||||
if(mapaddr_) {
|
if(mapaddr_) {
|
||||||
ssize_t readlen;
|
ssize_t readlen;
|
||||||
|
@ -187,7 +187,7 @@ ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::seek(off_t offset)
|
void AbstractDiskWriter::seek(int64_t offset)
|
||||||
{
|
{
|
||||||
if(a2lseek(fd_, offset, SEEK_SET) == (off_t)-1) {
|
if(a2lseek(fd_, offset, SEEK_SET) == (off_t)-1) {
|
||||||
int errNum = errno;
|
int errNum = errno;
|
||||||
|
@ -198,20 +198,20 @@ void AbstractDiskWriter::seek(off_t offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::ensureMmapWrite(size_t len, off_t offset)
|
void AbstractDiskWriter::ensureMmapWrite(size_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_MMAP
|
#ifdef HAVE_MMAP
|
||||||
if(enableMmap_) {
|
if(enableMmap_) {
|
||||||
if(mapaddr_) {
|
if(mapaddr_) {
|
||||||
if(static_cast<off_t>(len + offset) > maplen_) {
|
if(static_cast<int64_t>(len + offset) > maplen_) {
|
||||||
munmap(mapaddr_, maplen_);
|
munmap(mapaddr_, maplen_);
|
||||||
mapaddr_ = 0;
|
mapaddr_ = 0;
|
||||||
maplen_ = 0;
|
maplen_ = 0;
|
||||||
enableMmap_ = false;
|
enableMmap_ = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
off_t filesize = size();
|
int64_t filesize = size();
|
||||||
if(static_cast<off_t>(len + offset) <= filesize) {
|
if(static_cast<int64_t>(len + offset) <= filesize) {
|
||||||
mapaddr_ = reinterpret_cast<unsigned char*>
|
mapaddr_ = reinterpret_cast<unsigned char*>
|
||||||
(mmap(0, size(), PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0));
|
(mmap(0, size(), PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0));
|
||||||
if(mapaddr_) {
|
if(mapaddr_) {
|
||||||
|
@ -231,7 +231,7 @@ void AbstractDiskWriter::ensureMmapWrite(size_t len, off_t offset)
|
||||||
#endif // HAVE_MMAP
|
#endif // HAVE_MMAP
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t offset)
|
void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
ensureMmapWrite(len, offset);
|
ensureMmapWrite(len, offset);
|
||||||
if(writeDataInternal(data, len, offset) < 0) {
|
if(writeDataInternal(data, len, offset) < 0) {
|
||||||
|
@ -256,7 +256,7 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, off_t offset)
|
ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
if((ret = readDataInternal(data, len, offset)) < 0) {
|
if((ret = readDataInternal(data, len, offset)) < 0) {
|
||||||
|
@ -271,7 +271,7 @@ ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, off_t offs
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::truncate(off_t length)
|
void AbstractDiskWriter::truncate(int64_t length)
|
||||||
{
|
{
|
||||||
if(fd_ == -1) {
|
if(fd_ == -1) {
|
||||||
throw DL_ABORT_EX("File not opened.");
|
throw DL_ABORT_EX("File not opened.");
|
||||||
|
@ -297,7 +297,7 @@ void AbstractDiskWriter::truncate(off_t length)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::allocate(off_t offset, off_t length)
|
void AbstractDiskWriter::allocate(int64_t offset, int64_t length)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SOME_FALLOCATE
|
#ifdef HAVE_SOME_FALLOCATE
|
||||||
if(fd_ == -1) {
|
if(fd_ == -1) {
|
||||||
|
@ -346,7 +346,7 @@ void AbstractDiskWriter::allocate(off_t offset, off_t length)
|
||||||
#endif // HAVE_SOME_FALLOCATE
|
#endif // HAVE_SOME_FALLOCATE
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t AbstractDiskWriter::size()
|
int64_t AbstractDiskWriter::size()
|
||||||
{
|
{
|
||||||
return File(filename_).size();
|
return File(filename_).size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,37 +49,37 @@ private:
|
||||||
|
|
||||||
bool enableMmap_;
|
bool enableMmap_;
|
||||||
unsigned char* mapaddr_;
|
unsigned char* mapaddr_;
|
||||||
off_t maplen_;
|
int64_t maplen_;
|
||||||
|
|
||||||
ssize_t writeDataInternal(const unsigned char* data, size_t len,
|
ssize_t writeDataInternal(const unsigned char* data, size_t len,
|
||||||
off_t offset);
|
int64_t offset);
|
||||||
ssize_t readDataInternal(unsigned char* data, size_t len, off_t offset);
|
ssize_t readDataInternal(unsigned char* data, size_t len, int64_t offset);
|
||||||
|
|
||||||
void seek(off_t offset);
|
void seek(int64_t offset);
|
||||||
|
|
||||||
void ensureMmapWrite(size_t len, off_t offset);
|
void ensureMmapWrite(size_t len, int64_t offset);
|
||||||
protected:
|
protected:
|
||||||
void createFile(int addFlags = 0);
|
void createFile(int addFlags = 0);
|
||||||
public:
|
public:
|
||||||
AbstractDiskWriter(const std::string& filename);
|
AbstractDiskWriter(const std::string& filename);
|
||||||
virtual ~AbstractDiskWriter();
|
virtual ~AbstractDiskWriter();
|
||||||
|
|
||||||
virtual void openFile(off_t totalLength = 0);
|
virtual void openFile(int64_t totalLength = 0);
|
||||||
|
|
||||||
virtual void closeFile();
|
virtual void closeFile();
|
||||||
|
|
||||||
virtual void openExistingFile(off_t totalLength = 0);
|
virtual void openExistingFile(int64_t totalLength = 0);
|
||||||
|
|
||||||
virtual void writeData(const unsigned char* data, size_t len, off_t offset);
|
virtual void writeData(const unsigned char* data, size_t len, int64_t offset);
|
||||||
|
|
||||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset);
|
virtual ssize_t readData(unsigned char* data, size_t len, int64_t offset);
|
||||||
|
|
||||||
virtual void truncate(off_t length);
|
virtual void truncate(int64_t length);
|
||||||
|
|
||||||
// File must be opened before calling this function.
|
// File must be opened before calling this function.
|
||||||
virtual void allocate(off_t offset, off_t length);
|
virtual void allocate(int64_t offset, int64_t length);
|
||||||
|
|
||||||
virtual off_t size();
|
virtual int64_t size();
|
||||||
|
|
||||||
virtual void enableReadOnly();
|
virtual void enableReadOnly();
|
||||||
|
|
||||||
|
|
|
@ -69,13 +69,13 @@ void AbstractSingleDiskAdaptor::openExistingFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractSingleDiskAdaptor::writeData
|
void AbstractSingleDiskAdaptor::writeData
|
||||||
(const unsigned char* data, size_t len, off_t offset)
|
(const unsigned char* data, size_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
diskWriter_->writeData(data, len, offset);
|
diskWriter_->writeData(data, len, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t AbstractSingleDiskAdaptor::readData
|
ssize_t AbstractSingleDiskAdaptor::readData
|
||||||
(unsigned char* data, size_t len, off_t offset)
|
(unsigned char* data, size_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
return diskWriter_->readData(data, len, offset);
|
return diskWriter_->readData(data, len, offset);
|
||||||
}
|
}
|
||||||
|
@ -85,12 +85,12 @@ bool AbstractSingleDiskAdaptor::fileExists()
|
||||||
return File(getFilePath()).exists();
|
return File(getFilePath()).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t AbstractSingleDiskAdaptor::size()
|
int64_t AbstractSingleDiskAdaptor::size()
|
||||||
{
|
{
|
||||||
return File(getFilePath()).size();
|
return File(getFilePath()).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractSingleDiskAdaptor::truncate(off_t length)
|
void AbstractSingleDiskAdaptor::truncate(int64_t length)
|
||||||
{
|
{
|
||||||
diskWriter_->truncate(length);
|
diskWriter_->truncate(length);
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ void AbstractSingleDiskAdaptor::setDiskWriter
|
||||||
diskWriter_ = diskWriter;
|
diskWriter_ = diskWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractSingleDiskAdaptor::setTotalLength(const off_t& totalLength)
|
void AbstractSingleDiskAdaptor::setTotalLength(int64_t totalLength)
|
||||||
{
|
{
|
||||||
totalLength_ = totalLength;
|
totalLength_ = totalLength;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class FileAllocationIterator;
|
||||||
class AbstractSingleDiskAdaptor : public DiskAdaptor {
|
class AbstractSingleDiskAdaptor : public DiskAdaptor {
|
||||||
private:
|
private:
|
||||||
SharedHandle<DiskWriter> diskWriter_;
|
SharedHandle<DiskWriter> diskWriter_;
|
||||||
off_t totalLength_;
|
int64_t totalLength_;
|
||||||
bool readOnly_;
|
bool readOnly_;
|
||||||
public:
|
public:
|
||||||
AbstractSingleDiskAdaptor();
|
AbstractSingleDiskAdaptor();
|
||||||
|
@ -61,15 +61,15 @@ public:
|
||||||
virtual void openExistingFile();
|
virtual void openExistingFile();
|
||||||
|
|
||||||
virtual void writeData(const unsigned char* data, size_t len,
|
virtual void writeData(const unsigned char* data, size_t len,
|
||||||
off_t offset);
|
int64_t offset);
|
||||||
|
|
||||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset);
|
virtual ssize_t readData(unsigned char* data, size_t len, int64_t offset);
|
||||||
|
|
||||||
virtual bool fileExists();
|
virtual bool fileExists();
|
||||||
|
|
||||||
virtual off_t size();
|
virtual int64_t size();
|
||||||
|
|
||||||
virtual void truncate(off_t length);
|
virtual void truncate(int64_t length);
|
||||||
|
|
||||||
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
|
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
|
||||||
|
|
||||||
|
@ -94,9 +94,9 @@ public:
|
||||||
return diskWriter_;
|
return diskWriter_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTotalLength(const off_t& totalLength);
|
void setTotalLength(int64_t totalLength);
|
||||||
|
|
||||||
off_t getTotalLength() const
|
int64_t getTotalLength() const
|
||||||
{
|
{
|
||||||
return totalLength_;
|
return totalLength_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
AdaptiveFileAllocationIterator::AdaptiveFileAllocationIterator
|
AdaptiveFileAllocationIterator::AdaptiveFileAllocationIterator
|
||||||
(BinaryStream* stream, off_t offset, off_t totalLength)
|
(BinaryStream* stream, int64_t offset, int64_t totalLength)
|
||||||
: stream_(stream),
|
: stream_(stream),
|
||||||
offset_(offset),
|
offset_(offset),
|
||||||
totalLength_(totalLength)
|
totalLength_(totalLength)
|
||||||
|
@ -60,7 +60,8 @@ void AdaptiveFileAllocationIterator::allocateChunk()
|
||||||
try {
|
try {
|
||||||
A2_LOG_DEBUG("Testing file system supports fallocate.");
|
A2_LOG_DEBUG("Testing file system supports fallocate.");
|
||||||
if(offset_ < totalLength_) {
|
if(offset_ < totalLength_) {
|
||||||
off_t len = std::min(totalLength_-offset_, static_cast<off_t>(4096));
|
int64_t len = std::min(totalLength_-offset_,
|
||||||
|
static_cast<int64_t>(4096));
|
||||||
stream_->allocate(offset_, len);
|
stream_->allocate(offset_, len);
|
||||||
offset_ += len;
|
offset_ += len;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +96,7 @@ bool AdaptiveFileAllocationIterator::finished()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t AdaptiveFileAllocationIterator::getCurrentLength()
|
int64_t AdaptiveFileAllocationIterator::getCurrentLength()
|
||||||
{
|
{
|
||||||
if(!allocator_) {
|
if(!allocator_) {
|
||||||
return offset_;
|
return offset_;
|
||||||
|
@ -104,7 +105,7 @@ off_t AdaptiveFileAllocationIterator::getCurrentLength()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t AdaptiveFileAllocationIterator::getTotalLength()
|
int64_t AdaptiveFileAllocationIterator::getTotalLength()
|
||||||
{
|
{
|
||||||
return totalLength_;
|
return totalLength_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,12 +48,12 @@ private:
|
||||||
|
|
||||||
BinaryStream* stream_;
|
BinaryStream* stream_;
|
||||||
|
|
||||||
off_t offset_;
|
int64_t offset_;
|
||||||
|
|
||||||
off_t totalLength_;
|
int64_t totalLength_;
|
||||||
public:
|
public:
|
||||||
AdaptiveFileAllocationIterator
|
AdaptiveFileAllocationIterator
|
||||||
(BinaryStream* stream, off_t offset, off_t totalLength);
|
(BinaryStream* stream, int64_t offset, int64_t totalLength);
|
||||||
|
|
||||||
virtual ~AdaptiveFileAllocationIterator();
|
virtual ~AdaptiveFileAllocationIterator();
|
||||||
|
|
||||||
|
@ -61,9 +61,9 @@ public:
|
||||||
|
|
||||||
virtual bool finished();
|
virtual bool finished();
|
||||||
|
|
||||||
virtual off_t getCurrentLength();
|
virtual int64_t getCurrentLength();
|
||||||
|
|
||||||
virtual off_t getTotalLength();
|
virtual int64_t getTotalLength();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -47,17 +47,18 @@ class BinaryStream {
|
||||||
public:
|
public:
|
||||||
virtual ~BinaryStream() {}
|
virtual ~BinaryStream() {}
|
||||||
|
|
||||||
virtual void writeData(const unsigned char* data, size_t len, off_t offset) = 0;
|
virtual void writeData(const unsigned char* data, size_t len,
|
||||||
|
int64_t offset) = 0;
|
||||||
|
|
||||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset) = 0;
|
virtual ssize_t readData(unsigned char* data, size_t len, int64_t offset) = 0;
|
||||||
|
|
||||||
// Truncates a file to given length. The default implementation does
|
// Truncates a file to given length. The default implementation does
|
||||||
// nothing.
|
// nothing.
|
||||||
virtual void truncate(off_t length) {}
|
virtual void truncate(int64_t length) {}
|
||||||
|
|
||||||
// Allocates given length bytes of disk space from given offset. The
|
// Allocates given length bytes of disk space from given offset. The
|
||||||
// default implementation does nothing.
|
// default implementation does nothing.
|
||||||
virtual void allocate(off_t offset, off_t length) {}
|
virtual void allocate(int64_t offset, int64_t length) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BinaryStream> BinaryStreamHandle;
|
typedef SharedHandle<BinaryStream> BinaryStreamHandle;
|
||||||
|
|
|
@ -103,7 +103,8 @@ void BtPieceMessage::doReceivedAction()
|
||||||
if(!RequestSlot::isNull(slot)) {
|
if(!RequestSlot::isNull(slot)) {
|
||||||
getPeer()->snubbing(false);
|
getPeer()->snubbing(false);
|
||||||
SharedHandle<Piece> piece = getPieceStorage()->getPiece(index_);
|
SharedHandle<Piece> piece = getPieceStorage()->getPiece(index_);
|
||||||
off_t offset = (off_t)index_*downloadContext_->getPieceLength()+begin_;
|
int64_t offset =
|
||||||
|
static_cast<int64_t>(index_)*downloadContext_->getPieceLength()+begin_;
|
||||||
A2_LOG_DEBUG(fmt(MSG_PIECE_RECEIVED,
|
A2_LOG_DEBUG(fmt(MSG_PIECE_RECEIVED,
|
||||||
getCuid(),
|
getCuid(),
|
||||||
static_cast<unsigned long>(index_),
|
static_cast<unsigned long>(index_),
|
||||||
|
@ -181,8 +182,8 @@ void BtPieceMessage::send()
|
||||||
A2_LOG_DEBUG(fmt("msglength = %lu bytes",
|
A2_LOG_DEBUG(fmt("msglength = %lu bytes",
|
||||||
static_cast<unsigned long>(msgHdrLen+blockLength_)));
|
static_cast<unsigned long>(msgHdrLen+blockLength_)));
|
||||||
getPeerConnection()->pushBytes(msgHdr, msgHdrLen);
|
getPeerConnection()->pushBytes(msgHdr, msgHdrLen);
|
||||||
off_t pieceDataOffset =
|
int64_t pieceDataOffset =
|
||||||
(off_t)index_*downloadContext_->getPieceLength()+begin_;
|
static_cast<int64_t>(index_)*downloadContext_->getPieceLength()+begin_;
|
||||||
pushPieceData(pieceDataOffset, blockLength_);
|
pushPieceData(pieceDataOffset, blockLength_);
|
||||||
}
|
}
|
||||||
writtenLength = getPeerConnection()->sendPendingData();
|
writtenLength = getPeerConnection()->sendPendingData();
|
||||||
|
@ -190,7 +191,7 @@ void BtPieceMessage::send()
|
||||||
setSendingInProgress(!getPeerConnection()->sendBufferIsEmpty());
|
setSendingInProgress(!getPeerConnection()->sendBufferIsEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtPieceMessage::pushPieceData(off_t offset, int32_t length) const
|
void BtPieceMessage::pushPieceData(int64_t offset, int32_t length) const
|
||||||
{
|
{
|
||||||
assert(length <= 16*1024);
|
assert(length <= 16*1024);
|
||||||
unsigned char* buf = new unsigned char[length];
|
unsigned char* buf = new unsigned char[length];
|
||||||
|
@ -224,7 +225,8 @@ bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
|
||||||
return
|
return
|
||||||
piece->getDigest() == downloadContext_->getPieceHash(piece->getIndex());
|
piece->getDigest() == downloadContext_->getPieceHash(piece->getIndex());
|
||||||
} else {
|
} else {
|
||||||
off_t offset = (off_t)piece->getIndex()*downloadContext_->getPieceLength();
|
int64_t offset = static_cast<int64_t>(piece->getIndex())
|
||||||
|
*downloadContext_->getPieceLength();
|
||||||
return message_digest::staticSHA1Digest
|
return message_digest::staticSHA1Digest
|
||||||
(getPieceStorage()->getDiskAdaptor(), offset, piece->getLength())
|
(getPieceStorage()->getDiskAdaptor(), offset, piece->getLength())
|
||||||
== downloadContext_->getPieceHash(piece->getIndex());
|
== downloadContext_->getPieceHash(piece->getIndex());
|
||||||
|
@ -256,7 +258,8 @@ void BtPieceMessage::erasePieceOnDisk(const SharedHandle<Piece>& piece)
|
||||||
size_t BUFSIZE = 4096;
|
size_t BUFSIZE = 4096;
|
||||||
unsigned char buf[BUFSIZE];
|
unsigned char buf[BUFSIZE];
|
||||||
memset(buf, 0, BUFSIZE);
|
memset(buf, 0, BUFSIZE);
|
||||||
off_t offset = (off_t)piece->getIndex()*downloadContext_->getPieceLength();
|
int64_t offset =
|
||||||
|
static_cast<int64_t>(piece->getIndex())*downloadContext_->getPieceLength();
|
||||||
div_t res = div(piece->getLength(), BUFSIZE);
|
div_t res = div(piece->getLength(), BUFSIZE);
|
||||||
for(int i = 0; i < res.quot; ++i) {
|
for(int i = 0; i < res.quot; ++i) {
|
||||||
getPieceStorage()->getDiskAdaptor()->writeData(buf, BUFSIZE, offset);
|
getPieceStorage()->getDiskAdaptor()->writeData(buf, BUFSIZE, offset);
|
||||||
|
|
|
@ -65,7 +65,7 @@ private:
|
||||||
|
|
||||||
void erasePieceOnDisk(const SharedHandle<Piece>& piece);
|
void erasePieceOnDisk(const SharedHandle<Piece>& piece);
|
||||||
|
|
||||||
void pushPieceData(off_t offset, int32_t length) const;
|
void pushPieceData(int64_t offset, int32_t length) const;
|
||||||
public:
|
public:
|
||||||
BtPieceMessage(size_t index = 0, int32_t begin = 0, int32_t blockLength = 0);
|
BtPieceMessage(size_t index = 0, int32_t begin = 0, int32_t blockLength = 0);
|
||||||
|
|
||||||
|
|
|
@ -50,47 +50,49 @@ void ByteArrayDiskWriter::clear()
|
||||||
buf_.str(A2STR::NIL);
|
buf_.str(A2STR::NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteArrayDiskWriter::initAndOpenFile(off_t totalLength)
|
void ByteArrayDiskWriter::initAndOpenFile(int64_t totalLength)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteArrayDiskWriter::openFile(off_t totalLength) {}
|
void ByteArrayDiskWriter::openFile(int64_t totalLength) {}
|
||||||
|
|
||||||
void ByteArrayDiskWriter::closeFile() {}
|
void ByteArrayDiskWriter::closeFile() {}
|
||||||
|
|
||||||
void ByteArrayDiskWriter::openExistingFile(off_t totalLength)
|
void ByteArrayDiskWriter::openExistingFile(int64_t totalLength)
|
||||||
{
|
{
|
||||||
openFile();
|
openFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteArrayDiskWriter::writeData(const unsigned char* data, size_t dataLength, off_t position)
|
void ByteArrayDiskWriter::writeData(const unsigned char* data,
|
||||||
|
size_t dataLength, int64_t offset)
|
||||||
{
|
{
|
||||||
if(position+dataLength > maxLength_) {
|
if(offset+dataLength > maxLength_) {
|
||||||
throw DL_ABORT_EX(fmt("Maximum length(%lu) exceeded.",
|
throw DL_ABORT_EX(fmt("Maximum length(%lu) exceeded.",
|
||||||
static_cast<unsigned long>(maxLength_)));
|
static_cast<unsigned long>(maxLength_)));
|
||||||
}
|
}
|
||||||
off_t length = size();
|
int64_t length = size();
|
||||||
if(length < position) {
|
if(length < offset) {
|
||||||
buf_.seekp(length, std::ios::beg);
|
buf_.seekp(length, std::ios::beg);
|
||||||
for(off_t i = length; i < position; ++i) {
|
for(int64_t i = length; i < offset; ++i) {
|
||||||
buf_.put('\0');
|
buf_.put('\0');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buf_.seekp(position, std::ios::beg);
|
buf_.seekp(offset, std::ios::beg);
|
||||||
}
|
}
|
||||||
buf_.write(reinterpret_cast<const char*>(data), dataLength);
|
buf_.write(reinterpret_cast<const char*>(data), dataLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ByteArrayDiskWriter::readData(unsigned char* data, size_t len, off_t position)
|
ssize_t ByteArrayDiskWriter::readData(unsigned char* data, size_t len,
|
||||||
|
int64_t offset)
|
||||||
{
|
{
|
||||||
buf_.seekg(position, std::ios::beg);
|
buf_.seekg(offset, std::ios::beg);
|
||||||
buf_.read(reinterpret_cast<char*>(data), len);
|
buf_.read(reinterpret_cast<char*>(data), len);
|
||||||
buf_.clear();
|
buf_.clear();
|
||||||
return buf_.gcount();
|
return buf_.gcount();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t ByteArrayDiskWriter::size()
|
int64_t ByteArrayDiskWriter::size()
|
||||||
{
|
{
|
||||||
buf_.seekg(0, std::ios::end);
|
buf_.seekg(0, std::ios::end);
|
||||||
buf_.clear();
|
buf_.clear();
|
||||||
|
|
|
@ -49,18 +49,18 @@ public:
|
||||||
ByteArrayDiskWriter(size_t maxLength = 5*1024*1024);
|
ByteArrayDiskWriter(size_t maxLength = 5*1024*1024);
|
||||||
virtual ~ByteArrayDiskWriter();
|
virtual ~ByteArrayDiskWriter();
|
||||||
|
|
||||||
virtual void initAndOpenFile(off_t totalLength = 0);
|
virtual void initAndOpenFile(int64_t totalLength = 0);
|
||||||
|
|
||||||
virtual void openFile(off_t totalLength = 0);
|
virtual void openFile(int64_t totalLength = 0);
|
||||||
|
|
||||||
virtual void closeFile();
|
virtual void closeFile();
|
||||||
|
|
||||||
virtual void openExistingFile(off_t totalLength = 0);
|
virtual void openExistingFile(int64_t totalLength = 0);
|
||||||
|
|
||||||
virtual void writeData(const unsigned char* data, size_t len, off_t position);
|
virtual void writeData(const unsigned char* data, size_t len, int64_t offset);
|
||||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t position);
|
virtual ssize_t readData(unsigned char* data, size_t len, int64_t offset);
|
||||||
|
|
||||||
virtual off_t size();
|
virtual int64_t size();
|
||||||
|
|
||||||
void setString(const std::string& s);
|
void setString(const std::string& s);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ void CheckIntegrityEntry::validateChunk()
|
||||||
validator_->validateChunk();
|
validator_->validateChunk();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t CheckIntegrityEntry::getTotalLength()
|
int64_t CheckIntegrityEntry::getTotalLength()
|
||||||
{
|
{
|
||||||
if(!validator_) {
|
if(!validator_) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -65,7 +65,7 @@ off_t CheckIntegrityEntry::getTotalLength()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t CheckIntegrityEntry::getCurrentLength()
|
int64_t CheckIntegrityEntry::getCurrentLength()
|
||||||
{
|
{
|
||||||
if(!validator_) {
|
if(!validator_) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -61,9 +61,9 @@ public:
|
||||||
|
|
||||||
virtual ~CheckIntegrityEntry();
|
virtual ~CheckIntegrityEntry();
|
||||||
|
|
||||||
virtual off_t getTotalLength();
|
virtual int64_t getTotalLength();
|
||||||
|
|
||||||
virtual off_t getCurrentLength();
|
virtual int64_t getCurrentLength();
|
||||||
|
|
||||||
virtual void validateChunk();
|
virtual void validateChunk();
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ DefaultDiskWriter::DefaultDiskWriter(const std::string& filename):
|
||||||
|
|
||||||
DefaultDiskWriter::~DefaultDiskWriter() {}
|
DefaultDiskWriter::~DefaultDiskWriter() {}
|
||||||
|
|
||||||
void DefaultDiskWriter::initAndOpenFile(off_t totalLength)
|
void DefaultDiskWriter::initAndOpenFile(int64_t totalLength)
|
||||||
{
|
{
|
||||||
createFile();
|
createFile();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
|
|
||||||
virtual ~DefaultDiskWriter();
|
virtual ~DefaultDiskWriter();
|
||||||
|
|
||||||
virtual void initAndOpenFile(off_t totalLength = 0);
|
virtual void initAndOpenFile(int64_t totalLength = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<DefaultDiskWriter> DefaultDiskWriterHandle;
|
typedef SharedHandle<DefaultDiskWriter> DefaultDiskWriterHandle;
|
||||||
|
|
|
@ -66,7 +66,7 @@ public:
|
||||||
|
|
||||||
virtual bool fileExists() = 0;
|
virtual bool fileExists() = 0;
|
||||||
|
|
||||||
virtual off_t size() = 0;
|
virtual int64_t size() = 0;
|
||||||
|
|
||||||
template<typename InputIterator>
|
template<typename InputIterator>
|
||||||
void setFileEntries(InputIterator first, InputIterator last)
|
void setFileEntries(InputIterator first, InputIterator last)
|
||||||
|
|
|
@ -51,9 +51,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Opens file. If the file exists, then it is truncated to 0 length.
|
* Opens file. If the file exists, then it is truncated to 0 length.
|
||||||
*/
|
*/
|
||||||
virtual void initAndOpenFile(off_t totalLength = 0) = 0;
|
virtual void initAndOpenFile(int64_t totalLength = 0) = 0;
|
||||||
|
|
||||||
virtual void openFile(off_t totalLength = 0) = 0;
|
virtual void openFile(int64_t totalLength = 0) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes this output stream.
|
* Closes this output stream.
|
||||||
|
@ -65,10 +65,10 @@ public:
|
||||||
* Opens a file. If the file doesnot exists, an exception may be
|
* Opens a file. If the file doesnot exists, an exception may be
|
||||||
* thrown.
|
* thrown.
|
||||||
*/
|
*/
|
||||||
virtual void openExistingFile(off_t totalLength = 0) = 0;
|
virtual void openExistingFile(int64_t totalLength = 0) = 0;
|
||||||
|
|
||||||
// Returns file length
|
// Returns file length
|
||||||
virtual off_t size() = 0;
|
virtual int64_t size() = 0;
|
||||||
|
|
||||||
// Enables read-only mode. After this call, openExistingFile() opens
|
// Enables read-only mode. After this call, openExistingFile() opens
|
||||||
// file in read-only mode. This is an optional functionality. The
|
// file in read-only mode. This is an optional functionality. The
|
||||||
|
|
|
@ -197,7 +197,7 @@ bool XmlParser::parseBinaryStream(BinaryStream* bs)
|
||||||
SessionData sessionData(psm_);
|
SessionData sessionData(psm_);
|
||||||
XML_Parser parser = createParser(&sessionData);
|
XML_Parser parser = createParser(&sessionData);
|
||||||
auto_delete<XML_Parser> deleter(parser, XML_ParserFree);
|
auto_delete<XML_Parser> deleter(parser, XML_ParserFree);
|
||||||
off_t readOffset = 0;
|
int64_t readOffset = 0;
|
||||||
while(1) {
|
while(1) {
|
||||||
ssize_t res = bs->readData(buf, bufSize, readOffset);
|
ssize_t res = bs->readData(buf, bufSize, readOffset);
|
||||||
if(res == 0) {
|
if(res == 0) {
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
FallocFileAllocationIterator::FallocFileAllocationIterator
|
FallocFileAllocationIterator::FallocFileAllocationIterator
|
||||||
(BinaryStream* stream, off_t offset, off_t totalLength):
|
(BinaryStream* stream, int64_t offset, int64_t totalLength):
|
||||||
stream_(stream), offset_(offset), totalLength_(totalLength) {}
|
stream_(stream), offset_(offset), totalLength_(totalLength) {}
|
||||||
|
|
||||||
void FallocFileAllocationIterator::allocateChunk()
|
void FallocFileAllocationIterator::allocateChunk()
|
||||||
|
@ -57,12 +57,12 @@ bool FallocFileAllocationIterator::finished()
|
||||||
return offset_ == totalLength_;
|
return offset_ == totalLength_;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t FallocFileAllocationIterator::getCurrentLength()
|
int64_t FallocFileAllocationIterator::getCurrentLength()
|
||||||
{
|
{
|
||||||
return offset_;
|
return offset_;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t FallocFileAllocationIterator::getTotalLength()
|
int64_t FallocFileAllocationIterator::getTotalLength()
|
||||||
{
|
{
|
||||||
return totalLength_;
|
return totalLength_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,19 +44,19 @@ namespace aria2 {
|
||||||
class FallocFileAllocationIterator:public FileAllocationIterator {
|
class FallocFileAllocationIterator:public FileAllocationIterator {
|
||||||
private:
|
private:
|
||||||
BinaryStream* stream_;
|
BinaryStream* stream_;
|
||||||
off_t offset_;
|
int64_t offset_;
|
||||||
off_t totalLength_;
|
int64_t totalLength_;
|
||||||
public:
|
public:
|
||||||
FallocFileAllocationIterator(BinaryStream* stream, off_t offset,
|
FallocFileAllocationIterator(BinaryStream* stream, int64_t offset,
|
||||||
off_t totalLength);
|
int64_t totalLength);
|
||||||
|
|
||||||
virtual void allocateChunk();
|
virtual void allocateChunk();
|
||||||
|
|
||||||
virtual bool finished();
|
virtual bool finished();
|
||||||
|
|
||||||
virtual off_t getCurrentLength();
|
virtual int64_t getCurrentLength();
|
||||||
|
|
||||||
virtual off_t getTotalLength();
|
virtual int64_t getTotalLength();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -49,12 +49,12 @@ FileAllocationEntry::FileAllocationEntry(RequestGroup* requestGroup, Command* ne
|
||||||
FileAllocationEntry:: ~FileAllocationEntry()
|
FileAllocationEntry:: ~FileAllocationEntry()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
off_t FileAllocationEntry::getCurrentLength()
|
int64_t FileAllocationEntry::getCurrentLength()
|
||||||
{
|
{
|
||||||
return fileAllocationIterator_->getCurrentLength();
|
return fileAllocationIterator_->getCurrentLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t FileAllocationEntry::getTotalLength()
|
int64_t FileAllocationEntry::getTotalLength()
|
||||||
{
|
{
|
||||||
return fileAllocationIterator_->getTotalLength();
|
return fileAllocationIterator_->getTotalLength();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,9 @@ public:
|
||||||
|
|
||||||
~FileAllocationEntry();
|
~FileAllocationEntry();
|
||||||
|
|
||||||
virtual off_t getCurrentLength();
|
virtual int64_t getCurrentLength();
|
||||||
|
|
||||||
virtual off_t getTotalLength();
|
virtual int64_t getTotalLength();
|
||||||
|
|
||||||
virtual bool finished();
|
virtual bool finished();
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,9 @@ public:
|
||||||
|
|
||||||
virtual bool finished() = 0;
|
virtual bool finished() = 0;
|
||||||
|
|
||||||
virtual off_t getCurrentLength() = 0;
|
virtual int64_t getCurrentLength() = 0;
|
||||||
|
|
||||||
virtual off_t getTotalLength() = 0;
|
virtual int64_t getTotalLength() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -92,7 +92,7 @@ bool IteratableChecksumValidator::finished() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t IteratableChecksumValidator::getTotalLength() const
|
int64_t IteratableChecksumValidator::getTotalLength() const
|
||||||
{
|
{
|
||||||
return dctx_->getTotalLength();
|
return dctx_->getTotalLength();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ private:
|
||||||
|
|
||||||
SharedHandle<PieceStorage> pieceStorage_;
|
SharedHandle<PieceStorage> pieceStorage_;
|
||||||
|
|
||||||
off_t currentOffset_;
|
int64_t currentOffset_;
|
||||||
|
|
||||||
SharedHandle<MessageDigest> ctx_;
|
SharedHandle<MessageDigest> ctx_;
|
||||||
public:
|
public:
|
||||||
|
@ -65,12 +65,12 @@ public:
|
||||||
|
|
||||||
virtual bool finished() const;
|
virtual bool finished() const;
|
||||||
|
|
||||||
virtual off_t getCurrentOffset() const
|
virtual int64_t getCurrentOffset() const
|
||||||
{
|
{
|
||||||
return currentOffset_;
|
return currentOffset_;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual off_t getTotalLength() const;
|
virtual int64_t getTotalLength() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<IteratableChecksumValidator> IteratableChecksumValidatorHandle;
|
typedef SharedHandle<IteratableChecksumValidator> IteratableChecksumValidatorHandle;
|
||||||
|
|
|
@ -101,7 +101,7 @@ void IteratableChunkChecksumValidator::validateChunk()
|
||||||
|
|
||||||
std::string IteratableChunkChecksumValidator::calculateActualChecksum()
|
std::string IteratableChunkChecksumValidator::calculateActualChecksum()
|
||||||
{
|
{
|
||||||
off_t offset = getCurrentOffset();
|
int64_t offset = getCurrentOffset();
|
||||||
size_t length;
|
size_t length;
|
||||||
// When validating last piece
|
// When validating last piece
|
||||||
if(currentIndex_+1 == dctx_->getNumPieces()) {
|
if(currentIndex_+1 == dctx_->getNumPieces()) {
|
||||||
|
@ -119,14 +119,14 @@ void IteratableChunkChecksumValidator::init()
|
||||||
currentIndex_ = 0;
|
currentIndex_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string IteratableChunkChecksumValidator::digest(off_t offset, size_t length)
|
std::string IteratableChunkChecksumValidator::digest(int64_t offset, size_t length)
|
||||||
{
|
{
|
||||||
unsigned char buf[4096];
|
unsigned char buf[4096];
|
||||||
ctx_->reset();
|
ctx_->reset();
|
||||||
off_t max = offset+length;
|
int64_t max = offset+length;
|
||||||
while(offset < max) {
|
while(offset < max) {
|
||||||
size_t r = pieceStorage_->getDiskAdaptor()->readData
|
size_t r = pieceStorage_->getDiskAdaptor()->readData
|
||||||
(buf, std::min(static_cast<off_t>(sizeof(buf)), max-offset), offset);
|
(buf, std::min(static_cast<int64_t>(sizeof(buf)), max-offset), offset);
|
||||||
if(r == 0) {
|
if(r == 0) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt(EX_FILE_READ, dctx_->getBasePath().c_str(),
|
(fmt(EX_FILE_READ, dctx_->getBasePath().c_str(),
|
||||||
|
@ -147,12 +147,12 @@ bool IteratableChunkChecksumValidator::finished() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t IteratableChunkChecksumValidator::getCurrentOffset() const
|
int64_t IteratableChunkChecksumValidator::getCurrentOffset() const
|
||||||
{
|
{
|
||||||
return static_cast<off_t>(currentIndex_)*dctx_->getPieceLength();
|
return static_cast<int64_t>(currentIndex_)*dctx_->getPieceLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t IteratableChunkChecksumValidator::getTotalLength() const
|
int64_t IteratableChunkChecksumValidator::getTotalLength() const
|
||||||
{
|
{
|
||||||
return dctx_->getTotalLength();
|
return dctx_->getTotalLength();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ private:
|
||||||
|
|
||||||
std::string calculateActualChecksum();
|
std::string calculateActualChecksum();
|
||||||
|
|
||||||
std::string digest(off_t offset, size_t length);
|
std::string digest(int64_t offset, size_t length);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IteratableChunkChecksumValidator(const SharedHandle<DownloadContext>& dctx,
|
IteratableChunkChecksumValidator(const SharedHandle<DownloadContext>& dctx,
|
||||||
|
@ -71,9 +71,9 @@ public:
|
||||||
|
|
||||||
virtual bool finished() const;
|
virtual bool finished() const;
|
||||||
|
|
||||||
virtual off_t getCurrentOffset() const;
|
virtual int64_t getCurrentOffset() const;
|
||||||
|
|
||||||
virtual off_t getTotalLength() const;
|
virtual int64_t getTotalLength() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<IteratableChunkChecksumValidator> IteratableChunkChecksumValidatorHandle;
|
typedef SharedHandle<IteratableChunkChecksumValidator> IteratableChunkChecksumValidatorHandle;
|
||||||
|
|
|
@ -60,9 +60,9 @@ public:
|
||||||
|
|
||||||
virtual bool finished() const = 0;
|
virtual bool finished() const = 0;
|
||||||
|
|
||||||
virtual off_t getCurrentOffset() const = 0;
|
virtual int64_t getCurrentOffset() const = 0;
|
||||||
|
|
||||||
virtual off_t getTotalLength() const = 0;
|
virtual int64_t getTotalLength() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<IteratableValidator> IteratableValidatorHandle;
|
typedef SharedHandle<IteratableValidator> IteratableValidatorHandle;
|
||||||
|
|
|
@ -46,13 +46,13 @@ JsonDiskWriter::JsonDiskWriter()
|
||||||
JsonDiskWriter::~JsonDiskWriter()
|
JsonDiskWriter::~JsonDiskWriter()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void JsonDiskWriter::initAndOpenFile(off_t totalLength)
|
void JsonDiskWriter::initAndOpenFile(int64_t totalLength)
|
||||||
{
|
{
|
||||||
parser_.reset();
|
parser_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonDiskWriter::writeData(const unsigned char* data, size_t len,
|
void JsonDiskWriter::writeData(const unsigned char* data, size_t len,
|
||||||
off_t offset)
|
int64_t offset)
|
||||||
{
|
{
|
||||||
// Return value is ignored here but handled in finalize()
|
// Return value is ignored here but handled in finalize()
|
||||||
parser_.parseUpdate(reinterpret_cast<const char*>(data), len);
|
parser_.parseUpdate(reinterpret_cast<const char*>(data), len);
|
||||||
|
|
|
@ -53,28 +53,28 @@ public:
|
||||||
|
|
||||||
virtual ~JsonDiskWriter();
|
virtual ~JsonDiskWriter();
|
||||||
|
|
||||||
virtual void initAndOpenFile(off_t totalLength = 0);
|
virtual void initAndOpenFile(int64_t totalLength = 0);
|
||||||
|
|
||||||
virtual void openFile(off_t totalLength = 0)
|
virtual void openFile(int64_t totalLength = 0)
|
||||||
{
|
{
|
||||||
initAndOpenFile(totalLength);
|
initAndOpenFile(totalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void closeFile() {}
|
virtual void closeFile() {}
|
||||||
|
|
||||||
virtual void openExistingFile(off_t totalLength = 0)
|
virtual void openExistingFile(int64_t totalLength = 0)
|
||||||
{
|
{
|
||||||
initAndOpenFile(totalLength);
|
initAndOpenFile(totalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual off_t size()
|
virtual int64_t size()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void writeData(const unsigned char* data, size_t len, off_t offset);
|
virtual void writeData(const unsigned char* data, size_t len, int64_t offset);
|
||||||
|
|
||||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset)
|
virtual ssize_t readData(unsigned char* data, size_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ bool DiskWriterEntry::fileExists()
|
||||||
return fileEntry_->exists();
|
return fileEntry_->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t DiskWriterEntry::size() const
|
int64_t DiskWriterEntry::size() const
|
||||||
{
|
{
|
||||||
return File(getFilePath()).size();
|
return File(getFilePath()).size();
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
||||||
++itr;
|
++itr;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
off_t pieceStartOffset =
|
int64_t pieceStartOffset =
|
||||||
(fileEntry->getOffset()/pieceLength_)*pieceLength_;
|
(fileEntry->getOffset()/pieceLength_)*pieceLength_;
|
||||||
if(itr != diskWriterEntries_.begin()) {
|
if(itr != diskWriterEntries_.begin()) {
|
||||||
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
||||||
|
@ -182,7 +182,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileEntry->getLength() > 0) {
|
if(fileEntry->getLength() > 0) {
|
||||||
off_t lastPieceStartOffset =
|
int64_t lastPieceStartOffset =
|
||||||
(fileEntry->getOffset()+fileEntry->getLength()-1)/
|
(fileEntry->getOffset()+fileEntry->getLength()-1)/
|
||||||
pieceLength_*pieceLength_;
|
pieceLength_*pieceLength_;
|
||||||
A2_LOG_DEBUG(fmt("Checking adjacent backward file to %s"
|
A2_LOG_DEBUG(fmt("Checking adjacent backward file to %s"
|
||||||
|
@ -201,7 +201,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
||||||
(*itr)->getFileEntry()->getPath().c_str(),
|
(*itr)->getFileEntry()->getPath().c_str(),
|
||||||
(*itr)->getFileEntry()->getOffset()));
|
(*itr)->getFileEntry()->getOffset()));
|
||||||
if((*itr)->getFileEntry()->getOffset() <
|
if((*itr)->getFileEntry()->getOffset() <
|
||||||
static_cast<off_t>(lastPieceStartOffset+pieceLength_)) {
|
lastPieceStartOffset+pieceLength_) {
|
||||||
A2_LOG_DEBUG
|
A2_LOG_DEBUG
|
||||||
(fmt("%s needs diskwriter",
|
(fmt("%s needs diskwriter",
|
||||||
(*itr)->getFileEntry()->getPath().c_str()));
|
(*itr)->getFileEntry()->getPath().c_str()));
|
||||||
|
@ -305,7 +305,7 @@ void MultiDiskAdaptor::closeFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool isInRange(const DiskWriterEntryHandle entry, off_t offset)
|
bool isInRange(const DiskWriterEntryHandle entry, int64_t offset)
|
||||||
{
|
{
|
||||||
return entry->getFileEntry()->getOffset() <= offset &&
|
return entry->getFileEntry()->getOffset() <= offset &&
|
||||||
offset < entry->getFileEntry()->getLastOffset();
|
offset < entry->getFileEntry()->getLastOffset();
|
||||||
|
@ -314,7 +314,7 @@ bool isInRange(const DiskWriterEntryHandle entry, off_t offset)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
ssize_t calculateLength(const DiskWriterEntryHandle entry,
|
ssize_t calculateLength(const DiskWriterEntryHandle entry,
|
||||||
off_t fileOffset, ssize_t rem)
|
int64_t fileOffset, ssize_t rem)
|
||||||
{
|
{
|
||||||
if(entry->getFileEntry()->getLength() < fileOffset+rem) {
|
if(entry->getFileEntry()->getLength() < fileOffset+rem) {
|
||||||
return entry->getFileEntry()->getLength()-fileOffset;
|
return entry->getFileEntry()->getLength()-fileOffset;
|
||||||
|
@ -327,7 +327,7 @@ ssize_t calculateLength(const DiskWriterEntryHandle entry,
|
||||||
namespace {
|
namespace {
|
||||||
class OffsetCompare {
|
class OffsetCompare {
|
||||||
public:
|
public:
|
||||||
bool operator()(off_t offset, const SharedHandle<DiskWriterEntry>& dwe)
|
bool operator()(int64_t offset, const SharedHandle<DiskWriterEntry>& dwe)
|
||||||
{
|
{
|
||||||
return offset < dwe->getFileEntry()->getOffset();
|
return offset < dwe->getFileEntry()->getOffset();
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ public:
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
DiskWriterEntries::const_iterator findFirstDiskWriterEntry
|
DiskWriterEntries::const_iterator findFirstDiskWriterEntry
|
||||||
(const DiskWriterEntries& diskWriterEntries, off_t offset)
|
(const DiskWriterEntries& diskWriterEntries, int64_t offset)
|
||||||
{
|
{
|
||||||
DiskWriterEntries::const_iterator first =
|
DiskWriterEntries::const_iterator first =
|
||||||
std::upper_bound(diskWriterEntries.begin(), diskWriterEntries.end(),
|
std::upper_bound(diskWriterEntries.begin(), diskWriterEntries.end(),
|
||||||
|
@ -355,7 +355,7 @@ DiskWriterEntries::const_iterator findFirstDiskWriterEntry
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
|
void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
|
||||||
off_t offset)
|
int64_t offset)
|
||||||
{
|
{
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt("DiskWriter for offset=%" PRId64 ", filename=%s is not opened.",
|
(fmt("DiskWriter for offset=%" PRId64 ", filename=%s is not opened.",
|
||||||
|
@ -365,13 +365,13 @@ void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
|
void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
|
||||||
off_t offset)
|
int64_t offset)
|
||||||
{
|
{
|
||||||
DiskWriterEntries::const_iterator first =
|
DiskWriterEntries::const_iterator first =
|
||||||
findFirstDiskWriterEntry(diskWriterEntries_, offset);
|
findFirstDiskWriterEntry(diskWriterEntries_, offset);
|
||||||
|
|
||||||
ssize_t rem = len;
|
ssize_t rem = len;
|
||||||
off_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
|
int64_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
|
||||||
for(DiskWriterEntries::const_iterator i = first,
|
for(DiskWriterEntries::const_iterator i = first,
|
||||||
eoi = diskWriterEntries_.end(); i != eoi; ++i) {
|
eoi = diskWriterEntries_.end(); i != eoi; ++i) {
|
||||||
ssize_t writeLength = calculateLength(*i, fileOffset, rem);
|
ssize_t writeLength = calculateLength(*i, fileOffset, rem);
|
||||||
|
@ -392,14 +392,14 @@ void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t MultiDiskAdaptor::readData
|
ssize_t MultiDiskAdaptor::readData
|
||||||
(unsigned char* data, size_t len, off_t offset)
|
(unsigned char* data, size_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
DiskWriterEntries::const_iterator first =
|
DiskWriterEntries::const_iterator first =
|
||||||
findFirstDiskWriterEntry(diskWriterEntries_, offset);
|
findFirstDiskWriterEntry(diskWriterEntries_, offset);
|
||||||
|
|
||||||
ssize_t rem = len;
|
ssize_t rem = len;
|
||||||
ssize_t totalReadLength = 0;
|
ssize_t totalReadLength = 0;
|
||||||
off_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
|
int64_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
|
||||||
for(DiskWriterEntries::const_iterator i = first,
|
for(DiskWriterEntries::const_iterator i = first,
|
||||||
eoi = diskWriterEntries_.end(); i != eoi; ++i) {
|
eoi = diskWriterEntries_.end(); i != eoi; ++i) {
|
||||||
ssize_t readLength = calculateLength(*i, fileOffset, rem);
|
ssize_t readLength = calculateLength(*i, fileOffset, rem);
|
||||||
|
@ -428,9 +428,9 @@ bool MultiDiskAdaptor::fileExists()
|
||||||
getFileEntries().end();
|
getFileEntries().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t MultiDiskAdaptor::size()
|
int64_t MultiDiskAdaptor::size()
|
||||||
{
|
{
|
||||||
off_t size = 0;
|
int64_t size = 0;
|
||||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||||
getFileEntries().begin(), eoi = getFileEntries().end(); i != eoi; ++i) {
|
getFileEntries().begin(), eoi = getFileEntries().end(); i != eoi; ++i) {
|
||||||
size += File((*i)->getPath()).size();
|
size += File((*i)->getPath()).size();
|
||||||
|
@ -464,9 +464,9 @@ void MultiDiskAdaptor::cutTrailingGarbage()
|
||||||
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
||||||
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
|
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
|
||||||
i != eoi; ++i) {
|
i != eoi; ++i) {
|
||||||
off_t length = (*i)->getFileEntry()->getLength();
|
int64_t length = (*i)->getFileEntry()->getLength();
|
||||||
if(File((*i)->getFilePath()).size() > length) {
|
if(File((*i)->getFilePath()).size() > length) {
|
||||||
// We need open file before calling DiskWriter::truncate(off_t)
|
// We need open file before calling DiskWriter::truncate(int64_t)
|
||||||
openIfNot(*i, &DiskWriterEntry::openFile);
|
openIfNot(*i, &DiskWriterEntry::openFile);
|
||||||
(*i)->getDiskWriter()->truncate(length);
|
(*i)->getDiskWriter()->truncate(length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
|
|
||||||
bool fileExists();
|
bool fileExists();
|
||||||
|
|
||||||
off_t size() const;
|
int64_t size() const;
|
||||||
|
|
||||||
const SharedHandle<FileEntry>& getFileEntry() const
|
const SharedHandle<FileEntry>& getFileEntry() const
|
||||||
{
|
{
|
||||||
|
@ -134,13 +134,13 @@ public:
|
||||||
virtual void closeFile();
|
virtual void closeFile();
|
||||||
|
|
||||||
virtual void writeData(const unsigned char* data, size_t len,
|
virtual void writeData(const unsigned char* data, size_t len,
|
||||||
off_t offset);
|
int64_t offset);
|
||||||
|
|
||||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset);
|
virtual ssize_t readData(unsigned char* data, size_t len, int64_t offset);
|
||||||
|
|
||||||
virtual bool fileExists();
|
virtual bool fileExists();
|
||||||
|
|
||||||
virtual off_t size();
|
virtual int64_t size();
|
||||||
|
|
||||||
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
|
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ bool MultiFileAllocationIterator::finished()
|
||||||
(!fileAllocationIterator_ || fileAllocationIterator_->finished());
|
(!fileAllocationIterator_ || fileAllocationIterator_->finished());
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t MultiFileAllocationIterator::getCurrentLength()
|
int64_t MultiFileAllocationIterator::getCurrentLength()
|
||||||
{
|
{
|
||||||
if(!fileAllocationIterator_) {
|
if(!fileAllocationIterator_) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -104,7 +104,7 @@ off_t MultiFileAllocationIterator::getCurrentLength()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t MultiFileAllocationIterator::getTotalLength()
|
int64_t MultiFileAllocationIterator::getTotalLength()
|
||||||
{
|
{
|
||||||
if(!fileAllocationIterator_) {
|
if(!fileAllocationIterator_) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -49,7 +49,7 @@ private:
|
||||||
MultiDiskAdaptor* diskAdaptor_;
|
MultiDiskAdaptor* diskAdaptor_;
|
||||||
std::deque<SharedHandle<DiskWriterEntry> > entries_;
|
std::deque<SharedHandle<DiskWriterEntry> > entries_;
|
||||||
SharedHandle<FileAllocationIterator> fileAllocationIterator_;
|
SharedHandle<FileAllocationIterator> fileAllocationIterator_;
|
||||||
off_t offset_;
|
int64_t offset_;
|
||||||
public:
|
public:
|
||||||
MultiFileAllocationIterator(MultiDiskAdaptor* diskAdaptor);
|
MultiFileAllocationIterator(MultiDiskAdaptor* diskAdaptor);
|
||||||
|
|
||||||
|
@ -59,9 +59,9 @@ public:
|
||||||
|
|
||||||
virtual bool finished();
|
virtual bool finished();
|
||||||
|
|
||||||
virtual off_t getCurrentLength();
|
virtual int64_t getCurrentLength();
|
||||||
|
|
||||||
virtual off_t getTotalLength();
|
virtual int64_t getTotalLength();
|
||||||
|
|
||||||
const std::deque<SharedHandle<DiskWriterEntry> >&
|
const std::deque<SharedHandle<DiskWriterEntry> >&
|
||||||
getDiskWriterEntries() const;
|
getDiskWriterEntries() const;
|
||||||
|
|
|
@ -48,9 +48,9 @@ class ProgressAwareEntry {
|
||||||
public:
|
public:
|
||||||
virtual ~ProgressAwareEntry() {}
|
virtual ~ProgressAwareEntry() {}
|
||||||
|
|
||||||
virtual off_t getCurrentLength() = 0;
|
virtual int64_t getCurrentLength() = 0;
|
||||||
|
|
||||||
virtual off_t getTotalLength() = 0;
|
virtual int64_t getTotalLength() = 0;
|
||||||
|
|
||||||
virtual bool finished() = 0;
|
virtual bool finished() = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,7 +51,7 @@ void ShareRatioSeedCriteria::reset() {}
|
||||||
|
|
||||||
bool ShareRatioSeedCriteria::evaluate()
|
bool ShareRatioSeedCriteria::evaluate()
|
||||||
{
|
{
|
||||||
off_t completedLength = pieceStorage_->getCompletedLength();
|
int64_t completedLength = pieceStorage_->getCompletedLength();
|
||||||
if(completedLength == 0) {
|
if(completedLength == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,8 @@ namespace aria2 {
|
||||||
|
|
||||||
SingleFileAllocationIterator::SingleFileAllocationIterator
|
SingleFileAllocationIterator::SingleFileAllocationIterator
|
||||||
(BinaryStream* stream,
|
(BinaryStream* stream,
|
||||||
off_t offset,
|
int64_t offset,
|
||||||
off_t totalLength)
|
int64_t totalLength)
|
||||||
: stream_(stream),
|
: stream_(stream),
|
||||||
offset_(offset),
|
offset_(offset),
|
||||||
totalLength_(totalLength),
|
totalLength_(totalLength),
|
||||||
|
|
|
@ -46,16 +46,16 @@ class SingleFileAllocationIterator:public FileAllocationIterator
|
||||||
private:
|
private:
|
||||||
BinaryStream* stream_;
|
BinaryStream* stream_;
|
||||||
|
|
||||||
off_t offset_;
|
int64_t offset_;
|
||||||
|
|
||||||
off_t totalLength_;
|
int64_t totalLength_;
|
||||||
|
|
||||||
unsigned char* buffer_;
|
unsigned char* buffer_;
|
||||||
public:
|
public:
|
||||||
SingleFileAllocationIterator
|
SingleFileAllocationIterator
|
||||||
(BinaryStream* stream,
|
(BinaryStream* stream,
|
||||||
off_t offset,
|
int64_t offset,
|
||||||
off_t totalLength);
|
int64_t totalLength);
|
||||||
|
|
||||||
virtual ~SingleFileAllocationIterator();
|
virtual ~SingleFileAllocationIterator();
|
||||||
|
|
||||||
|
@ -63,12 +63,12 @@ public:
|
||||||
|
|
||||||
virtual bool finished();
|
virtual bool finished();
|
||||||
|
|
||||||
virtual off_t getCurrentLength()
|
virtual int64_t getCurrentLength()
|
||||||
{
|
{
|
||||||
return offset_;
|
return offset_;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual off_t getTotalLength()
|
virtual int64_t getTotalLength()
|
||||||
{
|
{
|
||||||
return totalLength_;
|
return totalLength_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,13 @@ XmlRpcDiskWriter::XmlRpcDiskWriter()
|
||||||
XmlRpcDiskWriter::~XmlRpcDiskWriter()
|
XmlRpcDiskWriter::~XmlRpcDiskWriter()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void XmlRpcDiskWriter::initAndOpenFile(off_t totalLength)
|
void XmlRpcDiskWriter::initAndOpenFile(int64_t totalLength)
|
||||||
{
|
{
|
||||||
parser_.reset();
|
parser_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcDiskWriter::writeData(const unsigned char* data, size_t len,
|
void XmlRpcDiskWriter::writeData(const unsigned char* data, size_t len,
|
||||||
off_t offset)
|
int64_t offset)
|
||||||
{
|
{
|
||||||
// Return value is ignored here but handled in finalize()
|
// Return value is ignored here but handled in finalize()
|
||||||
parser_.parseUpdate(reinterpret_cast<const char*>(data), len);
|
parser_.parseUpdate(reinterpret_cast<const char*>(data), len);
|
||||||
|
|
|
@ -54,28 +54,28 @@ public:
|
||||||
|
|
||||||
virtual ~XmlRpcDiskWriter();
|
virtual ~XmlRpcDiskWriter();
|
||||||
|
|
||||||
virtual void initAndOpenFile(off_t totalLength = 0);
|
virtual void initAndOpenFile(int64_t totalLength = 0);
|
||||||
|
|
||||||
virtual void openFile(off_t totalLength = 0)
|
virtual void openFile(int64_t totalLength = 0)
|
||||||
{
|
{
|
||||||
initAndOpenFile(totalLength);
|
initAndOpenFile(totalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void closeFile() {}
|
virtual void closeFile() {}
|
||||||
|
|
||||||
virtual void openExistingFile(off_t totalLength = 0)
|
virtual void openExistingFile(int64_t totalLength = 0)
|
||||||
{
|
{
|
||||||
initAndOpenFile(totalLength);
|
initAndOpenFile(totalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual off_t size()
|
virtual int64_t size()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void writeData(const unsigned char* data, size_t len, off_t offset);
|
virtual void writeData(const unsigned char* data, size_t len, int64_t offset);
|
||||||
|
|
||||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset)
|
virtual ssize_t readData(unsigned char* data, size_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,7 +249,7 @@ void extractFileEntries
|
||||||
error_code::BITTORRENT_PARSE_ERROR);
|
error_code::BITTORRENT_PARSE_ERROR);
|
||||||
}
|
}
|
||||||
length += fileLengthData->i();
|
length += fileLengthData->i();
|
||||||
if(length > std::numeric_limits<off_t>::max()) {
|
if(fileLengthData->i() > std::numeric_limits<off_t>::max()) {
|
||||||
throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, length));
|
throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, length));
|
||||||
}
|
}
|
||||||
std::string pathKey;
|
std::string pathKey;
|
||||||
|
|
|
@ -66,7 +66,7 @@ void staticSHA1DigestFree()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string staticSHA1Digest
|
std::string staticSHA1Digest
|
||||||
(const BinaryStreamHandle& bs, off_t offset, off_t length)
|
(const BinaryStreamHandle& bs, int64_t offset, int64_t length)
|
||||||
{
|
{
|
||||||
sha1Ctx_->reset();
|
sha1Ctx_->reset();
|
||||||
return digest(sha1Ctx_, bs, offset, length);
|
return digest(sha1Ctx_, bs, offset, length);
|
||||||
|
@ -75,7 +75,7 @@ std::string staticSHA1Digest
|
||||||
std::string digest
|
std::string digest
|
||||||
(const SharedHandle<MessageDigest>& ctx,
|
(const SharedHandle<MessageDigest>& ctx,
|
||||||
const SharedHandle<BinaryStream>& bs,
|
const SharedHandle<BinaryStream>& bs,
|
||||||
off_t offset, off_t length)
|
int64_t offset, int64_t length)
|
||||||
{
|
{
|
||||||
size_t BUFSIZE = 4096;
|
size_t BUFSIZE = 4096;
|
||||||
unsigned char BUF[BUFSIZE];
|
unsigned char BUF[BUFSIZE];
|
||||||
|
|
|
@ -63,7 +63,7 @@ void staticSHA1DigestInit();
|
||||||
void staticSHA1DigestFree();
|
void staticSHA1DigestFree();
|
||||||
|
|
||||||
std::string staticSHA1Digest
|
std::string staticSHA1Digest
|
||||||
(const SharedHandle<BinaryStream>& bs, off_t offset, off_t length);
|
(const SharedHandle<BinaryStream>& bs, int64_t offset, int64_t length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ctx must be initialized or reseted before calling this function.
|
* ctx must be initialized or reseted before calling this function.
|
||||||
|
@ -72,7 +72,7 @@ std::string staticSHA1Digest
|
||||||
std::string digest
|
std::string digest
|
||||||
(const SharedHandle<MessageDigest>& ctx,
|
(const SharedHandle<MessageDigest>& ctx,
|
||||||
const SharedHandle<BinaryStream>& bs,
|
const SharedHandle<BinaryStream>& bs,
|
||||||
off_t offset, off_t length);
|
int64_t offset, int64_t length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores *raw* message digest into md.
|
* Stores *raw* message digest into md.
|
||||||
|
|
|
@ -145,7 +145,7 @@ SharedHandle<Metalinker> parseBinaryStream
|
||||||
xml::XmlParser ps(&psm);
|
xml::XmlParser ps(&psm);
|
||||||
unsigned char buf[4096];
|
unsigned char buf[4096];
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
off_t offread = 0;
|
int64_t offread = 0;
|
||||||
bool retval = true;
|
bool retval = true;
|
||||||
while((nread = bs->readData(buf, sizeof(buf), offread)) > 0) {
|
while((nread = bs->readData(buf, sizeof(buf), offread)) > 0) {
|
||||||
if(ps.parseUpdate(reinterpret_cast<const char*>(buf), nread) < 0) {
|
if(ps.parseUpdate(reinterpret_cast<const char*>(buf), nread) < 0) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ void ByteArrayDiskWriterTest::testWriteAndRead() {
|
||||||
buf[c] = '\0';
|
buf[c] = '\0';
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("ello World !!"), std::string(buf));
|
CPPUNIT_ASSERT_EQUAL(std::string("ello World !!"), std::string(buf));
|
||||||
CPPUNIT_ASSERT_EQUAL((off_t)14, bw.size());
|
CPPUNIT_ASSERT_EQUAL((int64_t)14, bw.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteArrayDiskWriterTest::testWriteAndRead2() {
|
void ByteArrayDiskWriterTest::testWriteAndRead2() {
|
||||||
|
@ -59,7 +59,7 @@ void ByteArrayDiskWriterTest::testWriteAndRead2() {
|
||||||
buf[c] = '\0';
|
buf[c] = '\0';
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Hello From Mars"), std::string(buf));
|
CPPUNIT_ASSERT_EQUAL(std::string("Hello From Mars"), std::string(buf));
|
||||||
CPPUNIT_ASSERT_EQUAL((off_t)15, bw.size());
|
CPPUNIT_ASSERT_EQUAL((int64_t)15, bw.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -25,7 +25,7 @@ void DefaultDiskWriterTest::testSize()
|
||||||
DefaultDiskWriter dw(A2_TEST_DIR"/4096chunk.txt");
|
DefaultDiskWriter dw(A2_TEST_DIR"/4096chunk.txt");
|
||||||
dw.enableReadOnly();
|
dw.enableReadOnly();
|
||||||
dw.openExistingFile();
|
dw.openExistingFile();
|
||||||
CPPUNIT_ASSERT_EQUAL((off_t)4096LL, dw.size());
|
CPPUNIT_ASSERT_EQUAL((int64_t)4096LL, dw.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -413,7 +413,7 @@ void MultiDiskAdaptorTest::testSize()
|
||||||
|
|
||||||
adaptor.openFile();
|
adaptor.openFile();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((off_t)2, adaptor.size());
|
CPPUNIT_ASSERT_EQUAL((int64_t)2, adaptor.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiDiskAdaptorTest::testUtime()
|
void MultiDiskAdaptorTest::testUtime()
|
||||||
|
|
|
@ -35,8 +35,8 @@ void SingleFileAllocationIteratorTest::testAllocate()
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)10, x.size());
|
CPPUNIT_ASSERT_EQUAL((int64_t)10, x.size());
|
||||||
|
|
||||||
DefaultDiskWriter writer(fn);
|
DefaultDiskWriter writer(fn);
|
||||||
off_t offset = 10;
|
int64_t offset = 10;
|
||||||
off_t totalLength = 16*1024*2+8*1024;
|
int64_t totalLength = 16*1024*2+8*1024;
|
||||||
|
|
||||||
// we have to open file first.
|
// we have to open file first.
|
||||||
writer.openExistingFile();
|
writer.openExistingFile();
|
||||||
|
|
Loading…
Reference in New Issue