summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorLibravatar Terin Stock <terinjokes@gmail.com>2026-01-01 18:12:44 +0100
committerLibravatar Terin Stock <terinjokes@gmail.com>2026-01-01 18:24:02 +0100
commit9e5c5ada9907247cbeeadf2e9b817a015abf888f (patch)
tree65111d833a28abe545f392f70e1026916581f7d9 /main.go
parentinitial commit (diff)
downloadodescsitoolbox-6163643b019fbaf422cdce04f2d1ed0fa2855b23.tar.xz
feat: SCSI Toolbox for Linuxv0.1.0
Support the SCSI Toolbox API on Linux using "SCSI Generic" driver and the "SG_IO" ioctl, along with an extremely simple CLI tool to interact with the SCSI emulator.
Diffstat (limited to 'main.go')
-rw-r--r--main.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..676ae29
--- /dev/null
+++ b/main.go
@@ -0,0 +1,55 @@
+// SPDX-FileCopyrightText: 2026 Terin Stock <terinjokes@gmail.com>
+// SPDX-License-Identifier: EUPL-1.2
+
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+
+ humanize "github.com/dustin/go-humanize"
+ "go.terinstock.com/odescsitoolbox/toolbox"
+)
+
+func listCDs(d *toolbox.Device) {
+ fileEntries, err := d.ListCDs()
+ if err != nil {
+ fmt.Printf("unable to fetch CD list: %v\n", err)
+ os.Exit(1)
+ }
+
+ fmt.Printf("index,name,size\n")
+
+ for _, entry := range fileEntries {
+ fmt.Printf("%d,%s,%s\n", entry.Index(), entry.Name(), humanize.IBytes(entry.Size()))
+ }
+}
+
+func setCD(d *toolbox.Device, idx int) {
+ err := d.SetCDByIndex(idx)
+ if err != nil {
+ fmt.Printf("unable to set CD index: %v\n", err)
+ os.Exit(1)
+ }
+}
+
+func main() {
+ device := flag.String("dev", "/dev/sr0", "the ODE device")
+ index := flag.Int("index", -1, "the index to set")
+ flag.Parse()
+
+ d, err := toolbox.Open(*device)
+ if err != nil {
+ fmt.Printf("unable to open device: %v\n", err)
+ os.Exit(1)
+ }
+ defer d.Close()
+
+ if *index >= 0 {
+ setCD(d, *index)
+ } else {
+ listCDs(d)
+ }
+
+}