vdfmount.h
#ifndef VDFMOUNT_H
#define VDFMOUNT_H
#include <sys/mount.h>
#include "public.h"
#include "WidgetConst.h"
#include "Logger.h"
using namespace LogFile;
class vdfMount
{
public:
vdfMount()
{
m_isMount = -1;
m_imagePath = "";
m_mapExtType[".vmdk"] = "VMDK";
m_mapExtType[".vdi"] = "VDI";
m_mapExtType[".vhd"] = "VHD";
}
~vdfMount();
bool CheckVDMount(const string& fPath);
bool isContainLoop(std::vector<string>& vecDevLoop);
bool isContainFs(const std::string& str);
bool umountAll();
public:
int m_isMount;
std::string m_imagePath;
std::map<std::string, std::string> m_mapExtType;
std::vector<std::string> m_vecBasicPartition;
std::vector<std::string> m_vecDevLoop;
};
#endif
vdfmount.cpp
#include "vdfmount.h"
bool vdfMount::CheckVDMount(const string& fPath)
{
if (fPath.empty())
{
return false;
}
m_vecBasicPartition.clear();
m_vecDevLoop.clear();
string tmpPath = CDir::getFullPath(fPath.c_str());
if (0 != access(tmpPath.c_str(), F_OK))
{
LOG_INFO("fuse fPath(not found)==%s", fPath.c_str());
return false;
}
std::size_t pos;
std::string ext;
if((pos = tmpPath.rfind(".")) != std::string::npos)
{
ext = tmpPath.substr(pos);
}
auto iter = m_mapExtType.find(ext);
if (iter == m_mapExtType.end())
{
LOG_INFO("fuse fPath(type error)==%s", fPath.c_str());
return false;
}
string Type = iter->second;
if ((false == MKDIR(TmpVDRawPartition.c_str(), false)) ||(false == MKDIR(TmpVDBasicPartition.c_str(), f