From 35aa5c305381e4d637dd80204995501bc5f9bb51 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Dec 2024 15:00:43 +0800 Subject: [PATCH] fix readlink path Signed-off-by: unknown --- services/ptable_parse/ufs_ptable.cpp | 10 ++++++---- services/ptable_parse/ufs_ptable.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/services/ptable_parse/ufs_ptable.cpp b/services/ptable_parse/ufs_ptable.cpp index b4cee23a..0c6e7e01 100644 --- a/services/ptable_parse/ufs_ptable.cpp +++ b/services/ptable_parse/ufs_ptable.cpp @@ -45,13 +45,15 @@ uint32_t UfsPtable::GetPtableExtraOffset(void) } // avoid u disk being recognized as a valid gpt lun device -bool UfsPtable::IsUsbPath(const char* filePath) +bool UfsPtable::IsUsbPath(const uint32_t lunIndex) { + char lunIndexName = 'a' + lunIndex; const char* targetUsbString = "usb"; const char* targetXhciString = "xhci"; char linkBuf[READ_LINK_BUFFER_LENTH] = {0}; - ssize_t retSize = readlink(filePath, linkBuf, READ_LINK_BUFFER_LENTH - 1); - LOG(INFO) << "readlibk " << filePath << " retSzie " << retSize << ", linkBuf is: " << linkBuf; + std::string filePath = std::string(PREFIX_SYS_CLASS_BLOCK) + lunIndexName; + ssize_t retSize = readlink(filePath.c_str(), linkBuf, READ_LINK_BUFFER_LENTH - 1); + LOG(INFO) << "readlink " << filePath << " retSzie " << retSize << ", linkBuf is: " << linkBuf; if (retSize > 0 && (strstr(linkBuf, targetUsbString) != nullptr || strstr(linkBuf, targetXhciString) != nullptr)) { return true; } @@ -101,7 +103,7 @@ void UfsPtable::SetDeviceLunNum() break; } #ifndef UPDATER_UT - if (CheckDeviceLunRemoveable(lunIndex) || IsUsbPath(ufsNode.c_str())) { + if (CheckDeviceLunRemoveable(lunIndex) || IsUsbPath(lunIndex)) { LOG(ERROR) << "device " << ufsNode << " is removable, may be a u disk"; break; } diff --git a/services/ptable_parse/ufs_ptable.h b/services/ptable_parse/ufs_ptable.h index 96ae8fe7..f6ee7809 100644 --- a/services/ptable_parse/ufs_ptable.h +++ b/services/ptable_parse/ufs_ptable.h @@ -78,7 +78,7 @@ public: uint8_t *GetPtableImageUfsLunPmbrStart(uint8_t *imageBuf, const uint32_t lunIndex); uint8_t *GetPtableImageUfsLunGptHeaderStart(uint8_t *imageBuf, const uint32_t lunIndex); uint8_t *GetPtableImageUfsLunEntryStart(uint8_t *imageBuf, const uint32_t lunIndex); - bool IsUsbPath(const char* filePath); + bool IsUsbPath(const uint32_t lunIndex); }; } // namespace Updater #endif // UPDATER_UFS_PTABLE_H \ No newline at end of file -- Gitee