* 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));
return status;
}
TRACE(("udf_recognize: blockShift: %ld\n", blockShift));
// Check for a valid volume recognition sequence // Check for a valid volume recognition sequence
error = walk_volume_recognition_sequence(device, offset, blockSize, blockShift); 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 // Now hunt down a volume descriptor sequence from one of
// the anchor volume pointers (if there are any). // the anchor volume pointers (if there are any).
if (!error) { status = walk_anchor_volume_descriptor_sequences(device, offset, length,
error = walk_anchor_volume_descriptor_sequences(device, offset, length, blockSize, blockShift, logicalVolumeDescriptor,
blockSize, blockShift, partitionDescriptors, partitionDescriptorCount);
logicalVolumeDescriptor, if (status != B_OK) {
partitionDescriptors, TRACE_ERROR(("udf_recognize: cannot find volume descriptor. status = %d\n",
partitionDescriptorCount); status));
return status;
} }
// Now walk the integrity sequence and make sure the last integrity // Now walk the integrity sequence and make sure the last integrity
// descriptor is a closed descriptor // descriptor is a closed descriptor
if (!error) { status = walk_integrity_sequence(device, blockSize, blockShift,
error = walk_integrity_sequence(device, blockSize, blockShift,
logicalVolumeDescriptor.integrity_sequence_extent()); logicalVolumeDescriptor.integrity_sequence_extent());
} if (status != B_OK) {
} else { TRACE_ERROR(("udf_recognize: last integrity descriptor not closed. "
PRINT(("Block size must be a positive power of two! (blockSize = %ld)\n", blockSize)); "status = %d\n", status));
return status;
} }
RETURN(error); return B_OK;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -85,53 +94,56 @@ 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 "
"MemoryChunk\n"));
return B_ERROR;
}
bool foundISO = false; bool foundISO = false;
bool foundExtended = false; bool foundExtended = false;
bool foundECMA167 = false; bool foundECMA167 = false;
bool foundECMA168 = false; bool foundECMA168 = false;
bool foundBoot = false; bool foundBoot = false;
for (uint32 block = 16; true; block++) { for (uint32 block = 16; true; block++) {
PRINT(("block %ld: ", block)) TRACE(("walk_volume_recognition_sequence: block %ld: ", block));
off_t address = (offset + block) << blockShift; off_t address = (offset + block) << blockShift;
ssize_t bytesRead = read_pos(device, address, chunk.Data(), blockSize); ssize_t bytesRead = read_pos(device, address, chunk.Data(), blockSize);
if (bytesRead == (ssize_t)blockSize) if (bytesRead == (ssize_t)blockSize)
{ {
volume_structure_descriptor_header* descriptor = volume_structure_descriptor_header* descriptor
reinterpret_cast<volume_structure_descriptor_header*>(chunk.Data()); = (volume_structure_descriptor_header *)(chunk.Data());
if (descriptor->id_matches(kVSDID_ISO)) { if (descriptor->id_matches(kVSDID_ISO)) {
SIMPLE_PRINT(("found ISO9660 descriptor\n")); TRACE(("found ISO9660 descriptor\n"));
foundISO = true; foundISO = true;
} else if (descriptor->id_matches(kVSDID_BEA)) { } else if (descriptor->id_matches(kVSDID_BEA)) {
SIMPLE_PRINT(("found BEA descriptor\n")); TRACE(("found BEA descriptor\n"));
foundExtended = true; foundExtended = true;
} else if (descriptor->id_matches(kVSDID_TEA)) { } else if (descriptor->id_matches(kVSDID_TEA)) {
SIMPLE_PRINT(("found TEA descriptor\n")); TRACE(("found TEA descriptor\n"));
foundExtended = true; foundExtended = true;
} else if (descriptor->id_matches(kVSDID_ECMA167_2)) { } else if (descriptor->id_matches(kVSDID_ECMA167_2)) {
SIMPLE_PRINT(("found ECMA-167 rev 2 descriptor\n")); TRACE(("found ECMA-167 rev 2 descriptor\n"));
foundECMA167 = true; foundECMA167 = true;
} else if (descriptor->id_matches(kVSDID_ECMA167_3)) { } else if (descriptor->id_matches(kVSDID_ECMA167_3)) {
SIMPLE_PRINT(("found ECMA-167 rev 3 descriptor\n")); TRACE(("found ECMA-167 rev 3 descriptor\n"));
foundECMA167 = true; foundECMA167 = true;
} else if (descriptor->id_matches(kVSDID_BOOT)) { } else if (descriptor->id_matches(kVSDID_BOOT)) {
SIMPLE_PRINT(("found boot descriptor\n")); TRACE(("found boot descriptor\n"));
foundBoot = true; foundBoot = true;
} else if (descriptor->id_matches(kVSDID_ECMA168)) { } else if (descriptor->id_matches(kVSDID_ECMA168)) {
SIMPLE_PRINT(("found ECMA-168 descriptor\n")); TRACE(("found ECMA-168 descriptor\n"));
foundECMA168 = true; foundECMA168 = true;
} else { } else {
SIMPLE_PRINT(("found invalid descriptor, id = `%.5s'\n", descriptor->id)); TRACE(("found invalid descriptor, id = `%.5s'\n", descriptor->id));
break; break;
} }
} else { } else {
SIMPLE_PRINT(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n", address, TRACE_ERROR(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n", address,
blockSize, bytesRead)); blockSize, bytesRead));
break; break;
} }
@@ -141,10 +153,7 @@ walk_volume_recognition_sequence(int device, off_t offset, uint32 blockSize, uin
// or terminating extended area descriptor with NO ECMA-168 // or terminating extended area descriptor with NO ECMA-168
// descriptors, we return B_OK to signal that we should go // descriptors, we return B_OK to signal that we should go
// looking for valid anchors. // looking for valid anchors.
error = foundECMA167 || (foundExtended && !foundECMA168) ? B_OK : B_ERROR; return foundECMA167 || (foundExtended && !foundECMA168) ? B_OK : B_ERROR;
}
RETURN(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