initrd/losetup.go

27 lines
531 B
Go
Raw Normal View History

2023-12-04 12:59:37 +00:00
package main
import (
"syscall"
"github.com/freddierice/go-losetup/v2"
)
var loDevices = map[string]losetup.Device{}
func losetupAttach(file string) losetup.Device {
if _, ok := loDevices[file]; !ok {
dev, err := losetup.Attach(file, 0, true)
if err != nil {
fatalf("failed to attach %q to a loop device: %v", file, err)
}
loDevices[file] = dev
}
return loDevices[file]
}
func mountSquahfs(source, target string) {
dev := losetupAttach(source)
mount(dev.Path(), target, "squashfs", syscall.MS_RDONLY, "")
}