-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract disk wiping from disk partitioning
Signed-off-by: Moath Qasim <[email protected]>
- Loading branch information
1 parent
5f58001
commit 7d47827
Showing
3 changed files
with
57 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package storage | ||
|
||
import ( | ||
"os" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/tinkerbell/hub/actions/rootio/v1/pkg/types.go" | ||
) | ||
|
||
// Wipe will clean the table from a disk. | ||
func Wipe(d types.Disk) error { | ||
disk, err := os.OpenFile(d.Device, os.O_CREATE|os.O_WRONLY, 0o644) | ||
if err != nil { | ||
return err | ||
} | ||
defer disk.Close() | ||
bigBuff := make([]byte, 1024*1024*1024) | ||
n, err := disk.Write(bigBuff) | ||
if err != nil { | ||
return err | ||
} | ||
log.Infof("Wrote [%d] bytes to [%s]", n, d.Device) | ||
log.Infoln("Flushing writes to new partition") | ||
err = disk.Sync() | ||
if err != nil { | ||
return err | ||
} | ||
err = disk.Close() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |