From f64b86d7e636c8462c81a37a908d9692376adc13 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Mon, 8 Jul 2024 13:29:21 -0400 Subject: [PATCH 1/2] Add support for wiping disks using hdparm This will use either ATA Sanitize or ATA Secure Erase to wipe the drive quickly and securely if supported by the drive. --- cmd/disk_wipe.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/disk_wipe.go b/cmd/disk_wipe.go index faaa460..a766eb1 100644 --- a/cmd/disk_wipe.go +++ b/cmd/disk_wipe.go @@ -80,16 +80,26 @@ func init() { case "nvme": wiper = utils.NewNvmeCmd(verbose) case "sata": - // Lets figure out if the drive supports TRIM + // Lets figure out the drive capabilities in an easier format + var sanitize bool + var esee bool var trim bool for _, cap := range drive.Capabilities { - if strings.HasPrefix(cap.Description, "Data Set Management TRIM supported") { + switch { + case cap.Description == "encryption supports enhanced erase": + esee = cap.Enabled + case cap.Description == "SANITIZE feature": + sanitize = cap.Enabled + case strings.HasPrefix(cap.Description, "Data Set Management TRIM supported"): trim = cap.Enabled - break } } - if trim { + switch { + case sanitize || esee: + // Drive supports Sanitize or Enhanced Erase, so we use hdparm + wiper = utils.NewHdparmCmd(verbose) + case trim: // Drive supports TRIM, so we use blkdiscard wiper = utils.NewBlkdiscardCmd(verbose) } From 953df1378b0371ccb77a097dde3dbdcb32176f6b Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 9 Jul 2024 10:37:34 -0400 Subject: [PATCH 2/2] Pass Debug enabled logger to WipeDrive WipeDrive funcs now log at either .Debug or .Error levels but we want to see the same messages so need to change the LogLevel to Debug. Need a new logger instead of current logger so the change only applies to WipeDrive. --- cmd/disk_wipe.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/disk_wipe.go b/cmd/disk_wipe.go index a766eb1..accc2b3 100644 --- a/cmd/disk_wipe.go +++ b/cmd/disk_wipe.go @@ -112,6 +112,8 @@ func init() { }).Fatal("failed find appropriate drive wiper") } + logger = logrus.New() + logger.SetLevel(logrus.DebugLevel) err = wiper.WipeDrive(ctx, logger, drive) if err != nil { l.Fatal("failed to wipe drive")