file_systems/udf: Reduce indent

Reduce indent in walk_volume_descriptor_sequence() for readability.

Change-Id: Ie4d46fc69ebee3b74f0410639f06010351e71894
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3294
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Murai Takashi
2020-10-11 15:48:14 +00:00
committed by waddlesplash
parent 1e22d0d338
commit d3179631c9
@@ -166,13 +166,13 @@ walk_volume_recognition_sequence(int device, off_t offset, uint32 blockSize,
// 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.
return foundECMA167 || (foundExtended && !foundECMA168) ? B_OK : B_ERROR; return foundECMA167 || (foundExtended && !foundECMA168) ? B_OK : B_ERROR;
} }
static status_t static status_t
walk_anchor_volume_descriptor_sequences(int device, off_t offset, off_t length, walk_anchor_volume_descriptor_sequences(int device, off_t offset, off_t length,
uint32 blockSize, uint32 blockShift, uint32 blockSize, uint32 blockShift,
primary_volume_descriptor &primaryVolumeDescriptor, primary_volume_descriptor &primaryVolumeDescriptor,
logical_volume_descriptor &logicalVolumeDescriptor, logical_volume_descriptor &logicalVolumeDescriptor,
partition_descriptor partitionDescriptors[], partition_descriptor partitionDescriptors[],
@@ -182,7 +182,7 @@ walk_anchor_volume_descriptor_sequences(int device, off_t offset, off_t length,
const uint8 avds_location_count = 4; const uint8 avds_location_count = 4;
const off_t avds_locations[avds_location_count] const off_t avds_locations[avds_location_count]
= { 256, length-1-256, length-1, 512, }; = { 256, length-1-256, length-1, 512, };
bool found_vds = false; bool found_vds = false;
for (int32 i = 0; i < avds_location_count; i++) { for (int32 i = 0; i < avds_location_count; i++) {
off_t block = avds_locations[i]; off_t block = avds_locations[i];
off_t address = (offset + block) << blockShift; off_t address = (offset + block) << blockShift;
@@ -222,7 +222,7 @@ walk_anchor_volume_descriptor_sequences(int device, off_t offset, off_t length,
anchorErr = walk_volume_descriptor_sequence(anchor->reserve_vds(), anchorErr = walk_volume_descriptor_sequence(anchor->reserve_vds(),
device, blockSize, blockShift, primaryVolumeDescriptor, device, blockSize, blockShift, primaryVolumeDescriptor,
logicalVolumeDescriptor, partitionDescriptors, logicalVolumeDescriptor, partitionDescriptors,
partitionDescriptorCount); partitionDescriptorCount);
} }
if (!anchorErr) { if (!anchorErr) {
PRINT(("block %" B_PRIdOFF ": found valid vds\n", PRINT(("block %" B_PRIdOFF ": found valid vds\n",
@@ -239,6 +239,87 @@ walk_anchor_volume_descriptor_sequences(int device, off_t offset, off_t length,
RETURN(error); RETURN(error);
} }
static status_t
walk_tagid_partition_descriptor(descriptor_tag *tag, off_t block,
uint8& uniquePartitions, partition_descriptor* partitionDescriptors)
{
DEBUG_INIT(NULL);
status_t error = B_OK;
partition_descriptor *partition =
reinterpret_cast<partition_descriptor*>(tag);
PDUMP(partition);
if (partition->tag().init_check(block) == B_OK) {
// Check for a previously discovered partition descriptor with
// the same number as this partition. If found, keep the one with
// the higher vds number.
bool foundDuplicate = false;
int num;
for (num = 0; num < uniquePartitions; num++) {
if (partitionDescriptors[num].partition_number()
== partition->partition_number()) {
foundDuplicate = true;
if (partitionDescriptors[num].vds_number()
< partition->vds_number()) {
partitionDescriptors[num] = *partition;
PRINT(("Replacing previous partition #%d "
"(vds_number: %" B_PRIu32 ") with new partition #%d "
"(vds_number: %" B_PRIu32 ")\n",
partitionDescriptors[num].partition_number(),
partitionDescriptors[num].vds_number(),
partition->partition_number(),
partition->vds_number()));
}
break;
}
}
// If we didn't find a duplicate, see if we have any open descriptor
// spaces left.
if (!foundDuplicate) {
if (num < kMaxPartitionDescriptors) {
// At least one more partition descriptor allowed
partitionDescriptors[num] = *partition;
uniquePartitions++;
PRINT(("Adding partition #%d (vds_number: %" B_PRIu32 ")\n",
partition->partition_number(),
partition->vds_number()));
} else {
// We've found more than kMaxPartitionDescriptor uniquely-
// numbered partitions. So, search through the partitions
// we already have again, this time just looking for a
// partition with a lower vds number. If we find one,
// replace it with this one. If we don't, scream bloody
// murder.
bool foundReplacement = false;
for (int j = 0; j < uniquePartitions; j++) {
if (partitionDescriptors[j].vds_number()
< partition->vds_number()) {
foundReplacement = true;
partitionDescriptors[j] = *partition;
PRINT(("Replacing partition #%d "
"(vds_number: %" B_PRIu32 ") "
"with partition #%d "
"(vds_number: %" B_PRIu32 ")\n",
partitionDescriptors[j].partition_number(),
partitionDescriptors[j].vds_number(),
partition->partition_number(),
partition->vds_number()));
break;
}
}
if (!foundReplacement) {
PRINT(("Found more than kMaxPartitionDescriptors == %d "
"unique partition descriptors!\n",
kMaxPartitionDescriptors));
error = B_BAD_VALUE;
}
}
}
}
RETURN(error);
}
static static
status_t status_t
walk_volume_descriptor_sequence(extent_address descriptorSequence, walk_volume_descriptor_sequence(extent_address descriptorSequence,
@@ -252,16 +333,16 @@ walk_volume_descriptor_sequence(extent_address descriptorSequence,
"descriptorSequence.len:%" PRIu32, "descriptorSequence.len:%" PRIu32,
descriptorSequence.location(), descriptorSequence.length())); descriptorSequence.location(), descriptorSequence.length()));
uint32 count = descriptorSequence.length() >> blockShift; uint32 count = descriptorSequence.length() >> blockShift;
bool foundLogicalVolumeDescriptor = false; bool foundLogicalVolumeDescriptor = false;
bool foundUnallocatedSpaceDescriptor = false; bool foundUnallocatedSpaceDescriptor = false;
bool foundUdfImplementationUseDescriptor = false; bool foundUdfImplementationUseDescriptor = false;
uint8 uniquePartitions = 0; uint8 uniquePartitions = 0;
status_t error = B_OK; status_t error = B_OK;
for (uint32 i = 0; i < count; i++) { for (uint32 i = 0; i < count; i++) {
off_t block = descriptorSequence.location()+i; off_t block = descriptorSequence.location()+i;
off_t address = block << blockShift; off_t address = block << blockShift;
MemoryChunk chunk(blockSize); MemoryChunk chunk(blockSize);
descriptor_tag *tag = NULL; descriptor_tag *tag = NULL;
@@ -269,7 +350,8 @@ walk_volume_descriptor_sequence(extent_address descriptorSequence,
status_t loopError = chunk.InitCheck(); status_t loopError = chunk.InitCheck();
if (!loopError) { if (!loopError) {
ssize_t bytesRead = read_pos(device, address, chunk.Data(), blockSize); ssize_t bytesRead = read_pos(device, address, chunk.Data(),
blockSize);
loopError = bytesRead == (ssize_t)blockSize ? B_OK : B_IO_ERROR; loopError = bytesRead == (ssize_t)blockSize ? B_OK : B_IO_ERROR;
if (loopError) { if (loopError) {
PRINT(("block %" B_PRIdOFF ": read_pos(pos:%" B_PRIdOFF ", " PRINT(("block %" B_PRIdOFF ": read_pos(pos:%" B_PRIdOFF ", "
@@ -289,166 +371,104 @@ walk_volume_descriptor_sequence(extent_address descriptorSequence,
case TAGID_PRIMARY_VOLUME_DESCRIPTOR: case TAGID_PRIMARY_VOLUME_DESCRIPTOR:
{ {
primary_volume_descriptor *primary = reinterpret_cast<primary_volume_descriptor*>(tag); primary_volume_descriptor *primary =
PDUMP(primary); reinterpret_cast<primary_volume_descriptor*>(tag);
PDUMP(primary);
primaryVolumeDescriptor = *primary; primaryVolumeDescriptor = *primary;
break; break;
} }
case TAGID_ANCHOR_VOLUME_DESCRIPTOR_POINTER: case TAGID_ANCHOR_VOLUME_DESCRIPTOR_POINTER:
break; break;
case TAGID_VOLUME_DESCRIPTOR_POINTER: case TAGID_VOLUME_DESCRIPTOR_POINTER:
break; break;
case TAGID_IMPLEMENTATION_USE_VOLUME_DESCRIPTOR: case TAGID_IMPLEMENTATION_USE_VOLUME_DESCRIPTOR:
{ {
implementation_use_descriptor *impUse = reinterpret_cast<implementation_use_descriptor*>(tag); implementation_use_descriptor *impUse =
reinterpret_cast<implementation_use_descriptor*>(tag);
PDUMP(impUse); PDUMP(impUse);
// Check for a matching implementation id string (note that the // Check for a matching implementation id string
// revision version is not checked) // (note that the revision version is not checked)
if (impUse->tag().init_check(block) == B_OK if (impUse->tag().init_check(block) == B_OK
&& impUse->implementation_id().matches(kLogicalVolumeInfoId201)) { && impUse->implementation_id().matches(
foundUdfImplementationUseDescriptor = true; kLogicalVolumeInfoId201)) {
foundUdfImplementationUseDescriptor = true;
} }
break; break;
} }
case TAGID_PARTITION_DESCRIPTOR: case TAGID_PARTITION_DESCRIPTOR:
{ {
partition_descriptor *partition = reinterpret_cast<partition_descriptor*>(tag); error = walk_tagid_partition_descriptor(
PDUMP(partition); tag, block, uniquePartitions, partitionDescriptors);
if (partition->tag().init_check(block) == B_OK) {
// Check for a previously discovered partition descriptor with
// the same number as this partition. If found, keep the one with
// the higher vds number.
bool foundDuplicate = false;
int num;
for (num = 0; num < uniquePartitions; num++) {
if (partitionDescriptors[num].partition_number()
== partition->partition_number()) {
foundDuplicate = true;
if (partitionDescriptors[num].vds_number()
< partition->vds_number()) {
partitionDescriptors[num] = *partition;
PRINT(("Replacing previous partition #%d "
"(vds_number: %" B_PRIu32 ") "
"with new partition #%d "
"(vds_number: %" B_PRIu32 ")\n",
partitionDescriptors[num].partition_number(),
partitionDescriptors[num].vds_number(),
partition->partition_number(),
partition->vds_number()));
}
break;
}
}
// If we didn't find a duplicate, see if we have any open descriptor
// spaces left.
if (!foundDuplicate) {
if (num < kMaxPartitionDescriptors) {
// At least one more partition descriptor allowed
partitionDescriptors[num] = *partition;
uniquePartitions++;
PRINT(("Adding partition #%d (vds_number: %" B_PRIu32
")\n",
partition->partition_number(),
partition->vds_number()));
} else {
// We've found more than kMaxPartitionDescriptor uniquely-
// numbered partitions. So, search through the partitions
// we already have again, this time just looking for a
// partition with a lower vds number. If we find one,
// replace it with this one. If we don't, scream bloody
// murder.
bool foundReplacement = false;
for (int j = 0; j < uniquePartitions; j++) {
if (partitionDescriptors[j].vds_number()
< partition->vds_number()) {
foundReplacement = true;
partitionDescriptors[j] = *partition;
PRINT(("Replacing partition #%d "
"(vds_number: %" B_PRIu32 ") "
"with partition #%d "
"(vds_number: %" B_PRIu32 ")\n",
partitionDescriptors[j].partition_number(),
partitionDescriptors[j].vds_number(),
partition->partition_number(),
partition->vds_number()));
break;
}
}
if (!foundReplacement) {
PRINT(("Found more than kMaxPartitionDescriptors == %d "
"unique partition descriptors!\n",
kMaxPartitionDescriptors));
error = B_BAD_VALUE;
break;
}
}
}
}
break; break;
} }
case TAGID_LOGICAL_VOLUME_DESCRIPTOR: case TAGID_LOGICAL_VOLUME_DESCRIPTOR:
{ {
logical_volume_descriptor *logical = reinterpret_cast<logical_volume_descriptor*>(tag); logical_volume_descriptor *logical =
reinterpret_cast<logical_volume_descriptor*>(tag);
PDUMP(logical); PDUMP(logical);
if (foundLogicalVolumeDescriptor) { if (foundLogicalVolumeDescriptor) {
// Keep the vd with the highest vds_number // Keep the vd with the highest vds_number
if (logicalVolumeDescriptor.vds_number() < logical->vds_number()) if (logicalVolumeDescriptor.vds_number()
logicalVolumeDescriptor = *logical; < logical->vds_number()) {
logicalVolumeDescriptor = *logical;
}
} else { } else {
logicalVolumeDescriptor = *logical; logicalVolumeDescriptor = *logical;
foundLogicalVolumeDescriptor = true; foundLogicalVolumeDescriptor = true;
} }
break; break;
} }
case TAGID_UNALLOCATED_SPACE_DESCRIPTOR: case TAGID_UNALLOCATED_SPACE_DESCRIPTOR:
{ {
unallocated_space_descriptor *unallocated = reinterpret_cast<unallocated_space_descriptor*>(tag); unallocated_space_descriptor *unallocated =
reinterpret_cast<unallocated_space_descriptor*>(tag);
PDUMP(unallocated); PDUMP(unallocated);
foundUnallocatedSpaceDescriptor = true; foundUnallocatedSpaceDescriptor = true;
(void)unallocated; // kill the warning (void)unallocated; // kill the warning
break; break;
} }
case TAGID_TERMINATING_DESCRIPTOR: case TAGID_TERMINATING_DESCRIPTOR:
{ {
terminating_descriptor *terminating = reinterpret_cast<terminating_descriptor*>(tag); terminating_descriptor *terminating =
reinterpret_cast<terminating_descriptor*>(tag);
PDUMP(terminating); PDUMP(terminating);
(void)terminating; // kill the warning (void)terminating; // kill the warning
break; break;
} }
case TAGID_LOGICAL_VOLUME_INTEGRITY_DESCRIPTOR: case TAGID_LOGICAL_VOLUME_INTEGRITY_DESCRIPTOR:
// Not found in this descriptor sequence // Not found in this descriptor sequence
break; break;
default: default:
break; break;
} }
} }
} }
PRINT(("found %d unique partition%s\n", uniquePartitions, PRINT(("found %d unique partition%s\n", uniquePartitions,
(uniquePartitions == 1 ? "" : "s"))); (uniquePartitions == 1 ? "" : "s")));
if (!error && !foundUdfImplementationUseDescriptor) { if (!error && !foundUdfImplementationUseDescriptor) {
INFORM(("WARNING: no valid udf implementation use descriptor found\n")); INFORM(("WARNING: no valid udf implementation use descriptor found\n"));
} }
if (!error) if (!error)
error = foundLogicalVolumeDescriptor error = foundLogicalVolumeDescriptor
&& foundUnallocatedSpaceDescriptor && foundUnallocatedSpaceDescriptor
? B_OK : B_ERROR; ? B_OK : B_ERROR;
if (!error) if (!error)
error = uniquePartitions >= 1 ? B_OK : B_ERROR; error = uniquePartitions >= 1 ? B_OK : B_ERROR;
if (!error) if (!error)
partitionDescriptorCount = uniquePartitions; partitionDescriptorCount = uniquePartitions;
RETURN(error); RETURN(error);
} }
@@ -456,27 +476,27 @@ walk_volume_descriptor_sequence(extent_address descriptorSequence,
\return \return
- \c B_OK: Success. the sequence was terminated by a valid, closed - \c B_OK: Success. the sequence was terminated by a valid, closed
integrity descriptor. integrity descriptor.
- \c B_ENTRY_NOT_FOUND: The sequence was empty. - \c B_ENTRY_NOT_FOUND: The sequence was empty.
- (other error code): The sequence was non-empty and did not end in a valid, - (other error code): The sequence was non-empty and did not end in a valid,
closed integrity descriptor. closed integrity descriptor.
*/ */
static status_t static status_t
walk_integrity_sequence(int device, uint32 blockSize, uint32 blockShift, walk_integrity_sequence(int device, uint32 blockSize, uint32 blockShift,
extent_address descriptorSequence, uint32 sequenceNumber) extent_address descriptorSequence, uint32 sequenceNumber)
{ {
DEBUG_INIT_ETC(NULL, DEBUG_INIT_ETC(NULL,
("descriptorSequence.loc:%" B_PRIu32 ", " ("descriptorSequence.loc:%" B_PRIu32 ", "
"descriptorSequence.len:%" B_PRIu32 , "descriptorSequence.len:%" B_PRIu32 ,
descriptorSequence.location(), descriptorSequence.length())); descriptorSequence.location(), descriptorSequence.length()));
uint32 count = descriptorSequence.length() >> blockShift; uint32 count = descriptorSequence.length() >> blockShift;
bool lastDescriptorWasClosed = false; bool lastDescriptorWasClosed = false;
uint16 highestMinimumUDFReadRevision = 0x0000; uint16 highestMinimumUDFReadRevision = 0x0000;
status_t error = count > 0 ? B_OK : B_ENTRY_NOT_FOUND; status_t error = count > 0 ? B_OK : B_ENTRY_NOT_FOUND;
for (uint32 i = 0; error == B_OK && i < count; i++) { for (uint32 i = 0; error == B_OK && i < count; i++) {
off_t block = descriptorSequence.location()+i; off_t block = descriptorSequence.location()+i;
off_t address = block << blockShift; off_t address = block << blockShift;
MemoryChunk chunk(blockSize); MemoryChunk chunk(blockSize);
descriptor_tag *tag = NULL; descriptor_tag *tag = NULL;
@@ -490,8 +510,8 @@ walk_integrity_sequence(int device, uint32 blockSize, uint32 blockShift,
loopError = check_size_error(bytesRead, blockSize); loopError = check_size_error(bytesRead, blockSize);
if (loopError) { if (loopError) {
PRINT(("block %" B_PRIdOFF": read_pos(pos:%" B_PRIdOFF PRINT(("block %" B_PRIdOFF": read_pos(pos:%" B_PRIdOFF
", len:%" B_PRIu32 ") failed with error 0x%lx\n", ", len:%" B_PRIu32 ") failed with error 0x%lx\n",
block, address, blockSize, bytesRead)); block, address, blockSize, bytesRead));
} }
} }
if (!loopError) { if (!loopError) {
@@ -501,7 +521,7 @@ walk_integrity_sequence(int device, uint32 blockSize, uint32 blockShift,
if (!loopError) { if (!loopError) {
// Check the descriptor type and see if it's closed. // Check the descriptor type and see if it's closed.
loopError = tag->id() == TAGID_LOGICAL_VOLUME_INTEGRITY_DESCRIPTOR loopError = tag->id() == TAGID_LOGICAL_VOLUME_INTEGRITY_DESCRIPTOR
? B_OK : B_BAD_DATA; ? B_OK : B_BAD_DATA;
if (!loopError) { if (!loopError) {
logical_volume_integrity_descriptor *descriptor = logical_volume_integrity_descriptor *descriptor =
reinterpret_cast<logical_volume_integrity_descriptor*>(chunk.Data()); reinterpret_cast<logical_volume_integrity_descriptor*>(chunk.Data());
@@ -513,36 +533,36 @@ walk_integrity_sequence(int device, uint32 blockSize, uint32 blockShift,
highestMinimumUDFReadRevision = minimumRevision; highestMinimumUDFReadRevision = minimumRevision;
} else if (minimumRevision < highestMinimumUDFReadRevision) { } else if (minimumRevision < highestMinimumUDFReadRevision) {
INFORM(("WARNING: found decreasing minimum udf read revision in integrity " INFORM(("WARNING: found decreasing minimum udf read revision in integrity "
"sequence (last highest: 0x%04x, current: 0x%04x); using higher " "sequence (last highest: 0x%04x, current: 0x%04x); using higher "
"revision.\n", highestMinimumUDFReadRevision, minimumRevision)); "revision.\n", highestMinimumUDFReadRevision, minimumRevision));
} }
} }
// Check a continuation extent if necessary. Note that this effectively // Check a continuation extent if necessary. Note that this effectively
// ends our search through this extent // ends our search through this extent
extent_address &next = descriptor->next_integrity_extent(); extent_address &next = descriptor->next_integrity_extent();
if (next.length() > 0) { if (next.length() > 0) {
status_t nextError = walk_integrity_sequence(device, blockSize, blockShift, status_t nextError = walk_integrity_sequence(device, blockSize, blockShift,
next, sequenceNumber+1); next, sequenceNumber+1);
if (nextError && nextError != B_ENTRY_NOT_FOUND) { if (nextError && nextError != B_ENTRY_NOT_FOUND) {
// Continuation proved invalid // Continuation proved invalid
error = nextError; error = nextError;
break; break;
} else { } else {
// Either the continuation was valid or empty; either way, // Either the continuation was valid or empty; either way,
// we're done searching. // we're done searching.
break; break;
} }
} }
} else { } else {
PDUMP(tag); PDUMP(tag);
} }
} }
// If we hit an error on the first item, consider the extent empty, // If we hit an error on the first item, consider the extent empty,
// otherwise just break out of the loop and assume part of the // otherwise just break out of the loop and assume part of the
// extent is unrecorded // extent is unrecorded
if (loopError) { if (loopError) {
if (i == 0) if (i == 0)
error = B_ENTRY_NOT_FOUND; error = B_ENTRY_NOT_FOUND;
else else
break; break;
@@ -556,5 +576,5 @@ walk_integrity_sequence(int device, uint32 blockSize, uint32 blockShift,
FATAL(("found udf revision 0x%x more than max 0x%x\n", FATAL(("found udf revision 0x%x more than max 0x%x\n",
highestMinimumUDFReadRevision, UDF_MAX_READ_REVISION)); highestMinimumUDFReadRevision, UDF_MAX_READ_REVISION));
} }
RETURN(error); RETURN(error);
} }