From 5f2185ea05ee86e4e7f244269242934807b6dfba Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Sat, 10 Jul 2004 17:55:21 +0000 Subject: [PATCH] Fix for large (i.e. > 4GB) image bug; was rather stupidly using uint32s as byte offsets into the file in a number of places. I am a jackass. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8368 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/makeudfimage/Allocator.cpp | 22 ++++- src/apps/bin/makeudfimage/Allocator.h | 2 +- .../PhysicalPartitionAllocator.cpp | 23 +++-- .../makeudfimage/PhysicalPartitionAllocator.h | 2 +- src/apps/bin/makeudfimage/SimulatedStream.cpp | 5 +- src/apps/bin/makeudfimage/Statistics.h | 4 +- src/apps/bin/makeudfimage/UdfBuilder.cpp | 96 +++++++++---------- src/apps/bin/makeudfimage/UdfBuilder.h | 2 +- 8 files changed, 91 insertions(+), 65 deletions(-) diff --git a/src/apps/bin/makeudfimage/Allocator.cpp b/src/apps/bin/makeudfimage/Allocator.cpp index 4b5ec94232..1eb0d6ed64 100644 --- a/src/apps/bin/makeudfimage/Allocator.cpp +++ b/src/apps/bin/makeudfimage/Allocator.cpp @@ -102,7 +102,7 @@ Allocator::GetExtent(Udf::extent_address extent) return B_OK; } } - // No matching chunk found, we're SOL. + // No matching chunk found, we're SOL. error = B_ERROR; } } @@ -157,9 +157,11 @@ Allocator::GetNextExtent(uint32 _length, bool contiguous, Udf::extent_address &extent, uint32 minimumStartingBlock) { + DEBUG_INIT_ETC("Allocator", ("length: %lld, contiguous: %d", _length, contiguous)); uint32 length = BlocksFor(_length); bool isPartial = false; status_t error = InitCheck(); + PRINT(("allocation length: %lu\n", Length())); if (!error) { for (list::iterator i = fChunkList.begin(); i != fChunkList.end(); @@ -213,7 +215,9 @@ Allocator::GetNextExtent(uint32 _length, bool contiguous, } } // No sufficient chunk found, so try to allocate from the tail - uint32 maxLength = BlocksFor(ULONG_MAX)-Length(); + PRINT(("ULONG_MAX: %lu\n", ULONG_MAX)); + uint32 maxLength = ULONG_MAX-Length(); + PRINT(("maxLength: %lu\n", maxLength)); error = maxLength > 0 ? B_OK : B_DEVICE_FULL; if (!error) { if (minimumStartingBlock > Tail()) @@ -243,16 +247,26 @@ Allocator::GetNextExtent(uint32 _length, bool contiguous, given number of bytes. */ uint32 -Allocator::BlocksFor(uint32 bytes) +Allocator::BlocksFor(off_t bytes) { if (BlockSize() == 0) { DEBUG_INIT_ETC("Allocator", ("bytes: %ld\n", bytes)); PRINT(("WARNING: Allocator::BlockSize() == 0!\n")); return 0; } else { - uint32 blocks = bytes / BlockSize(); + off_t blocks = bytes >> BlockShift(); if (bytes % BlockSize() != 0) blocks++; + uint64 mask = 0xffffffff; + mask <<= 32; + if (blocks & mask) { + // ToDo: Convert this to actually signal an error + DEBUG_INIT_ETC("Allocator", ("bytes: %ld\n", bytes)); + PRINT(("WARNING: bytes argument too large for corresponding number " + "of blocks to be specified with a uint32! (bytes: %Ld, blocks: %Ld, " + "maxblocks: %ld).\n", bytes, blocks, ULONG_MAX)); + blocks = 0; + } return blocks; } } diff --git a/src/apps/bin/makeudfimage/Allocator.h b/src/apps/bin/makeudfimage/Allocator.h index fc7e4894b7..b5618b9360 100644 --- a/src/apps/bin/makeudfimage/Allocator.h +++ b/src/apps/bin/makeudfimage/Allocator.h @@ -40,7 +40,7 @@ public: uint32 BlockSize() const { return fBlockSize; } uint32 BlockShift() const { return fBlockShift; } - uint32 BlocksFor(uint32 bytes); + uint32 BlocksFor(off_t bytes); private: list fChunkList; uint32 fLength; //!< Length of allocation so far, in blocks. diff --git a/src/apps/bin/makeudfimage/PhysicalPartitionAllocator.cpp b/src/apps/bin/makeudfimage/PhysicalPartitionAllocator.cpp index f4ef6ecb7a..ebcefbe8b1 100644 --- a/src/apps/bin/makeudfimage/PhysicalPartitionAllocator.cpp +++ b/src/apps/bin/makeudfimage/PhysicalPartitionAllocator.cpp @@ -96,9 +96,10 @@ PhysicalPartitionAllocator::GetNextExtent(uint32 length, - error code: Failure. */ status_t -PhysicalPartitionAllocator::GetNextExtents(uint32 length, std::list &extents, +PhysicalPartitionAllocator::GetNextExtents(off_t length, std::list &extents, std::list &physicalExtents) { + DEBUG_INIT_ETC("PhysicalPartitionAllocator", ("length: %lld", length)); extents.empty(); physicalExtents.empty(); @@ -107,20 +108,28 @@ PhysicalPartitionAllocator::GetNextExtents(uint32 length, std::list= length) { - // All done - break; + if (physicalExtent.length() > chunkLength) { + // This should never happen, but just to be safe + PRINT(("ERROR: allocated extent length longer than requested " + " extent length (allocated: %ld, requested: %ld)\n", + physicalExtent.length(), chunkLength)); + error = B_ERROR; } else { - // More to go + // ToDo: Might want to add some checks for 0 length allocations here length -= physicalExtent.length(); + if (length == 0) { + // All done + break; + } } } } - return error; + RETURN(error); } /*! \brief Returns the length of the partition in blocks. diff --git a/src/apps/bin/makeudfimage/PhysicalPartitionAllocator.h b/src/apps/bin/makeudfimage/PhysicalPartitionAllocator.h index 1cfbc18926..ff93a420cc 100644 --- a/src/apps/bin/makeudfimage/PhysicalPartitionAllocator.h +++ b/src/apps/bin/makeudfimage/PhysicalPartitionAllocator.h @@ -27,7 +27,7 @@ public: status_t GetNextBlock(uint32 &block, uint32 &physicalBlock); status_t GetNextExtent(uint32 length, bool contiguous, Udf::long_address &extent, Udf::extent_address &physicalExtent = dummyExtent); - status_t GetNextExtents(uint32 length, std::list &extents, + status_t GetNextExtents(off_t length, std::list &extents, std::list &physicalExtents); diff --git a/src/apps/bin/makeudfimage/SimulatedStream.cpp b/src/apps/bin/makeudfimage/SimulatedStream.cpp index 27ceb107b8..2506b3e62d 100644 --- a/src/apps/bin/makeudfimage/SimulatedStream.cpp +++ b/src/apps/bin/makeudfimage/SimulatedStream.cpp @@ -13,6 +13,7 @@ #include #include #include +#include "UdfDebug.h" SimulatedStream::SimulatedStream(DataStream &stream) : fPosition(0) @@ -154,6 +155,7 @@ SimulatedStream::WriteAt(off_t pos, const void *_buffer, size_t size) ssize_t SimulatedStream::Write(BDataIO &data, size_t size) { + DEBUG_INIT_ETC("SimulatedStream", ("size: %ld", size)); status_t error = B_OK; ssize_t bytesTotal = 0; while (error == B_OK && size > 0) { @@ -161,6 +163,7 @@ SimulatedStream::Write(BDataIO &data, size_t size) error = _GetExtent(fPosition, size, extent); if (!error) { if (extent.size > 0) { + PRINT(("writing to underlying stream (offset: %llu, size: %ld)\n", extent.offset, extent.size)); ssize_t bytes = fStream.WriteAt(extent.offset, data, extent.size); if (bytes >= 0) { size -= bytes; @@ -175,7 +178,7 @@ SimulatedStream::Write(BDataIO &data, size_t size) } } } - return !error ? bytesTotal : ssize_t(error); + RETURN(!error ? bytesTotal : ssize_t(error)); } /*! \brief Writes \a size bytes worth of data from \a data at position diff --git a/src/apps/bin/makeudfimage/Statistics.h b/src/apps/bin/makeudfimage/Statistics.h index 7aa8810e3f..028a42c77f 100644 --- a/src/apps/bin/makeudfimage/Statistics.h +++ b/src/apps/bin/makeudfimage/Statistics.h @@ -33,8 +33,8 @@ public: void AddSymlink() { fSymlinks++; } void AddAttribute() { fAttributes++; } - void AddDirectoryBytes(uint32 count) { fDirectoryBytes += count; } - void AddFileBytes(uint32 count) { fFileBytes += count; } + void AddDirectoryBytes(uint64 count) { fDirectoryBytes += count; } + void AddFileBytes(uint64 count) { fFileBytes += count; } void SetImageSize(uint64 size) { fImageSize = size; } diff --git a/src/apps/bin/makeudfimage/UdfBuilder.cpp b/src/apps/bin/makeudfimage/UdfBuilder.cpp index ddc2f4f23e..5e85d29a4e 100644 --- a/src/apps/bin/makeudfimage/UdfBuilder.cpp +++ b/src/apps/bin/makeudfimage/UdfBuilder.cpp @@ -81,7 +81,7 @@ UdfBuilder::UdfBuilder(const char *outputFile, uint32 blockSize, bool doUdf, const char *isoVolumeName, const char *rootDirectory, const ProgressListener &listener) : fInitStatus(B_NO_INIT) - , fOutputFile(outputFile, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE) + , fOutputFile(outputFile, B_READ_WRITE | B_CREATE_FILE)// | B_ERASE_FILE) , fOutputFilename(outputFile) , fBlockSize(blockSize) , fBlockShift(0) @@ -335,11 +335,11 @@ UdfBuilder::Build() // reserve primary vds (min length = 16 blocks, which is plenty for us) if (!error) { _PrintUpdate(VERBOSITY_HIGH, "udf: Reserving space for primary vds"); - error = _Allocator().GetNextExtent(16 << _BlockShift(), true, primaryVdsExtent); + error = _Allocator().GetNextExtent(off_t(16) << _BlockShift(), true, primaryVdsExtent); if (!error) { _PrintUpdate(VERBOSITY_HIGH, "udf: (location: %ld, length: %ld)", primaryVdsExtent.location(), primaryVdsExtent.length()); - ssize_t bytes = _OutputFile().ZeroAt(primaryVdsExtent.location() << _BlockShift(), + ssize_t bytes = _OutputFile().ZeroAt(off_t(primaryVdsExtent.location()) << _BlockShift(), primaryVdsExtent.length()); error = check_size_error(bytes, primaryVdsExtent.length()); } @@ -351,14 +351,14 @@ UdfBuilder::Build() if (!error) { _PrintUpdate(VERBOSITY_HIGH, "udf: Reserving space for reserve vds"); reserveVdsExtent.set_location(256-16); - reserveVdsExtent.set_length(16 << _BlockShift()); + reserveVdsExtent.set_length(off_t(16) << _BlockShift()); error = _Allocator().GetExtent(reserveVdsExtent); if (error) - error = _Allocator().GetNextExtent(16 << _BlockShift(), true, reserveVdsExtent); + error = _Allocator().GetNextExtent(off_t(16) << _BlockShift(), true, reserveVdsExtent); if (!error) { _PrintUpdate(VERBOSITY_HIGH, "udf: (location: %ld, length: %ld)", reserveVdsExtent.location(), reserveVdsExtent.length()); - ssize_t bytes = _OutputFile().ZeroAt(reserveVdsExtent.location() << _BlockShift(), + ssize_t bytes = _OutputFile().ZeroAt(off_t(reserveVdsExtent.location()) << _BlockShift(), reserveVdsExtent.length()); error = check_size_error(bytes, reserveVdsExtent.length()); } @@ -373,7 +373,7 @@ UdfBuilder::Build() tag.set_serial_number(0); tag.set_location(256); tag.set_checksums(anchor256); - _OutputFile().Seek(256 << _BlockShift(), SEEK_SET); + _OutputFile().Seek(off_t(256) << _BlockShift(), SEEK_SET); ssize_t bytes = _OutputFile().Write(&anchor256, sizeof(anchor256)); error = check_size_error(bytes, sizeof(anchor256)); if (!error && bytes < ssize_t(_BlockSize())) { @@ -439,12 +439,12 @@ UdfBuilder::Build() // write primary_vd to primary vds primary.tag().set_location(primaryVdsExtent.location()+vdsNumber); primary.tag().set_checksums(primary); - ssize_t bytes = _OutputFile().WriteAt(primary.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(primary.tag().location()) << _BlockShift(), &primary, sizeof(primary)); error = check_size_error(bytes, sizeof(primary)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((primary.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(primary.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -452,12 +452,12 @@ UdfBuilder::Build() if (!error) { primary.tag().set_location(reserveVdsExtent.location()+vdsNumber); primary.tag().set_checksums(primary); - ssize_t bytes = _OutputFile().WriteAt(primary.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(primary.tag().location()) << _BlockShift(), &primary, sizeof(primary)); error = check_size_error(bytes, sizeof(primary)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((primary.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt(off_t((primary.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -499,12 +499,12 @@ UdfBuilder::Build() // write partition descriptor to primary vds partition.tag().set_location(primaryVdsExtent.location()+vdsNumber); partition.tag().set_checksums(partition); - ssize_t bytes = _OutputFile().WriteAt(partition.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(partition.tag().location()) << _BlockShift(), &partition, sizeof(partition)); error = check_size_error(bytes, sizeof(partition)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((partition.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(partition.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -512,12 +512,12 @@ UdfBuilder::Build() if (!error) { partition.tag().set_location(reserveVdsExtent.location()+vdsNumber); partition.tag().set_checksums(partition); - ssize_t bytes = _OutputFile().WriteAt(partition.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(partition.tag().location()) << _BlockShift(), &partition, sizeof(partition)); error = check_size_error(bytes, sizeof(partition)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((partition.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(partition.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -542,12 +542,12 @@ UdfBuilder::Build() // write freespace descriptor to primary vds freespace.tag().set_location(primaryVdsExtent.location()+vdsNumber); freespace.tag().set_checksums(freespace); - ssize_t bytes = _OutputFile().WriteAt(freespace.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(freespace.tag().location()) << _BlockShift(), &freespace, sizeof(freespace)); error = check_size_error(bytes, sizeof(freespace)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((freespace.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(freespace.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -555,12 +555,12 @@ UdfBuilder::Build() if (!error) { freespace.tag().set_location(reserveVdsExtent.location()+vdsNumber); freespace.tag().set_checksums(freespace); - ssize_t bytes = _OutputFile().WriteAt(freespace.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(freespace.tag().location()) << _BlockShift(), &freespace, sizeof(freespace)); error = check_size_error(bytes, sizeof(freespace)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((freespace.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(freespace.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -631,12 +631,12 @@ UdfBuilder::Build() uint32 logicalSize = Udf::kLogicalVolumeDescriptorBaseSize + sizeof(map); logical.tag().set_location(primaryVdsExtent.location()+vdsNumber); logical.tag().set_checksums(logical, logicalSize); - ssize_t bytes = _OutputFile().WriteAt(logical.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(logical.tag().location()) << _BlockShift(), &logical, logicalSize); error = check_size_error(bytes, logicalSize); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((logical.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(logical.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -644,12 +644,12 @@ UdfBuilder::Build() if (!error) { logical.tag().set_location(reserveVdsExtent.location()+vdsNumber); logical.tag().set_checksums(logical, logicalSize); - ssize_t bytes = _OutputFile().WriteAt(logical.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(logical.tag().location()) << _BlockShift(), &logical, sizeof(logical)); error = check_size_error(bytes, sizeof(logical)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((logical.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(logical.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -707,13 +707,13 @@ UdfBuilder::Build() // write implementationUse descriptor to primary vds implementationUse.tag().set_location(primaryVdsExtent.location()+vdsNumber); implementationUse.tag().set_checksums(implementationUse); - bytes = _OutputFile().WriteAt(implementationUse.tag().location() << _BlockShift(), + bytes = _OutputFile().WriteAt(off_t(implementationUse.tag().location()) << _BlockShift(), &implementationUse, sizeof(implementationUse)); error = check_size_error(bytes, sizeof(implementationUse)); } if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((implementationUse.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(implementationUse.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -721,12 +721,12 @@ UdfBuilder::Build() if (!error) { implementationUse.tag().set_location(reserveVdsExtent.location()+vdsNumber); implementationUse.tag().set_checksums(implementationUse); - ssize_t bytes = _OutputFile().WriteAt(implementationUse.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(implementationUse.tag().location()) << _BlockShift(), &implementationUse, sizeof(implementationUse)); error = check_size_error(bytes, sizeof(implementationUse)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((implementationUse.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(implementationUse.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -746,12 +746,12 @@ UdfBuilder::Build() // write terminator to primary vds terminator.tag().set_location(primaryVdsExtent.location()+vdsNumber); terminator.tag().set_checksums(terminator); - ssize_t bytes = _OutputFile().WriteAt(terminator.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(terminator.tag().location()) << _BlockShift(), &terminator, sizeof(terminator)); error = check_size_error(bytes, sizeof(terminator)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((terminator.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(terminator.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -759,12 +759,12 @@ UdfBuilder::Build() if (!error) { terminator.tag().set_location(reserveVdsExtent.location()+vdsNumber); terminator.tag().set_checksums(terminator); - ssize_t bytes = _OutputFile().WriteAt(terminator.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(terminator.tag().location()) << _BlockShift(), &terminator, sizeof(terminator)); error = check_size_error(bytes, sizeof(terminator)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((terminator.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(terminator.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -815,12 +815,12 @@ UdfBuilder::Build() fileset.tag().set_checksums(fileset); DUMP(fileset); // write fsd - ssize_t bytes = _OutputFile().WriteAt(filesetExtent.location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(filesetExtent.location()) << _BlockShift(), &fileset, sizeof(fileset)); error = check_size_error(bytes, sizeof(fileset)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((filesetExtent.location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(filesetExtent.location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -845,12 +845,12 @@ UdfBuilder::Build() fileset.tag().set_checksums(fileset); DUMP(fileset); // write fsd - ssize_t bytes = _OutputFile().WriteAt(filesetExtent.location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(filesetExtent.location()) << _BlockShift(), &fileset, sizeof(fileset)); error = check_size_error(bytes, sizeof(fileset)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((filesetExtent.location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(filesetExtent.location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -864,12 +864,12 @@ UdfBuilder::Build() // write partition descriptor to primary vds partition.tag().set_location(primaryVdsExtent.location()+partition.vds_number()); partition.tag().set_checksums(partition); - ssize_t bytes = _OutputFile().WriteAt(partition.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(partition.tag().location()) << _BlockShift(), &partition, sizeof(partition)); error = check_size_error(bytes, sizeof(partition)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((partition.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(partition.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -877,12 +877,12 @@ UdfBuilder::Build() if (!error) { partition.tag().set_location(reserveVdsExtent.location()+partition.vds_number()); partition.tag().set_checksums(partition); - ssize_t bytes = _OutputFile().WriteAt(partition.tag().location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(partition.tag().location()) << _BlockShift(), &partition, sizeof(partition)); error = check_size_error(bytes, sizeof(partition)); if (!error && bytes < ssize_t(_BlockSize())) { ssize_t bytesLeft = _BlockSize() - bytes; - bytes = _OutputFile().ZeroAt((partition.tag().location() << _BlockShift()) + bytes = _OutputFile().ZeroAt((off_t(partition.tag().location()) << _BlockShift()) + bytes, bytesLeft); error = check_size_error(bytes, bytesLeft); } @@ -929,7 +929,7 @@ UdfBuilder::Build() lvid->tag().set_checksums(*lvid, lvid->descriptor_size()); PDUMP(lvid); // write lvid - ssize_t bytes = _OutputFile().WriteAt(integrityExtent.location() << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t(integrityExtent.location()) << _BlockShift(), lvid, _BlockSize()); error = check_size_error(bytes, _BlockSize()); } @@ -945,7 +945,7 @@ UdfBuilder::Build() terminator->tag().set_checksums(*terminator); PDUMP(terminator); // write terminator - ssize_t bytes = _OutputFile().WriteAt((integrityExtent.location()+1) << _BlockShift(), + ssize_t bytes = _OutputFile().WriteAt(off_t((integrityExtent.location()+1)) << _BlockShift(), terminator, _BlockSize()); error = check_size_error(bytes, _BlockSize()); } @@ -969,7 +969,7 @@ UdfBuilder::Build() tag.set_serial_number(0); tag.set_location(blockN); tag.set_checksums(anchorN); - _OutputFile().Seek(blockN << _BlockShift(), SEEK_SET); + _OutputFile().Seek(off_t(blockN) << _BlockShift(), SEEK_SET); ssize_t bytes = _OutputFile().Write(&anchorN, sizeof(anchorN)); error = check_size_error(bytes, sizeof(anchorN)); if (!error && bytes < ssize_t(_BlockSize())) { @@ -1427,10 +1427,10 @@ UdfBuilder::_ProcessFile(BEntry &entry, const char *path, struct stat stats, { DEBUG_INIT_ETC("UdfBuilder", ("path: `%s'", path)); status_t error = entry.InitCheck() == B_OK && path ? B_OK : B_BAD_VALUE; - uint32 udfDataLength = stats.st_size; - if (!error && stats.st_size > ULONG_MAX) { - _PrintError("File `%s' too large (filesize: %Lu bytes, max: %lu bytes)", - path, stats.st_size, ULONG_MAX); + off_t udfDataLength = stats.st_size; + if (udfDataLength > ULONG_MAX && _DoIso()) { + _PrintError("File `%s' too large for iso9660 filesystem (filesize: %Lu bytes, max: %lu bytes)", + path, udfDataLength, ULONG_MAX); error = B_ERROR; } if (!error) { @@ -1476,7 +1476,7 @@ UdfBuilder::_ProcessFile(BEntry &entry, const char *path, struct stat stats, } else { // Udf can handle multiple extents if necessary error = _PartitionAllocator().GetNextExtents(udfDataLength, udfDataAddresses, - udfDataExtents); + udfDataExtents); } if (!error) { int extents = udfDataAddresses.size(); @@ -1549,7 +1549,7 @@ UdfBuilder::_ProcessFile(BEntry &entry, const char *path, struct stat stats, if (!error) { _Stats().AddFile(); - uint32 totalLength = udfDataLength + _BlockSize(); + off_t totalLength = udfDataLength + _BlockSize(); _Stats().AddFileBytes(totalLength); } RETURN(error); diff --git a/src/apps/bin/makeudfimage/UdfBuilder.h b/src/apps/bin/makeudfimage/UdfBuilder.h index 35615554b1..5b6cf4dd1a 100644 --- a/src/apps/bin/makeudfimage/UdfBuilder.h +++ b/src/apps/bin/makeudfimage/UdfBuilder.h @@ -194,7 +194,7 @@ UdfBuilder::_WriteFileEntry(FileEntry *icb, uint8 fileType, uint16 linkCount, if (!error) { _PrintUpdate(VERBOSITY_MEDIUM, "udf: Writing icb"); // write icb - _OutputFile().Seek(icbExtent.location() << _BlockShift(), SEEK_SET); + _OutputFile().Seek(off_t(icbExtent.location()) << _BlockShift(), SEEK_SET); PRINT(("position, icbsize: %Ld, %ld\n", _OutputFile().Position(), sizeof(icb))); ssize_t bytes = _OutputFile().Write(icb, _BlockSize()); PRINT(("position: %Ld\n", _OutputFile().Position()));