Skip to content

Commit f592802

Browse files
committed
fix: pass all device_overrides protocols to smartctl, not just SAT
Closes #29
1 parent 3edf2a5 commit f592802

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

agent/discover.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ func probeOneDrive(smartctlPath, path, protocol string) discoverDriveResult {
180180
r := discoverDriveResult{path: path, scanProto: protocol}
181181

182182
args := []string{"--json", "-a"}
183-
if strings.EqualFold(protocol, "sat") {
184-
args = append(args, "-d", "sat")
183+
if protocol != "" && !isAutoDetectedProtocol(protocol) {
184+
args = append(args, "-d", protocol)
185185
}
186186
args = append(args, path)
187187

agent/main.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,19 @@ func decodeHealthBits(code int) string {
779779
return strings.Join(flags, ", ")
780780
}
781781

782+
// isAutoDetectedProtocol returns true for protocols that smartctl assigns during
783+
// --scan/--scan-open. These don't need an explicit -d flag because smartctl
784+
// already knows how to talk to them. Custom protocols from device_overrides
785+
// (e.g. "sat", "jmb39x-q,0", "usbcypress") are NOT in this list and will be
786+
// passed to smartctl via -d.
787+
func isAutoDetectedProtocol(p string) bool {
788+
switch strings.ToLower(p) {
789+
case "scsi", "ata", "nvme":
790+
return true
791+
}
792+
return false
793+
}
794+
782795
// runSmartctl runs smartctl with the given args and returns (output, exitCode, error).
783796
// error is non-nil only for non-ExitError failures (missing binary, permissions, etc.).
784797
func runSmartctl(smartctlPath string, args []string) ([]byte, int, error) {
@@ -809,8 +822,8 @@ func (dc *DriveCache) fetchDriveInfo(devicePath, protocol string, skipStandby bo
809822
if dc.standbyMode != "never" && !skipStandby {
810823
args = append(args, "-n", dc.standbyMode)
811824
}
812-
if strings.EqualFold(protocol, "sat") {
813-
args = append(args, "-d", "sat")
825+
if protocol != "" && !isAutoDetectedProtocol(protocol) {
826+
args = append(args, "-d", protocol)
814827
}
815828
args = append(args, devicePath)
816829

0 commit comments

Comments
 (0)