写磁带记录结束 linux

Write magnetic tape end of record linux

任务是在一个文件条目中创建两条不同大小的记录。 我正在使用 python 3.4.5 进行测试:

import fcntl
import os
import struct

MTIOCTOP = 0x40086d01  # refer to mtio.h
MTSETBLK = 20

fh = os.open('/dev/st2', os.O_WRONLY )
fcntl.ioctl(fh, MTIOCTOP, struct.pack('hi', MTSETBLK, 1024))
os.write(fh, b'a'*1024)
fcntl.ioctl(fh, MTIOCTOP, struct.pack('hi', MTSETBLK, 2048))
os.write(fh, b'b'*2048)
os.close(fh)


[root@dev2 mhvtl]# tcopy /dev/st2
file 0: block size 4096: 1 records
file 0: eof after 1 records: 4096 bytes <<< should be 2 records
eot
total length: 4096 bytes
[root@dev2 mhvtl]# ^C

是否有 ioctl opt 代码可以在磁带上以可变记录长度启动新记录。 或任何其他解决此错误的方法?

问题出在 tcopy 上,它使用设备上的块大小而不是检测它。

fcntl.ioctl(fh, MTIOCTOP, struct.pack('hi', MTSETBLK, 0))

在上次写入后允许 tcopy 按预期显示数据。

喜欢的东西怎么样commands.getstatus('mt -f /dev/st2 fsf')