diff options
Diffstat (limited to 'cmd/earlyinit/mount.go')
| -rw-r--r-- | cmd/earlyinit/mount.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/cmd/earlyinit/mount.go b/cmd/earlyinit/mount.go new file mode 100644 index 00000000..6ac59a46 --- /dev/null +++ b/cmd/earlyinit/mount.go @@ -0,0 +1,69 @@ +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) + } + } +} |
