赞
踩
#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(); /* Added for 虚拟文件系统检查 by chenkun 2020/10/27 below */ // TODO:注意:逻辑分区不能挂载 bool CheckVDMount(const string& fPath); bool isContainLoop(std::vector<string>& vecDevLoop); bool isContainFs(const std::string& str);// 判断某文件系统是否存在 bool umountAll(); /* Added for 虚拟文件系统检查 by chenkun 2020/10/27 above */ public: int m_isMount; // 挂载状态: -1-未知, 0-已经挂载, 1-未挂载 std::string m_imagePath; // 挂载的镜像文件路径 std::map<std::string, std::string> m_mapExtType; // 文件后缀-vdfuseType std::vector<std::string> m_vecBasicPartition; // 虚拟机文件挂载点 std::vector<std::string> m_vecDevLoop; // loop分区 }; #endif // VDFMOUNT_H
#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; } // 根据后缀名判断属于哪种虚拟机文件 // (VDI, VMDK, VHD) //fs::path fp = fs::absolute(fs::path(tmpPath)); //string ext = fp.extension().string(); 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; // 组合命令产生raw文件 // ./vdfuse -tVMDK -w -f "/disk3/fd/fd.vmdk" "/tmp/test2" if ((false == MKDIR(TmpVDRawPartition.c_str(), false)) ||(false == MKDIR(TmpVDBasicPartition.c_str(), false))) { return false
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。