2018-12-24 07:42:30 -08:00

46 lines
927 B
Go

// Package xfs provides an interface to xfsprogs.
package xfs
import (
"os"
"os/exec"
)
// GrowFS expands a XFS filesystem to the maximum possible. The partition
// MUST be mounted, or this will fail.
func GrowFS(partname string) error {
return cmd("xfs_growfs", "-d", partname)
}
// MakeFS creates a XFS filesystem on the specified partition.
func MakeFS(partname string, setters ...Option) error {
opts := NewDefaultOptions(setters...)
// The ftype=1 naming option is required by overlayfs.
args := []string{"-n", "ftype=1"}
if opts.Force {
args = append(args, "-f")
}
if opts.Label != "" {
args = append(args, "-L", opts.Label)
}
args = append(args, partname)
return cmd("mkfs.xfs", args...)
}
func cmd(name string, args ...string) error {
cmd := exec.Command(name, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
err := cmd.Start()
if err != nil {
return err
}
return cmd.Wait()
}