feat: Add block-scoped seeking to stfs-seek-tape

This commit is contained in:
Felicitas Pojtinger
2021-11-18 00:07:12 +01:00
parent 9337962b04
commit c0687fb390
2 changed files with 28 additions and 5 deletions

View File

@@ -1,7 +1,10 @@
package main
import (
"archive/tar"
"bufio"
"flag"
"log"
"os"
"syscall"
"unsafe"
@@ -11,6 +14,8 @@ import (
const (
MTIOCTOP = 0x40086d01 // Do magnetic tape operation
MTSEEK = 22 // Seek to block
blockSize = 512
)
// Operation is struct for MTIOCTOP
@@ -21,8 +26,10 @@ type Operation struct {
}
func main() {
file := flag.String("file", "/dev/nst0", "File of tape drive to open")
file := flag.String("file", "/dev/nst0", "File (tape drive or tar file) to open")
recordSize := flag.Int("recordSize", 20, "Amount of 512-bit blocks per record")
record := flag.Int("record", 0, "Record to seek too")
block := flag.Int("block", 0, "Block in record to seek too")
flag.Parse()
@@ -32,7 +39,7 @@ func main() {
}
defer f.Close()
syscall.Syscall(
if _, _, err := syscall.Syscall(
syscall.SYS_IOCTL,
f.Fd(),
MTIOCTOP,
@@ -42,5 +49,21 @@ func main() {
Count: int32(*record),
},
)),
)
); err != 0 {
panic(err)
}
br := bufio.NewReaderSize(f, blockSize**recordSize)
if _, err := br.Read(make([]byte, *block*blockSize)); err != nil {
panic(err)
}
tr := tar.NewReader(br)
hdr, err := tr.Next()
if err != nil {
panic(err)
}
log.Println(hdr)
}

View File

@@ -125,7 +125,7 @@ func main() {
for {
hdr, err := tr.Next()
if err == io.EOF {
if err := gotoNextFileOnTape(f); err != nil {
if err := goToNextFileOnTape(f); err != nil {
panic(err)
}
@@ -166,7 +166,7 @@ func main() {
}
}
func gotoNextFileOnTape(f *os.File) error {
func goToNextFileOnTape(f *os.File) error {
if _, _, err := syscall.Syscall(
syscall.SYS_IOCTL,
f.Fd(),