[disk][freebsd] implement SerialNumberWithContext

pull/1217/head
Ville Skyttä 3 years ago
parent 2f8da0a394
commit df68a56e2d

@ -4,10 +4,14 @@
package disk
import (
"bufio"
"bytes"
"context"
"encoding/binary"
"fmt"
"os/exec"
"strconv"
"strings"
"golang.org/x/sys/unix"
@ -163,7 +167,22 @@ func getFsType(stat unix.Statfs_t) string {
}
func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
return "", common.ErrNotImplementedError
geom, err := exec.LookPath("geom")
if err != nil {
return "", fmt.Errorf("find geom: %w", err)
}
geomOut, err := invoke.CommandWithContext(ctx, geom, "disk", "list", name)
if err != nil {
return "", fmt.Errorf("exec geom: %w", err)
}
s := bufio.NewScanner(bytes.NewReader(geomOut))
for s.Scan() {
flds := strings.Fields(s.Text())
if len(flds) == 2 && flds[0] == "ident:" {
return flds[1], nil
}
}
return "", nil
}
func LabelWithContext(ctx context.Context, name string) (string, error) {

Loading…
Cancel
Save