File: isworm

package info (click to toggle)
bacula 15.0.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,780 kB
  • sloc: ansic: 194,276; cpp: 41,177; sh: 28,258; python: 6,669; makefile: 5,275; perl: 3,666; sql: 1,371; java: 345; xml: 196; awk: 51; sed: 25
file content (84 lines) | stat: -rwxr-xr-x 2,305 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
#
# Copyright (C) 2000-2020 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Bacula interface to get worm status of tape
#
#  isworm %l (control device name)
#
# Typical output:
# sdparm --page=0x1D -f /dev/sg0
#    /dev/st0: HP        Ultrium 5-SCSI    I5AW  [tape]
# Medium configuration (SSC) mode page:
#   WORMM       1  [cha: n, def:  1, sav:  1]
#   WMLR        1  [cha: n, def:  1, sav:  1]
#   WMFR        2  [cha: n, def:  2, sav:  2]
#
# Where WORMM is worm mode
#       WMLR is worm mode label restrictions
#          0 - No blocks can be overwritten
#          1 - Some types of format labels may not be overwritten
#          2 - All format labels can be overwritten
#       WMFR is worm mode filemark restrictions
#          0-1  - Reserved
#          2    - Any number of filemarks immediately preceding EOD can be
#                 overwritten except file mark closest to BOP (beginning of
#                 partition).
#          3    - Any number of filemarks immediately preceding the EOD
#                 can be overwritten
#          4-FF - Reserved
#

if [ x$1 = x ] ; then
   echo "First argument missing. Must be device control name."
   exit 1
fi

sdparm=`which sdparm`
if [ x${sdparm} = x ] ; then
   echo "sdparm program not found, but is required."
   exit 0
fi

#
# This should be the correct way to determine if the tape is WORM
#   but it does not work for mhvtl.  Comment out the next 5 lines
#   and the code that follows will detect correctly on mhtvl.
#
worm=`$sdparm --page=0x1D -f $1 |grep " *WORMM"|cut -b12-16|sed "s:^ *::"`
if [ $? = 0 ] ; then
   echo $worm
   exit 0
fi

tapeinfo=`which tapeinfo`
if [ x${tapeinfo} = x ] ; then
   echo "tapeinfo program not found, but is required."
   exit 1
fi

#
# Unfortunately IBM and HP handle the Medium Type differently,
#  so we detect the vendor and get the appropriate Worm flag.
#
vendor=`$tapeinfo -f $1|grep "^Vendor ID:"|cut -b13-15`
if [ x$vendor = xHP ] ; then
   worm=`$tapeinfo -f $1|grep "^Medium Type: 0x"|cut -b16-16`
   echo $worm
   exit 0
fi

if [ x$vendor = xIBM ] ; then
   worm=`$tapeinfo -f $1|grep "^Medium Type: 0x"|cut -b17-17`
   if [ x$worm = xc ]; then
      echo "1"
      exit 0
   fi
   if [ x$worm = xC ]; then
      echo "1"
      exit 0
   fi
fi
echo "0"
exit 0