feat: Add cmd to seek to specific block

This commit is contained in:
Felix Pojtinger
2021-11-14 12:04:28 +01:00
parent be834c1155
commit bfc4f0e80b
2 changed files with 48 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ import (
"unsafe"
)
// See https://github.com/benmcclelland/mtio/blob/f929531fb4fe6433f7198ccd89d1c1414ef8fa3f/mtst.go#L46
// See https://github.com/benmcclelland/mtio
const (
MTIOCTOP = 0x40086d01 // Do magnetic tape operation
MTSEEK = 22 // Seek to block
@@ -15,11 +15,9 @@ const (
// Operation is struct for MTIOCTOP
type Operation struct {
op int16 // Operation ID
pad int16 // Padding to match C structures
count int32 // Operation count
Op int16 // Operation ID
Pad int16 // Padding to match C structures
Count int32 // Operation count
}
func main() {
@@ -40,8 +38,8 @@ func main() {
MTIOCTOP,
uintptr(unsafe.Pointer(
&Operation{
op: MTSEEK,
count: int32(*record),
Op: MTSEEK,
Count: int32(*record),
},
)),
)

42
cmd/stfs-tell/main.go Normal file
View File

@@ -0,0 +1,42 @@
package main
import (
"flag"
"fmt"
"os"
"syscall"
"unsafe"
)
// See https://github.com/benmcclelland/mtio
const (
MTIOCPOS = 0x80086d03 // Get tape position
)
// Position is struct for MTIOCPOS
type Position struct {
BlkNo int64 // Current block number
}
func main() {
file := flag.String("file", "/dev/nst0", "File of tape drive to open")
flag.Parse()
f, err := os.OpenFile(*file, os.O_RDONLY, os.ModeCharDevice)
if err != nil {
panic(err)
}
defer f.Close()
pos := &Position{}
syscall.Syscall(
syscall.SYS_IOCTL,
f.Fd(),
MTIOCPOS,
uintptr(unsafe.Pointer(pos)),
)
fmt.Println(pos.BlkNo)
}