code static check problems fix

Signed-off-by: xianghengliang <xianghengliang1@huawei.com>
This commit is contained in:
xianghengliang 2022-01-28 09:03:13 +08:00
parent c641cfe0cd
commit bd40866497
3 changed files with 48 additions and 62 deletions

View File

@ -48,4 +48,3 @@ public:
} // namespace StorageDaemon } // namespace StorageDaemon
} // namespace OHOS } // namespace OHOS
#endif // UTILS_MOUNT_ARGUMENT_H #endif // UTILS_MOUNT_ARGUMENT_H

View File

@ -13,16 +13,16 @@
* limitations under the License. * limitations under the License.
*/ */
#include "crypto/key_manager.h"
#include "ipc/istorage_daemon.h"
#include "parameter.h"
#include "user/user_manager.h" #include "user/user_manager.h"
#include <stdlib.h>
#include "utils/errno.h" #include "utils/errno.h"
#include "utils/file_utils.h" #include "utils/file_utils.h"
#include "utils/string_utils.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/mount_argument_utils.h" #include "utils/mount_argument_utils.h"
#include "ipc/istorage_daemon.h" #include "utils/string_utils.h"
#include "crypto/key_manager.h" #include <stdlib.h>
#include "parameter.h"
#include <sys/mount.h> #include <sys/mount.h>
using namespace std; using namespace std;
@ -35,41 +35,32 @@ std::shared_ptr<UserManager> UserManager::instance_ = nullptr;
const std::string HMDFS_SYS_CAP = "const.distributed_file_property.enabled"; const std::string HMDFS_SYS_CAP = "const.distributed_file_property.enabled";
const int32_t HMDFS_VAL_LEN = 6; const int32_t HMDFS_VAL_LEN = 6;
UserManager::UserManager() UserManager::UserManager()
: rootDirVec_{ : rootDirVec_{{"/data/app/%s/%d", 0711, OID_ROOT, OID_ROOT},
{"/data/app/%s/%d", 0711, OID_ROOT, OID_ROOT}, {"/data/service/%s/%d", 0711, OID_ROOT, OID_ROOT},
{"/data/service/%s/%d", 0711, OID_ROOT, OID_ROOT}, {"/data/chipset/%s/%d", 0711, OID_ROOT, OID_ROOT}},
{"/data/chipset/%s/%d", 0711, OID_ROOT, OID_ROOT} subDirVec_{{"/data/app/%s/%d/base", 0711, OID_ROOT, OID_ROOT},
}, {"/data/app/%s/%d/database", 0711, OID_ROOT, OID_ROOT}},
subDirVec_{ hmdfsDirVec_{{"/data/service/el2/%d/hmdfs", 0711, OID_SYSTEM, OID_SYSTEM},
{"/data/app/%s/%d/base", 0711, OID_ROOT, OID_ROOT}, {"/data/service/el2/%d/hmdfs/account", 0711, OID_SYSTEM, OID_SYSTEM},
{"/data/app/%s/%d/database", 0711, OID_ROOT, OID_ROOT} {"/data/service/el2/%d/hmdfs/account/files", 0711, OID_SYSTEM, OID_SYSTEM},
}, {"/data/service/el2/%d/hmdfs/account/data", 0711, OID_SYSTEM, OID_SYSTEM},
hmdfsDirVec_{ {"/data/service/el2/%d/hmdfs/account/cache", 0711, OID_SYSTEM, OID_SYSTEM},
{"/data/service/el2/%d/hmdfs", 0711, OID_SYSTEM, OID_SYSTEM}, {"/data/service/el2/%d/hmdfs/non_account", 0711, OID_SYSTEM, OID_SYSTEM},
{"/data/service/el2/%d/hmdfs/account", 0711, OID_SYSTEM, OID_SYSTEM}, {"/data/service/el2/%d/hmdfs/non_account/files", 0711, OID_SYSTEM, OID_SYSTEM},
{"/data/service/el2/%d/hmdfs/account/files", 0711, OID_SYSTEM, OID_SYSTEM}, {"/data/service/el2/%d/hmdfs/non_account/data", 0711, OID_SYSTEM, OID_SYSTEM},
{"/data/service/el2/%d/hmdfs/account/data", 0711, OID_SYSTEM, OID_SYSTEM}, {"/data/service/el2/%d/hmdfs/non_account/cache", 0711, OID_SYSTEM, OID_SYSTEM}},
{"/data/service/el2/%d/hmdfs/account/cache", 0711, OID_SYSTEM, OID_SYSTEM}, virtualDir_{{"/storage/media/%d", 0711, OID_ROOT, OID_ROOT},
{"/data/service/el2/%d/hmdfs/non_account", 0711, OID_SYSTEM, OID_SYSTEM}, {"/storage/media/%d/local", 0711, OID_ROOT, OID_ROOT},
{"/data/service/el2/%d/hmdfs/non_account/files", 0711, OID_SYSTEM, OID_SYSTEM}, {"/mnt/hmdfs/%d/", 0711, OID_ROOT, OID_ROOT},
{"/data/service/el2/%d/hmdfs/non_account/data", 0711, OID_SYSTEM, OID_SYSTEM}, {"/mnt/hmdfs/%d/account", 0711, OID_ROOT, OID_ROOT},
{"/data/service/el2/%d/hmdfs/non_account/cache", 0711, OID_SYSTEM, OID_SYSTEM} {"/mnt/hmdfs/%d/non_account", 0711, OID_ROOT, OID_ROOT}}
}, {
virtualDir_{ }
{"/storage/media/%d", 0711, OID_ROOT, OID_ROOT},
{"/storage/media/%d/local", 0711, OID_ROOT, OID_ROOT},
{"/mnt/hmdfs/%d/", 0711, OID_ROOT, OID_ROOT},
{"/mnt/hmdfs/%d/account", 0711, OID_ROOT, OID_ROOT},
{"/mnt/hmdfs/%d/non_account", 0711, OID_ROOT, OID_ROOT}
}
{}
std::shared_ptr<UserManager> UserManager::GetInstance() std::shared_ptr<UserManager> UserManager::GetInstance()
{ {
static std::once_flag onceFlag; static std::once_flag onceFlag;
std::call_once(onceFlag, [&] () mutable{ std::call_once(onceFlag, [&]() mutable { instance_ = std::make_shared<UserManager>(); });
instance_ = std::make_shared<UserManager>();
});
return instance_; return instance_;
} }
@ -77,27 +68,24 @@ std::shared_ptr<UserManager> UserManager::GetInstance()
int32_t UserManager::HmdfsMount(int32_t userId) int32_t UserManager::HmdfsMount(int32_t userId)
{ {
Utils::MountArgument hmdfsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, true)); Utils::MountArgument hmdfsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, true));
int ret = Mount(StringPrintf(hmdfsSrc_.c_str(), userId), int ret = Mount(StringPrintf(hmdfsSrc_.c_str(), userId), StringPrintf(hmdfsDest_.c_str(), userId), "hmdfs",
StringPrintf(hmdfsDest_.c_str(), userId), hmdfsMntArgs.GetFlags(), hmdfsMntArgs.OptionsToString().c_str());
"hmdfs", hmdfsMntArgs.GetFlags(), hmdfsMntArgs.OptionsToString().c_str());
if (ret == -1 && errno != EEXIST && errno != EBUSY) { if (ret == -1 && errno != EEXIST && errno != EBUSY) {
LOGE("failed to mount hmdfs, err %{public}d", errno); LOGE("failed to mount hmdfs, err %{public}d", errno);
return E_MOUNT; return E_MOUNT;
} }
Utils::MountArgument hmdfsAuthMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, false)); Utils::MountArgument hmdfsAuthMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, false));
ret = Mount(StringPrintf(hmdfAuthSrc_.c_str(), userId), ret = Mount(StringPrintf(hmdfAuthSrc_.c_str(), userId), StringPrintf(hmdfsAuthDest_.c_str(), userId), "hmdfs",
StringPrintf(hmdfsAuthDest_.c_str(), userId), hmdfsAuthMntArgs.GetFlags(), hmdfsAuthMntArgs.OptionsToString().c_str());
"hmdfs", hmdfsAuthMntArgs.GetFlags(), hmdfsAuthMntArgs.OptionsToString().c_str());
if (ret == -1 && errno != EEXIST && errno != EBUSY) { if (ret == -1 && errno != EEXIST && errno != EBUSY) {
LOGE("failed to mount auth group hmdfs, err %{public}d", errno); LOGE("failed to mount auth group hmdfs, err %{public}d", errno);
return E_MOUNT; return E_MOUNT;
} }
// bind mount // bind mount
ret = Mount(StringPrintf((hmdfsDest_ + "device_view/").c_str(), userId), ret = Mount(StringPrintf((hmdfsDest_ + "device_view/").c_str(), userId), StringPrintf(ComDataDir_.c_str(), userId),
StringPrintf(ComDataDir_.c_str(), userId), nullptr, MS_BIND, nullptr);
nullptr, MS_BIND, nullptr);
if (ret == -1 && errno != EEXIST && errno != EBUSY) { if (ret == -1 && errno != EEXIST && errno != EBUSY) {
LOGE("failed to bind mount, err %{public}d", errno); LOGE("failed to bind mount, err %{public}d", errno);
return E_MOUNT; return E_MOUNT;
@ -112,22 +100,22 @@ int32_t UserManager::HmdfsUnMount(int32_t userId)
// un bind mount // un bind mount
err = UMount(StringPrintf(ComDataDir_.c_str(), userId)); err = UMount(StringPrintf(ComDataDir_.c_str(), userId));
if (err != E_OK) { if (err != E_OK) {
LOGE("failed to un bind mount, errno %{public}d, ComDataDir_ dst %{public}s", LOGE("failed to un bind mount, errno %{public}d, ComDataDir_ dst %{public}s", err,
err, StringPrintf(ComDataDir_.c_str(), userId).c_str()); StringPrintf(ComDataDir_.c_str(), userId).c_str());
} }
Utils::MountArgument hmdfsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, true)); Utils::MountArgument hmdfsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, true));
err = UMount2(hmdfsMntArgs.GetFullDst().c_str(), MNT_DETACH); err = UMount2(hmdfsMntArgs.GetFullDst().c_str(), MNT_DETACH);
if (err != E_OK) { if (err != E_OK) {
LOGE("identical account hmdfs umount failed, errno %{public}d, hmdfs dst %{public}s", LOGE("identical account hmdfs umount failed, errno %{public}d, hmdfs dst %{public}s", err,
err, hmdfsMntArgs.GetFullDst().c_str()); hmdfsMntArgs.GetFullDst().c_str());
} }
Utils::MountArgument hmdfsAuthMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, false)); Utils::MountArgument hmdfsAuthMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, false));
err += UMount2(hmdfsAuthMntArgs.GetFullDst().c_str(), MNT_DETACH); err += UMount2(hmdfsAuthMntArgs.GetFullDst().c_str(), MNT_DETACH);
if (err != E_OK) { if (err != E_OK) {
LOGE("umount auth hmdfs, errno %{public}d, auth hmdfs dst %{public}s", LOGE("umount auth hmdfs, errno %{public}d, auth hmdfs dst %{public}s", err,
err, hmdfsAuthMntArgs.GetFullDst().c_str()); hmdfsAuthMntArgs.GetFullDst().c_str());
} }
return err; return err;
@ -147,8 +135,7 @@ bool UserManager::SupportHmdfs()
int32_t UserManager::LocalMount(int32_t userId) int32_t UserManager::LocalMount(int32_t userId)
{ {
if (Mount(StringPrintf((hmdfsSrc_ + "files/").c_str(), userId), if (Mount(StringPrintf((hmdfsSrc_ + "files/").c_str(), userId),
StringPrintf((ComDataDir_ + "local/").c_str(), userId), StringPrintf((ComDataDir_ + "local/").c_str(), userId), nullptr, MS_BIND, nullptr)) {
nullptr, MS_BIND, nullptr)) {
LOGE("failed to bind mount, err %{public}d", errno); LOGE("failed to bind mount, err %{public}d", errno);
return E_MOUNT; return E_MOUNT;
} }
@ -354,5 +341,5 @@ int32_t UserManager::DestroyHmdfsDirs(int32_t userId)
return err ? E_OK : E_DESTROY_DIR; return err ? E_OK : E_DESTROY_DIR;
} }
} // StorageDaemon } // namespace StorageDaemon
} // OHOS } // namespace OHOS

View File

@ -31,9 +31,9 @@ string MountArgument::GetFullSrc() const
{ {
stringstream ss; stringstream ss;
if (sameAccount_ == true) { if (sameAccount_ == true) {
ss << DATA_POINT << userId_ << "/hmdfs/account/"; ss << DATA_POINT << userId_ << "/hmdfs/account/";
} else { } else {
ss << DATA_POINT << userId_ << "/hmdfs/non_account/" ; ss << DATA_POINT << userId_ << "/hmdfs/non_account/";
} }
return ss.str(); return ss.str();
@ -43,9 +43,9 @@ string MountArgument::GetFullDst() const
{ {
stringstream ss; stringstream ss;
if (sameAccount_ == true) { if (sameAccount_ == true) {
ss << BASE_MOUNT_POINT << userId_ << "/account/"; ss << BASE_MOUNT_POINT << userId_ << "/account/";
} else { } else {
ss << BASE_MOUNT_POINT << userId_ << "/non_account/" ; ss << BASE_MOUNT_POINT << userId_ << "/non_account/";
} }
return ss.str(); return ss.str();
@ -55,9 +55,9 @@ string MountArgument::GetCachePath() const
{ {
stringstream ss; stringstream ss;
if (sameAccount_ == true) { if (sameAccount_ == true) {
ss << DATA_POINT << userId_ << "/hmdfs/account/cache/"; ss << DATA_POINT << userId_ << "/hmdfs/account/cache/";
} else { } else {
ss << DATA_POINT << userId_ << "/hmdfs/non_account/cache/" ; ss << DATA_POINT << userId_ << "/hmdfs/non_account/cache/";
} }
return ss.str(); return ss.str();