get connection type
This commit is contained in:
parent
d8584486b9
commit
d76cb1a195
@ -25,6 +25,14 @@ public:
|
||||
FROZEN
|
||||
} state;
|
||||
|
||||
enum ConnectionType
|
||||
{
|
||||
UNKNOWN,
|
||||
USB,
|
||||
SATA,
|
||||
NVME
|
||||
} connectionType;
|
||||
|
||||
struct
|
||||
{
|
||||
time_t u32ShredTimeDelta;
|
||||
@ -33,9 +41,9 @@ public:
|
||||
unsigned long ulSpeedMetricBytesWritten;
|
||||
} sShredSpeed;
|
||||
|
||||
bool bWasShredded = false; // all shred iterations done
|
||||
bool bWasShredded = false; // all shred iterations done
|
||||
bool bWasShredStarted = false; // shred was atleast once started
|
||||
bool bWasChecked = false; // all shred iterations and optional checking done
|
||||
bool bWasChecked = false; // all shred iterations and optional checking done
|
||||
bool bWasDeleted = false;
|
||||
bool bIsOffline = false;
|
||||
uint32_t u32DriveChecksumAfterShredding = 0U;
|
||||
|
@ -31,7 +31,7 @@
|
||||
#endif
|
||||
|
||||
// Logic
|
||||
// #define DRYRUN // don't touch the drives
|
||||
#define DRYRUN // don't touch the drives
|
||||
#define FROZEN_ALERT // show alert if drive is frozen
|
||||
#define ZERO_CHECK // check drive after shred if all bytes are zero, show alert if this fails
|
||||
|
||||
|
@ -306,41 +306,51 @@ void reHDD::filterNewDrives(list<Drive> *plistOldDrives, list<Drive> *plistNewDr
|
||||
* \param pointer of list <Drive>* plistDrives
|
||||
* \return void
|
||||
*/
|
||||
void reHDD::searchDrives(list<Drive> *plistDrives)
|
||||
void reHDD::searchDrives(std::list<Drive> *plistDrives)
|
||||
{
|
||||
// Logger::logThis()->info("--> search drives <--");
|
||||
char *cLine = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
FILE *outputfileHwinfo = popen("lsblk -e 11 -d -o NAME", "r");
|
||||
|
||||
if (outputfileHwinfo == NULL)
|
||||
FILE *fp = popen("lsblk -d -n -o NAME,TRAN", "r");
|
||||
if (!fp)
|
||||
{
|
||||
Logger::logThis()->error("Unable to scan attached drives");
|
||||
Logger::logThis()->error("Unable to execute lsblk to scan drives");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while ((getline(&cLine, &len, outputfileHwinfo)) != -1)
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (string(cLine).length() == 4)
|
||||
{
|
||||
Drive *tmpDrive = new Drive("/dev/" + string(cLine).substr(0, 3));
|
||||
tmpDrive->state = Drive::NONE;
|
||||
tmpDrive->bIsOffline = false;
|
||||
plistDrives->push_back(*tmpDrive);
|
||||
// Logger::logThis()->info("SATA drive found: " + tmpDrive->getPath());
|
||||
}
|
||||
std::string devName, transport;
|
||||
std::istringstream iss(line);
|
||||
iss >> devName >> transport;
|
||||
|
||||
if (string(cLine).length() == 8)
|
||||
{
|
||||
Drive *tmpDrive = new Drive("/dev/" + string(cLine).substr(0, 7));
|
||||
tmpDrive->state = Drive::NONE;
|
||||
tmpDrive->bIsOffline = false;
|
||||
plistDrives->push_back(*tmpDrive);
|
||||
// Logger::logThis()->info("NVME drive found: " + tmpDrive->getPath());
|
||||
}
|
||||
if (devName.empty())
|
||||
continue;
|
||||
|
||||
Drive *tmpDrive = new Drive("/dev/" + devName);
|
||||
tmpDrive->state = Drive::NONE;
|
||||
tmpDrive->bIsOffline = false;
|
||||
|
||||
// Set connection type
|
||||
if (transport == "sata")
|
||||
tmpDrive->connectionType = Drive::SATA;
|
||||
else if (transport == "usb")
|
||||
tmpDrive->connectionType = Drive::USB;
|
||||
else if (transport == "nvme")
|
||||
tmpDrive->connectionType = Drive::NVME;
|
||||
else
|
||||
tmpDrive->connectionType = Drive::UNKNOWN;
|
||||
|
||||
plistDrives->push_back(*tmpDrive);
|
||||
|
||||
Logger::logThis()->info(
|
||||
"Drive found: " + tmpDrive->getPath() +
|
||||
" (type: " +
|
||||
(tmpDrive->connectionType == Drive::USB ? "USB" : tmpDrive->connectionType == Drive::SATA ? "SATA"
|
||||
: tmpDrive->connectionType == Drive::NVME ? "NVME"
|
||||
: "UNKNOWN") +
|
||||
")");
|
||||
}
|
||||
pclose(outputfileHwinfo);
|
||||
|
||||
pclose(fp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user