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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
#!/bin/sh
#==============================================================================
# Copyright IBM Corp. 2003, 2006.
#
# lstape ($Revision: 1.12.2.1 $)
#
# Script to generate /proc/tapedevices output for kernels beyond 2.4.
# (Designed to work with 2.4 as well.)
#
# Author(s): S. Bader <shbader@de.ibm.com>
#
# This file is part of s390-tools
#
# s390-tools is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# s390-tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with s390-tools; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#==============================================================================
CMD=$(basename $0)
function RequireArgument() {
if [ $2 -eq 1 ]; then
echo "The $1 option requires an argument" >&2
else
echo "The $1 option requires $2 arguments" >&2
fi
}
function PrintUsage() {
cat <<-EOD | cut -c2-
:Usage: $(basename $0) [<options>]
:
: <options>
: -h|--help
: Print this help text.
: -t|--type <list of device types>
: Limit output to the given devices. The list
: consists of device types seperated by ','.
: (e.g. -t 3480,3490)
: --online|--offline
: Show only devices that are either online or
: offline (only one option is allowed).
: -s|--shortid
: Show only devices on channel subsytem 0 with
: subchannel set 0 and remove the leading '0.0.'
: from the displayed bus id.
: --version
: Display the tools and command version.
EOD
}
function PrintVersion()
{
local TVER=$(echo '$Revision: 1.12.2.1 $'|awk '{print $2}')
cat <<-EOD
$CMD: version %S390_TOOLS_VERSION% ($TVER).
Copyright IBM Corp. 2003, 2006.
EOD
}
DEVLIST="3480,3490,3590"
FILTERONLINE=false
FILTEROFFLINE=false
SHORTID=false
FLSEP=""
while [ $# -ne 0 ]; do
case $1 in
-h|--help)
PrintUsage
exit 1
;;
-t|--type)
if [ $# -lt 2 ]; then
RequireArgument $1 1
exit 1
fi
shift
DEVLIST="$1"
;;
--online)
if $FILTEROFFLINE; then
echo -n "Option --online and --offline " >&2
echo "are exclusive" >&2
exit 1
fi
FILTERONLINE=true
;;
--offline)
if $FILTERONLINE; then
echo -n "Option --online and --offline " >&2
echo "are exclusive" >&2
exit 1
fi
FILTEROFFLINE=true
;;
-s|--shortid)
SHORTID=true
;;
--version)
PrintVersion
exit 0
;;
-*|--*)
echo "$CMD: Invalid option $1" >&2
echo "Try 'lstape --help' for more information." >&2
exit 1
;;
*)
FILTERLIST="$FILTERLIST$FLSEP$1"
FLSEP=","
;;
esac
shift
done
function SysfsCreateList() {
echo -n "TapeNo BusID CuType/Model DevType/Model "
echo "BlkSize State Op MedState"
(
find $1/bus/ccw/drivers/tape_34xx -type l \
-printf '%f\n' 2>/dev/null
find $1/bus/ccw/drivers/tape_3590 -type l \
-printf '%f\n' 2>/dev/null
) | awk '
BEGIN{
medium_state_str[0] = "UNKNOWN "
medium_state_str[1] = "LOADED "
medium_state_str[2] = "UNLOADED"
split("'$DEVLIST'", A, ",")
for(i = 1; i in A; i++) {
devlist[A[i]] = 1
}
}
function Read(file) {
value = ""
getline value <file
close(file)
return value
}
{
bus_id = tolower($1)
devdir = "'$1'/bus/ccw/devices/" bus_id
devtype = Read(devdir "/devtype")
split(devtype, A, "/")
if (!(A[1] in devlist))
next
cutype = Read(devdir "/cutype")
"/online")
majmin = Read(devdir "/non-rewinding/dev")
if (majmin != "") {
split(majmin, A, ":")
first_minor = A[2]
} else {
first_minor = Read(devdir "/first_minor")
}
if(first_minor == "")
next
medium_state = Read(devdir "/medium_state")
state = Read(devdir "/state")
operation = Read(devdir "/operation")
blocksize = Read(devdir "/blocksize")
printf("%-7.7s %-10.10s %-12.12s %-13.13s %-7.7s ",
( ? "N/A" : first_minor / 2,
bus_id,
tolower(cutype),
tolower(devtype),
( ? "N/A" : \
((blocksize == 0) ? "auto" : blocksize))
printf("%-7.7s %-7.7s %-8.8s\n",
( ? "OFFLINE" : state,
( ? "---" : operation,
( ? "N/A" : \
medium_state_str[medium_state])
}
' | sort
}
case $(uname -r|cut -d. -f1-2) in
1.*|2.[012])
echo "Not supported!" >&2
exit 1
;;
2.3|2.4)
SYSFS=false
;;
*)
SYSFS=true
if [ "$(cat /proc/filesystems|grep sysfs)" = "" ]; then
echo "WARNING: no sysfs support. Using proc!" >&2
SYSFS=false
fi
SYSFSDIR=$(cat /proc/mounts|awk '$3=="sysfs"{print $2; exit}')
if [ "$SYSFSDIR" = "" ]; then
echo "WARNING: sysfs not mounted. Using proc!" >&2
SYSFS=false
fi
if ! $SYSFS; then
echo -n "WARNING: proc interface will not find offline"
echo " devices on kernel $(uname -r|cut -d. -f1-2)."
echo
fi
;;
esac
if $SYSFS; then
SysfsCreateList $SYSFSDIR
else
if [ ! -r /proc/tapedevices ]; then
echo "ERROR: neither proc nor sysfs interface found!" >&2
exit 1
fi
cat /proc/tapedevices
fi | awk -v LIST="$FILTERLIST" '
function PrintEntry(e) {
if("'$SHORTID'" == "true") {
p1 = substr(e, 1, 8)
p2 = substr(e, 9, 10)
p3 = substr(e, 19)
if(substr(p2, 1, 4) == "0.0.")
print p1 substr(p2, 5) " " p3
} else {
print e
}
}
BEGIN{
if(LIST != "")
split(LIST, A, ",")
}
"'$FILTERONLINE'" == "true" && /OFFLINE/{
next
}
"'$FILTEROFFLINE'" == "true" && !/OFFLINE/{
next
}
LIST != ""{
for(i in A) {
if(index($2, A[i]) > 0) {
PrintEntry($0)
next
}
}
next
}
{
PrintEntry($0)
}
'
exit 0
|