#!/bin/bash

get_subchannel() {
gdb -c /proc/kcore << EOF | tail -n2 | head -n1 | cut -f2 | cut -c7-
x/x 0x10404
EOF
}
linux_ver=`uname -r | cut -f1 -d"."`
linux_rel=`uname -r | cut -f2 -d"."`
min_ver=2
min_rel=4

if [ $linux_ver -lt $min_ver ]; then
   echo "You must be running a 2.4 kernel or higher to use this command."
   exit
fi
if [ $linux_rel -lt $min_rel ]; then
   echo "You must be running a 2.4 kernel or higher to use this command."
   exit
fi

uid=`id | cut -f1 -d"("`
eval $uid
if [ ! $uid -eq "0" ]; then
   echo "You must be UID=0 to run this command, due to the permissions on /proc/kcore."
   exit
fi

if [ ! -r /proc/subchannels ]; then
   echo "The /proc/subchannels file is not on your system, so I can't run."
   exit
fi

subchannel=`get_subchannel`

iplvol=`grep -i " $subchannel" /proc/subchannels | cut -f 1 -d" "`
echo "IPL volume was device number $iplvol"

