From 360b87502c87957f0fb2cdc0644c61345bf80f46 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 16 Jul 2023 22:23:09 -0500 Subject: [PATCH] Add proper detection --- .../SeagateControllerDetect.cpp | 62 +++++++++++++++++-- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/Controllers/SeagateController/SeagateControllerLinux/SeagateControllerDetect.cpp b/Controllers/SeagateController/SeagateControllerLinux/SeagateControllerDetect.cpp index c5a06166a..4c398c148 100644 --- a/Controllers/SeagateController/SeagateControllerLinux/SeagateControllerDetect.cpp +++ b/Controllers/SeagateController/SeagateControllerLinux/SeagateControllerDetect.cpp @@ -1,4 +1,5 @@ #include "Detector.h" +#include "LogManager.h" #include "SeagateController.h" #include "RGBController.h" #include "RGBController_Seagate.h" @@ -31,16 +32,65 @@ void DetectSeagateControllers() { - int fd = open("/dev/sdb", O_RDWR); + /*---------------------------------------------------------------------*\ + | Search for /dev/sgX nodes with model matching "FireCuda HDD" | + \*---------------------------------------------------------------------*/ + unsigned int sg_idx = 0; - if(fd > 0) + while(1) + { + /*-------------------------------------------------*\ + | Create the scsi_generic class model path | + \*-------------------------------------------------*/ + char sg_dev_buf[1024]; + + snprintf(sg_dev_buf, 1024, "/sys/class/scsi_generic/sg%d/device/model", sg_idx); + + /*-------------------------------------------------*\ + | Open the input event path to get the name | + \*-------------------------------------------------*/ + int sg_model_fd = open(sg_dev_buf, O_RDONLY|O_NONBLOCK); + + if(sg_model_fd < 0) { - SeagateController* controller = new SeagateController(fd, "/dev/sdb"); - RGBController_Seagate* rgb_controller = new RGBController_Seagate(controller); - - ResourceManager::get()->RegisterRGBController(rgb_controller); + break; } + memset(sg_dev_buf, 0, 1024); + + if(read(sg_model_fd, sg_dev_buf, 1024) < 0) + { + LOG_WARNING("[Seagate Firecuda HDD] Probing %d, failed to read NVMe model", sg_idx); + } + else + { + LOG_DEBUG("[Seagate Firecuda HDD] Probing %d, model: %s", sg_idx, sg_dev_buf); + } + + close(sg_model_fd); + + /*-------------------------------------------------*\ + | Check if this SCSI device is a Seagate Firecuda | + | HDD | + \*-------------------------------------------------*/ + if(strncmp(sg_dev_buf, "FireCuda HDD", 12) == 0) + { + snprintf(sg_dev_buf, 1024, "/dev/sg%d", sg_idx); + + int fd = open(sg_dev_buf, O_RDWR); + + if(fd > 0) + { + SeagateController* controller = new SeagateController(fd, sg_dev_buf); + RGBController_Seagate* rgb_controller = new RGBController_Seagate(controller); + + ResourceManager::get()->RegisterRGBController(rgb_controller); + } + } + + sg_idx++; + } + } /* DetectSpectrixS40GControllers() */ REGISTER_DETECTOR( "Seagate Firecuda HDD", DetectSeagateControllers);