From 267ac15e2881e483b05596495af51e6524571ce6 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 25 Jun 2024 15:52:55 -0400 Subject: [PATCH] Add blkdiscard based wipe for TRIM drives Expand drive wiping capabilities by using blkdiscard for devices that support it. --- cmd/disk_wipe.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/disk_wipe.go b/cmd/disk_wipe.go index a3326a6..26e995d 100644 --- a/cmd/disk_wipe.go +++ b/cmd/disk_wipe.go @@ -5,6 +5,7 @@ import ( "context" "errors" "os" + "strings" "time" "github.com/bmc-toolbox/common" @@ -15,6 +16,7 @@ import ( "github.com/spf13/cobra" ) +// nolint:gocyclo // easier to read in one big function I think func init() { cmd := &cobra.Command{ Use: "wipe /dev/disk", @@ -74,10 +76,23 @@ func init() { // Pick the most appropriate wipe based on the disk type and/or features supported var wiper actions.DriveWiper - // nolint:gocritic // will have more cases soon, remove nolint then switch drive.Protocol { case "nvme": wiper = utils.NewNvmeCmd(verbose) + case "sata": + // Lets figure out if the drive supports TRIM + var trim bool + for _, cap := range drive.Capabilities { + if strings.HasPrefix(cap.Description, "Data Set Management TRIM supported") { + trim = cap.Enabled + break + } + } + + if trim { + // Drive supports TRIM, so we use blkdiscard + wiper = utils.NewBlkdiscardCmd(verbose) + } } if wiper == nil {