Compare commits
1 Commits
master
...
feature/sh
| Author | SHA1 | Date | |
|---|---|---|---|
| 612d531dae |
@ -8,7 +8,7 @@
|
||||
#ifndef REHDD_H_
|
||||
#define REHDD_H_
|
||||
|
||||
#define REHDD_VERSION "V1.3.0"
|
||||
#define REHDD_VERSION "V1.2.1"
|
||||
|
||||
// Drive handling Settings
|
||||
#define WORSE_HOURS 19200 // mark drive if at this limit or beyond
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
|
||||
#define CHUNK_SIZE 1024 * 1024 * 32 // amount of bytes that are overwritten at once --> 32MB
|
||||
#define TFNG_DATA_SIZE CHUNK_SIZE // amount of bytes used by tfng
|
||||
#define O_DIRECT_PAGE_SIZE 4096 // needed page size for O_DIRECT
|
||||
|
||||
// #define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB
|
||||
// #define DEMO_DRIVE_SIZE 1024*1024*1024L // 1GB
|
||||
@ -38,8 +39,8 @@ public:
|
||||
private:
|
||||
fileDescriptor randomSrcFileDiscr;
|
||||
fileDescriptor driveFileDiscr;
|
||||
unsigned char caTfngData[TFNG_DATA_SIZE];
|
||||
unsigned char caReadBuffer[CHUNK_SIZE];
|
||||
unsigned char *caTfngData;
|
||||
unsigned char *caReadBuffer;
|
||||
unsigned long ulDriveByteSize;
|
||||
unsigned long ulDriveByteOverallCount = 0; // all bytes shredded in all iterations + checking -> used for progress calculation
|
||||
double d32Percent = 0.0;
|
||||
|
||||
108
src/reHDD.cpp
108
src/reHDD.cpp
@ -418,8 +418,8 @@ void reHDD::searchDrives(std::list<Drive> *plistDrives)
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief filter out drives that are listed in "ignoreDrives.conf", loop devices, and optical drives
|
||||
* \param pointer of list <Drive>* plistDrives
|
||||
* \brief filter out drives that are listed in "ignoreDrives.conf"
|
||||
* \param pointer of list <Drive>* plistDrives
|
||||
* \return void
|
||||
*/
|
||||
void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
|
||||
@ -428,8 +428,9 @@ void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
|
||||
if (getSystemDrive(systemDrivePath))
|
||||
{
|
||||
// Logger::logThis()->info("Found system drive: " + systemDrivePath);
|
||||
list<Drive>::iterator it = plistDrives->begin();
|
||||
while (it != plistDrives->end())
|
||||
|
||||
list<Drive>::iterator it;
|
||||
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
|
||||
{
|
||||
string driveName = it->getPath();
|
||||
// Remove /dev/ prefix
|
||||
@ -437,7 +438,6 @@ void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
|
||||
{
|
||||
driveName = driveName.substr(5); // Skip "/dev/"
|
||||
}
|
||||
|
||||
if (systemDrivePath.find(driveName) != std::string::npos) // compare found system drive and current drive
|
||||
{
|
||||
// system drive found --> ignore this drive
|
||||
@ -446,123 +446,59 @@ void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
|
||||
#endif
|
||||
it = plistDrives->erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out loop devices (loop0, loop1, etc.)
|
||||
list<Drive>::iterator it = plistDrives->begin();
|
||||
while (it != plistDrives->end())
|
||||
{
|
||||
string driveName = it->getPath();
|
||||
if (driveName.find("/dev/") == 0)
|
||||
{
|
||||
driveName = driveName.substr(5);
|
||||
}
|
||||
|
||||
if (driveName.find("loop") == 0)
|
||||
{
|
||||
#ifdef LOG_LEVEL_HIGH
|
||||
Logger::logThis()->info("loop device found --> ignore this drive: " + it->getPath());
|
||||
#endif
|
||||
it = plistDrives->erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out optical drives (sr0, sr1, cdrom, dvd, etc.)
|
||||
it = plistDrives->begin();
|
||||
while (it != plistDrives->end())
|
||||
{
|
||||
string driveName = it->getPath();
|
||||
if (driveName.find("/dev/") == 0)
|
||||
{
|
||||
driveName = driveName.substr(5);
|
||||
}
|
||||
|
||||
if (driveName.find("sr") == 0 ||
|
||||
driveName.find("cdrom") == 0 ||
|
||||
driveName.find("dvd") == 0 ||
|
||||
driveName.find("cdrw") == 0)
|
||||
{
|
||||
#ifdef LOG_LEVEL_HIGH
|
||||
Logger::logThis()->info("optical drive found --> ignore this drive: " + it->getPath());
|
||||
#endif
|
||||
it = plistDrives->erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// Read ignored drives from config file
|
||||
list<tuple<string>> vtlIgnoredDevices;
|
||||
ifstream input("ignoreDrives.conf");
|
||||
list<tuple<string>> vtlIgnoredDevices; // store drives from ignore file
|
||||
ifstream input("ignoreDrives.conf"); // read ignore file
|
||||
|
||||
for (string sLine; getline(input, sLine);)
|
||||
{
|
||||
// Skip empty lines and comments
|
||||
if (!sLine.empty() && sLine[0] != '#')
|
||||
{
|
||||
vtlIgnoredDevices.emplace_back(sLine);
|
||||
}
|
||||
// Logger::logThis()->info("read uuid: " + sLine);
|
||||
vtlIgnoredDevices.emplace_back(sLine); // add found path and uuid from ignore file to vector
|
||||
}
|
||||
|
||||
// Loop through found entries in ignore file
|
||||
// loop through found entries in ignore file
|
||||
for (auto row : vtlIgnoredDevices)
|
||||
{
|
||||
it = plistDrives->begin();
|
||||
while (it != plistDrives->end())
|
||||
list<Drive>::iterator it;
|
||||
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
|
||||
{
|
||||
string sUUID;
|
||||
char *cLine = NULL;
|
||||
size_t len = 0;
|
||||
string sCMD = "blkid ";
|
||||
sCMD.append(it->getPath());
|
||||
|
||||
FILE *outputfileBlkid = popen(sCMD.c_str(), "r");
|
||||
// cout << "cmd: " << sCMD << endl;
|
||||
FILE *outputfileBlkid = popen(sCMD.c_str(), "r"); // get UUID from drive
|
||||
if (outputfileBlkid == NULL)
|
||||
{
|
||||
Logger::logThis()->error("Failed to execute blkid for: " + it->getPath());
|
||||
++it;
|
||||
continue;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while ((getline(&cLine, &len, outputfileBlkid)) != -1)
|
||||
while ((getline(&cLine, &len, outputfileBlkid)) != -1) // parse UUID from blkid
|
||||
{
|
||||
size_t ptuuidPos = string(cLine).find("PTUUID");
|
||||
if (ptuuidPos != string::npos)
|
||||
{
|
||||
string sBlkidOut = string(cLine);
|
||||
sBlkidOut.erase(0, ptuuidPos + 8);
|
||||
if (sBlkidOut.length() >= 8)
|
||||
{
|
||||
sBlkidOut.erase(8, sBlkidOut.length());
|
||||
}
|
||||
sBlkidOut.erase(8, sBlkidOut.length());
|
||||
sUUID = sBlkidOut;
|
||||
// cout << "blkid uuid:" << sUUID << endl;
|
||||
}
|
||||
}
|
||||
free(cLine);
|
||||
pclose(outputfileBlkid);
|
||||
// cout << "blkid uuid:" << sUUID << endl;
|
||||
|
||||
if (!get<0>(row).compare(sUUID))
|
||||
if (!get<0>(row).compare(sUUID)) // compare uuid from ignore file and uuid from drive
|
||||
{
|
||||
// same uuid found than in ignore file --> ignore this drive
|
||||
#ifdef LOG_LEVEL_HIGH
|
||||
Logger::logThis()->info("same uuid found in ignore file --> ignore this drive: " + it->getPath());
|
||||
Logger::logThis()->info("same uuid found than in ignore file --> ignore this drive: " + it->getPath());
|
||||
#endif
|
||||
it = plistDrives->erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,10 +21,30 @@ const static char *randomsrc = (char *)"/dev/urandom";
|
||||
|
||||
Shred::Shred()
|
||||
{
|
||||
// Allocate aligned buffers for O_DIRECT
|
||||
if (posix_memalign((void **)&caTfngData, O_DIRECT_PAGE_SIZE, TFNG_DATA_SIZE) != 0)
|
||||
{
|
||||
Logger::logThis()->error("Failed to allocate aligned buffer for tfng data");
|
||||
caTfngData = nullptr;
|
||||
}
|
||||
|
||||
if (posix_memalign((void **)&caReadBuffer, O_DIRECT_PAGE_SIZE, CHUNK_SIZE) != 0)
|
||||
{
|
||||
Logger::logThis()->error("Failed to allocate aligned buffer for read buffer");
|
||||
caReadBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Shred::~Shred()
|
||||
{
|
||||
if (caTfngData != nullptr)
|
||||
{
|
||||
free(caTfngData);
|
||||
}
|
||||
if (caReadBuffer != nullptr)
|
||||
{
|
||||
free(caReadBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,6 +63,12 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd)
|
||||
drive->u32DriveChecksumAfterShredding = UINT32_MAX;
|
||||
drive->state = Drive::TaskState::SHRED_ACTIVE;
|
||||
|
||||
if ((caTfngData == nullptr) || (caReadBuffer == nullptr))
|
||||
{
|
||||
Logger::logThis()->error("Shred-Task: Aligned memory not available! - Drive: " + drive->getSerial());
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef DRYRUN
|
||||
for (int i = 0; i <= 100; i++)
|
||||
{
|
||||
@ -69,7 +95,13 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd)
|
||||
}
|
||||
|
||||
// open disk
|
||||
driveFileDiscr = open(cpDrivePath, O_RDWR | O_LARGEFILE);
|
||||
driveFileDiscr = open(cpDrivePath, O_RDWR | O_LARGEFILE | O_DIRECT);
|
||||
if (driveFileDiscr == -1 && errno == EINVAL)
|
||||
{
|
||||
driveFileDiscr = open(cpDrivePath, O_RDWR | O_LARGEFILE);
|
||||
Logger::logThis()->warning("O_DIRECT not supported, using standard I/O - Drive: " + drive->getSerial());
|
||||
}
|
||||
|
||||
if (driveFileDiscr == -1)
|
||||
{
|
||||
std::string errorMsg(strerror(errno));
|
||||
|
||||
Reference in New Issue
Block a user