From 253a3cb1a0f2b684bedd1d940c91f7d9eb430784 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Dec 2024 14:45:09 +0800 Subject: [PATCH 1/3] add usb path judge Signed-off-by: unknown --- services/ptable_parse/ufs_ptable.cpp | 15 ++++++++++++++- services/ptable_parse/ufs_ptable.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/services/ptable_parse/ufs_ptable.cpp b/services/ptable_parse/ufs_ptable.cpp index cfda373b..ea6a59e6 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}; + sszie_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 b0180f91..99e5f4b1 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; 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 -- Gitee From 006e200dc997f139b9009550fe84dcc819a8d15b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Dec 2024 15:23:52 +0800 Subject: [PATCH 2/3] fix Signed-off-by: unknown --- services/ptable_parse/ufs_ptable.cpp | 2 +- services/ptable_parse/ufs_ptable.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/ptable_parse/ufs_ptable.cpp b/services/ptable_parse/ufs_ptable.cpp index ea6a59e6..93ee0c32 100644 --- a/services/ptable_parse/ufs_ptable.cpp +++ b/services/ptable_parse/ufs_ptable.cpp @@ -50,7 +50,7 @@ bool UfsPtable::IsUsbPath(const char* filePath) const char* targetUsbString = "usb"; const char* targetXhciString = "xhci"; char linkBuf[READ_LINK_BUFFER_LENTH] = {0}; - sszie_t retSize = readlink(filePath, linkBuf, READ_LINK_BUFFER_LENTH - 1); + 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; diff --git a/services/ptable_parse/ufs_ptable.h b/services/ptable_parse/ufs_ptable.h index 99e5f4b1..96ae8fe7 100644 --- a/services/ptable_parse/ufs_ptable.h +++ b/services/ptable_parse/ufs_ptable.h @@ -41,7 +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; + static constexpr uint32_t READ_LINK_BUFFER_LENTH = 1024; // readlink buffer size struct UfsPartitionDataInfo { bool isGptVaild; -- Gitee From 057e30d19059fe68160075411cae04263b2b42d4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Dec 2024 15:23:52 +0800 Subject: [PATCH 3/3] fix Signed-off-by: unknown --- services/ptable_parse/ufs_ptable.cpp | 4 ++-- services/ptable_parse/ufs_ptable.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/ptable_parse/ufs_ptable.cpp b/services/ptable_parse/ufs_ptable.cpp index ea6a59e6..b4cee23a 100644 --- a/services/ptable_parse/ufs_ptable.cpp +++ b/services/ptable_parse/ufs_ptable.cpp @@ -50,9 +50,9 @@ bool UfsPtable::IsUsbPath(const char* filePath) const char* targetUsbString = "usb"; const char* targetXhciString = "xhci"; char linkBuf[READ_LINK_BUFFER_LENTH] = {0}; - sszie_t retSize = readlink(filePath, linkBuf, READ_LINK_BUFFER_LENTH - 1); + 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)) { + if (retSize > 0 && (strstr(linkBuf, targetUsbString) != nullptr || strstr(linkBuf, targetXhciString) != nullptr)) { return true; } return false; diff --git a/services/ptable_parse/ufs_ptable.h b/services/ptable_parse/ufs_ptable.h index 99e5f4b1..96ae8fe7 100644 --- a/services/ptable_parse/ufs_ptable.h +++ b/services/ptable_parse/ufs_ptable.h @@ -41,7 +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; + static constexpr uint32_t READ_LINK_BUFFER_LENTH = 1024; // readlink buffer size struct UfsPartitionDataInfo { bool isGptVaild; -- Gitee