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 ea575b0 commit 3079cb4
Showing 1 changed file with 20 additions and 8 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.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.
Expand Down

0 comments on commit 3079cb4

Please sign in to comment.