From 3079cb4d1b387a49f2efc99efb9e84557836c29c Mon Sep 17 00:00:00 2001
From: Manuel Mendez <github@i.m.mmlb.dev>
Date: Mon, 8 Jul 2024 07:21:56 -0400
Subject: [PATCH] Add hdparm to examples/diskwipe

---
 examples/diskwipe/main.go | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/examples/diskwipe/main.go b/examples/diskwipe/main.go
index afdb314e..873e9518 100644
--- a/examples/diskwipe/main.go
+++ b/examples/diskwipe/main.go
@@ -66,18 +66,30 @@ func main() {
 	case "nvme":
 		wiper = utils.NewNvmeCmd(*verbose)
 	case "sata":
-		// Lets see if drive supports TRIM, if so we'll use blkdiscard
+		// 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") {
-				if cap.Enabled {
-					wiper = utils.NewBlkdiscardCmd(*verbose)
-				}
-				break
+			switch {
+			case cap.Name == "esee":
+				esee = cap.Enabled
+			case cap.Description == "SANITIZE":
+				sanitize = cap.Enabled
+			case strings.HasPrefix(cap.Description, "Data Set Management TRIM supported"):
+				trim = cap.Enabled
 			}
 		}
 
-		// drive does not support TRIM so we fall back to filling it up with zero
-		if wiper == nil {
+		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)
+		default:
+			// Drive does not support any preferred wipe method so we fall back to filling it up with zero
 			wiper = utils.NewFillZeroCmd(*verbose)
 
 			// If the user supplied a non-default timeout then we'll honor it, otherwise we just go with a huge timeout.