On Thu, May 24, 2001 at 06:44:25PM -0700, Tom Rini wrote: > On Thu, May 24, 2001 at 04:44:35PM -0800, Ethan Benson wrote: > > On Thu, May 24, 2001 at 05:10:52PM -0700, Tom Rini wrote: > > > I would too. I just couldn't think of any way to do that. > > > > what about grabbing the ids and host numbers out, and sorting the > > devices out? im not quite sure how do to that... some substitution > > and a for loop maybe. getting the logic right would be tricky. > > Er, hmm. It might be possible to do it this way. It looks like > most of the logic is there. I'll play around with this sometime > soonish.
Okay. I've attached a patch which cleans up fixdevfs() slightly, and makes it parse /proc/scsi/scsi for it's info. It also changes smalltr() to go from a number to a letter as well. It also fixed a slight logic goof so it should correctly translate devices other then hda/hdc. -- Tom Rini (TR1265) http://gate.crashing.org/~trini/
--- /usr/sbin/ofpath.orig Thu May 24 17:37:14 2001 +++ /usr/sbin/ofpath Sat May 26 16:29:37 2001 @@ -103,6 +103,10 @@ a) echo 1 ;; b) echo 2 ;; c) echo 3 ;; d) echo 4 ;; e) echo 5 ;; f) echo 6 ;; g) echo 7 ;; h) echo 8 ;; i) echo 9 ;; j) echo 10 ;; k) echo 11 ;; l) echo 12 ;; m) echo 13 ;; n) echo 14 ;; o) echo 15 ;; p) echo 16 ;; + 1) echo a ;; 2) echo b ;; 3) echo c ;; 4) echo d ;; 5) echo e ;; + 6) echo f ;; 7) echo g ;; 8) echo h ;; 9) echo i ;; 10) echo j ;; + 11) echo k ;; 12) echo l ;; 13) echo m ;; 14) echo n ;; 15) echo o ;; + 16) echo p ;; esac return 0 } @@ -540,35 +544,36 @@ else DISC="$1" fi - ## Find the bus type - TYPE="${DISC#/dev/}" - TYPE="${TYPE%/host*}" + ## Find the bus type. + TYPE="$(v=${DISC#/dev/} ; echo ${v%/host*})" + ## Find the host number. + HOST=$(v=${1#/dev/*/host} ; echo ${v%/bus*}) + ## Find the bus number. + BUS=$(v=${1#/dev/*/bus} ; echo ${v%/tar*}) + ## Find the target. + TARGET=$(v=${1#/dev/*/target} ; echo ${v%/lun*}) ## Partition number PARTNUM="${DISC#/dev/*/part}" case "$TYPE" in ide) - DRIVE="${DISC#/dev/ide/}" - DRIVE="${DRIVE%/bus*}" - BUS="${DISC#/dev/ide/host*/}" - BUS="${BUS%/target*}" - case "$DRIVE" in - host0) - case "$BUS" in - bus0) + case "$HOST" in + 0) + case "$TARGET" in + 0) DEV=hda ;; - bus1) + 1) DEV=hdb ;; esac ;; - host1) - case "$BUS" in - bus0) + 1) + case "$TARGET" in + 0) DEV=hdc ;; - bus1) + 1) DEV=hdd ;; esac @@ -580,43 +585,62 @@ DEV="${DEV}$PARTNUM" ;; scsi) - BASEDEV=${DISC#/dev/} - SDA=`ls -l /dev/sda$PARTNUM 2>/dev/null` - SDA="${SDA#l*> }" - SDB=`ls -l /dev/sdb$PARTNUM 2>/dev/null` - SDB="${SDB#l*> }" - SDC=`ls -l /dev/sdc$PARTNUM 2>/dev/null` - SDC="${SDC#l*> }" - SDD=`ls -l /dev/sdd$PARTNUM 2>/dev/null` - SDD="${SDD#l*> }" - SDE=`ls -l /dev/sde$PARTNUM 2>/dev/null` - SDE="${SDE#l*> }" - SDF=`ls -l /dev/sdf$PARTNUM 2>/dev/null` - SDF="${SDF#l*> }" - SDG=`ls -l /dev/sdg$PARTNUM 2>/dev/null` - SDG="${SDG#l*> }" - SDH=`ls -l /dev/sdh$PARTNUM 2>/dev/null` - SDH="${SDH#l*> }" - if [ "$BASEDEV" == "$SDA" ]; then - DEV="sda${PARTNUM}" - elif [ "$BASEDEV" == "$SDB" ]; then - DEV="sdb${PARTNUM}" - elif [ "$BASEDEV" == "$SDC" ]; then - DEV="sdc${PARTNUM}" - elif [ "$BASEDEV" == "$SDC" ]; then - DEV="sdd${PARTNUM}" - elif [ "$BASEDEV" == "$SDE" ]; then - DEV="sde${PARTNUM}" - elif [ "$BASEDEV" == "$SDF" ]; then - DEV="sdf${PARTNUM}" - elif [ "$BASEDEV" == "$SDG" ]; then - DEV="sdg${PARTNUM}" - elif [ "$BASEDEV" == "$SDH" ]; then - DEV="sdh${PARTNUM}" - else - echo 1>&2 "$PRG: Can't convert this devfs name, try again without devfs" - return 1 - fi + LUN=$(v=${1#/dev/*/lun} ; echo ${v%/*}) + + ## In this case, we need to figure out what number our device is + DEVCOUNT=0 + + ## copy scsi file into a variable removing "Attached Devices" + ## which is the first line. this avoids a lot of + ## [incmopatible] crap later, and improves readability. + + ## find number of lines once and recycle that number, to save + ## some time (linecount is a bit slow). subtract one line + ## to scrap Attached Devices: + + SCSILINES=$(($(linecount /proc/scsi/scsi) - 1)) + PROCSCSI=`cat /proc/scsi/scsi | tail -n $SCSILINES` + + for i in $(smallseq $(($SCSILINES / 3))) ; do + + ## put every scsi device into one single line + DEVINFO=$(echo "$PROCSCSI" | head -n $(($i * 3)) | tail -n 3) + [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVINFO=$DEVINFO" + + ## cut the type field, expect "Direct-Access" later. + DEVTYPE=$(v=$(echo ${DEVINFO##*Type: }) ; echo ${v%% *}) + [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVTYPE=$DEVTYPE" + + if [ "$DEVTYPE" = "Direct-Access" ] ; then + ## Lets find out some more information + ## get the device id. + DEVID=$(v=$(echo ${DEVINFO##*Id: }) ; n=$(echo ${v%% *}) ; echo ${n#*0}) + [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVID=$DEVID" + + ## get the device lun. + DEVLUN=$(v=$(echo ${DEVINFO##*Lun: }) ; n=$(echo ${v%% *}) ; echo ${n#*0}) + [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVLUN=$DEVLUN" + + ## get the device channel. + DEVCHAN=$(v=$(echo ${DEVINFO##*Channel: }) ; n=$(echo ${v%% *}) ; echo ${n#*0}) + [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVCHAN=$DEVCHAN" + + ## get the scsi host id. + DEVHOST=$(v=$(echo ${DEVINFO##*Host: scsi}) ; echo ${v%% *}) + [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVHOST=$DEVHOST" + + DEVCOUNT=$(($DEVCOUNT + 1)) + [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVCOUNT=$DEVCOUNT" + if [ "$DEVHOST" = "$HOST" -a "$DEVCHAN" = "$BUS" -a \ + "$DEVID" = "$TARGET" -a "$DEVLUN" = "$LUN" ] ; then + FINALDEV=sd$(smalltr $DEVCOUNT)${1#/dev/*part} + echo $FINALDEV + return 0 + fi + fi + done + echo "Couldn't translate this device." + return 1 ;; *) echo 1>&2 "$PRG: Unknown bus $TYPE"