Patchwork [4/5] ofpath: Support systems with a large number of devices

login
register
mail settings
Submitter Brian King
Date July 11, 2011, 2:02 p.m.
Message ID <201107111408.p6BE81F0016467@d03av06.boulder.ibm.com>
Download mbox | patch
Permalink /patch/104213/
State Superseded
Headers show

Comments

Brian King - July 11, 2011, 2:02 p.m.
Improve the ofpath script to be able to display the OF path
for more than just the first 16 devices on the system.

Signed-off-by: Brian King <brking@linux.vnet.ibm.com>
---

 ybin/ofpath |   44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)

Patch

diff -puN ybin/ofpath~ofpath_more_devs ybin/ofpath
--- yaboot/ybin/ofpath~ofpath_more_devs	2011-06-24 13:55:41.000000000 -0500
+++ yaboot-bjking1/ybin/ofpath	2011-06-24 13:56:17.000000000 -0500
@@ -116,15 +116,41 @@  linecount()
 ## small tr replacment which handles a specific need of this script.
 smalltr()
 {
-    case "$1" in
-	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
+        local i a d t val out mod cur
+
+        val="$1"
+        out="0"
+
+        d=$(printf "%d\n" \'${val:0:1})
+
+        if (( $d > 57 )) ; then  # is a letter
+                for ((i=0; i < ${#val}; i++)) ; do
+                        d=$(printf "%d\n" \'${val:$i:1})
+                        a=$(($d - 96))
+                        out=$(($out * 26))
+                        out=$(($out + $a))
+                done
+
+        else  # is a number
+                t=$val
+                out=""
+
+                while ((t != 0)) ; do
+                        mod=$(($t % 26))
+                        t=$(($t / 26))
+                        if (($mod == 0)) ; then
+                                cur="z"
+                                t=$(($t - 1))
+                        else
+                                mod=$(($mod + 96))
+                                cur=$(echo $mod | gawk '{printf "%c", $1}')
+                        fi
+                        out="$cur$out"
+                done
+        fi
+
+        echo "$out"
+
     return 0
 }