summaryrefslogtreecommitdiff
path: root/toolbox/toolbox.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 /toolbox/toolbox.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 'toolbox/toolbox.go')
-rw-r--r--toolbox/toolbox.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/toolbox/toolbox.go b/toolbox/toolbox.go
new file mode 100644
index 0000000..535fe9f
--- /dev/null
+++ b/toolbox/toolbox.go
@@ -0,0 +1,68 @@
+// SPDX-FileCopyrightText: 2026 Terin Stock <terinjokes@gmail.com>
+// SPDX-License-Identifier: EUPL-1.2
+
+package toolbox
+
+import (
+ "strings"
+)
+
+const (
+ TOOLBOX_COUNT_CDS = 0xDA
+ TOOLBOX_LIST_CDS = 0xD7
+ TOOLBOX_SET_NEXT_CD = 0xD8
+ TOOLBOX_LIST_DEVICES = 0xD9
+)
+
+// FileType represents the type of file in a [FileEntry].
+type FileType uint8
+
+const (
+ File FileType = iota
+ Directory
+)
+
+// DeviceType represents the type of emulated device.
+type DeviceType uint8
+
+const (
+ Fixed DeviceType = iota
+ Removeable
+ Optical
+ Floppy14MB
+ MO
+ Sequential
+ Network
+ Zip100
+
+ None DeviceType = 0xFF
+)
+
+// FileEntry describes each file recognized by the ODE as
+// emulatable media.
+type FileEntry [40]byte
+
+// Index is the file's index, to be used with [Device.SetCDByIndex].
+func (e *FileEntry) Index() int {
+ return int(e[0])
+}
+
+// FileType returns the entry's file type.
+func (e *FileEntry) FileType() FileType {
+ return FileType(e[1])
+}
+
+// Name is the entry's name, truncated to 32 characters.
+func (e *FileEntry) Name() string {
+ str := string(e[2:35])
+ idx := strings.IndexByte(str, 0)
+ if idx < 0 {
+ idx = 33
+ }
+ return str[:idx]
+}
+
+// Size returns the size of the entry in bytes.
+func (e *FileEntry) Size() uint64 {
+ return uint64(e[36])<<24 | uint64(e[37])<<16 | uint64(e[38])<<8 | uint64(e[39])
+}