From daa723fc49543a1341fec30e871fa85c240a5714 Mon Sep 17 00:00:00 2001 From: Kathryn Baldauf Date: Tue, 4 Apr 2023 12:47:43 -0700 Subject: [PATCH] Add code to format source as ext4 Signed-off-by: Kathryn Baldauf --- internal/guest/storage/ext4/format.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 internal/guest/storage/ext4/format.go diff --git a/internal/guest/storage/ext4/format.go b/internal/guest/storage/ext4/format.go new file mode 100644 index 0000000000..a8230c57a1 --- /dev/null +++ b/internal/guest/storage/ext4/format.go @@ -0,0 +1,27 @@ +//go:build linux +// +build linux + +package ext4 + +import ( + "context" + "fmt" + "os/exec" +) + +// mkfsExt4Command runs mkfs.ext4 with the provided arguments +func mkfsExt4Command(args []string) error { + cmd := exec.Command("mkfs.ext4", args...) + output, err := cmd.CombinedOutput() + if err != nil { + return fmt.Errorf("failed to execute mkfs.ext4: %s: %w", string(output), err) + } + return nil +} +func FormatExt4(ctx context.Context, source string) error { + // Format source as ext4 + if err := mkfsExt4Command([]string{source}); err != nil { + return fmt.Errorf("mkfs.ext4 failed to format %s: %w", source, err) + } + return nil +}