void EraseEngine::discardBlock(unsigned long long offset, blksize_t size)
{
- char zeros[ERASE_SIZE] = "";
+ char zero[ERASE_SIZE] = {};
if (size > ERASE_SIZE) {
throw runtime::Exception("[eraseBlock] : size is too big");
}
- runtime::File zero("/dev/zero");
- zero.open(O_RDONLY);
- zero.read(zeros, sizeof(zeros));
- zero.close();
-
runtime::File device(target);
device.open(O_WRONLY);
device.lseek(offset, SEEK_SET);
- device.write(zeros, size);
+ device.write(zero, size);
device.close();
}
#include <fstream>
#include <vconf.h>
#include <unistd.h>
+#include <mntent.h>
#include "ext4-tool.h"
#include "engine/erase/erase-engine.h"
-#include "engine/erase/mmc-engine.h"
#include "rmi/secure-erase.h"
-
#define ERASE_ENGINE EraseEngine
#define PRIVILEGE_PLATFORM "http://tizen.org/privilege/internal/default/platform"
typedef std::unordered_map<std::string, std::string> DeviceList;
std::unique_ptr<ERASE_ENGINE> engine;
-const std::string evaluateTarget(const std::string &path)
+std::string findDevPath(const std::string &mntPath)
{
- DeviceList deviceList;
- DeviceList::const_iterator deviceListIter;
- std::string subStr(path);
- subStr.append("//");
- std::size_t pos = 0;
- std::string mountInfo;
- std::string name;
- std::string source;
- std::string type;
-
- runtime::File resource(path);
- if (!resource.exists()) {
- throw runtime::Exception("target doesn't exist");
- }
-
- std::ifstream file("/etc/mtab");
- if (file.fail()) {
- throw runtime::Exception("failed to access /etc/mtab");
- }
-
- while (std::getline(file, mountInfo)) {
- pos = mountInfo.find(" ");
- name = mountInfo.substr(0, pos);
- mountInfo.erase(0, pos+1);
-
- pos = mountInfo.find(" ");
- source = mountInfo.substr(0, pos);
- mountInfo.erase(0, pos+1);
-
- pos = mountInfo.find(" ");
- type = mountInfo.substr(0, pos);
- if (!type.compare("ext2") && !type.compare("ext3")
- && !type.compare("ext4")) {
- continue;
- }
- runtime::File device(name);
- if (!device.exists()) {
+ std::string ret;
+ FILE* mtab = ::setmntent("/etc/mtab", "r");
+ struct ::mntent* entry = NULL;
+ while ((entry = ::getmntent(mtab)) != NULL) {
+ if (strcmp(entry->mnt_type, "ext2") && strcmp(entry->mnt_type, "ext3") && strcmp(entry->mnt_type, "ext4"))
continue;
- }
- if (device.isDevice()) {
- deviceList.insert(std::make_pair(source, name));
- }
- }
-
- pos = subStr.size();
- while ((pos = subStr.rfind('/', pos - 1)) != std::string::npos && pos != 0) {
- std::string subPath = subStr.substr(0, pos);
- deviceListIter = deviceList.find(subPath);
- if (deviceListIter != deviceList.end()) {
- return deviceListIter->second;
+ if (mntPath == entry->mnt_dir) {
+ ret = entry->mnt_fsname;
+ break;
}
}
- return "";
+ ::endmntent(mtab);
+ return ret;
}
} /* namespace */
{
auto cleanWorker = [name, this]() {
try {
- std::string target;
- target = evaluateTarget(name);
+ std::string target = findDevPath(name);
engine->cleanDevice(target);
} catch (runtime::Exception &e) {}
};