Update App version to 0.1.2

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
This commit is contained in:
luckfox-eng29
2026-03-16 21:49:37 +08:00
parent 9a4e604c61
commit d5bfaffd86
32 changed files with 4064 additions and 229 deletions

57
boot_storage.go Normal file
View File

@@ -0,0 +1,57 @@
package kvm
import (
"os"
"strings"
"sync"
)
type BootStorageType string
const (
BootStorageUnknown BootStorageType = "unknown"
BootStorageEMMC BootStorageType = "emmc"
BootStorageSD BootStorageType = "sd"
)
var (
bootStorageOnce sync.Once
bootStorageType BootStorageType = BootStorageUnknown
)
func GetBootStorageType() BootStorageType {
bootStorageOnce.Do(func() {
bootStorageType = detectBootStorageType()
})
return bootStorageType
}
func IsBootFromSD() bool {
return GetBootStorageType() == BootStorageSD
}
func detectBootStorageType() BootStorageType {
cmdlineBytes, err := os.ReadFile("/proc/cmdline")
if err != nil {
return BootStorageUnknown
}
cmdline := strings.TrimSpace(string(cmdlineBytes))
for _, field := range strings.Fields(cmdline) {
if !strings.HasPrefix(field, "root=") {
continue
}
root := strings.TrimPrefix(field, "root=")
switch {
case strings.HasPrefix(root, "/dev/mmcblk0"):
return BootStorageEMMC
case strings.HasPrefix(root, "/dev/mmcblk1"):
return BootStorageSD
default:
return BootStorageUnknown
}
}
return BootStorageUnknown
}