3 ###############################################################################
5 ## ofpath: determine OpenFirmware path from unix device node
6 ## Copyright (C) 2000, 2001, 2002, 2003 Ethan Benson
8 ## Portions based on show_of_path.sh:
10 ## Copyright (C) 2000 Olaf Hering <olh@suse.de>
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.
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.
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.
26 ###############################################################################
28 PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
39 Written by Ethan Benson
40 Portions based on show_of_path.sh written by Olaf Hering
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."
52 "Usage: $PRG [OPTION]... FILE
53 Find OpenFirmware device path from unix device node.
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"
60 ## a small seq replacement, seq is not present on boot/rescue floppies.
66 while [ "$v" -gt 1 ] ; do
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.
83 local file="$(cat $1)"
87 if [ -z "$file" ] ; then
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)"
105 for i in `smallseq 145` ; do
106 local b="$(echo "$file" | tail -n $i)"
107 if [ "$v" = "$b" ] ; then
116 ## small tr replacment which handles a specific need of this script.
120 a) echo 1 ;; b) echo 2 ;; c) echo 3 ;; d) echo 4 ;; e) echo 5 ;; f) echo 6 ;;
121 g) echo 7 ;; h) echo 8 ;; i) echo 9 ;; j) echo 10 ;; k) echo 11 ;; l) echo 12 ;;
122 m) echo 13 ;; n) echo 14 ;; o) echo 15 ;; p) echo 16 ;;
123 1) echo a ;; 2) echo b ;; 3) echo c ;; 4) echo d ;; 5) echo e ;;
124 6) echo f ;; 7) echo g ;; 8) echo h ;; 9) echo i ;; 10) echo j ;;
125 11) echo k ;; 12) echo l ;; 13) echo m ;; 14) echo n ;; 15) echo o ;;
131 ## replacment for grep -l which is not supported by busybox grep.
132 ## echo $(cat..) hack needed because busybox grep barfs with `line too
133 ## long' when fed /proc files. the for loop is needed since busybox
134 ## grep seems to have somewhat broken regexp support.
135 ## usage: lgrep filename regexp regexp ...
141 echo "$(cat "$f")" | grep -q "$i" && echo "$f" && break
146 ## if readlink is missing use a kludge
147 if (command -v readlink > /dev/null 2>&1) ; then
152 local SYMTARGET="$(v=`ls -l "$1" 2>/dev/null` ; echo ${v##*> })"
153 if [ -n "$SYMTARGET" ] ; then
162 ## a function to print relevant scsi host path when there is more then
163 ## one. this function also takes care of stripping off the trailing
184 ## this finds information we need on both newworld and oldworld macs.
185 ## mainly what scsi host a disk is attached to.
188 ## see if system has scsi at all
189 if [ ! -f /proc/scsi/scsi ] ; then
190 local kver="$(uname -r)"
193 if [ -d /sys/bus/scsi/devices -a \
194 -n "$(ls /sys/bus/scsi/devices 2>/dev/null)" ] ; then
195 echo 1>&2 "$PRG: /proc/scsi/scsi does not exist"
196 echo 1>&2 "$PRG: Make sure you compiled your kernel with CONFIG_SCSI_PROC_FS=y"
201 echo 1>&2 "$PRG: /dev/$DEVNODE: Device not configured"
205 ## first we have to figure out the SCSI ID, have to do that
206 ## anyway [to] find the attached scsi disks = "Direct-Access" and
207 ## stop at sda=1 sdb=2 or whatever count in 3 lines steps
209 ## get last letter of device node, ie sda -> a
210 SUBNODE=${DEVNODE##*sd}
212 ## turn SUBNODE above into a number starting at 1, ie a -> 1
213 SUBDEV="$(smalltr $SUBNODE)"
214 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: SUBNODE=$SUBNODE SUBDEV=$SUBDEV"
218 ## copy scsi file into a variable removing "Attached Devices"
219 ## which is the first line. this avoids a lot of
220 ## [incmopatible] crap later, and improves readability.
222 ## find number of lines once and recycle that number, to save
223 ## some time (linecount is a bit slow). subtract one line
224 ## to scrap Attached Devices:
226 SCSILINES="$(($(linecount /proc/scsi/scsi) - 1))"
228 if [ "$SUBDEV" -gt "$(cat /proc/scsi/scsi | grep Direct-Access | linecount)" ] ; then
229 echo 1>&2 "$PRG: /dev/$DEVNODE: Device not configured"
233 PROCSCSI="$(cat /proc/scsi/scsi | tail -n $SCSILINES)"
235 for i in $(smallseq $(($SCSILINES / 3))) ; do
237 ## put every scsi device into one single line
238 DEVINFO="$(echo "$PROCSCSI" | head -n $(($i * 3)) | tail -n 3)"
239 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVINFO=$DEVINFO"
241 ## cut the type field, expect "Direct-Access" later.
242 DEVTYPE="$(v=$(echo ${DEVINFO##*Type: }) ; echo ${v%% *})"
243 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVTYPE=$DEVTYPE"
245 ## get the device id.
246 DEVID="$(v=$(echo ${DEVINFO##*Id: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
247 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVID=$DEVID"
249 ## get the scsi host id.
250 DEVHOST="$(v=$(echo ${DEVINFO##*Host: scsi}) ; echo ${v%% *})"
251 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVHOST=$DEVHOST"
253 if [ "$DEVTYPE" = "Direct-Access" ] ; then
254 DEVCOUNT="$(($DEVCOUNT + 1))"
255 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVCOUNT=$DEVCOUNT"
256 if [ "$SUBDEV" = "$DEVCOUNT" ] ; then
259 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVICE_HOST=$DEVICE_HOST"
265 ## figure out what the scsi driver is, it is /proc/scsi/dirname.
266 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVICE_HOST=$DEVICE_HOST"
267 SCSI_DRIVER="$(x=`ls /proc/scsi/*/$DEVICE_HOST 2>/dev/null | cat` ; y=`echo ${x##*proc/scsi/}` ; echo ${y%%/*})"
268 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: SCSI_DRIVER=$SCSI_DRIVER"
270 ## figure out which host we found.
271 SCSI_HOSTNUMBER="$(v=`ls /proc/scsi/$SCSI_DRIVER/* 2>/dev/null | cat | grep -n "$DEVICE_HOST\>"` ; echo ${v%%:*})"
272 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: SCSI_HOSTNUMBER=$SCSI_HOSTNUMBER"
277 ## generic function that can find OF device paths for scsi devices,
278 ## must be run after scsiinfo().
281 case "$SCSI_DRIVER" in
283 HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
284 lgrep "$i" "^ADPT" "^pci900[45]" "^pciclass,01000" ; done)"
285 DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
286 echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
289 HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
290 lgrep "$i" "^Symbios" "^pci1000" "^pciclass,01000" ; done)"
291 DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
292 echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
295 HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
296 lgrep "$i" "mesh" ; done)"
297 DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
298 echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
301 HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
302 lgrep "$i" "k2-s-ata" ; done)"
303 DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
304 echo "${DEVICE_PATH##*device-tree}/k2-sata@$DEVICE_ID/disk@0:$PARTITION"
307 echo 1>&2 "$PRG: Driver: $SCSI_DRIVER is not supported"
316 if [ ! -L "/proc/ide/$DEVNODE" ] ; then
317 echo 2>&1 "$PRG: /dev/$DEVNODE: Device not configured"
321 local IDEBUS="$(v=`readlink /proc/ide/$DEVNODE` ; echo ${v%%/*} )"
322 if [ -z "$IDEBUS" ] ; then
323 echo 1>&2 "$PRG: BUG: IDEBUS == NULL"
326 local OF1275IDE="/proc/ide/$IDEBUS/devspec"
328 if [ ! -f "$OF1275IDE" ] ; then
329 case "$(cat /proc/device-tree/model)" in
331 local CDROM="$(grep "^drive name:" /proc/sys/dev/cdrom/info 2> /dev/null | grep $DEVNODE)"
332 if [ -z "$CDROM" ] ; then
333 echo 1>&2 "$PRG: WARNING: Your kernel is too old for proper support, device may be innaccurate."
334 echo "ultra2:$PARTITION"
340 local CDROM="$(grep "^drive name:" /proc/sys/dev/cdrom/info 2> /dev/null | grep $DEVNODE)"
341 if [ -z "$CDROM" ] ; then
342 if [ "$DEVNODE" = hda ] ; then
345 echo "ultra1:$PARTITION"
353 local DEVSPEC="$(cat $OF1275IDE)"
354 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVSPEC=$DEVSPEC"
355 if [ -z "$DEVSPEC" ] ; then
356 echo 1>&2 "$PRG: KERNEL BUG: $OF1275IDE exists, but is empty"
360 if [ ! -f "/proc/ide/${IDEBUS}/channel" ] ; then
361 echo 1>&2 "$PRG: KERNEL BUG: /proc/ide/${IDEBUS}/channel does not exist"
365 case "$(cat /proc/device-tree${DEVSPEC}/device_type 2> /dev/null)" in
367 local MASTER="/disk@0"
368 local SLAVE="/disk@1"
371 local MASTER="/@$(cat /proc/ide/${IDEBUS}/channel)/disk@0"
372 local SLAVE="/@$(cat /proc/ide/${IDEBUS}/channel)/disk@1"
374 scsi) ## some lame controllers pretend they are scsi, hopefully all kludges are created equal.
375 local MASTER="/@$(($(cat /proc/ide/${IDEBUS}/channel) * 2 + 0))"
376 local SLAVE="/@$(($(cat /proc/ide/${IDEBUS}/channel) * 2 + 1))"
379 echo 2>&1 "$PRG: Unsupported IDE device type: \"$(cat /proc/device-tree${DEVSPEC}/device_type 2> /dev/null)\""
385 hda|hdc|hde|hdg|hdi|hdk|hdm|hdo)
386 echo "${DEVSPEC}${MASTER}:$PARTITION"
389 hdb|hdd|hdf|hdh|hdj|hdl|hdn|hdp)
390 echo "${DEVSPEC}${SLAVE}:$PARTITION"
394 echo 1>&2 "$PRG: /dev/$DEVNODE is not supported"
401 ## figure out the OpenFirmware device path for newworld macs.
402 ## sd* scsi disks , hd* ide disks.
407 if ls -l /proc/device-tree | grep -q ^lr ; then
410 echo 1>&2 "$PRG: /proc/device-tree is broken. Do not use BootX to boot, use yaboot."
411 echo 1>&2 "$PRG: The yaboot HOWTO can be found here: http://www.alaska.net/~erbenson/doc"
415 ## use common scsiinfo function to get info we need.
418 ## now we have the data for /@$DEVID:$PARTITION
419 ## find the actual OF path.
420 scsi_ofpath || return 1
423 ide_ofpath || return 1
426 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
435 ## for some reason 2.4 kernels put OF aliases in aliases@0/ instead of plain aliases/
436 if [ -d "/proc/device-tree/aliases" ] ; then
437 local ALIASES="aliases"
438 elif [ -d "/proc/device-tree/aliases@0" ] ; then
439 local ALIASES="aliases@0"
441 echo 1>&2 "$PRG: Cannot find OpenFirmware aliases directory in /proc/device-tree/"
445 local MODEL="$(cat /proc/device-tree/compatible)"
446 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: Oldworld subarch: $MODEL"
449 AAPL,7300*|AAPL,7500*|AAPL,8500*|AAPL,9500*|AAPL,\?\?\?\?*)
453 case "$SCSI_DRIVER" in
455 echo $(cat /proc/device-tree/$ALIASES/scsi-int)/sd\@$DEVICE_ID:$PARTITION
458 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
461 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
467 echo 1>&2 "$PRG: Unsupported device: /dev/$DEVNODE"
476 case "$SCSI_DRIVER" in
478 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
481 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
487 echo $(cat /proc/device-tree/$ALIASES/ata)/ATA-Disk\@0:$PARTITION
490 echo $(cat /proc/device-tree/$ALIASES/ata)/ATA-Disk\@1:$PARTITION
493 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
501 case "$SCSI_DRIVER" in
503 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
506 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
512 echo $(cat /proc/device-tree/$ALIASES/ata)/ata-disk\@0:$PARTITION
515 echo $(cat /proc/device-tree/$ALIASES/ata)/ata-disk\@1:$PARTITION
518 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
522 AAPL,Gossamer*|AAPL,PowerMac\ G3*)
526 case "$SCSI_DRIVER" in
528 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
531 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
537 echo $(cat /proc/device-tree/$ALIASES/ide0)/ata-disk\@0:$PARTITION
540 echo $(cat /proc/device-tree/$ALIASES/ide0)/ata-disk\@1:$PARTITION
543 echo $(cat /proc/device-tree/$ALIASES/ide1)/ata-disk\@0:$PARTITION
546 echo $(cat /proc/device-tree/$ALIASES/ide1)/ata-disk\@1:$PARTITION
549 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
554 if [ -f /proc/device-tree/$ALIASES/ata0 ] ; then
559 if [ -f /proc/device-tree/$ALIASES/ata1 ] ; then
567 case "$SCSI_DRIVER" in
569 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITON
572 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
578 echo $(cat /proc/device-tree/$ALIASES/$ATA0)/ata-disk\@0:$PARTITION
581 echo $(cat /proc/device-tree/$ALIASES/$ATA0)/ata-disk\@1:$PARTITION
584 echo $(cat /proc/device-tree/$ALIASES/$ATA1)/atapi-disk\@0:$PARTITION
587 echo $(cat /proc/device-tree/$ALIASES/$ATA1)/atapi-disk\@1:$PARTITION
590 echo 1>&2 "$PRG: Unsupported device: /dev/$DEVNODE"
599 case "$SCSI_DRIVER" in
601 echo $(cat /proc/device-tree/$ALIASES/scsi-int)/sd\@$DEVICE_ID:$PARTITON
604 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITON
607 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
613 echo $(cat /proc/device-tree/$ALIASES/ata0)/ata-disk\@0:$PARTITION
616 echo $(cat /proc/device-tree/$ALIASES/ata0)/ata-disk\@1:$PARTITION
619 echo $(cat /proc/device-tree/$ALIASES/ata1)/atapi-disk\@0:$PARTITION
622 echo $(cat /proc/device-tree/$ALIASES/ata1)/atapi-disk\@1:$PARTITION
625 echo $(cat /proc/device-tree/$ALIASES/ata2):$PARTITION
628 echo $(cat /proc/device-tree/$ALIASES/ata3):$PARTITION
631 echo 1>&2 "$PRG: Unsupported device: /dev/$DEVNODE"
637 echo 1>&2 "$PRG: This machine is not supported: $MODEL"
644 ## find OpenFirmware device path for IBM CHRP hardware (scsi only)
649 if ls -l /proc/device-tree | grep -q ^lr ; then
652 echo 1>&2 "$PRG: /proc/device-tree is broken."
656 ## use common scsiinfo function to get info we need.
659 ## now we have the data for /@$DEVID:$PARTITION
660 ## find the actual OF path.
661 scsi_ofpath || return 1
664 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
671 ## If we get lame devfs name, we need to make it foad
675 /dev/ide/*|/dev/scsi/*|/dev/discs/*)
684 ## convert devfs names into normal short ones, written by Tom Rini.
687 ## get partition number, if any
688 local PARTNUM="${1##*[a-z]}"
689 ## Find the bus type.
690 local TYPE="$(v=${1#/dev/} ; echo ${v%/host*})"
691 ## Find the host number.
692 local HOST="$(v=${1#/dev/*/host} ; echo ${v%/bus*})"
693 ## Find the bus number.
694 local BUS="$(v=${1#/dev/*/bus} ; echo ${v%/tar*})"
696 local TARGET="$(v=${1#/dev/*/target} ; echo ${v%/lun*})"
722 echo 1>&2 "$PRG: $1: Unable to translate this device, try again without devfs."
725 local DEV="${DEV}${PARTNUM}"
730 local LUN="$(v=${1#/dev/*/lun} ; echo ${v%/*})"
732 ## In this case, we need to figure out what number our device is
735 ## copy scsi file into a variable removing "Attached Devices"
736 ## which is the first line. this avoids a lot of
737 ## [incmopatible] crap later, and improves readability.
739 ## find number of lines once and recycle that number, to save
740 ## some time (linecount is a bit slow). subtract one line
741 ## to scrap Attached Devices:
743 local SCSILINES="$(($(linecount /proc/scsi/scsi) - 1))"
744 local PROCSCSI="$(cat /proc/scsi/scsi | tail -n $SCSILINES)"
746 for i in $(smallseq $(($SCSILINES / 3))) ; do
748 ## put every scsi device into one single line
749 local DEVINFO="$(echo "$PROCSCSI" | head -n $(($i * 3)) | tail -n 3)"
750 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVINFO=$DEVINFO"
752 ## cut the type field, expect "Direct-Access" later.
753 local DEVTYPE="$(v=$(echo ${DEVINFO##*Type: }) ; echo ${v%% *})"
754 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVTYPE=$DEVTYPE"
756 if [ "$DEVTYPE" = "Direct-Access" ] ; then
757 ## Lets find out some more information
758 ## get the device id.
759 local DEVID="$(v=$(echo ${DEVINFO##*Id: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
760 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVID=$DEVID"
762 ## get the device lun.
763 local DEVLUN="$(v=$(echo ${DEVINFO##*Lun: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
764 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVLUN=$DEVLUN"
766 ## get the device channel.
767 local DEVCHAN="$(v=$(echo ${DEVINFO##*Channel: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
768 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVCHAN=$DEVCHAN"
770 ## get the scsi host id.
771 local DEVHOST="$(v=$(echo ${DEVINFO##*Host: scsi}) ; echo ${v%% *})"
772 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVHOST=$DEVHOST"
774 local DEVCOUNT="$(($DEVCOUNT + 1))"
775 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVCOUNT=$DEVCOUNT"
776 if [ "$DEVHOST" = "$HOST" -a "$DEVCHAN" = "$BUS" -a \
777 "$DEVID" = "$TARGET" -a "$DEVLUN" = "$LUN" ] ; then
778 local DEV="sd$(smalltr $DEVCOUNT)${PARTNUM}"
784 echo 1>&2 "$PRG: $1: Unable to translate this device, try again without devfs."
788 echo 1>&2 "$PRG: Unknown bus $TYPE"
792 ## we should never get here
796 ## make sure that find, head and tail can be found. otherwise the
797 ## script will silently give bogus paths. these are the only /usr/*
798 ## utilities this script depends on.
801 if command -v find > /dev/null 2>&1 ; then
802 [ -x `command -v find` ] || FAIL=1 ; else FAIL=1 ; fi
803 if command -v head > /dev/null 2>&1 ; then
804 [ -x `command -v head` ] || FAIL=1 ; else FAIL=1 ; fi
805 if command -v tail > /dev/null 2>&1 ; then
806 [ -x `command -v tail` ] || FAIL=1 ; else FAIL=1 ; fi
808 if [ "$FAIL" = 1 ] ; then
809 echo 1>&2 "$PRG: \`find', \`head', or \`tail' could not be found, aborting."
816 ## parse command line switches.
817 if [ $# != 0 ] ; then
833 echo 1>&2 "$PRG: unrecognized option \`$1'"
834 echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
838 echo 1>&2 "$PRG: You must specify a filename"
839 echo 1>&2 "Try \`$PRG --help' for more information."
849 echo 1>&2 "$PRG: You must specify a /dev device"
850 echo 1>&2 "Try \`$PRG --help' for more information."
854 ## check that FILE is a block device and exists.
855 if [ ! -e "$device" ] ; then
856 echo 1>&2 "$PRG: $device: No such file or directory"
858 elif [ ! -b "$device" ] ; then
859 echo 1>&2 "$PRG: $device is not a block device"
863 ## check that we are running on a GNU/Linux system, OSX/BSD does not
864 ## have the same /proc stuff
865 if [ `uname -s` != Linux ] ; then
866 echo 1>&2 "$PRG: This utility will only work with GNU/Linux"
870 ## check for ppc, i think uname -m is safe for this...
871 if [ `uname -m` != ppc -a `uname -m` != ppc64 ] ; then
872 echo 1>&2 "$PRG: This utility will only work on PowerPC hardware"
876 ## ofpath cannot live without procfs
877 if [ ! -f /proc/uptime ] ; then
878 echo 1>&2 "$PRG: This utility requires the /proc filesystem"
882 ## check for retarded devfs names and tell them to foad.
883 if ckdevfs "$device" ; then
884 device="$(fixdevfs $device)" || exit 1
887 ## check for newworld mac. use cat hack due to /proc wierdness.
888 if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:[ ]})" = NewWorld ] ; then
890 elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:[ ]})" = OldWorld ] ; then
892 elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
894 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
897 echo 1>&2 "$PRG: This machine is not yet supported"
901 ## make sure /proc/device-tree exists
902 if [ ! -d /proc/device-tree ] ; then
903 echo 1>&2 "$PRG: /proc/device-tree does not exist"
904 echo 1>&2 "$PRG: Make sure you compiled your kernel with CONFIG_PROC_DEVICETREE=y"
908 ## make sure we have what we need.
911 ## get the base device node and scrap /dev/ ie /dev/hda2 -> hda
912 DEVICE="${device##*/}"
913 DEVNODE="${DEVICE%%[0-9]*}"
914 PARTITION="${DEVICE##*[a-z]}"
916 ## use appropriate search for right sub arch.