diff --git a/src/add-ons/kernel/disk_scanner/partition/intel.cpp b/src/add-ons/kernel/disk_scanner/partition/intel.cpp index a26aaa0b85..830a8371f0 100644 --- a/src/add-ons/kernel/disk_scanner/partition/intel.cpp +++ b/src/add-ons/kernel/disk_scanner/partition/intel.cpp @@ -153,6 +153,7 @@ PartitionMapParser::_ParseExtended(PrimaryPartition *primary, off_t offset) status_t error = B_OK; int32 partitionCount = 0; while (error == B_OK) { + // check for cycles if (++partitionCount > kMaxLogicalPartitionCount) { TRACE(("intel: _ParseExtended(): Maximal number of logical " "partitions for extended partition reached. Cycle?\n")); @@ -162,10 +163,17 @@ PartitionMapParser::_ParseExtended(PrimaryPartition *primary, off_t offset) if (error == B_OK) error = _ReadPTS(offset); // check the signature - if (error == B_OK && fPTS->signature != kPartitionTableSectorSignature) { + if (error == B_OK + && fPTS->signature != kPartitionTableSectorSignature) { TRACE(("intel: _ParseExtended(): invalid PTS signature\n")); error = B_BAD_DATA; } + // ignore the PTS, if any error occured till now + if (error != B_OK) { + TRACE(("intel: _ParseExtended(): ignoring this PTS\n")); + error = B_OK; + break; + } // examine the table LogicalPartition extended; LogicalPartition nonExtended; @@ -333,8 +341,7 @@ intel_get_nth_info(int deviceFD, const session_info *sessionInfo, partitionInfo->flags = 0; } partitionInfo->partition_name[0] = '\0'; - strcpy(partitionInfo->partition_type, - partition->TypeString()); + partition->GetTypeString(partitionInfo->partition_type); partitionInfo->partition_code = partition->Type(); } else error = B_ENTRY_NOT_FOUND; diff --git a/src/add-ons/kernel/disk_scanner/partition/intel_partition_map.cpp b/src/add-ons/kernel/disk_scanner/partition/intel_partition_map.cpp index 62e85b75d7..4125623f7c 100644 --- a/src/add-ons/kernel/disk_scanner/partition/intel_partition_map.cpp +++ b/src/add-ons/kernel/disk_scanner/partition/intel_partition_map.cpp @@ -9,6 +9,7 @@ */ #include +#include #include #include @@ -58,6 +59,7 @@ static const struct partition_type kPartitionTypes[] = { }; // partition_type_string +static const char * partition_type_string(uint8 type) { @@ -67,7 +69,19 @@ partition_type_string(uint8 type) if (type == kPartitionTypes[i].type) return kPartitionTypes[i].name; } - return "unknown"; + return NULL; +} + +// get_partition_type_string +void +get_partition_type_string(uint8 type, char *buffer) +{ + if (buffer) { + if (const char *str = partition_type_string(type)) + strcpy(buffer, str); + else + sprintf(buffer, "Unrecognized Type 0x%x", type); + } } diff --git a/src/add-ons/kernel/disk_scanner/partition/intel_partition_map.h b/src/add-ons/kernel/disk_scanner/partition/intel_partition_map.h index 34c6280eb5..220e873ce9 100644 --- a/src/add-ons/kernel/disk_scanner/partition/intel_partition_map.h +++ b/src/add-ons/kernel/disk_scanner/partition/intel_partition_map.h @@ -29,7 +29,7 @@ is_extended_type(uint8 type) return (type == 0x05 || type == 0x0f || type == 0x85); } -const char *partition_type_string(uint8 type); +void get_partition_type_string(uint8 type, char *buffer); // chs struct chs { @@ -82,7 +82,8 @@ public: off_t Size() const { return fSize; } uint8 Type() const { return fType; } bool Active() const { return fActive; } - const char *TypeString() const { return partition_type_string(fType); } + void GetTypeString(char *buffer) const + { get_partition_type_string(fType, buffer); } void SetPTSOffset(off_t offset) { fPTSOffset = offset; } void SetOffset(off_t offset) { fOffset = offset; }