diff --git a/include/drive.h b/include/drive.h index 71b2d1d..1297e13 100644 --- a/include/drive.h +++ b/include/drive.h @@ -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; diff --git a/include/reHDD.h b/include/reHDD.h index 519a4ce..78fbd11 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -20,7 +20,7 @@ // Logger Settings #define LOG_PATH "./reHDD.log" -#define DESCRIPTION "reHDD - Copyright Hendrik Schutter 2024" +#define DESCRIPTION "reHDD - Copyright Hendrik Schutter 2025" #define DEVICE_ID "generic" #define SOFTWARE_VERSION REHDD_VERSION #define HARDWARE_VERSION "generic" @@ -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 diff --git a/include/tui.h b/include/tui.h index 4ae017a..b1b3416 100644 --- a/include/tui.h +++ b/include/tui.h @@ -67,7 +67,7 @@ private: static WINDOW *createOverViewWindow(int iXSize, int iYSize); static WINDOW *createDetailViewWindow(int iXSize, int iYSize, int iXStart, Drive drive); static WINDOW *overwriteDetailViewWindow(int iXSize, int iYSize, int iXStart); - static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, string sModelFamily, string sSerial, string sCapacity, string sState, string sTime, string sSpeed, string sTemp, bool bSelected); + static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, string sModelFamily, string sSerial, string sCapacity, string sState, string sTime, string sSpeed, string sTemp, string sConnection, bool bSelected); static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart); static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate); static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB); diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 7ab8f03..e4f15ce 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -306,41 +306,51 @@ void reHDD::filterNewDrives(list *plistOldDrives, list *plistNewDr * \param pointer of list * plistDrives * \return void */ -void reHDD::searchDrives(list *plistDrives) +void reHDD::searchDrives(std::list *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); } /** diff --git a/src/tui.cpp b/src/tui.cpp index edb3532..9c822bc 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -93,6 +93,9 @@ void TUI::updateTUI(list *plistDrives, uint8_t u8SelectedEntry) string sSpeed = " "; string sTime = " "; string sTemp = it->sTemperatureToText(); + string sConnection = (it->connectionType == Drive::USB ? "USB" : it->connectionType == Drive::SATA ? "SATA" + : it->connectionType == Drive::NVME ? "NVME" + : ""); bool bSelectedEntry = false; @@ -182,7 +185,7 @@ void TUI::updateTUI(list *plistDrives, uint8_t u8SelectedEntry) uint16_t u16StartOffsetY = (2 * (u8Index)); - WINDOW *tmp = createEntryWindow((int)(u16StdscrX * (float)(3.0 / 7.0) - 2), 2, 3, u16StartOffsetY + 2, (distance(plistDrives->begin(), it) + 1), sModelFamily, sSerial, sCapacity, sState, sTime, sSpeed, sTemp, bSelectedEntry); + WINDOW *tmp = createEntryWindow((int)(u16StdscrX * (float)(3.0 / 7.0) - 2), 2, 3, u16StartOffsetY + 2, (distance(plistDrives->begin(), it) + 1), sModelFamily, sSerial, sCapacity, sState, sTime, sSpeed, sTemp, sConnection, bSelectedEntry); wrefresh(tmp); u8Index++; } // end loop though drives @@ -345,7 +348,7 @@ WINDOW *TUI::overwriteDetailViewWindow(int iXSize, int iYSize, int iXStart) return newWindow; } -WINDOW *TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, string sModelFamily, string sSerial, string sCapacity, string sState, string sTime, string sSpeed, string sTemp, bool bSelected) +WINDOW *TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, string sModelFamily, string sSerial, string sCapacity, string sState, string sTime, string sSpeed, string sTemp, string sConnection, bool bSelected) { WINDOW *newWindow; newWindow = newwin(iYSize, iXSize, iYStart, iXStart); @@ -390,6 +393,7 @@ WINDOW *TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, 37-43: Capacity 44: space 47-49: Temp + 57-60: Connection Type line:02 0-2: space @@ -406,6 +410,7 @@ WINDOW *TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, mvwaddstr(newWindow, 0, 3, sModelFamily.c_str()); mvwaddstr(newWindow, 0, 37, sCapacity.c_str()); mvwaddstr(newWindow, 0, 47, sTemp.c_str()); + mvwaddstr(newWindow, 0, 57, sConnection.c_str()); vTruncateText(&sSerial, 28); mvwaddstr(newWindow, 1, 3, sSerial.c_str());