]> git.ozlabs.org Git - yaboot.git/blob - ybin/ofpath
a487149416a07d59bf7a492d88646898adddd336
[yaboot.git] / ybin / ofpath
1 #! /bin/sh
2
3 ###############################################################################
4 ##
5 ## ofpath: determine OpenFirmware path from unix device node
6 ## Copyright (C) 2000, 2001, 2002, 2003 Ethan Benson
7 ##
8 ## Portions based on show_of_path.sh:
9 ##
10 ## Copyright (C) 2000 Olaf Hering <olh@suse.de>
11 ##
12 ## This program is free software; you can redistribute it and/or
13 ## modify it under the terms of the GNU General Public License
14 ## as published by the Free Software Foundation; either version 2
15 ## of the License, or (at your option) any later version.
16 ##
17 ## This program is distributed in the hope that it will be useful,
18 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ## GNU General Public License for more details.
21 ##
22 ## You should have received a copy of the GNU General Public License
23 ## along with this program; if not, write to the Free Software
24 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 ##
26 ###############################################################################
27
28 PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
29 PRG="${0##*/}"
30 VERSION=1.0.7
31 DEBUG=0
32 export LC_COLLATE=C
33
34 ## --version output.
35 version()
36 {
37 echo \
38 "$PRG $VERSION
39 Written by Ethan Benson
40 Portions based on show_of_path.sh written by Olaf Hering
41
42 Copyright (C) 2000, 2001, 2002, 2003 Ethan Benson
43 Portions Copyright (C) 2000 Olaf Hering
44 This is free software; see the source for copying conditions.  There is NO
45 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
46 }
47
48 ## --help output.
49 usage()
50 {
51 echo \
52 "Usage: $PRG [OPTION]... FILE
53 Find OpenFirmware device path from unix device node.
54
55       --debug                print boring junk only useful for debugging
56   -h, --help                 display this help and exit
57   -V, --version              output version information and exit"
58 }
59
60 ## a small seq replacement, seq is not present on boot/rescue floppies.
61 smallseq()
62 {
63     local v="$1"
64     local n=1
65     echo 1
66     while [ "$v" -gt 1 ] ; do
67         echo "$(($n + 1))"
68         local n="$(($n + 1))"
69         local v="$(($v - 1))"
70     done
71     return 0
72 }
73
74 ## a kludge to replace wc -l, wc is not present on boot/rescue
75 ## floppies. max file is 145 lines, 3 hosts * 16 devs each * 3 lines
76 ## per device, + 1 "Attached Devices:" line.
77 linecount()
78 {
79     if [ $# = 0 ] ; then
80         local file="$(cat)"
81         local v="$file"
82     else
83         local file="$(cat $1)"
84         local v="$file"
85     fi
86
87     if [ -z "$file" ] ; then
88         echo 0
89         return 0
90     fi
91
92     ## use real wc if available
93     if (command -v wc > /dev/null 2>&1) ; then
94         if [ -x `command -v wc` ] ; then
95             lines="$(echo "$file" | wc -l)"
96             if [ $? = 0 ] ; then
97                 echo $lines
98                 unset lines
99                 return 0
100             fi
101         fi
102     fi
103
104     while true ; do
105         for i in `smallseq 145` ; do
106             local b="$(echo "$file" | tail -n $i)"
107             if [ "$v" = "$b" ] ; then
108                 echo "$i"
109                 break 2
110             fi
111         done
112     done
113     return 0
114 }
115
116 ## small tr replacment which handles a specific need of this script.
117 smalltr()
118 {
119         local i a d t val out mod cur
120
121         val="$1"
122         out="0"
123
124         d=$(printf "%d\n" \'${val:0:1})
125
126         if (( $d > 57 )) ; then  # is a letter
127                 for ((i=0; i < ${#val}; i++)) ; do
128                         d=$(printf "%d\n" \'${val:$i:1})
129                         a=$(($d - 96))
130                         out=$(($out * 26))
131                         out=$(($out + $a))
132                 done
133
134         else  # is a number
135                 t=$val
136                 out=""
137
138                 while ((t != 0)) ; do
139                         mod=$(($t % 26))
140                         t=$(($t / 26))
141                         if (($mod == 0)) ; then
142                                 cur="z"
143                                 t=$(($t - 1))
144                         else
145                                 mod=$(($mod + 96))
146                                 cur=$(echo $mod | gawk '{printf "%c", $1}')
147                         fi
148                         out="$cur$out"
149                 done
150         fi
151
152         echo "$out"
153
154     return 0
155 }
156
157 ## replacment for grep -l which is not supported by busybox grep.
158 ## echo $(cat..) hack needed because busybox grep barfs with `line too
159 ## long' when fed /proc files.  the for loop is needed since busybox
160 ## grep seems to have somewhat broken regexp support.
161 ## usage: lgrep filename regexp regexp ...
162 lgrep()
163 {
164     local f="$1"
165     shift
166     for i in "$@" ; do
167         echo "$(cat "$f")" | grep -q "$i" && echo "$f" && break
168     done
169     return 0
170 }
171
172 ## if readlink is missing use a kludge
173 if (command -v readlink > /dev/null 2>&1) ; then
174     true
175 else
176     readlink()
177     {
178         local SYMTARGET="$(v=`ls -l "$1" 2>/dev/null` ; echo ${v##*> })"
179         if [ -n "$SYMTARGET" ] ; then
180             echo "$SYMTARGET"
181             return 0
182         else
183             return 1
184         fi
185     }
186 fi
187
188 ## a function to print relevant scsi host path when there is more then
189 ## one.  this function also takes care of stripping off the trailing
190 ## /compatible.
191 printhost()
192 {
193     case "$1" in
194         1)
195         echo "${2%/*}"
196         ;;
197         2)
198         echo "${3%/*}"
199         ;;
200         3)
201         echo "${4%/*}"
202         ;;
203         4)
204         echo "${5%/*}"
205         ;;
206     esac
207     return 0
208 }
209
210 ## this finds information we need on both newworld and oldworld macs.
211 ## mainly what scsi host a disk is attached to.
212 scsiinfo()
213 {
214     ## see if system has scsi at all
215     if [ ! -f /proc/scsi/scsi ] ; then
216         local kver="$(uname -r)"
217         case "$kver" in
218             2.5.*|2.6.*)
219                 if [ -d /sys/bus/scsi/devices -a \
220                     -n "$(ls /sys/bus/scsi/devices 2>/dev/null)" ] ; then
221                     echo 1>&2 "$PRG: /proc/scsi/scsi does not exist"
222                     echo 1>&2 "$PRG: Make sure you compiled your kernel with CONFIG_SCSI_PROC_FS=y"
223                     return 1
224                 fi
225                 ;;
226         esac
227         echo 1>&2 "$PRG: /dev/$DEVNODE: Device not configured"
228         return 1
229     fi
230
231     ## first we have to figure out the SCSI ID, have to do that
232     ## anyway [to] find the attached scsi disks = "Direct-Access" and
233     ## stop at sda=1 sdb=2 or whatever count in 3 lines steps
234
235     ## get last letter of device node, ie sda -> a
236     SUBNODE=${DEVNODE##*sd}
237
238     ## turn SUBNODE above into a number starting at 1, ie a -> 1
239     SUBDEV="$(smalltr $SUBNODE)"
240     [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: SUBNODE=$SUBNODE SUBDEV=$SUBDEV"
241
242     DEVCOUNT=0
243
244     ## copy scsi file into a variable removing "Attached Devices"
245     ## which is the first line. this avoids a lot of
246     ## [incmopatible] crap later, and improves readability.
247
248     ## find number of lines once and recycle that number, to save
249     ## some time (linecount is a bit slow). subtract one line
250     ## to scrap Attached Devices:
251
252     SCSILINES="$(($(linecount /proc/scsi/scsi) - 1))"
253
254     if [ "$SUBDEV" -gt "$(cat /proc/scsi/scsi | grep Direct-Access | linecount)" ] ; then
255         echo 1>&2 "$PRG: /dev/$DEVNODE: Device not configured"
256         return 1
257     fi
258
259     PROCSCSI="$(cat /proc/scsi/scsi | tail -n $SCSILINES)"
260
261     for i in $(smallseq $(($SCSILINES / 3))) ; do
262
263         ## put every scsi device into one single line
264         DEVINFO="$(echo "$PROCSCSI" | head -n $(($i * 3)) | tail -n 3)"
265         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVINFO=$DEVINFO"
266
267         ## cut the type field, expect "Direct-Access" later.
268         DEVTYPE="$(v=$(echo ${DEVINFO##*Type: }) ; echo ${v%% *})"
269         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVTYPE=$DEVTYPE"
270
271         ## get the device LUN.
272         DEVLUN="$(v=$(echo ${DEVINFO##*Lun: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
273         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVLUN=$DEVLUN"
274
275         ## get the device id.
276         DEVID="$(v=$(echo ${DEVINFO##*Id: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
277         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVID=$DEVID"
278
279         ## get the device bus.
280         DEVBUS="$(v=$(echo ${DEVINFO##*Channel: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
281         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVBUS=$DEVBUS"
282
283         ## get the scsi host id.
284         DEVHOST="$(v=$(echo ${DEVINFO##*Host: scsi}) ; echo ${v%% *})"
285         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVHOST=$DEVHOST"
286
287         if [ "$DEVTYPE" = "Direct-Access" ] || [ "$DEVTYPE" = "Direct-Access-RBC" ] ; then
288             DEVCOUNT="$(($DEVCOUNT + 1))"
289             [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVCOUNT=$DEVCOUNT"
290             if [ "$SUBDEV" = "$DEVCOUNT" ] ; then
291                 DEVICE_HOST=$DEVHOST
292                 DEVICE_BUS=$DEVBUS
293                 DEVICE_ID=$DEVID
294                 DEVICE_LUN=$DEVLUN
295                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVICE_HOST=$DEVICE_HOST"
296                 break
297             fi
298         fi
299     done
300
301     ## figure out what the scsi driver is, it is /proc/scsi/dirname.
302     [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVICE_HOST=$DEVICE_HOST"
303     SCSI_DRIVER="$(x=`ls /proc/scsi/*/$DEVICE_HOST 2>/dev/null | cat` ; y=`echo ${x##*proc/scsi/}` ; echo ${y%%/*})"
304     [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: SCSI_DRIVER=$SCSI_DRIVER"
305
306     ## figure out which host we found.
307     SCSI_HOSTNUMBER="$(v=`ls /proc/scsi/$SCSI_DRIVER/* 2>/dev/null | cat | grep -n "$DEVICE_HOST\>"` ; echo ${v%%:*})"
308     [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: SCSI_HOSTNUMBER=$SCSI_HOSTNUMBER"
309
310     return 0
311 }
312
313 read_attr()
314 {
315         local ATTR=$1
316         local START=$2
317         local OLDDIR=$(pwd)
318         local RET
319
320         cd -P "$START"
321         while [[ $PWD != "/" ]]; do
322                 ls $ATTR > /dev/null 2>&1
323                 if [[ $? -eq 0 ]]; then
324                         RET=$(cat $ATTR)
325                         cd $OLDDIR
326                         echo "$RET"
327                         return 0
328                 fi
329                 cd ..
330         done
331
332         cd $OLDDIR
333         echo 1>&2 "$PRG: Cannot find $RET for $DEVICE"
334         exit 1
335 }
336
337 read_dev_attr()
338 {
339         local ATTR=$1
340         local DEVICE="$DEVICE_HOST:$DEVICE_BUS:$DEVICE_ID:$DEVICE_LUN"
341         local START="/sys/bus/scsi/devices/$DEVICE"
342
343         read_attr $ATTR $START
344 }
345
346 read_parent_attr()
347 {
348         local ATTR=$1
349         local DEVICE="$DEVICE_HOST:$DEVICE_BUS:$DEVICE_ID:$DEVICE_LUN"
350         local START="/sys/bus/scsi/devices/$DEVICE/.."
351
352         read_attr $ATTR $START
353 }
354
355 get_vdisk_lun()
356 {
357         local B C D
358         typeset -i B C D
359
360         B=$((0x$DEVICE_ID << 8))
361         C=$((0x$DEVICE_BUS << 5))
362         D=$((0x$DEVICE_LUN))
363
364         local vdiskno vdisk
365         typeset -i vdiskno
366         vdiskno=$((0x8000 | $B | $C | $D ))
367         vdisk=${vdiskno##-}
368
369         vdisk=$(printf "%x" $vdisk)
370         local extrazeroes="000000000000"
371         echo $vdisk$extrazeroes
372 }
373
374 int_to_scsilun()
375 {
376         local lunint=$1
377         local A B C D
378
379         A=$(( ($lunint >> 8) & 0xff ))
380         B=$(($lunint & 0xff))
381         C=$(( ($lunint >> 24) & 0xff ))
382         D=$(( ($lunint >> 16) & 0xff ))
383
384         local lunstr=$(printf "%02x%02x%02x%02x00000000" $A $B $C $D)
385         lunstr=$(echo $lunstr | sed 's/^[0]*//')
386         echo "$lunstr"
387 }
388
389 get_fc_scsilun()
390 {
391         local L=$(echo "$DEVICE_LUN"|gawk '{$1=tolower($1);print}')
392         L=$(printf "%d" $L)
393
394         local fc_lun=$(int_to_scsilun $L)
395         echo "$fc_lun"
396 }
397
398 get_fc_wwpn()
399 {
400         local start_dir=$1
401
402         for f in `find -H $start_dir -maxdepth 2 -name port_name`; do
403                 local wwpn=$(cat $f)
404                 break
405         done
406
407         # strip the leading 0x
408         wwpn=${wwpn:2}
409         echo "$wwpn"
410 }
411
412 scsi_ofpath2()
413 {
414         local DEVSPEC=$(read_parent_attr devspec)
415         local COMPAT=$(cat "/proc/device-tree$DEVSPEC/compatible")
416         local DEVICE_PATH="/sys/bus/scsi/devices/$DEVICE_HOST:$DEVICE_BUS:$DEVICE_ID:$DEVICE_LUN"
417
418         case "$COMPAT" in
419             IBM,v-scsi)
420                 local vdisk=$(get_vdisk_lun)
421                 if [[ $PARTITION = "" ]]; then
422                         echo "$DEVSPEC/disk@$vdisk"
423                 else
424                         echo "$DEVSPEC/disk@$vdisk:$PARTITION"
425                 fi
426                 return 0
427                 ;;
428             IBM,vfc-client)
429                 local vfc_lun=$(get_fc_scsilun)
430                 local wwpn=$(get_fc_wwpn "$DEVICE_PATH/../../fc_remote_ports*")
431                 if [[ $DEVICE_LUN != "0" ]]; then
432                         local vfc_lun=$(get_fc_scsilun)
433                         echo "$DEVSPEC/disk@$wwpn,$vfc_lun"
434                 else
435                         echo "$DEVSPEC/disk@$wwpn"
436                 fi
437                 return 0
438                 ;;
439             *)
440                 ;;
441         esac
442
443         if [[ -d "/proc/device-tree$DEVSPEC/sas" ]]; then
444                 local vendor_id=$(read_parent_attr vendor)
445                 local sas_addr
446
447                 if [[ $vendor_id = "0x1000" ]]; then
448                         sas_addr=$(read_dev_attr sas_address)
449                         sas_addr=${sas_addr##0x}
450                         if [[ $DEVICE_LUN != "0" ]]; then
451                                 local LUN=$(int_to_scsilun $DEVICE_LUN)
452                                 echo "$DEVSPEC/sas/disk@$sas_addr,$LUN"
453                         else
454                                 echo "$DEVSPEC/sas/disk@$sas_addr"
455                         fi
456                         return 0
457                 fi
458
459                 local fwtype="0"
460                 if [[ -e /sys/class/scsi_host/host$DEVICE_HOST/fw_type ]]; then
461                         fwtype=$(cat /sys/class/scsi_host/host$DEVICE_HOST/fw_type)
462                 fi
463
464                 if [[ $fwtype = "1" ]]; then
465                         sas_addr=$(read_dev_attr device_id)
466                         sas_addr=${sas_addr##0x}
467                         if [[ $DEVICE_LUN != "0" ]]; then
468                                 local LUN=$(int_to_scsilun $DEVICE_LUN)
469                                 echo "$DEVSPEC/sas/disk@$sas_addr,$LUN"
470                         else
471                                 echo "$DEVSPEC/sas/disk@$sas_addr"
472                         fi
473                 else
474                         local B T L
475
476                         B=$(echo "$DEVICE_BUS"|gawk '{$1=tolower($1);print}')
477                         B=$(printf "%d" $B)
478                         T=$(echo "$DEVICE_ID"|gawk '{$1=tolower($1);print}')
479                         T=$(printf "%d" $T)
480                         L=$(echo "$DEVICE_LUN"|gawk '{$1=tolower($1);print}')
481                         L=$(printf "%d" $L)
482
483                         sas_addr=$(( ($B << 16) | ($T << 8) | $L ))
484                         if [[ $DEVICE_LUN != "0" ]]; then
485                                 printf "%s/sas/disk@%x,%x\n" $DEVSPEC $sas_addr $DEVICE_LUN
486                         else
487                                 printf "%s/sas/disk@%x\n" $DEVSPEC $sas_addr
488                         fi
489                 fi
490                 return 0
491         fi
492
493         local fc=${DEVSPEC%@*}
494         fc=${fc##/*/}
495
496         if [[ -e /proc/device-tree$DEVSPEC/device_type ]]; then
497                 local devtype=$(cat /proc/device-tree$DEVSPEC/device_type);
498                 if [[ $devtype = "fcp" || $devtype = "scsi-fcp" ]]; then
499                         fc="fibre-channel";
500                 fi
501         fi
502
503         if [[ $fc = "fibre-channel" ]]; then
504                 local wwpn=$(get_fc_wwpn "$DEVICE_PATH/../../fc_remote_ports*")
505                 local ofpath=$DEVSPEC
506
507                 if [[ ! -e /proc/device-tree$DEVSPEC/disk ]]; then
508                         for dir in `find /proc/device-tree$DEVSPEC -type d`; do
509                                 if [[ -e $dir/disk ]]; then
510                                         ofpath=${dir##/proc/device-tree}
511                                         break;
512                                 fi
513                         done
514                 fi
515
516                 ofpath=$(printf "%s/disk@%s" $ofpath $wwpn)
517
518                 if [[ $DEVICE_LUN != "0" ]]; then
519                         local fc_lun=$(get_fc_scsilun $DEVICE_LUN)
520                         ofpath=$(printf "%s,%s" $ofpath $fc_lun)
521                 fi
522
523                 echo "$ofpath"
524                 return 0
525         fi
526
527         echo 1>&2 "$PRG: Driver: $SCSI_DRIVER is not supported"
528         return 1
529 }
530
531 ## generic function that can find OF device paths for scsi devices,
532 ## must be run after scsiinfo().
533 scsi_ofpath()
534 {
535     case "$SCSI_DRIVER" in
536         aic7xxx)
537             HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
538                         lgrep "$i" "^ADPT" "^pci900[45]" "^pciclass,01000" ; done)"
539             DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
540             echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
541             ;;
542         sym53c8xx)
543             HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
544                         lgrep "$i" "^Symbios" "^pci1000" "^pciclass,01000" ; done)"
545             DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
546             echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
547             ;;
548         mesh)
549             HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
550                         lgrep "$i" "mesh" ; done)"
551             DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
552             echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
553             ;;
554         ata_k2|sata_svw)
555             #Not all G5 device trees have a compatible "k2-sata" node 
556             #per channel use parent
557             HOST_LIST="$(for i in `find /proc/device-tree -name compatible ` ; do
558                         lgrep "$i" "k2-s-ata" ; done | sort)"
559             DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
560             K2_DEVICE_ID=0
561             while [ "$DEVICE_PATH" = "" ] ; do
562                 SCSI_HOSTNUMBER=`expr $SCSI_HOSTNUMBER - 1`
563                 let "K2_DEVICE_ID += 1"
564                 DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
565             done
566             echo "${DEVICE_PATH##*device-tree}/k2-sata@$K2_DEVICE_ID/disk@0:$PARTITION"
567             ;;
568         usb-storage)
569             HOST_LIST="$(for i in `find /proc/device-tree -name name | grep usb` ; do
570                         lgrep "$i" "disk" ; done)"
571             DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
572             echo "${DEVICE_PATH##*device-tree}:$PARTITION"
573             ;;
574         sbp2|"")
575             # sbp-2 driver may not have a dir in /proc/scsi
576             HOST_LIST="$(for i in `find /proc/device-tree -name name` ; do
577                         lgrep "$i" "sbp-2" ; done)"
578             if [ "$HOST_LIST" = "" ] ; then
579                 scsi_ofpath2
580             else
581                 if [ "$SCSI_HOSTNUMBER" = "" ] ; then
582                         SCSI_HOSTNUMBER=1
583                 fi
584                 DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
585                 echo "${DEVICE_PATH##*device-tree}/disk@0:$PARTITION"
586             fi
587             ;;
588         *)
589             echo 1>&2 "$PRG: Driver: $SCSI_DRIVER is not supported"
590             return 1
591             ;;
592     esac
593     return 0
594 }
595
596 ide_ofpath()
597 {
598     if [ ! -L "/proc/ide/$DEVNODE" ] ; then
599         echo 1>&2 "$PRG: /dev/$DEVNODE: Device not configured"
600         return 1
601     fi
602
603     local IDEBUS="$(v=`readlink /proc/ide/$DEVNODE` ; echo ${v%%/*} )"
604     if [ -z "$IDEBUS" ] ; then
605         echo 1>&2 "$PRG: BUG: IDEBUS == NULL"
606         return 1
607     fi
608
609     case "$(uname -r)" in
610         2.5.*|2.6.0*|2.6.1|2.6.1-*|2.6.2|2.6.2-*)
611             echo 1>&2 "$PRG: Linux kernel `uname -r` is not supported"
612             return 1
613             ;;
614         2.6.*|2.7.*)
615             if ! (grep -q '.* .* sysfs ' /proc/mounts 2> /dev/null) ; then
616                 echo 1>&2 "$PRG: sysfs must be mounted for ofpath to support this system"
617                 return 1
618             fi
619             local SYS="$(m=`grep '.* .* sysfs ' /proc/mounts | head -n 1` ; echo `d=${m#* };echo ${d%% *}`)"
620             if [ -z "$SYS" -o ! -d "$SYS" ] ; then
621                 echo 1>&2 "$PRG: Unable to determine sysfs mountpoint"
622                 return 1
623             fi
624             local OF1275IDE="${SYS}/block/${DEVNODE}/device/../../devspec"
625             ;;
626         *)
627             local OF1275IDE="/proc/ide/$IDEBUS/devspec"
628             ;;
629     esac
630
631     if [ ! -f "$OF1275IDE" ] ; then
632         case "$(cat /proc/device-tree/model)" in
633             PowerMac3*|PowerMac4*|PowerMac5*|PowerMac6*|PowerMac7*|RackMac*)
634                 local CDROM="$(grep "^drive name:" /proc/sys/dev/cdrom/info 2> /dev/null | grep $DEVNODE)"
635                 if [ -z "$CDROM" ] ; then
636                     echo 1>&2 "$PRG: WARNING: Your kernel is too old for proper support, device may be innaccurate."
637                     echo "ultra2:$PARTITION"
638                 else
639                     echo "cd:$PARTITION"
640                 fi
641                 ;;
642             *)
643                 local CDROM="$(grep "^drive name:" /proc/sys/dev/cdrom/info 2> /dev/null | grep $DEVNODE)"
644                 if [ -z "$CDROM" ] ; then
645                     if [ "$DEVNODE" = hda ] ; then
646                         echo "hd:$PARTITION"
647                     else
648                         echo "ultra1:$PARTITION"
649                     fi
650                 else
651                     echo "cd:$PARTITION"
652                 fi
653                 ;;
654         esac
655     else
656         local DEVSPEC="$(cat $OF1275IDE)"
657         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVSPEC=$DEVSPEC"
658         if [ -z "$DEVSPEC" ] ; then
659             echo 1>&2 "$PRG: KERNEL BUG: $OF1275IDE exists, but is empty"
660             return 1
661         fi
662
663         if [ ! -f "/proc/ide/${IDEBUS}/channel" ] ; then
664             echo 1>&2 "$PRG: KERNEL BUG: /proc/ide/${IDEBUS}/channel does not exist"
665             return 1
666         fi
667
668         case "$(cat /proc/device-tree${DEVSPEC}/device_type 2> /dev/null)" in
669             ide|ata)
670                 local MASTER="/disk@0"
671                 local SLAVE="/disk@1"
672                 ;;
673             pci-ide|pci-ata)
674                 local MASTER="/@$(cat /proc/ide/${IDEBUS}/channel)/disk@0"
675                 local SLAVE="/@$(cat /proc/ide/${IDEBUS}/channel)/disk@1"
676                 ;;
677             scsi) ## some lame controllers pretend they are scsi, hopefully all kludges are created equal.
678                 local MASTER="/@$(($(cat /proc/ide/${IDEBUS}/channel) * 2 + 0))"
679                 local SLAVE="/@$(($(cat /proc/ide/${IDEBUS}/channel) * 2 + 1))"
680                 ;;
681             spi)
682                 local MASTER="/disk@$(cat /proc/ide/${IDEBUS}/channel),0"
683                 local SLAVE="/disk@$(cat /proc/ide/${IDEBUS}/channel),1"
684                 ;;
685             *)
686                 echo 1>&2 "$PRG: Unsupported IDE device type: \"$(cat /proc/device-tree${DEVSPEC}/device_type 2> /dev/null)\""
687                 return 1
688                 ;;
689         esac
690
691         case "$DEVNODE" in
692             hda|hdc|hde|hdg|hdi|hdk|hdm|hdo)
693                 echo "${DEVSPEC}${MASTER}:$PARTITION"
694                 return 0
695                 ;;
696             hdb|hdd|hdf|hdh|hdj|hdl|hdn|hdp)
697                 echo "${DEVSPEC}${SLAVE}:$PARTITION"
698                 return 0
699                 ;;
700             *)
701                 echo 1>&2 "$PRG: /dev/$DEVNODE is not supported"
702                 return 1
703                 ;;
704         esac
705     fi
706 }
707
708 ## figure out the OpenFirmware device path for newworld macs.
709 ## sd* scsi disks , hd* ide disks.
710 newworld()
711 {
712     case "$DEVNODE" in
713         sd*)
714             ## use common scsiinfo function to get info we need.
715             scsiinfo || return 1
716
717             ## now we have the data for /@$DEVID:$PARTITION
718             ## find the actual OF path.
719             scsi_ofpath || return 1
720             ;;
721         hd*)
722             ide_ofpath || return 1
723             ;;
724         *)
725             echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
726             return 1
727             ;;
728     esac
729     return 0
730 }
731
732 oldworld()
733 {
734     ## for some reason 2.4 kernels put OF aliases in aliases@0/ instead of plain aliases/
735     if [ -d "/proc/device-tree/aliases" ] ; then
736         local ALIASES="aliases"
737     elif [ -d "/proc/device-tree/aliases@0" ] ; then
738         local ALIASES="aliases@0"
739     else
740         echo 1>&2 "$PRG: Cannot find OpenFirmware aliases directory in /proc/device-tree/"
741         return 1
742     fi
743
744     local MODEL="$(cat /proc/device-tree/compatible)"
745     [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: Oldworld subarch: $MODEL"
746
747     case "$MODEL" in
748         AAPL,7300*|AAPL,7500*|AAPL,8500*|AAPL,9500*|AAPL,\?\?\?\?*)
749             case "$DEVNODE" in
750                 sd*)
751                 scsiinfo || return 1
752                 case "$SCSI_DRIVER" in
753                     mesh)
754                     echo $(cat /proc/device-tree/$ALIASES/scsi-int)/sd\@$DEVICE_ID:$PARTITION
755                     ;;
756                     53c94)
757                     echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
758                     ;;
759                     *)
760                     echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
761                     return 1
762                     ;;
763                 esac
764                 ;;
765                 *)
766                 echo 1>&2 "$PRG: Unsupported device: /dev/$DEVNODE"
767                 return 1
768                 ;;
769             esac
770             ;;
771         AAPL,e407*)
772             case "$DEVNODE" in
773                 sd*)
774                 scsiinfo || return 1
775                 case "$SCSI_DRIVER" in
776                     mesh)
777                     echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
778                     ;;
779                     *)
780                     echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
781                     return 1
782                     ;;
783                 esac
784                 ;;
785                 hda*)
786                 echo $(cat /proc/device-tree/$ALIASES/ata)/ATA-Disk\@0:$PARTITION
787                 ;;
788                 hdb*)
789                 echo $(cat /proc/device-tree/$ALIASES/ata)/ATA-Disk\@1:$PARTITION
790                 ;;
791                 hd*)
792                 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
793                 ;;
794             esac
795             ;;
796         AAPL,e826*)
797             case "$DEVNODE" in
798                 sd*)
799                 scsiinfo || return 1
800                 case "$SCSI_DRIVER" in
801                     mesh)
802                     echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
803                     ;;
804                     *)
805                     echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
806                     return 1
807                     ;;
808                 esac
809                 ;;
810                 hda*)
811                 echo $(cat /proc/device-tree/$ALIASES/ata)/ata-disk\@0:$PARTITION
812                 ;;
813                 hdb*)
814                 echo $(cat /proc/device-tree/$ALIASES/ata)/ata-disk\@1:$PARTITION
815                 ;;
816                 hd*)
817                 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
818                 ;;
819             esac
820             ;;
821         AAPL,Gossamer*|AAPL,PowerMac\ G3*)
822             case "$DEVNODE" in
823                 sd*)
824                 scsiinfo || return 1
825                 case "$SCSI_DRIVER" in
826                     mesh)
827                     echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
828                     ;;
829                     *)
830                     echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
831                     return 1
832                     ;;
833                 esac
834                 ;;
835                 hda*)
836                 echo $(cat /proc/device-tree/$ALIASES/ide0)/ata-disk\@0:$PARTITION
837                 ;;
838                 hdb*)
839                 echo $(cat /proc/device-tree/$ALIASES/ide0)/ata-disk\@1:$PARTITION
840                 ;;
841                 hdc*)
842                 echo $(cat /proc/device-tree/$ALIASES/ide1)/ata-disk\@0:$PARTITION
843                 ;;
844                 hdd*)
845                 echo $(cat /proc/device-tree/$ALIASES/ide1)/ata-disk\@1:$PARTITION
846                 ;;
847                 hd*)
848                 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
849                 ;;
850             esac
851             ;;
852         AAPL,PowerBook1998*)
853             if [ -f  /proc/device-tree/$ALIASES/ata0 ] ; then
854                 local ATA0=ata0
855             else
856                 local ATA0=ide0
857             fi
858             if [ -f  /proc/device-tree/$ALIASES/ata1 ] ; then
859                 local ATA1=ata1
860             else
861                 local ATA1=bay-ata1
862             fi
863             case "$DEVNODE" in
864                 sd*)
865                 scsiinfo || return 1
866                 case "$SCSI_DRIVER" in
867                     mesh)
868                     echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITON
869                     ;;
870                     *)
871                     echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
872                     return 1
873                     ;;
874                 esac
875                 ;;
876                 hda*)
877                 echo $(cat /proc/device-tree/$ALIASES/$ATA0)/ata-disk\@0:$PARTITION
878                 ;;
879                 hdb*)
880                 echo $(cat /proc/device-tree/$ALIASES/$ATA0)/ata-disk\@1:$PARTITION
881                 ;;
882                 hdc*)
883                 echo $(cat /proc/device-tree/$ALIASES/$ATA1)/atapi-disk\@0:$PARTITION
884                 ;;
885                 hdd*)
886                 echo $(cat /proc/device-tree/$ALIASES/$ATA1)/atapi-disk\@1:$PARTITION
887                 ;;
888                 *)
889                 echo 1>&2 "$PRG: Unsupported device: /dev/$DEVNODE"
890                 return 1
891                 ;;
892             esac
893             ;;
894         AAPL,3400/2400*)
895             case "$DEVNODE" in
896                 sd*)
897                 scsiinfo || return 1
898                 case "$SCSI_DRIVER" in
899                     mesh)
900                     echo $(cat /proc/device-tree/$ALIASES/scsi-int)/sd\@$DEVICE_ID:$PARTITON
901                     ;;
902                     53c94)
903                     echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITON
904                     ;;
905                     *)
906                     echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
907                     return 1
908                     ;;
909                 esac
910                 ;;
911                 hda*)
912                 echo $(cat /proc/device-tree/$ALIASES/ata0)/ata-disk\@0:$PARTITION
913                 ;;
914                 hdb*)
915                 echo $(cat /proc/device-tree/$ALIASES/ata0)/ata-disk\@1:$PARTITION
916                 ;;
917                 hdc*)
918                 echo $(cat /proc/device-tree/$ALIASES/ata1)/atapi-disk\@0:$PARTITION
919                 ;;
920                 hdd*)
921                 echo $(cat /proc/device-tree/$ALIASES/ata1)/atapi-disk\@1:$PARTITION
922                 ;;
923                 hde*)
924                 echo $(cat /proc/device-tree/$ALIASES/ata2):$PARTITION
925                 ;;
926                 hdf*)
927                 echo $(cat /proc/device-tree/$ALIASES/ata3):$PARTITION
928                 ;;
929                 *)
930                 echo 1>&2 "$PRG: Unsupported device: /dev/$DEVNODE"
931                 return 1
932                 ;;
933             esac
934             ;;
935         *)
936             echo 1>&2 "$PRG: This machine is not supported: $MODEL"
937             return 1
938             ;;
939     esac
940     return 0
941 }
942
943 eth_ofpath()
944 {
945         read_attr devspec /sys/class/net/$DEVICE/device
946 }
947
948 hfi_ofpath()
949 {
950         local hfnum=${DEVICE##hf}
951         local hfpath
952
953         if [[ $hfnum = "0" || $hfnum = "2" ]]; then
954                 hfpath=$(find /proc/device-tree -name hfi-ethernet* | sort | head -n 1)
955         elif [[ $hfnum = "1" || $hfnum = "3" ]]; then
956                 hfpath=$(find /proc/device-tree -name hfi-ethernet* | sort | tail -n 1)
957         else
958                 echo 1>&2 "$PRG: Unsupported device: $DEVICE"
959                 return 1
960         fi
961
962         hfpath=${hfpath##/proc/device-tree}
963         echo "$hfpath"
964 }
965
966 ## find OpenFirmware device path for IBM CHRP hardware (scsi only)
967 chrp()
968 {
969     case "$DEVNODE" in
970         sd*)
971
972             ## use common scsiinfo function to get info we need.
973             scsiinfo || return 1
974
975             ## now we have the data for /@$DEVID:$PARTITION
976             ## find the actual OF path.
977             scsi_ofpath || return 1
978             ;;
979         eth*)
980             eth_ofpath || return 1
981             ;;
982         hfi*)
983             hfi_ofpath || return 1
984             ;;
985         *)
986             echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
987             return 1
988             ;;
989     esac
990     return 0
991 }
992
993 ## If we get lame devfs name, we need to make it foad
994 ckdevfs()
995 {
996     case "$1" in
997         /dev/ide/*|/dev/scsi/*|/dev/discs/*)
998         return 0
999         ;;
1000         *)
1001         return 1
1002         ;;
1003     esac
1004 }
1005
1006 ## convert devfs names into normal short ones, written by Tom Rini.
1007 fixdevfs()
1008 {
1009     ## get partition number, if any
1010     local PARTNUM="${1##*[a-z]}"
1011     ## Find the bus type.
1012     local TYPE="$(v=${1#/dev/} ; echo ${v%/host*})"
1013     ## Find the host number.
1014     local HOST="$(v=${1#/dev/*/host} ; echo ${v%/bus*})"
1015     ## Find the bus number.
1016     local BUS="$(v=${1#/dev/*/bus} ; echo ${v%/tar*})"
1017     ## Find the target.
1018     local TARGET="$(v=${1#/dev/*/target} ; echo ${v%/lun*})"
1019
1020     case "$TYPE" in
1021         ide)
1022         case "$HOST" in
1023             0)
1024             case "$TARGET" in
1025                 0)
1026                 local DEV=hda
1027                 ;;
1028                 1)
1029                 local DEV=hdb
1030                 ;;
1031             esac
1032             ;;
1033             1)
1034             case "$TARGET" in
1035                 0)
1036                 local DEV=hdc
1037                 ;;
1038                 1)
1039                 local DEV=hdd
1040                 ;;
1041             esac
1042             ;;
1043             *)
1044                 echo 1>&2 "$PRG: $1: Unable to translate this device, try again without devfs."
1045                 return 1
1046         esac
1047         local DEV="${DEV}${PARTNUM}"
1048         echo "/dev/$DEV"
1049         return 0
1050         ;;
1051         scsi)
1052         local LUN="$(v=${1#/dev/*/lun} ; echo ${v%/*})"
1053
1054         ## In this case, we need to figure out what number our device is
1055         local DEVCOUNT=0
1056
1057         ## copy scsi file into a variable removing "Attached Devices"
1058         ## which is the first line. this avoids a lot of
1059         ## [incmopatible] crap later, and improves readability.
1060
1061         ## find number of lines once and recycle that number, to save
1062         ## some time (linecount is a bit slow). subtract one line
1063         ## to scrap Attached Devices:
1064
1065         local SCSILINES="$(($(linecount /proc/scsi/scsi) - 1))"
1066         local PROCSCSI="$(cat /proc/scsi/scsi | tail -n $SCSILINES)"
1067
1068         for i in $(smallseq $(($SCSILINES / 3))) ; do
1069
1070             ## put every scsi device into one single line
1071             local DEVINFO="$(echo "$PROCSCSI" | head -n $(($i * 3)) | tail -n 3)"
1072             [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVINFO=$DEVINFO"
1073
1074             ## cut the type field, expect "Direct-Access" later.
1075             local DEVTYPE="$(v=$(echo ${DEVINFO##*Type: }) ; echo ${v%% *})"
1076             [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVTYPE=$DEVTYPE"
1077
1078             if [ "$DEVTYPE" = "Direct-Access" ] || [ "$DEVTYPE" = "Direct-Access-RBC" ] ; then
1079                 ## Lets find out some more information
1080                 ## get the device id.
1081                 local DEVID="$(v=$(echo ${DEVINFO##*Id: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
1082                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVID=$DEVID"
1083
1084                 ## get the device lun.
1085                 local DEVLUN="$(v=$(echo ${DEVINFO##*Lun: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
1086                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVLUN=$DEVLUN"
1087
1088                 ## get the device channel.
1089                 local DEVCHAN="$(v=$(echo ${DEVINFO##*Channel: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
1090                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVCHAN=$DEVCHAN"
1091
1092                 ## get the scsi host id.
1093                 local DEVHOST="$(v=$(echo ${DEVINFO##*Host: scsi}) ; echo ${v%% *})"
1094                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVHOST=$DEVHOST"
1095
1096                 local DEVCOUNT="$(($DEVCOUNT + 1))"
1097                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVCOUNT=$DEVCOUNT"
1098                 if [ "$DEVHOST" = "$HOST" -a "$DEVCHAN" = "$BUS" -a \
1099                     "$DEVID" = "$TARGET" -a "$DEVLUN" = "$LUN" ] ; then
1100                     local DEV="sd$(smalltr $DEVCOUNT)${PARTNUM}"
1101                     echo "/dev/$DEV"
1102                     return 0
1103                 fi
1104             fi
1105         done
1106         echo 1>&2 "$PRG: $1: Unable to translate this device, try again without devfs."
1107         return 1
1108         ;;
1109         *)
1110         echo 1>&2 "$PRG: Unknown bus $TYPE"
1111         return 1
1112         ;;
1113     esac
1114     ## we should never get here
1115     return 1
1116 }
1117
1118 ## make sure that find, head and tail can be found.  otherwise the
1119 ## script will silently give bogus paths.  these are the only /usr/*
1120 ## utilities this script depends on.
1121 checkutils()
1122 {
1123     if command -v find > /dev/null 2>&1 ; then
1124         [ -x `command -v find` ] || FAIL=1 ; else FAIL=1 ; fi
1125     if command -v head > /dev/null 2>&1 ; then
1126         [ -x `command -v head` ] || FAIL=1 ; else FAIL=1 ; fi
1127     if command -v tail > /dev/null 2>&1 ; then
1128         [ -x `command -v tail` ] || FAIL=1 ; else FAIL=1 ; fi
1129
1130     if [ "$FAIL" = 1 ] ; then
1131         echo 1>&2 "$PRG: \`find', \`head', or \`tail' could not be found, aborting."
1132         return 1
1133     else
1134         return 0
1135     fi
1136 }
1137
1138 ## parse command line switches.
1139 if [ $# != 0 ] ; then
1140     while true ; do
1141         case "$1" in
1142             -V|--version)
1143                 version
1144                 exit 0
1145                 ;;
1146             -h|--help)
1147                 usage
1148                 exit 0
1149                 ;;
1150             --debug)
1151                 DEBUG=1
1152                 shift
1153                 ;;
1154             -*)
1155                 echo 1>&2 "$PRG: unrecognized option \`$1'"
1156                 echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
1157                 exit 1
1158                 ;;
1159             "")
1160                 echo 1>&2 "$PRG: You must specify a filename"
1161                 echo 1>&2 "Try \`$PRG --help' for more information."
1162                 exit 1
1163                 ;;
1164             *)
1165                 device="$1"
1166                 break
1167                 ;;
1168         esac
1169     done
1170 else
1171     echo 1>&2 "$PRG: You must specify a /dev device"
1172     echo 1>&2 "Try \`$PRG --help' for more information."
1173     exit 1
1174 fi
1175
1176 ## check that we are running on a GNU/Linux system, OSX/BSD does not
1177 ## have the same /proc stuff
1178 if [ `uname -s` != Linux ] ; then
1179     echo 1>&2 "$PRG: This utility will only work with GNU/Linux"
1180     exit 1
1181 fi
1182
1183 ## check for ppc, i think uname -m is safe for this...
1184 if [ `uname -m` != ppc -a `uname -m` != ppc64 ] ; then
1185     echo 1>&2 "$PRG: This utility will only work on PowerPC hardware"
1186     exit 1
1187 fi
1188
1189 ## ofpath cannot live without procfs
1190 if [ ! -f /proc/uptime ] ; then
1191     echo 1>&2 "$PRG: This utility requires the /proc filesystem"
1192     exit 1
1193 fi
1194
1195 ## check for retarded devfs names and tell them to foad.
1196 if ckdevfs "$device" ; then
1197     device="$(fixdevfs $device)" || exit 1
1198 fi
1199
1200 ## check for newworld mac. use cat hack due to /proc wierdness.
1201 if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:[ ]})" = NewWorld ] ; then
1202     SUBARCH=NewWorld
1203 elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:[ ]})" = OldWorld ] ; then
1204     SUBARCH=OldWorld
1205 elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
1206     SUBARCH=OldWorld
1207 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
1208     SUBARCH=CHRP
1209 elif (cat /proc/cpuinfo 2>/dev/null | grep ^machine | grep -q 'CHRP Pegasos') ; then
1210     SUBARCH=Pegasos
1211 else
1212     echo 1>&2 "$PRG: This machine is not yet supported"
1213     exit 1
1214 fi
1215
1216 ## make sure /proc/device-tree exists
1217 if [ ! -d /proc/device-tree ] ; then
1218     echo 1>&2 "$PRG: /proc/device-tree does not exist"
1219     echo 1>&2 "$PRG: Make sure you compiled your kernel with CONFIG_PROC_DEVICETREE=y"
1220     exit 1
1221 fi
1222
1223 ## make sure we have what we need.
1224 checkutils || exit 1
1225
1226 ## get the base device node and scrap /dev/ ie /dev/hda2 -> hda
1227 DEVICE="${device##*/}"
1228 DEVNODE="${DEVICE%%[0-9]*}"
1229 PARTITION="${DEVICE##*[a-z]}"
1230
1231 ## use appropriate search for right sub arch.
1232 case "$SUBARCH" in
1233     # Pegasos OF seems to be NewWorld-ish enough to cope with this.
1234     NewWorld|Pegasos)
1235         newworld || exit 1
1236         ;;
1237     OldWorld)
1238         oldworld || exit 1
1239         ;;
1240     CHRP)
1241         chrp || exit 1
1242         ;;
1243 esac
1244
1245 exit 0