feat: Add command which moves to EOD
This commit is contained in:
46
cmd/stfs-eod/main.go
Normal file
46
cmd/stfs-eod/main.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// See https://github.com/benmcclelland/mtio
|
||||
const (
|
||||
MTIOCTOP = 0x40086d01 // Do magnetic tape operation
|
||||
MTEOM = 12 // Goto end of recorded media (for appending files)
|
||||
)
|
||||
|
||||
// Operation is struct for MTIOCTOP
|
||||
type Operation struct {
|
||||
Op int16 // Operation ID
|
||||
Pad int16 // Padding to match C structures
|
||||
Count int32 // Operation count
|
||||
}
|
||||
|
||||
func main() {
|
||||
file := flag.String("file", "/dev/nst0", "File of tape drive to open")
|
||||
record := flag.Int("record", 0, "Record to seek too")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
f, err := os.OpenFile(*file, os.O_RDONLY, os.ModeCharDevice)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
syscall.Syscall(
|
||||
syscall.SYS_IOCTL,
|
||||
f.Fd(),
|
||||
MTIOCTOP,
|
||||
uintptr(unsafe.Pointer(
|
||||
&Operation{
|
||||
Op: MTEOM,
|
||||
Count: int32(*record),
|
||||
},
|
||||
)),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user