mirror of
https://gitee.com/openharmony/filemanagement_storage_service
synced 2024-11-23 06:59:59 +00:00
存储管理接入删除维测2.0系统
Signed-off-by: renguang1116 <renguang@huawei.com>
This commit is contained in:
parent
3bf731c1f6
commit
d51576b15d
@ -254,6 +254,7 @@ ohos_shared_library("storage_common_utils") {
|
||||
"./utils/file_utils.cpp",
|
||||
"./utils/mount_argument_utils.cpp",
|
||||
"./utils/storage_radar.cpp",
|
||||
"./utils/storage_utils.cpp",
|
||||
"./utils/string_utils.cpp",
|
||||
]
|
||||
|
||||
|
@ -128,6 +128,7 @@ private:
|
||||
void ActiveAppCloneUserKey();
|
||||
void AncoInitCryptKey();
|
||||
void AncoActiveCryptKey(uint32_t userId);
|
||||
void SetDeleteFlag4KeyFiles();
|
||||
};
|
||||
} // StorageDaemon
|
||||
} // OHOS
|
||||
|
33
services/storage_daemon/include/utils/storage_utils.h
Normal file
33
services/storage_daemon/include/utils/storage_utils.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_STORAGE_UTILS_H
|
||||
#define OHOS_STORAGE_UTILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace StorageService {
|
||||
|
||||
class StorageUtils {
|
||||
public:
|
||||
static void ParseDirPath(const std::string &path);
|
||||
static void SetDirDelFlags(const std::string &dirpath);
|
||||
static void SetFileDelFlags(const std::string &dirpath);
|
||||
};
|
||||
|
||||
} // namespace StorageService
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_STORAGE_UTILS_H
|
@ -21,6 +21,7 @@
|
||||
#include <thread>
|
||||
#include "hisysevent.h"
|
||||
#include "utils/storage_radar.h"
|
||||
#include "utils/storage_utils.h"
|
||||
|
||||
#ifdef USER_CRYPTO_MANAGER
|
||||
#include "crypto/anco_key_manager.h"
|
||||
@ -345,9 +346,17 @@ int32_t StorageDaemon::InitGlobalUserKeys(void)
|
||||
#ifdef USER_CRYPTO_MANAGER
|
||||
AncoInitCryptKey();
|
||||
#endif
|
||||
std::thread thread([this]() { SetDeleteFlag4KeyFiles(); });
|
||||
thread.detach();
|
||||
return result;
|
||||
}
|
||||
|
||||
void StorageDaemon::SetDeleteFlag4KeyFiles()
|
||||
{
|
||||
StorageService::StorageUtils::ParseDirPath(DATA_SERVICE_EL0_STORAGE_DAEMON_SD);
|
||||
StorageService::StorageUtils::ParseDirPath(DATA_SERVICE_EL1_PUBLIC_STORAGE_DAEMON_SD);
|
||||
}
|
||||
|
||||
int32_t StorageDaemon::GenerateUserKeys(uint32_t userId, uint32_t flags)
|
||||
{
|
||||
#ifdef USER_CRYPTO_MANAGER
|
||||
|
111
services/storage_daemon/utils/storage_utils.cpp
Normal file
111
services/storage_daemon/utils/storage_utils.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "storage_service_log.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "utils/storage_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace StorageService {
|
||||
#define HMFS_MONITOR_FL 0x00000002
|
||||
#define HMFS_IOCTL_HW_GET_FLAGS _IOR(0XF5, 70, unsigned int)
|
||||
#define HMFS_IOCTL_HW_SET_FLAGS _IOR(0XF5, 71, unsigned int)
|
||||
|
||||
void StorageUtils::ParseDirPath(const std::string &path)
|
||||
{
|
||||
LOGI("StorageUtils parse dirpath start.");
|
||||
SetDirDelFlags(path);
|
||||
std::filesystem::directory_iterator pathList(path);
|
||||
for (const auto& resPath : pathList) {
|
||||
if (std::filesystem::is_directory(resPath)) {
|
||||
ParseDirPath(resPath.path().c_str());
|
||||
}
|
||||
SetFileDelFlags(resPath.path().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void StorageUtils::SetFileDelFlags(const std::string &filepath)
|
||||
{
|
||||
LOGI("StorageUtils SetFileDelFlags for dirpath start.");
|
||||
char absPath[PATH_MAX] = {0};
|
||||
if (realpath(filepath.c_str(), absPath) == nullptr) {
|
||||
LOGE("StorageUtils Failed to get realpath");
|
||||
return;
|
||||
}
|
||||
int32_t fd = open(absPath, O_RDWR);
|
||||
if (fd < 0) {
|
||||
LOGE("StorageUtils Failed to open dir, errno: %{public}d", errno);
|
||||
return;
|
||||
}
|
||||
unsigned int flags = 0;
|
||||
int32_t ret = ioctl(fd, HMFS_IOCTL_HW_GET_FLAGS, &flags);
|
||||
if (ret < 0) {
|
||||
LOGE("StorageUtils Failed to get flags, errno: %{public}d", errno);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
if (flags & HMFS_MONITOR_FL) {
|
||||
LOGE("StorageUtils Delete control flag ia already set");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
flags |= HMFS_MONITOR_FL;
|
||||
ret = ioctl(fd, HMFS_IOCTL_HW_SET_FLAGS, &flags);
|
||||
if (ret < 0) {
|
||||
LOGE("StorageUtils Failed to set flags, errno: %{public}d", errno);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void StorageUtils::SetDirDelFlags(const std::string &dirpath)
|
||||
{
|
||||
LOGI("StorageUtils SetDirDelFlags for dirpath start.");
|
||||
char absPath[PATH_MAX] = {0};
|
||||
if (realpath(dirpath.c_str(), absPath) == nullptr) {
|
||||
LOGE("StorageUtils Failed to get realpath");
|
||||
return;
|
||||
}
|
||||
int32_t fd = open(absPath, O_DIRECTORY);
|
||||
if (fd < 0) {
|
||||
LOGE("StorageUtils Failed to open dir, errno: %{public}d", errno);
|
||||
return;
|
||||
}
|
||||
unsigned int flags = 0;
|
||||
int32_t ret = ioctl(fd, HMFS_IOCTL_HW_GET_FLAGS, &flags);
|
||||
if (ret < 0) {
|
||||
LOGE("StorageUtils Failed to get flags, errno: %{public}d", errno);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
if (flags & HMFS_MONITOR_FL) {
|
||||
LOGE("StorageUtils Delete control flag ia already set");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
flags |= HMFS_MONITOR_FL;
|
||||
ret = ioctl(fd, HMFS_IOCTL_HW_SET_FLAGS, &flags);
|
||||
if (ret < 0) {
|
||||
LOGE("StorageUtils Failed to set flags, errno: %{public}d", errno);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ ohos_fuzztest("StorageDaemonFuzzTest") {
|
||||
"${storage_daemon_path}/utils/file_utils.cpp",
|
||||
"${storage_daemon_path}/utils/mount_argument_utils.cpp",
|
||||
"${storage_daemon_path}/utils/storage_radar.cpp",
|
||||
"${storage_daemon_path}/utils/storage_utils.cpp",
|
||||
"${storage_daemon_path}/utils/string_utils.cpp",
|
||||
"${storage_service_path}/test/fuzztest/storagedaemon_fuzzer/storagedaemon_fuzzer.cpp",
|
||||
]
|
||||
|
@ -44,6 +44,7 @@ ohos_fuzztest("StorageDaemonCreateShareFileFuzzTest") {
|
||||
"${storage_daemon_path}/utils/file_utils.cpp",
|
||||
"${storage_daemon_path}/utils/mount_argument_utils.cpp",
|
||||
"${storage_daemon_path}/utils/storage_radar.cpp",
|
||||
"${storage_daemon_path}/utils/storage_utils.cpp",
|
||||
"${storage_daemon_path}/utils/string_utils.cpp",
|
||||
"${storage_service_path}/test/fuzztest/storagedaemoncreatesharefile_fuzzer/storagedaemoncreatesharefile_fuzzer.cpp",
|
||||
]
|
||||
|
@ -44,6 +44,7 @@ ohos_fuzztest("StorageDaemonDeleteShareFileFuzzTest") {
|
||||
"${storage_daemon_path}/utils/file_utils.cpp",
|
||||
"${storage_daemon_path}/utils/mount_argument_utils.cpp",
|
||||
"${storage_daemon_path}/utils/storage_radar.cpp",
|
||||
"${storage_daemon_path}/utils/storage_utils.cpp",
|
||||
"${storage_daemon_path}/utils/string_utils.cpp",
|
||||
"${storage_service_path}/test/fuzztest/storagedaemondeletesharefile_fuzzer/storagedaemondeletesharefile_fuzzer.cpp",
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user