Skip to content

Commit

Permalink
Add hdparm to examples/diskwipe
Browse files Browse the repository at this point in the history
  • Loading branch information
mmlb committed Jul 8, 2024
1 parent b39e610 commit 42f0690
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
28 changes: 20 additions & 8 deletions examples/diskwipe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.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
}
}

// 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.
Expand Down
8 changes: 4 additions & 4 deletions utils/hdparm.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ func (h *Hdparm) WipeDrive(ctx context.Context, logger *logrus.Logger, drive *co
)
for _, cap := range drive.Capabilities {
switch {
case cap.Name == "esee":
case cap.Description == "encryption supports enhanced erase":
esee = cap.Enabled
case cap.Name == "bee":
case cap.Description == "BLOCK ERASE EXT":
bee = cap.Enabled
case cap.Name == "cse":
case cap.Description == "CRYPTO SCRAMBLE EXT":
cse = cap.Enabled
case cap.Name == "sf":
case cap.Description == "SANITIZE feature":
sanitize = cap.Enabled
case strings.HasPrefix(cap.Description, "erase time:"):
eseu = strings.Contains(cap.Description, "enhanced")
Expand Down

0 comments on commit 42f0690

Please sign in to comment.