27 lines
531 B
Go
27 lines
531 B
Go
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, "")
|
|
}
|