From 7b5ba53ade670584bf1be7cb97c9f4e11758113f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 May 2025 10:23:55 +0800 Subject: [PATCH] add partType Signed-off-by: unknown --- services/ptable_parse/ptable.cpp | 40 +++++++++++++++--------- services/ptable_parse/ptable.h | 11 ++++++- services/ptable_parse/ptable_manager.cpp | 3 +- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/services/ptable_parse/ptable.cpp b/services/ptable_parse/ptable.cpp index 4f830475..d91e4b2a 100644 --- a/services/ptable_parse/ptable.cpp +++ b/services/ptable_parse/ptable.cpp @@ -458,7 +458,7 @@ void Ptable::PrintPtableInfo() const LOG(INFO) << "ptable.entry[" << i << "].name=" << partitionInfo_[i].dispName.c_str() << ", startAddr=0x" << std::hex << partitionInfo_[i].startAddr << ", size=0x" << partitionInfo_[i].partitionSize << ", lun=" << std::dec << partitionInfo_[i].lun - << ", partType=" << partitionInfo_[i].partType; + << ", partType=" << static_cast::type>(partitionInfo_[i].partType); } LOG(INFO) << "ptnInfo : ==========================================="; } @@ -475,25 +475,33 @@ void Ptable::PrintPtableInfo(const std::vector &ptnInfo) const for (size_t i = 0; i < ptnInfo.size(); i++) { LOG(INFO) << "ptable.entry[" << i << "].name=" << ptnInfo[i].dispName.c_str() << ", startAddr=0x" << std::hex << ptnInfo[i].startAddr << ", size=0x" << ptnInfo[i].partitionSize << ", lun=" << - std::dec << ptnInfo[i].lun << ", partType=" << ptnInfo[i].partType; + std::dec << ptnInfo[i].lun << ", partType=" << + static_cast::type>(ptnInfo[i].partType); } LOG(INFO) << "ptnInfo : ==========================================="; } void Ptable::SetPartitionType(const std::string &partName, PtnInfo &ptnInfo) { + if (partName.find("RESERVED") != std::string::npos) { + ptnInfo.partType = PartType::RESERVED_TYPE; + return; + } if (PARTITION_AB_SUFFIX_SIZE > partName.size()) { - ptnInfo.partType = PARTITION_NORMAL_TYPE; + ptnInfo.partType = PartType::COMMON_TYPE; return; } std::string partSuffix = partName.substr(partName.size() - PARTITION_AB_SUFFIX_SIZE, PARTITION_AB_SUFFIX_SIZE); - if (strcasecmp(partSuffix.c_str(), PARTITION_A_SUFFIX) == 0 || - strcasecmp(partSuffix.c_str(), PARTITION_B_SUFFIX) == 0) { - ptnInfo.partType = PARTITION_AB_TYPE; + if (strcasecmp(partSuffix.c_str(), PARTITION_A_SUFFIX) == 0) { + ptnInfo.partType = PartType::A_TYPE; return; } - ptnInfo.partType = PARTITION_NORMAL_TYPE; + if (strcasecmp(partSuffix.c_str(), PARTITION_B_SUFFIX) == 0) { + ptnInfo.partType = PartType::B_TYPE; + return; + } + ptnInfo.partType = PartType::COMMON_TYPE; } void Ptable::ParsePartitionName(const uint8_t *data, const uint32_t dataLen, @@ -658,9 +666,10 @@ bool Ptable::WritePartitionBufToFile(uint8_t *ptbImgBuffer, const uint32_t imgBu LOG(ERROR) << "Invalid param "; return false; } - std::ofstream ptbFile(PTABLE_TEMP_PATH, std::ios::ate | std::ios::binary); + const char *ptablePath = Utils::IsUpdaterMode() ? PTABLE_TEMP_PATH : PTABLE_NORMAL_PATH; + std::ofstream ptbFile(ptablePath, std::ios::ate | std::ios::binary); if (ptbFile.fail()) { - LOG(ERROR) << "Failed to open " << PTABLE_TEMP_PATH << strerror(errno); + LOG(ERROR) << "Failed to open " << ptablePath << strerror(errno); return false; } ptbFile.write(reinterpret_cast(ptbImgBuffer), imgBufSize); @@ -679,10 +688,10 @@ bool Ptable::ReadPartitionFileToBuffer(uint8_t *ptbImgBuffer, uint32_t &imgBufSi LOG(ERROR) << "Invalid param "; return false; } - - std::ifstream ptbFile(PTABLE_TEMP_PATH, std::ios::in | std::ios::binary); + const char *ptablePath = Utils::IsUpdaterMode() ? PTABLE_TEMP_PATH : PTABLE_NORMAL_PATH; + std::ifstream ptbFile(ptablePath, std::ios::in | std::ios::binary); if (!ptbFile.is_open()) { - LOG(ERROR) << "open " << PTABLE_TEMP_PATH << " failed " << strerror(errno); + LOG(ERROR) << "open " << ptablePath << " failed " << strerror(errno); return false; } @@ -704,10 +713,11 @@ bool Ptable::ReadPartitionFileToBuffer(uint8_t *ptbImgBuffer, uint32_t &imgBufSi void Ptable::DeletePartitionTmpFile() { - if (Utils::DeleteFile(PTABLE_TEMP_PATH) != 0) { - LOG(ERROR) << "delete ptable tmp file fail " << PTABLE_TEMP_PATH << strerror(errno); + const char *ptablePath = Utils::IsUpdaterMode() ? PTABLE_TEMP_PATH : PTABLE_NORMAL_PATH; + if (Utils::DeleteFile(ptablePath) != 0) { + LOG(ERROR) << "delete ptable tmp file fail " << ptablePath << strerror(errno); return; } - LOG(INFO) << "delete ptable tmp file success " << PTABLE_TEMP_PATH; + LOG(INFO) << "delete ptable tmp file success " << ptablePath; } } // namespace Updater \ No newline at end of file diff --git a/services/ptable_parse/ptable.h b/services/ptable_parse/ptable.h index f25fa585..7bab2056 100644 --- a/services/ptable_parse/ptable.h +++ b/services/ptable_parse/ptable.h @@ -23,8 +23,10 @@ namespace Updater { #ifndef UPDATER_UT constexpr const char *PTABLE_TEMP_PATH = "/tmp/update_ptable.img"; +constexpr const char *PTABLE_NORMAL_PATH = "/mnt/sys_installer/update_ptable.img"; #else constexpr const char *PTABLE_TEMP_PATH = "/data/update/update_ptable.img"; +constexpr const char *PTABLE_NORMAL_PATH = "/data/update/update_ptable.img"; #endif class Ptable { public: @@ -32,6 +34,13 @@ public: DISALLOW_COPY_MOVE(Ptable); virtual ~Ptable() {} + enum class PartType { + COMMON_TYPE = 0, + A_TYPE, + B_TYPE, + RESERVED_TYPE + }; + static constexpr uint32_t GPT_PARTITION_TYPE_GUID_LEN = 16; static constexpr const char *PREFIX_SYS_CLASS_BLOCK = "/sys/class/block/sd"; static constexpr const char *PARTITION_NORMAL_TYPE = "normal"; @@ -50,7 +59,7 @@ public: int gptEntryBufOffset {}; bool isTailPart {false}; std::string dispName {}; - std::string partType {PARTITION_NORMAL_TYPE}; + PartType partType {PartType::COMMON_TYPE}; std::string writeMode {"WRITE_RAW"}; std::string writePath {}; }; diff --git a/services/ptable_parse/ptable_manager.cpp b/services/ptable_parse/ptable_manager.cpp index 4ce63ec9..2534f183 100644 --- a/services/ptable_parse/ptable_manager.cpp +++ b/services/ptable_parse/ptable_manager.cpp @@ -288,7 +288,8 @@ void PtableManager::InitCompositePtable() bool PtableManager::LoadPartitionInfoWithFile() { - if (!Utils::IsFileExist(PTABLE_TEMP_PATH)) { + const char *ptablePath = Utils::IsUpdaterMode() ? PTABLE_TEMP_PATH : PTABLE_NORMAL_PATH; + if (!Utils::IsFileExist(ptablePath)) { LOG(ERROR) << "ptable file is not exist, no need write"; return false; } -- Gitee