Some checks failed
Test / ShareFS (push) Failing after 49s
Test / Create distribution (push) Failing after 51s
Test / Hakurei (race detector) (push) Failing after 59s
Test / Sandbox (push) Failing after 1m0s
Test / Hakurei (push) Failing after 1m11s
Test / Sandbox (race detector) (push) Failing after 1m7s
Test / Flake checks (push) Has been skipped
This currently relies on a trusted bootloader to determine the boot device. Signed-off-by: Ophestra <cat@gensokyo.uk>
70 lines
1.2 KiB
Go
70 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"syscall"
|
|
"time"
|
|
|
|
"hakurei.app/check"
|
|
"hakurei.app/fhs"
|
|
"hakurei.app/internal/kobject"
|
|
)
|
|
|
|
// mustMountSystem waits for and mounts a system device matching pattern.
|
|
func mustMountSystem(
|
|
ctx context.Context,
|
|
s *kobject.State,
|
|
pattern string,
|
|
) {
|
|
c, stop := context.WithTimeout(ctx, 30*time.Second)
|
|
defer stop()
|
|
|
|
for {
|
|
var matchErr error
|
|
var systemPath *check.Absolute
|
|
s.Range(c, func(o *kobject.Object) bool {
|
|
if o.Subsystem != "block" ||
|
|
o.Env["DEVTYPE"] != "disk" {
|
|
return true
|
|
}
|
|
|
|
if ok, err := filepath.Match(pattern, o.DevPath); err != nil {
|
|
matchErr = err
|
|
return false
|
|
} else if !ok {
|
|
return true
|
|
}
|
|
|
|
name, ok := o.Env["DEVNAME"]
|
|
if !ok {
|
|
return true
|
|
}
|
|
systemPath = fhs.AbsDev.Append(name)
|
|
return false
|
|
})
|
|
if c.Err() != nil {
|
|
fatal("devpath", strconv.Quote(pattern), "never appeared")
|
|
}
|
|
if matchErr != nil {
|
|
fatal("cannot match system devpath:", matchErr)
|
|
}
|
|
err := syscall.Mount(
|
|
systemPath.String(),
|
|
"/system/",
|
|
"squashfs",
|
|
0,
|
|
"threads=multi",
|
|
)
|
|
if err == nil {
|
|
break
|
|
}
|
|
if !errors.Is(err, os.ErrNotExist) {
|
|
fatal("cannot mount system:", err)
|
|
}
|
|
}
|
|
}
|