Skip to content

Commit

Permalink
checkpoint -- it actually kind of works but
Browse files Browse the repository at this point in the history
freebsd lacking private name spaces and bind mounts
makes this a bit of a pain.

The best way forward may be a jail.

Signed-off-by: Ronald G. Minnich <[email protected]>
  • Loading branch information
rminnich committed Nov 7, 2024
1 parent 07f3eab commit 50279c5
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions mount/mount_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"bufio"
"errors"
"fmt"
"os"
"io"
"io/ioutil"
"os/exec"
"path/filepath"
"strings"
Expand Down Expand Up @@ -74,7 +75,7 @@ func init() {
// iov returns an iovec for a string.
// there is no official package, and it is simple
// enough, that we just create it here.
func iov(val string) syscall.Iovec {
func iovstring(val string) syscall.Iovec {
s := val + "\x00"
vec := syscall.Iovec{Base: (*byte)(unsafe.Pointer(&[]byte(s)[0]))}
vec.SetLen(len(s))
Expand All @@ -89,10 +90,26 @@ func iov(val string) syscall.Iovec {
// a returned error, but be left in a situation in which further
// diagnostics are possible. i.e., follow the "Boots not Bricks"
// principle.
// Freebsd has very different ways of working than linux, so
// we shell out to mount for now.
func Mount(fstab string) error {
f, err := ioutil.TempFile("", "cpu")
if err != nil {
return err
}
defer f.Close()

if _, err := io.WriteString(f, fstab); err != nil {
return err
}

if o, err := exec.Command("mount", "-a", "-F", f.Name()).CombinedOutput(); err != nil {
return fmt.Errorf("mount -F %q:%s:%w", f.Name(), string(o), err)
}

return nil
var lineno int
s := bufio.NewScanner(strings.NewReader(fstab))
var err error
for s.Scan() {
lineno++
l := s.Text()
Expand Down Expand Up @@ -129,16 +146,8 @@ func Mount(fstab string) error {
// The man page implies that the Linux kernel handles flags of "defaults"
// we do no further manipulation of opts.
flags, data := parse(opts)
if false {
if _, e := mount.Mount(dev, where, fstype, data, flags); e != nil {
err = errors.Join(err, fmt.Errorf("Mount(%q, %q, %q, %q=>(%#x, %q)): %w", dev, where, fstype, opts, flags, data, e))
}
} else {
c := exec.Command("mount", "-o", data, "-t", "nfs", dev, where)
c.Stdout, c.Stderr = os.Stdout, os.Stderr
if err := c.Run(); err != nil {
fmt.Printf("%v:%v", c, err)
}
if _, e := mount.Mount(dev, where, fstype, data, flags); e != nil {
err = errors.Join(err, fmt.Errorf("Mount(%q, %q, %q, %q=>(%#x, %q)): %w", dev, where, fstype, opts, flags, data, e))
}
}
return err
Expand Down

0 comments on commit 50279c5

Please sign in to comment.