* Improve debug output

* Better formatting code

No functional changes.

Right now the code fails on recognizing the descriptor sequence.
I have to figure out if I pass the wrong values to the function.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27078 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Salvatore Benedetto
2008-08-20 12:28:16 +00:00
parent aab58d8730
commit 6960a91cd7
2 changed files with 92 additions and 83 deletions
@@ -36,45 +36,54 @@ walk_integrity_sequence(int device, uint32 blockSize, uint32 blockShift,
// externally visible functions // externally visible functions
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t status_t
udf_recognize(int device, off_t offset, off_t length, uint32 blockSize, udf_recognize(int device, off_t offset, off_t length, uint32 blockSize,
uint32 &blockShift, logical_volume_descriptor &logicalVolumeDescriptor, uint32 &blockShift, logical_volume_descriptor &logicalVolumeDescriptor,
partition_descriptor partitionDescriptors[], partition_descriptor partitionDescriptors[],
uint8 &partitionDescriptorCount) uint8 &partitionDescriptorCount)
{ {
DEBUG_INIT_ETC(NULL, ("device: %d, offset: %Ld, length: %Ld, " TRACE(("udf_recognize: device: = %d, offset = %Ld, length = %Ld, "
"blockSize: %ld, [...descriptors, etc...]", device, offset, "blockSize = %ld, [...descriptors, etc...]\n", device, offset,
length, blockSize)); length, blockSize));
// Check the block size // Check the block size
status_t error = get_block_shift(blockSize, blockShift); status_t status = get_block_shift(blockSize, blockShift);
if (!error) { if (status != B_OK) {
PRINT(("blockShift: %ld\n", blockShift)); TRACE_ERROR(("udf_recognize: Block size must be a positive power of "
"two! (blockSize = %ld)\n", blockSize));
// Check for a valid volume recognition sequence return status;
error = walk_volume_recognition_sequence(device, offset, blockSize, blockShift);
// Now hunt down a volume descriptor sequence from one of
// the anchor volume pointers (if there are any).
if (!error) {
error = walk_anchor_volume_descriptor_sequences(device, offset, length,
blockSize, blockShift,
logicalVolumeDescriptor,
partitionDescriptors,
partitionDescriptorCount);
}
// Now walk the integrity sequence and make sure the last integrity
// descriptor is a closed descriptor
if (!error) {
error = walk_integrity_sequence(device, blockSize, blockShift,
logicalVolumeDescriptor.integrity_sequence_extent());
}
} else {
PRINT(("Block size must be a positive power of two! (blockSize = %ld)\n", blockSize));
} }
TRACE(("udf_recognize: blockShift: %ld\n", blockShift));
RETURN(error);
// Check for a valid volume recognition sequence
status = walk_volume_recognition_sequence(device, offset, blockSize,
blockShift);
if (status != B_OK) {
TRACE_ERROR(("udf_recognize: Invalid sequence. status = %d\n", status));
return status;
}
// Now hunt down a volume descriptor sequence from one of
// the anchor volume pointers (if there are any).
status = walk_anchor_volume_descriptor_sequences(device, offset, length,
blockSize, blockShift, logicalVolumeDescriptor,
partitionDescriptors, partitionDescriptorCount);
if (status != B_OK) {
TRACE_ERROR(("udf_recognize: cannot find volume descriptor. status = %d\n",
status));
return status;
}
// Now walk the integrity sequence and make sure the last integrity
// descriptor is a closed descriptor
status = walk_integrity_sequence(device, blockSize, blockShift,
logicalVolumeDescriptor.integrity_sequence_extent());
if (status != B_OK) {
TRACE_ERROR(("udf_recognize: last integrity descriptor not closed. "
"status = %d\n", status));
return status;
}
return B_OK;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -85,66 +94,66 @@ static
status_t status_t
walk_volume_recognition_sequence(int device, off_t offset, uint32 blockSize, uint32 blockShift) walk_volume_recognition_sequence(int device, off_t offset, uint32 blockSize, uint32 blockShift)
{ {
DEBUG_INIT(NULL);
// vrs starts at block 16. Each volume structure descriptor (vsd) // vrs starts at block 16. Each volume structure descriptor (vsd)
// should be one block long. We're expecting to find 0 or more iso9660 // should be one block long. We're expecting to find 0 or more iso9660
// vsd's followed by some ECMA-167 vsd's. // vsd's followed by some ECMA-167 vsd's.
MemoryChunk chunk(blockSize); MemoryChunk chunk(blockSize);
status_t error = chunk.InitCheck(); if (chunk.InitCheck() != B_OK) {
if (!error) { TRACE_ERROR(("walk_volume_recognition_sequence: Failed to construct "
bool foundISO = false; "MemoryChunk\n"));
bool foundExtended = false; return B_ERROR;
bool foundECMA167 = false; }
bool foundECMA168 = false;
bool foundBoot = false; bool foundISO = false;
for (uint32 block = 16; true; block++) { bool foundExtended = false;
PRINT(("block %ld: ", block)) bool foundECMA167 = false;
off_t address = (offset + block) << blockShift; bool foundECMA168 = false;
ssize_t bytesRead = read_pos(device, address, chunk.Data(), blockSize); bool foundBoot = false;
if (bytesRead == (ssize_t)blockSize) for (uint32 block = 16; true; block++) {
{ TRACE(("walk_volume_recognition_sequence: block %ld: ", block));
volume_structure_descriptor_header* descriptor = off_t address = (offset + block) << blockShift;
reinterpret_cast<volume_structure_descriptor_header*>(chunk.Data()); ssize_t bytesRead = read_pos(device, address, chunk.Data(), blockSize);
if (descriptor->id_matches(kVSDID_ISO)) { if (bytesRead == (ssize_t)blockSize)
SIMPLE_PRINT(("found ISO9660 descriptor\n")); {
foundISO = true; volume_structure_descriptor_header* descriptor
} else if (descriptor->id_matches(kVSDID_BEA)) { = (volume_structure_descriptor_header *)(chunk.Data());
SIMPLE_PRINT(("found BEA descriptor\n")); if (descriptor->id_matches(kVSDID_ISO)) {
foundExtended = true; TRACE(("found ISO9660 descriptor\n"));
} else if (descriptor->id_matches(kVSDID_TEA)) { foundISO = true;
SIMPLE_PRINT(("found TEA descriptor\n")); } else if (descriptor->id_matches(kVSDID_BEA)) {
foundExtended = true; TRACE(("found BEA descriptor\n"));
} else if (descriptor->id_matches(kVSDID_ECMA167_2)) { foundExtended = true;
SIMPLE_PRINT(("found ECMA-167 rev 2 descriptor\n")); } else if (descriptor->id_matches(kVSDID_TEA)) {
foundECMA167 = true; TRACE(("found TEA descriptor\n"));
} else if (descriptor->id_matches(kVSDID_ECMA167_3)) { foundExtended = true;
SIMPLE_PRINT(("found ECMA-167 rev 3 descriptor\n")); } else if (descriptor->id_matches(kVSDID_ECMA167_2)) {
foundECMA167 = true; TRACE(("found ECMA-167 rev 2 descriptor\n"));
} else if (descriptor->id_matches(kVSDID_BOOT)) { foundECMA167 = true;
SIMPLE_PRINT(("found boot descriptor\n")); } else if (descriptor->id_matches(kVSDID_ECMA167_3)) {
foundBoot = true; TRACE(("found ECMA-167 rev 3 descriptor\n"));
} else if (descriptor->id_matches(kVSDID_ECMA168)) { foundECMA167 = true;
SIMPLE_PRINT(("found ECMA-168 descriptor\n")); } else if (descriptor->id_matches(kVSDID_BOOT)) {
foundECMA168 = true; TRACE(("found boot descriptor\n"));
} else { foundBoot = true;
SIMPLE_PRINT(("found invalid descriptor, id = `%.5s'\n", descriptor->id)); } else if (descriptor->id_matches(kVSDID_ECMA168)) {
break; TRACE(("found ECMA-168 descriptor\n"));
} foundECMA168 = true;
} else { } else {
SIMPLE_PRINT(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n", address, TRACE(("found invalid descriptor, id = `%.5s'\n", descriptor->id));
blockSize, bytesRead));
break; break;
} }
} else {
TRACE_ERROR(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n", address,
blockSize, bytesRead));
break;
} }
// If we find an ECMA-167 descriptor, OR if we find a beginning
// or terminating extended area descriptor with NO ECMA-168
// descriptors, we return B_OK to signal that we should go
// looking for valid anchors.
error = foundECMA167 || (foundExtended && !foundECMA168) ? B_OK : B_ERROR;
} }
RETURN(error); // If we find an ECMA-167 descriptor, OR if we find a beginning
// or terminating extended area descriptor with NO ECMA-168
// descriptors, we return B_OK to signal that we should go
// looking for valid anchors.
return foundECMA167 || (foundExtended && !foundECMA168) ? B_OK : B_ERROR;
} }
static static
@@ -229,8 +229,8 @@ private:
#define DUMP(x) ; #define DUMP(x) ;
#endif // ifdef DEBUG else #endif // ifdef DEBUG else
#define TRACE(x) DBG(dprintf x) #define TRACE(x) dprintf x
#define TRACE_ERROR(x) DBG(dprintf x) #define TRACE_ERROR(x) dprintf x
// These macros turn on or off extensive and generally unnecessary // These macros turn on or off extensive and generally unnecessary
// debugging output regarding table of contents parsing // debugging output regarding table of contents parsing