Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for wiping disks using hdparm #94

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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