1#!/bin/sh 2# 3# Copyright (C) 2000-2020 Kern Sibbald 4# License: BSD 2-Clause; see file LICENSE-FOSS 5# 6# Bacula interface to get worm status of tape 7# 8# isworm %l (control device name) 9# 10# Typical output: 11# sdparm --page=0x1D -f /dev/sg0 12# /dev/st0: HP Ultrium 5-SCSI I5AW [tape] 13# Medium configuration (SSC) mode page: 14# WORMM 1 [cha: n, def: 1, sav: 1] 15# WMLR 1 [cha: n, def: 1, sav: 1] 16# WMFR 2 [cha: n, def: 2, sav: 2] 17# 18# Where WORMM is worm mode 19# WMLR is worm mode label restrictions 20# 0 - No blocks can be overwritten 21# 1 - Some types of format labels may not be overwritten 22# 2 - All format labels can be overwritten 23# WMFR is worm mode filemark restrictions 24# 0-1 - Reserved 25# 2 - Any number of filemarks immediately preceding EOD can be 26# overwritten except file mark closest to BOP (beginning of 27# partition). 28# 3 - Any number of filemarks immediately preceding the EOD 29# can be overwritten 30# 4-FF - Reserved 31# 32 33if [ x$1 = x ] ; then 34 echo "First argument missing. Must be device control name." 35 exit 1 36fi 37 38sdparm=`which sdparm` 39if [ x${sdparm} = x ] ; then 40 echo "sdparm program not found, but is required." 41 exit 0 42fi 43 44# 45# This should be the correct way to determine if the tape is WORM 46# but it does not work for mhvtl. Comment out the next 5 lines 47# and the code that follows will detect correctly on mhtvl. 48# 49worm=`$sdparm --page=0x1D -f $1 |grep " *WORMM"|cut -b12-16|sed "s:^ *::"` 50if [ $? = 0 ] ; then 51 echo $worm 52 exit 0 53fi 54 55tapeinfo=`which tapeinfo` 56if [ x${tapeinfo} = x ] ; then 57 echo "tapeinfo program not found, but is required." 58 exit 1 59fi 60 61# 62# Unfortunately IBM and HP handle the Medium Type differently, 63# so we detect the vendor and get the appropriate Worm flag. 64# 65vendor=`$tapeinfo -f $1|grep "^Vendor ID:"|cut -b13-15` 66if [ x$vendor = xHP ] ; then 67 worm=`$tapeinfo -f $1|grep "^Medium Type: 0x"|cut -b16-16` 68 echo $worm 69 exit 0 70fi 71 72if [ x$vendor = xIBM ] ; then 73 worm=`$tapeinfo -f $1|grep "^Medium Type: 0x"|cut -b17-17` 74 if [ x$worm = xc ]; then 75 echo "1" 76 exit 0 77 fi 78 if [ x$worm = xC ]; then 79 echo "1" 80 exit 0 81 fi 82fi 83echo "0" 84exit 0 85