From a10587d9578686c1af2e24de9fe3a267c5a071de Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Tue, 3 Dec 2024 15:35:42 +0800 Subject: [PATCH 1/7] Revert "update services/storage_daemon/disk/src/disk_info.cpp." This reverts commit b440a57065966ad48ad319de95a731c0d58b0bd3. Signed-off-by: lixiyuan --- services/storage_daemon/disk/src/disk_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/storage_daemon/disk/src/disk_info.cpp b/services/storage_daemon/disk/src/disk_info.cpp index 0908fb22..8cd5c9a4 100644 --- a/services/storage_daemon/disk/src/disk_info.cpp +++ b/services/storage_daemon/disk/src/disk_info.cpp @@ -312,7 +312,7 @@ void DiskInfo::ProcessPartition(std::vector::iterator &it, const st std::string str = "0x0" + *it; int32_t type; int base = 16; - auto result = std::from_chars(str.data(), str.data() + str.size(), type, base); + auto result = std::from_chars(str.data(), str.size() + str.size(), type, base); if (result.ec != std::errc()) { LOGE("Volume type conversion failed"); } -- Gitee From fafb9267ca36df38eb1dd7f11e242ad1b778fced Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Tue, 3 Dec 2024 15:36:59 +0800 Subject: [PATCH 2/7] Revert "update services/storage_daemon/disk/src/disk_info.cpp." This reverts commit 0b5f560ba610ed30e36c134f7677291c16f541bf. Signed-off-by: lixiyuan --- services/storage_daemon/disk/src/disk_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/storage_daemon/disk/src/disk_info.cpp b/services/storage_daemon/disk/src/disk_info.cpp index 8cd5c9a4..4bb46c73 100644 --- a/services/storage_daemon/disk/src/disk_info.cpp +++ b/services/storage_daemon/disk/src/disk_info.cpp @@ -314,7 +314,7 @@ void DiskInfo::ProcessPartition(std::vector::iterator &it, const st int base = 16; auto result = std::from_chars(str.data(), str.size() + str.size(), type, base); if (result.ec != std::errc()) { - LOGE("Volume type conversion failed"); + LOGE("Volume type conversion failed"); //先不返回,因为createMRBVolume有校验 } if (CreateMBRVolume(type, partitionDev)) { foundPart = true; -- Gitee From 3455d5b2fc6381380baeff0dc267a1d0e4115667 Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Tue, 3 Dec 2024 15:37:26 +0800 Subject: [PATCH 3/7] Revert "update services/storage_daemon/disk/test/disk_manager_test.cpp." This reverts commit a0abaee9861ce1613ad22c27e509a26d079467e4. Signed-off-by: lixiyuan --- services/storage_daemon/disk/test/disk_manager_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/storage_daemon/disk/test/disk_manager_test.cpp b/services/storage_daemon/disk/test/disk_manager_test.cpp index 263c307c..fdf944d4 100644 --- a/services/storage_daemon/disk/test/disk_manager_test.cpp +++ b/services/storage_daemon/disk/test/disk_manager_test.cpp @@ -200,8 +200,8 @@ HWTEST_F(DiskManagerTest, Storage_Service_DiskManagerTest_ChangeDisk_001, TestSi auto nlData = std::make_unique(); nlData->Decode(msg); NetlinkData *data = nlData.get(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = (unsigned int) std::atoi(data.get()->GetParam("MAJOR").c_str()); + unsigned int minor = (unsigned int) std::atoi(data.get()->GetParam("MINOR").c_str()); dev_t device = makedev(major, minor); diskManager->ChangeDisk(device, data); -- Gitee From 2b38c9b2c6450a576fa8f7a747cf50f9b2c6a236 Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Tue, 3 Dec 2024 15:37:39 +0800 Subject: [PATCH 4/7] Revert "update services/storage_daemon/disk/src/disk_info.cpp." This reverts commit f5fa98d90d67ec11072e6540cb464496ba366e88. Signed-off-by: lixiyuan --- services/storage_daemon/disk/src/disk_info.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/storage_daemon/disk/src/disk_info.cpp b/services/storage_daemon/disk/src/disk_info.cpp index 4bb46c73..a164b05d 100644 --- a/services/storage_daemon/disk/src/disk_info.cpp +++ b/services/storage_daemon/disk/src/disk_info.cpp @@ -15,7 +15,6 @@ #include "disk/disk_info.h" -#include #include #include "disk/disk_manager.h" @@ -295,8 +294,7 @@ void DiskInfo::ProcessPartition(std::vector::iterator &it, const st if (++it == end) { return; } - int32_t index; - std::from_chars(it->data(), it->data() + it->size(), index); + int32_t index = std::atoi(it->data().c_str()); unsigned int majorId = major(device_); if ((index > maxVols && majorId == DISK_MMC_MAJOR) || index < 1) { LOGE("Invalid partition %{public}d", index); -- Gitee From d627ac16aca663b0f4ab47aae4f1efc07d74b4d0 Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Tue, 3 Dec 2024 15:37:55 +0800 Subject: [PATCH 5/7] Revert "update services/storage_daemon/crypto/src/fscrypt_key_v1.cpp." This reverts commit fc3de094588a92064ca577dd2bc77b2fd37f48a0. Signed-off-by: lixiyuan --- services/storage_daemon/crypto/src/fscrypt_key_v1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/storage_daemon/crypto/src/fscrypt_key_v1.cpp b/services/storage_daemon/crypto/src/fscrypt_key_v1.cpp index 73016b05..a13ecf0c 100644 --- a/services/storage_daemon/crypto/src/fscrypt_key_v1.cpp +++ b/services/storage_daemon/crypto/src/fscrypt_key_v1.cpp @@ -254,7 +254,7 @@ bool FscryptKeyV1::DoDecryptClassE(const UserAuth &auth, KeyBlob &eSecretFBE, Ke } // make sure a.length() >= PATH_KEY_VERSION.length() && b.length() >= PATH_KEY_VERSION.length() auto a_len = std::atoi((a.substr(PATH_KEY_VERSION.size() - 1)).c_str()); - auto b_len = std::atoi((b.substr(PATH_KEY_VERSION.size() - 1)).c_str()); + auto b_len = std::atoi((b.substr(PATH_KEY_VERSION.size() - 1)).c_str()) return a_len > b_len; }); for (const auto &it: files) { -- Gitee From bfd44c5d750fbf82f1b53e9303dd9f3acb0a1dba Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Tue, 3 Dec 2024 15:38:09 +0800 Subject: [PATCH 6/7] =?UTF-8?q?Revert=20"stoi=E6=95=B4=E6=94=B9"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d8774216f4197fa454e53c447185e338c2fa663e. Signed-off-by: lixiyuan --- services/storage_daemon/disk/src/disk_info.cpp | 3 +-- .../disk/test/disk_manager_test.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/services/storage_daemon/disk/src/disk_info.cpp b/services/storage_daemon/disk/src/disk_info.cpp index a164b05d..5d5a48bd 100644 --- a/services/storage_daemon/disk/src/disk_info.cpp +++ b/services/storage_daemon/disk/src/disk_info.cpp @@ -309,8 +309,7 @@ void DiskInfo::ProcessPartition(std::vector::iterator &it, const st } std::string str = "0x0" + *it; int32_t type; - int base = 16; - auto result = std::from_chars(str.data(), str.size() + str.size(), type, base); + auto result = std::from_chars(str.data(), str.size() + str.size(), type, 16); if (result.ec != std::errc()) { LOGE("Volume type conversion failed"); //先不返回,因为createMRBVolume有校验 } diff --git a/services/storage_daemon/disk/test/disk_manager_test.cpp b/services/storage_daemon/disk/test/disk_manager_test.cpp index fdf944d4..1a821551 100644 --- a/services/storage_daemon/disk/test/disk_manager_test.cpp +++ b/services/storage_daemon/disk/test/disk_manager_test.cpp @@ -172,8 +172,8 @@ HWTEST_F(DiskManagerTest, Storage_Service_DiskManagerTest_DestroyDisk_001, TestS \0PHYSDEVBUS=usb\0PHYSDEVDRIVER=usbhid\0MAJOR=13\0MINOR=34\0"}; auto data = std::make_unique(); data->Decode(msg); - unsigned int major = (unsigned int) std::atoi(data.get()->GetParam("MAJOR").c_str()); - unsigned int minor = (unsigned int) std::atoi(data.get()->GetParam("MINOR").c_str()); + unsigned int major = (unsigned int) std::stoi(data.get()->GetParam("MAJOR")); + unsigned int minor = (unsigned int) std::stoi(data.get()->GetParam("MINOR")); dev_t device = makedev(major, minor); diskManager->DestroyDisk(device); @@ -200,8 +200,8 @@ HWTEST_F(DiskManagerTest, Storage_Service_DiskManagerTest_ChangeDisk_001, TestSi auto nlData = std::make_unique(); nlData->Decode(msg); NetlinkData *data = nlData.get(); - unsigned int major = (unsigned int) std::atoi(data.get()->GetParam("MAJOR").c_str()); - unsigned int minor = (unsigned int) std::atoi(data.get()->GetParam("MINOR").c_str()); + unsigned int major = (unsigned int)std::stoi(data->GetParam("MAJOR")); + unsigned int minor = (unsigned int)std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); diskManager->ChangeDisk(device, data); @@ -227,8 +227,8 @@ HWTEST_F(DiskManagerTest, Storage_Service_DiskManagerTest_GetDisk_001, TestSize. \0PHYSDEVBUS=usb\0PHYSDEVDRIVER=usbhid\0MAJOR=13\0MINOR=34\0"}; auto data = std::make_unique(); data->Decode(msg); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); auto diskInfo = diskManager->GetDisk(device); @@ -256,8 +256,8 @@ HWTEST_F(DiskManagerTest, Storage_Service_DiskManagerTest_GetDisk_002, TestSize. \0PHYSDEVBUS=usb\0PHYSDEVDRIVER=usbhid\0MAJOR=13\0MINOR=34\0"}; auto data = std::make_unique(); data->Decode(msg); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); auto diskInfo = diskManager->MatchConfig(data.get()); -- Gitee From ffda0545b23ef8cb9df76f8e3f6df86d85fbfd13 Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Tue, 3 Dec 2024 15:38:21 +0800 Subject: [PATCH 7/7] =?UTF-8?q?Revert=20"stoi=E4=BD=BF=E7=94=A8=E6=95=B4?= =?UTF-8?q?=E6=94=B9"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 1f06fcf334f408ba6e6d44e1fa2d5b7d9efa0a7f. Signed-off-by: lixiyuan --- .../storage_daemon/crypto/src/base_key.cpp | 4 +- .../crypto/src/fscrypt_key_v1.cpp | 4 +- .../storage_daemon/disk/src/disk_info.cpp | 11 +-- .../storage_daemon/disk/src/disk_manager.cpp | 8 +- .../disk/test/disk_info_test.cpp | 88 +++++++++---------- .../storage_daemon/ipc/src/storage_daemon.cpp | 2 +- .../storage_daemon/user/src/mount_manager.cpp | 4 +- services/storage_daemon/utils/disk_utils.cpp | 2 +- 8 files changed, 57 insertions(+), 66 deletions(-) diff --git a/services/storage_daemon/crypto/src/base_key.cpp b/services/storage_daemon/crypto/src/base_key.cpp index d5fe1845..bc053ca6 100644 --- a/services/storage_daemon/crypto/src/base_key.cpp +++ b/services/storage_daemon/crypto/src/base_key.cpp @@ -507,9 +507,7 @@ bool BaseKey::RestoreKey(const UserAuth &auth, bool needSyncCandidate) return a.length() > b.length(); } // make sure a.length() >= PATH_KEY_VERSION.length() && b.length() >= PATH_KEY_VERSION.length() - auto a_len = std::atoi((a.substr(PATH_KEY_VERSION.size() - 1)).c_str()); - auto b_len = std::atoi((b.substr(PATH_KEY_VERSION.size() - 1)).c_str()); - return a_len > b_len; + return std::stoi(a.substr(PATH_KEY_VERSION.size() - 1)) > std::stoi(b.substr(PATH_KEY_VERSION.size() - 1)); }); for (const auto &it: files) { if (it != candidate) { diff --git a/services/storage_daemon/crypto/src/fscrypt_key_v1.cpp b/services/storage_daemon/crypto/src/fscrypt_key_v1.cpp index a13ecf0c..d38f6cd3 100644 --- a/services/storage_daemon/crypto/src/fscrypt_key_v1.cpp +++ b/services/storage_daemon/crypto/src/fscrypt_key_v1.cpp @@ -253,9 +253,7 @@ bool FscryptKeyV1::DoDecryptClassE(const UserAuth &auth, KeyBlob &eSecretFBE, Ke return a.length() > b.length(); } // make sure a.length() >= PATH_KEY_VERSION.length() && b.length() >= PATH_KEY_VERSION.length() - auto a_len = std::atoi((a.substr(PATH_KEY_VERSION.size() - 1)).c_str()); - auto b_len = std::atoi((b.substr(PATH_KEY_VERSION.size() - 1)).c_str()) - return a_len > b_len; + return std::stoi(a.substr(PATH_KEY_VERSION.size() - 1)) > std::stoi(b.substr(PATH_KEY_VERSION.size() - 1)); }); for (const auto &it: files) { if (it != candidate) { diff --git a/services/storage_daemon/disk/src/disk_info.cpp b/services/storage_daemon/disk/src/disk_info.cpp index 5d5a48bd..e3071e29 100644 --- a/services/storage_daemon/disk/src/disk_info.cpp +++ b/services/storage_daemon/disk/src/disk_info.cpp @@ -143,7 +143,7 @@ void DiskInfo::ReadMetadata() LOGE("open file %{public}s failed", path.c_str()); return; } - int manfid = std::atoi(str.c_str()); + int manfid = std::stoi(str); switch (manfid) { case 0x000003: { vendor_ = "SanDisk"; @@ -294,7 +294,7 @@ void DiskInfo::ProcessPartition(std::vector::iterator &it, const st if (++it == end) { return; } - int32_t index = std::atoi(it->data().c_str()); + int32_t index = std::stoi(*it); unsigned int majorId = major(device_); if ((index > maxVols && majorId == DISK_MMC_MAJOR) || index < 1) { LOGE("Invalid partition %{public}d", index); @@ -307,12 +307,7 @@ void DiskInfo::ProcessPartition(std::vector::iterator &it, const st if (++it == end) { return; } - std::string str = "0x0" + *it; - int32_t type; - auto result = std::from_chars(str.data(), str.size() + str.size(), type, 16); - if (result.ec != std::errc()) { - LOGE("Volume type conversion failed"); //先不返回,因为createMRBVolume有校验 - } + int32_t type = std::stoi("0x0" + *it, 0, 16); if (CreateMBRVolume(type, partitionDev)) { foundPart = true; } else { diff --git a/services/storage_daemon/disk/src/disk_manager.cpp b/services/storage_daemon/disk/src/disk_manager.cpp index 6b389789..61719185 100644 --- a/services/storage_daemon/disk/src/disk_manager.cpp +++ b/services/storage_daemon/disk/src/disk_manager.cpp @@ -55,8 +55,8 @@ void DiskManager::HandleDiskEvent(NetlinkData *data) return; } - unsigned int major = (unsigned int) std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = (unsigned int) std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = (unsigned int) std::stoi(data->GetParam("MAJOR")); + unsigned int minor = (unsigned int) std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); switch (data->GetAction()) { @@ -95,8 +95,8 @@ std::shared_ptr DiskManager::MatchConfig(NetlinkData *data) } std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = (unsigned int) std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = (unsigned int) std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = (unsigned int) std::stoi(data->GetParam("MAJOR")); + unsigned int minor = (unsigned int) std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); for (auto config : diskConfig_) { diff --git a/services/storage_daemon/disk/test/disk_info_test.cpp b/services/storage_daemon/disk/test/disk_info_test.cpp index 227824f9..99be2d93 100644 --- a/services/storage_daemon/disk/test/disk_info_test.cpp +++ b/services/storage_daemon/disk/test/disk_info_test.cpp @@ -57,8 +57,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_Create_001, TestSize.Level1) data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -90,8 +90,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_Create_002, TestSize.Level1) data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -123,8 +123,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_Destroy_001, TestSize.Level1 data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -156,8 +156,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_Destroy_002, TestSize.Level1 data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -189,8 +189,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_ReadPartition_001, TestSize. data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -222,8 +222,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_ReadPartition_002, TestSize. data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -255,8 +255,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_CreateVolume_001, TestSize.L data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -288,8 +288,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_CreateVolume_002, TestSize.L data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -321,8 +321,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_Partition_001, TestSize.Leve data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -354,8 +354,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_Partition_002, TestSize.Leve data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -387,8 +387,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_GetDevice_001, TestSize.Leve data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -420,8 +420,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_GetId_001, TestSize.Level1) data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -454,8 +454,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_GetDevPath_001, TestSize.Lev data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -487,8 +487,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_GetDevDSize_001, TestSize.Le data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -521,8 +521,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_GetSysPath_001, TestSize.Lev data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -554,8 +554,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_GetDevVendor_001, TestSize.L data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; std::string path(sysPath + "/device/manfid"); @@ -589,8 +589,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_GetDevFlag_001, TestSize.Lev data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -622,8 +622,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_GetDevInfo_001, TestSize.Lev data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -654,8 +654,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_Partition_003, TestSize.Leve data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -687,8 +687,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_Destroy_003, TestSize.Level1 data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -719,8 +719,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_CreateVolume_003, TestSize.L data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; @@ -751,8 +751,8 @@ HWTEST_F(DiskInfoTest, Storage_Service_DiskInfoTest_Partition_004, TestSize.Leve data->Decode(msg); std::string sysPath = data->GetSyspath(); std::string devPath = data->GetDevpath(); - unsigned int major = std::atoi(data->GetParam("MAJOR").c_str()); - unsigned int minor = std::atoi(data->GetParam("MINOR").c_str()); + unsigned int major = std::stoi(data->GetParam("MAJOR")); + unsigned int minor = std::stoi(data->GetParam("MINOR")); dev_t device = makedev(major, minor); int flag = 0; diff --git a/services/storage_daemon/ipc/src/storage_daemon.cpp b/services/storage_daemon/ipc/src/storage_daemon.cpp index 9d3964a6..ab92fc1e 100644 --- a/services/storage_daemon/ipc/src/storage_daemon.cpp +++ b/services/storage_daemon/ipc/src/storage_daemon.cpp @@ -1216,7 +1216,7 @@ int32_t StorageDaemon::UpdateMemoryPara(int32_t size, int32_t &oldSize) LOGE("Failed to read"); } if (!oldContent.empty()) { - oldSize = std::atoi(oldContent.c_str()); + oldSize = std::stoi(oldContent); } else { oldSize = DEFAULT_VFS_CACHE_PRESSURE; } diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index e82ed99a..e7cc8438 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -458,7 +458,7 @@ bool MountManager::GetProcessInfo(const std::string &filename, ProcessInfo &info ss >> pid; std::string processName; ss >> processName; - info.pid = std::atoi(pid.c_str()); + info.pid = std::stoi(pid); info.name = processName; LOGE("GetProcessInfo pid is %{public}s and name is %{public}s", pid.c_str(), processName.c_str()); inputStream.close(); @@ -1423,7 +1423,7 @@ void MountManager::GetAllUserId(std::vector &userIds) if (!StringIsNumber(subPath)) { continue; } - int32_t userId = atoi(subPath.c_str()); + int32_t userId = stoi(subPath); if (userId < DEFAULT_USERID) { continue; } diff --git a/services/storage_daemon/utils/disk_utils.cpp b/services/storage_daemon/utils/disk_utils.cpp index 430d4864..6d7677a3 100644 --- a/services/storage_daemon/utils/disk_utils.cpp +++ b/services/storage_daemon/utils/disk_utils.cpp @@ -84,7 +84,7 @@ int GetMaxVolume(dev_t device) LOGE("Get MmcMaxVolumes failed"); return E_ERR; } - return std::atoi(str.c_str()); + return std::stoi(str); } else { return MAX_SCSI_VOLUMES; } -- Gitee