diff --git a/internal/usbgadget/config.go b/internal/usbgadget/config.go index 5f08733..5cc3ed2 100644 --- a/internal/usbgadget/config.go +++ b/internal/usbgadget/config.go @@ -128,6 +128,15 @@ func (u *UsbGadget) GetConfigPath(itemKey string) (string, error) { return joinPath(u.kvmGadgetPath, item.configPath), nil } +// GetPath returns the path to the item. +func (u *UsbGadget) GetPath(itemKey string) (string, error) { + item, ok := u.configMap[itemKey] + if !ok { + return "", fmt.Errorf("config item %s not found", itemKey) + } + return joinPath(u.kvmGadgetPath, item.path), nil +} + func mountConfigFS() error { _, err := os.Stat(gadgetPath) // TODO: check if it's mounted properly diff --git a/usb_mass_storage.go b/usb_mass_storage.go index 45f613f..6578069 100644 --- a/usb_mass_storage.go +++ b/usb_mass_storage.go @@ -15,9 +15,9 @@ import ( "time" "github.com/gin-gonic/gin" - "github.com/psanford/httpreadat" "github.com/google/uuid" "github.com/pion/webrtc/v4" + "github.com/psanford/httpreadat" "github.com/jetkvm/kvm/resource" ) @@ -27,7 +27,7 @@ func writeFile(path string, data string) error { } func setMassStorageImage(imagePath string) error { - massStorageFunctionPath, err := gadget.GetConfigPath("mass_storage_lun0") + massStorageFunctionPath, err := gadget.GetPath("mass_storage_lun0") if err != nil { return fmt.Errorf("failed to get mass storage path: %w", err) } @@ -39,7 +39,7 @@ func setMassStorageImage(imagePath string) error { } func setMassStorageMode(cdrom bool) error { - massStorageFunctionPath, err := gadget.GetConfigPath("mass_storage_lun0") + massStorageFunctionPath, err := gadget.GetPath("mass_storage_lun0") if err != nil { return fmt.Errorf("failed to get mass storage path: %w", err) } @@ -110,7 +110,7 @@ func rpcMountBuiltInImage(filename string) error { } func getMassStorageMode() (bool, error) { - massStorageFunctionPath, err := gadget.GetConfigPath("mass_storage_lun0") + massStorageFunctionPath, err := gadget.GetPath("mass_storage_lun0") if err != nil { return false, fmt.Errorf("failed to get mass storage path: %w", err) }