Skip to content

Commit

Permalink
Add support for wiping disks using hdparm (#94)
Browse files Browse the repository at this point in the history
This will use either ATA Sanitize or ATA Secure Erase to wipe the drive
quickly and securely if supported by the drive.
  • Loading branch information
mmlb authored Jul 9, 2024
2 parents 2708b5d + 953df13 commit ab2a8fa
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cmd/disk_wipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -102,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")
Expand Down

0 comments on commit ab2a8fa

Please sign in to comment.