From 08fde432231a6a76310be83ab6f736a289b0adee Mon Sep 17 00:00:00 2001 From: Felix Pojtinger Date: Fri, 19 Nov 2021 00:16:42 +0100 Subject: [PATCH] refactor: Decompose `tell` syscall --- cmd/stfs-tell/main.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/stfs-tell/main.go b/cmd/stfs-tell/main.go index 4e0d479..8570d7c 100644 --- a/cmd/stfs-tell/main.go +++ b/cmd/stfs-tell/main.go @@ -29,14 +29,24 @@ func main() { } defer f.Close() - pos := &Position{} + currentRecord, err := getCurrentRecordFromTape(f) + if err != nil { + panic(err) + } - syscall.Syscall( + fmt.Println(currentRecord) +} + +func getCurrentRecordFromTape(f *os.File) (int64, error) { + pos := &Position{} + if _, _, err := syscall.Syscall( syscall.SYS_IOCTL, f.Fd(), MTIOCPOS, uintptr(unsafe.Pointer(pos)), - ) + ); err != 0 { + return 0, err + } - fmt.Println(pos.BlkNo) + return pos.BlkNo, nil }