Skip to content

Commit 439ef01

Browse files
authored
fix(usb_mass_storage): should use path instead of configPath (#272)
2 parents 8e2ed60 + f3c49b8 commit 439ef01

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

internal/usbgadget/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ func (u *UsbGadget) GetConfigPath(itemKey string) (string, error) {
128128
return joinPath(u.kvmGadgetPath, item.configPath), nil
129129
}
130130

131+
// GetPath returns the path to the item.
132+
func (u *UsbGadget) GetPath(itemKey string) (string, error) {
133+
item, ok := u.configMap[itemKey]
134+
if !ok {
135+
return "", fmt.Errorf("config item %s not found", itemKey)
136+
}
137+
return joinPath(u.kvmGadgetPath, item.path), nil
138+
}
139+
131140
func mountConfigFS() error {
132141
_, err := os.Stat(gadgetPath)
133142
// TODO: check if it's mounted properly

usb_mass_storage.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import (
1515
"time"
1616

1717
"github.com/gin-gonic/gin"
18-
"github.com/psanford/httpreadat"
1918
"github.com/google/uuid"
2019
"github.com/pion/webrtc/v4"
20+
"github.com/psanford/httpreadat"
2121

2222
"github.com/jetkvm/kvm/resource"
2323
)
@@ -27,7 +27,7 @@ func writeFile(path string, data string) error {
2727
}
2828

2929
func setMassStorageImage(imagePath string) error {
30-
massStorageFunctionPath, err := gadget.GetConfigPath("mass_storage_lun0")
30+
massStorageFunctionPath, err := gadget.GetPath("mass_storage_lun0")
3131
if err != nil {
3232
return fmt.Errorf("failed to get mass storage path: %w", err)
3333
}
@@ -39,7 +39,7 @@ func setMassStorageImage(imagePath string) error {
3939
}
4040

4141
func setMassStorageMode(cdrom bool) error {
42-
massStorageFunctionPath, err := gadget.GetConfigPath("mass_storage_lun0")
42+
massStorageFunctionPath, err := gadget.GetPath("mass_storage_lun0")
4343
if err != nil {
4444
return fmt.Errorf("failed to get mass storage path: %w", err)
4545
}
@@ -110,7 +110,7 @@ func rpcMountBuiltInImage(filename string) error {
110110
}
111111

112112
func getMassStorageMode() (bool, error) {
113-
massStorageFunctionPath, err := gadget.GetConfigPath("mass_storage_lun0")
113+
massStorageFunctionPath, err := gadget.GetPath("mass_storage_lun0")
114114
if err != nil {
115115
return false, fmt.Errorf("failed to get mass storage path: %w", err)
116116
}

0 commit comments

Comments
 (0)