diff --git a/services/ptable_parse/ufs_ptable.cpp b/services/ptable_parse/ufs_ptable.cpp index cfda373b524932e5dd64c3fb0a870a65b8c5b256..b4cee23a86f38c2680163081545400987ea4150f 100644 --- a/services/ptable_parse/ufs_ptable.cpp +++ b/services/ptable_parse/ufs_ptable.cpp @@ -45,6 +45,19 @@ uint32_t UfsPtable::GetPtableExtraOffset(void) } // avoid u disk being recognized as a valid gpt lun device +bool UfsPtable::IsUsbPath(const char* filePath) +{ + 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; + if (retSize > 0 && (strstr(linkBuf, targetUsbString) != nullptr || strstr(linkBuf, targetXhciString) != nullptr)) { + return true; + } + return false; +} + bool UfsPtable::CheckDeviceLunRemoveable(const uint32_t lunIndex) { constexpr uint32_t minRemoveableStartIdx = 3; @@ -88,7 +101,7 @@ void UfsPtable::SetDeviceLunNum() break; } #ifndef UPDATER_UT - if (CheckDeviceLunRemoveable(lunIndex)) { + if (CheckDeviceLunRemoveable(lunIndex) || IsUsbPath(ufsNode.c_str())) { 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 b0180f9129f483c7cc184e605913c8dfc2bf0417..96ae8fe7fd5021f3b0a383469a6c8ca914de5202 100644 --- a/services/ptable_parse/ufs_ptable.h +++ b/services/ptable_parse/ufs_ptable.h @@ -41,6 +41,7 @@ public: static constexpr uint32_t MAX_LUN_NUMBERS = 26; static constexpr uint32_t MIN_UFS_WRITE_SIZE = 4096; static constexpr uint32_t GPT_PTABLE_BACKUP_SIZE = 33; // back ptable at the end of lun + static constexpr uint32_t READ_LINK_BUFFER_LENTH = 1024; // readlink buffer size struct UfsPartitionDataInfo { bool isGptVaild; @@ -77,6 +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); }; } // namespace Updater #endif // UPDATER_UFS_PTABLE_H \ No newline at end of file