- %lld -> %Ld

- Patched up address mapping to work properly with multisession volumes


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4750 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder 2003-09-18 07:32:57 +00:00
parent eaa70c976c
commit bb182cf309
2 changed files with 30 additions and 25 deletions

View File

@ -23,7 +23,7 @@ Volume::Volume(nspace_id id)
: fId(id) : fId(id)
, fDevice(0) , fDevice(0)
, fReadOnly(false) , fReadOnly(false)
, fStart(0) , fOffset(0)
, fBlockSize(0) , fBlockSize(0)
, fBlockShift(0) , fBlockShift(0)
, fInitStatus(B_UNINITIALIZED) , fInitStatus(B_UNINITIALIZED)
@ -37,7 +37,7 @@ status_t
Volume::Identify(int device, off_t offset, off_t length, uint32 blockSize, char *volumeName) Volume::Identify(int device, off_t offset, off_t length, uint32 blockSize, char *volumeName)
{ {
DEBUG_INIT_ETC(CF_PUBLIC | CF_VOLUME_OPS, "static Volume", DEBUG_INIT_ETC(CF_PUBLIC | CF_VOLUME_OPS, "static Volume",
("device: %d, offset: %lld, volumeName: %p", device, offset, volumeName)); ("device: %d, offset: %Ld, volumeName: %p", device, offset, volumeName));
if (!volumeName) if (!volumeName)
RETURN(B_BAD_VALUE); RETURN(B_BAD_VALUE);
@ -70,7 +70,7 @@ Volume::Mount(const char *deviceName, off_t volumeStart, off_t volumeLength,
uint32 flags, uint32 blockSize) uint32 flags, uint32 blockSize)
{ {
DEBUG_INIT_ETC(CF_PUBLIC | CF_VOLUME_OPS, "Volume", DEBUG_INIT_ETC(CF_PUBLIC | CF_VOLUME_OPS, "Volume",
("devName = `%s'", deviceName)); ("deviceName: `%s', offset: %Ld, length %Ld", deviceName, volumeStart, volumeLength));
if (!deviceName) if (!deviceName)
RETURN(B_BAD_VALUE); RETURN(B_BAD_VALUE);
if (_InitStatus() == B_INITIALIZED) if (_InitStatus() == B_INITIALIZED)
@ -120,10 +120,15 @@ Volume::MapBlock(udf_long_address address, off_t *mappedBlock)
const udf_partition_descriptor* partition = fPartitionMap.Find(address.partition()); const udf_partition_descriptor* partition = fPartitionMap.Find(address.partition());
err = partition ? B_OK : B_BAD_ADDRESS; err = partition ? B_OK : B_BAD_ADDRESS;
if (!err) { if (!err) {
*mappedBlock = Start() + partition->start() + address.block(); PRINT(("Offset(): %Ld, partition->start(): %ld, address.block(): %ld\n", Offset(),
partition->start(), address.block()));
PRINT(("partition:\n"));
PDUMP(partition);
*mappedBlock = partition->start() + address.block();
} }
if (!err) { if (!err) {
PRINT(("mapped to block %lld\n", *mappedBlock)); PRINT(("mapped to block %Ld\n", *mappedBlock));
snooze(5000);
} }
} }
RETURN(err); RETURN(err);
@ -140,7 +145,7 @@ Volume::MapAddress(udf_long_address address, off_t *mappedAddress)
if (!err) if (!err)
*mappedAddress = *mappedAddress * BlockSize(); *mappedAddress = *mappedAddress * BlockSize();
if (!err) { if (!err) {
PRINT(("mapped to address %lld\n", *mappedAddress)); PRINT(("mapped to address %Ld\n", *mappedAddress));
} }
RETURN_ERROR(err); RETURN_ERROR(err);
} }
@ -161,7 +166,7 @@ Volume::_Read(udf_extent_address address, ssize_t length, void *data)
ssize_t bytesRead = read_pos(fDevice, mappedAddress, data, BlockSize()); ssize_t bytesRead = read_pos(fDevice, mappedAddress, data, BlockSize());
if (bytesRead != (ssize_t)BlockSize()) { if (bytesRead != (ssize_t)BlockSize()) {
err = B_IO_ERROR; err = B_IO_ERROR;
PRINT(("read_pos(pos:%lld, len:%ld) failed with: 0x%lx\n", mappedAddress, PRINT(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n", mappedAddress,
length, bytesRead)); length, bytesRead));
} }
} }
@ -182,7 +187,7 @@ Volume::_Read(AddressType address, ssize_t length, void *data)
ssize_t bytesRead = read_pos(fDevice, mappedAddress, data, BlockSize()); ssize_t bytesRead = read_pos(fDevice, mappedAddress, data, BlockSize());
if (bytesRead != (ssize_t)BlockSize()) { if (bytesRead != (ssize_t)BlockSize()) {
err = B_IO_ERROR; err = B_IO_ERROR;
PRINT(("read_pos(pos:%lld, len:%ld) failed with: 0x%lx\n", mappedAddress, PRINT(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n", mappedAddress,
length, bytesRead)); length, bytesRead));
} }
} }
@ -214,7 +219,7 @@ Volume::_Init(int device, off_t offset, off_t length, int blockSize)
fDevice = device; fDevice = device;
fReadOnly = true; fReadOnly = true;
fStart = offset; fOffset = offset;
fLength = length; fLength = length;
fBlockSize = blockSize; fBlockSize = blockSize;
@ -366,7 +371,7 @@ Volume::_WalkVolumeRecognitionSequence()
break; break;
} }
} else { } else {
SIMPLE_PRINT(("read_pos(pos:%lld, len:%ld) failed with: 0x%lx\n", address, SIMPLE_PRINT(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n", address,
BlockSize(), bytesRead)); BlockSize(), bytesRead));
break; break;
} }
@ -405,21 +410,21 @@ Volume::_WalkAnchorVolumeDescriptorSequences()
ssize_t bytesRead = read_pos(fDevice, address, chunk.Data(), BlockSize()); ssize_t bytesRead = read_pos(fDevice, address, chunk.Data(), BlockSize());
anchorErr = bytesRead == (ssize_t)BlockSize() ? B_OK : B_IO_ERROR; anchorErr = bytesRead == (ssize_t)BlockSize() ? B_OK : B_IO_ERROR;
if (anchorErr) { if (anchorErr) {
PRINT(("block %lld: read_pos(pos:%lld, len:%ld) failed with error 0x%lx\n", PRINT(("block %Ld: read_pos(pos:%Ld, len:%ld) failed with error 0x%lx\n",
block, address, BlockSize(), bytesRead)); block, address, BlockSize(), bytesRead));
} }
} }
if (!anchorErr) { if (!anchorErr) {
anchor = reinterpret_cast<udf_anchor_descriptor*>(chunk.Data()); anchor = reinterpret_cast<udf_anchor_descriptor*>(chunk.Data());
anchorErr = anchor->tag().init_check(block); anchorErr = anchor->tag().init_check(block+Offset());
if (anchorErr) { if (anchorErr) {
PRINT(("block %lld: invalid anchor\n", block)); PRINT(("block %Ld: invalid anchor\n", block));
} else { } else {
PRINT(("block %lld: valid anchor\n", block)); PRINT(("block %Ld: valid anchor\n", block));
} }
} }
if (!anchorErr) { if (!anchorErr) {
PRINT(("block %lld: anchor:\n", block)); PRINT(("block %Ld: anchor:\n", block));
PDUMP(anchor); PDUMP(anchor);
// Found an avds, so try the main sequence first, then // Found an avds, so try the main sequence first, then
// the reserve sequence if the main one fails. // the reserve sequence if the main one fails.
@ -430,12 +435,12 @@ Volume::_WalkAnchorVolumeDescriptorSequences()
} }
if (!anchorErr) { if (!anchorErr) {
PRINT(("block %lld: found valid vds\n", avds_locations[i])); PRINT(("block %Ld: found valid vds\n", avds_locations[i]));
found_vds = true; found_vds = true;
break; break;
} //else { } //else {
// Both failed, so loop around and try another avds // Both failed, so loop around and try another avds
// PRINT(("block %lld: vds search failed\n", avds_locations[i])); // PRINT(("block %Ld: vds search failed\n", avds_locations[i]));
// } // }
} }
status_t err = found_vds ? B_OK : B_ERROR; status_t err = found_vds ? B_OK : B_ERROR;
@ -454,18 +459,18 @@ Volume::_WalkVolumeDescriptorSequence(udf_extent_address extent)
for (uint32 i = 0; i < count; i++) for (uint32 i = 0; i < count; i++)
{ {
off_t block = extent.location()+i; off_t block = extent.location()+i;
off_t address = AddressForRelativeBlock(block); off_t address = block << BlockShift(); //AddressForRelativeBlock(block);
MemoryChunk chunk(BlockSize()); MemoryChunk chunk(BlockSize());
udf_tag *tag = NULL; udf_tag *tag = NULL;
PRINT(("descriptor #%ld (block %lld):\n", i, block)); PRINT(("descriptor #%ld (block %Ld):\n", i, block));
status_t err = chunk.InitCheck(); status_t err = chunk.InitCheck();
if (!err) { if (!err) {
ssize_t bytesRead = read_pos(fDevice, address, chunk.Data(), BlockSize()); ssize_t bytesRead = read_pos(fDevice, address, chunk.Data(), BlockSize());
err = bytesRead == (ssize_t)BlockSize() ? B_OK : B_IO_ERROR; err = bytesRead == (ssize_t)BlockSize() ? B_OK : B_IO_ERROR;
if (err) { if (err) {
PRINT(("block %lld: read_pos(pos:%lld, len:%ld) failed with error 0x%lx\n", PRINT(("block %Ld: read_pos(pos:%Ld, len:%ld) failed with error 0x%lx\n",
block, address, BlockSize(), bytesRead)); block, address, BlockSize(), bytesRead));
} }
} }

View File

@ -46,14 +46,14 @@ public:
int Device() const { return fDevice; } int Device() const { return fDevice; }
nspace_id Id() const { return fId; } nspace_id Id() const { return fId; }
off_t Start() const { return fStart; } off_t Offset() const { return fOffset; }
off_t Length() const { return fLength; } off_t Length() const { return fLength; }
uint32 BlockSize() const { return fBlockSize; } uint32 BlockSize() const { return fBlockSize; }
uint32 BlockShift() const { return fBlockShift; } uint32 BlockShift() const { return fBlockShift; }
off_t AddressForRelativeBlock(off_t block) { return (Start() + block) * BlockSize(); } off_t AddressForRelativeBlock(off_t block) { return (Offset() + block) * BlockSize(); }
off_t RelativeAddress(off_t address) { return Start() * BlockSize() + address; } off_t RelativeAddress(off_t address) { return Offset() * BlockSize() + address; }
bool IsReadOnly() const { return fReadOnly; } bool IsReadOnly() const { return fReadOnly; }
@ -101,7 +101,7 @@ private:
int fDevice; int fDevice;
bool fReadOnly; bool fReadOnly;
off_t fStart; //!< Starting block of the volume on the given device off_t fOffset; //!< Starting block of the volume on the given device
off_t fLength; //!< Block length of volume on the given device off_t fLength; //!< Block length of volume on the given device
uint32 fBlockSize; uint32 fBlockSize;
uint32 fBlockShift; uint32 fBlockShift;
@ -134,7 +134,7 @@ Volume::Read(AddressType address, ssize_t length, void *data)
ssize_t bytesRead = read_pos(fDevice, mappedAddress, data, BlockSize()); ssize_t bytesRead = read_pos(fDevice, mappedAddress, data, BlockSize());
if (bytesRead != (ssize_t)BlockSize()) { if (bytesRead != (ssize_t)BlockSize()) {
err = B_IO_ERROR; err = B_IO_ERROR;
PRINT(("read_pos(pos:%lld, len:%ld) failed with: 0x%lx\n", mappedAddress, PRINT(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n", mappedAddress,
length, bytesRead)); length, bytesRead));
} }
} }