Skip to content

Commit

Permalink
Add ro option for storage
Browse files Browse the repository at this point in the history
  • Loading branch information
xcellerator committed Nov 29, 2017
1 parent 79f8a53 commit 11f4d68
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetGadgets() []string {

func GetConfig() []string {
// Parse out options from options.txt and return as an array
var delay, vendorid, productid, serialnumber, manufacturer, productname, eth_hostaddr, eth_devaddr, post, storage string
var delay, vendorid, productid, serialnumber, manufacturer, productname, eth_hostaddr, eth_devaddr, post, storage, storage_ro string

// Check for options.txt locations
file_location := GetOptionLocation()
Expand Down Expand Up @@ -189,7 +189,17 @@ func GetConfig() []string {
if FileExist(val) {
storage = val
}
} else if key_val[0] == "storage_ro" {
// If == "yes", then set to "1", otherwise "" for default later

val := strings.TrimSpace(key_val[1])

if val == "yes" {
storage_ro = "1"
} else {
storage_ro = ""
}
}
}

if delay == "" {
Expand Down Expand Up @@ -222,8 +232,11 @@ func GetConfig() []string {
if storage == "" {
storage = SetDefaults("storage")
}
if storage_ro == "" {
storage_ro = SetDefaults("storage_ro")
}

return []string{delay, vendorid, productid, serialnumber, manufacturer, productname, eth_hostaddr, eth_devaddr, post, storage}
return []string{delay, vendorid, productid, serialnumber, manufacturer, productname, eth_hostaddr, eth_devaddr, post, storage, storage_ro}
}

func SetDefaults(options string) string {
Expand Down Expand Up @@ -257,6 +270,9 @@ func SetDefaults(options string) string {
if options == "storage" || options == "all" {
return "/lib/usbninja/storage.img"
}
if options == "storage_ro" || options == "all" {
return "0"
}
return "error"
}

Expand Down Expand Up @@ -419,6 +435,8 @@ func GetOption(config []string, option string) string {
return string(config[8])
case "storage":
return string(config[9])
case "storage_ro":
return string(config[10])
}
return "error"
}
6 changes: 4 additions & 2 deletions src/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (

func StorageGadgetSetup(config []string) {

//Get the storage.img from the config. If not set or points to nonexistent file, will be default in /lib/usbninja
// Get the storage.img from the config. If not set or points to nonexistent file, will be default in /lib/usbninja
// Also get the setting for read-only mode
storageimg := GetOption(config,"storage")
readonly := GetOption(config,"storage_ro")

// Sprintf the directory locations
function_loc := fmt.Sprintf("%sfunctions/mass_storage.usb0", configfs)
Expand Down Expand Up @@ -43,7 +45,7 @@ func StorageGadgetSetup(config []string) {

WriteLine("1", stall_loc)
WriteLine("0", cdrom_loc)
WriteLine("0", ro_loc)
WriteLine(readonly, ro_loc)
WriteLine("0", nofua_loc)
WriteLine(storageimg, file_loc)

Expand Down

0 comments on commit 11f4d68

Please sign in to comment.