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 echo 1>&2 "$PRG: /dev/$DEVNODE: Device not configured"
194 ## first we have to figure out the SCSI ID, have to do that
195 ## anyway [to] find the attached scsi disks = "Direct-Access" and
196 ## stop at sda=1 sdb=2 or whatever count in 3 lines steps
198 ## get last letter of device node, ie sda -> a
199 SUBNODE=${DEVNODE##*sd}
201 ## turn SUBNODE above into a number starting at 1, ie a -> 1
202 SUBDEV="$(smalltr $SUBNODE)"
203 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: SUBNODE=$SUBNODE SUBDEV=$SUBDEV"
207 ## copy scsi file into a variable removing "Attached Devices"
208 ## which is the first line. this avoids a lot of
209 ## [incmopatible] crap later, and improves readability.
211 ## find number of lines once and recycle that number, to save
212 ## some time (linecount is a bit slow). subtract one line
213 ## to scrap Attached Devices:
215 SCSILINES="$(($(linecount /proc/scsi/scsi) - 1))"
217 if [ "$SUBDEV" -gt "$(cat /proc/scsi/scsi | grep Direct-Access | linecount)" ] ; then
218 echo 1>&2 "$PRG: /dev/$DEVNODE: Device not configured"
222 PROCSCSI="$(cat /proc/scsi/scsi | tail -n $SCSILINES)"
224 for i in $(smallseq $(($SCSILINES / 3))) ; do
226 ## put every scsi device into one single line
227 DEVINFO="$(echo "$PROCSCSI" | head -n $(($i * 3)) | tail -n 3)"
228 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVINFO=$DEVINFO"
230 ## cut the type field, expect "Direct-Access" later.
231 DEVTYPE="$(v=$(echo ${DEVINFO##*Type: }) ; echo ${v%% *})"
232 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVTYPE=$DEVTYPE"
234 ## get the device id.
235 DEVID="$(v=$(echo ${DEVINFO##*Id: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
236 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVID=$DEVID"
238 ## get the scsi host id.
239 DEVHOST="$(v=$(echo ${DEVINFO##*Host: scsi}) ; echo ${v%% *})"
240 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVHOST=$DEVHOST"
242 if [ "$DEVTYPE" = "Direct-Access" ] ; then
243 DEVCOUNT="$(($DEVCOUNT + 1))"
244 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVCOUNT=$DEVCOUNT"
245 if [ "$SUBDEV" = "$DEVCOUNT" ] ; then
248 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVICE_HOST=$DEVICE_HOST"
254 ## figure out what the scsi driver is, it is /proc/scsi/dirname.
255 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVICE_HOST=$DEVICE_HOST"
256 SCSI_DRIVER="$(x=`ls /proc/scsi/*/$DEVICE_HOST 2>/dev/null | cat` ; y=`echo ${x##*proc/scsi/}` ; echo ${y%%/*})"
257 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: SCSI_DRIVER=$SCSI_DRIVER"
259 ## figure out which host we found.
260 SCSI_HOSTNUMBER="$(v=`ls /proc/scsi/$SCSI_DRIVER/* 2>/dev/null | cat | grep -n "$DEVICE_HOST\>"` ; echo ${v%%:*})"
261 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: SCSI_HOSTNUMBER=$SCSI_HOSTNUMBER"
266 ## generic function that can find OF device paths for scsi devices,
267 ## must be run after scsiinfo().
270 case "$SCSI_DRIVER" in
272 HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
273 lgrep "$i" "^ADPT" "^pci900[45]" "^pciclass,01000" ; done)"
274 DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
275 echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
278 HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
279 lgrep "$i" "^Symbios" "^pci1000" "^pciclass,01000" ; done)"
280 DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
281 echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
284 HOST_LIST="$(for i in `find /proc/device-tree -name compatible` ; do
285 lgrep "$i" "mesh" ; done)"
286 DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
287 echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
290 echo 1>&2 "$PRG: Driver: $SCSI_DRIVER is not supported"
299 if [ ! -L "/proc/ide/$DEVNODE" ] ; then
300 echo 2>&1 "$PRG: /dev/$DEVNODE: Device not configured"
304 local IDEBUS="$(v=`readlink /proc/ide/$DEVNODE` ; echo ${v%%/*} )"
305 if [ -z "$IDEBUS" ] ; then
306 echo 1>&2 "$PRG: BUG: IDEBUS == NULL"
309 local OF1275IDE="/proc/ide/$IDEBUS/devspec"
311 if [ ! -f "$OF1275IDE" ] ; then
312 case "$(cat /proc/device-tree/model)" in
314 local CDROM="$(grep "^drive name:" /proc/sys/dev/cdrom/info 2> /dev/null | grep $DEVNODE)"
315 if [ -z "$CDROM" ] ; then
316 echo 1>&2 "$PRG: WARNING: Your kernel is too old for proper support, device may be innaccurate."
317 echo "ultra2:$PARTITION"
323 local CDROM="$(grep "^drive name:" /proc/sys/dev/cdrom/info 2> /dev/null | grep $DEVNODE)"
324 if [ -z "$CDROM" ] ; then
325 if [ "$DEVNODE" = hda ] ; then
328 echo "ultra1:$PARTITION"
336 local DEVSPEC="$(cat $OF1275IDE)"
337 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVSPEC=$DEVSPEC"
338 if [ -z "$DEVSPEC" ] ; then
339 echo 1>&2 "$PRG: KERNEL BUG: $OF1275IDE exists, but is empty"
343 if [ ! -f "/proc/ide/${IDEBUS}/channel" ] ; then
344 echo 1>&2 "$PRG: KERNEL BUG: /proc/ide/${IDEBUS}/channel does not exist"
348 case "$(cat /proc/device-tree${DEVSPEC}/device_type 2> /dev/null)" in
350 local MASTER="/disk@0"
351 local SLAVE="/disk@1"
354 local MASTER="/@$(cat /proc/ide/${IDEBUS}/channel)/disk@0"
355 local SLAVE="/@$(cat /proc/ide/${IDEBUS}/channel)/disk@1"
357 scsi) ## some lame controllers pretend they are scsi, hopefully all kludges are created equal.
358 local MASTER="/$(($(cat /proc/ide/${IDEBUS}/channel) * 2 + 0)),0"
359 local SLAVE="/$(($(cat /proc/ide/${IDEBUS}/channel) * 2 + 1)),0"
362 echo 2>&1 "$PRG: Unsupported IDE device type: \"$(cat /proc/device-tree${DEVSPEC}/device_type 2> /dev/null)\""
368 hda|hdc|hde|hdg|hdi|hdk|hdm|hdo)
369 echo "${DEVSPEC}${MASTER}:$PARTITION"
372 hdb|hdd|hdf|hdh|hdj|hdl|hdn|hdp)
373 echo "${DEVSPEC}${SLAVE}:$PARTITION"
377 echo 1>&2 "$PRG: /dev/$DEVNODE is not supported"
384 ## figure out the OpenFirmware device path for newworld macs.
385 ## sd* scsi disks , hd* ide disks.
390 if ls -l /proc/device-tree | grep -q ^lr ; then
393 echo 1>&2 "$PRG: /proc/device-tree is broken. Do not use BootX to boot, use yaboot."
394 echo 1>&2 "$PRG: The yaboot HOWTO can be found here: http://www.alaska.net/~erbenson/doc"
398 ## use common scsiinfo function to get info we need.
401 ## now we have the data for /@$DEVID:$PARTITION
402 ## find the actual OF path.
403 scsi_ofpath || return 1
406 ide_ofpath || return 1
409 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
418 ## for some reason 2.4 kernels put OF aliases in aliases@0/ instead of plain aliases/
419 if [ -d "/proc/device-tree/aliases" ] ; then
420 local ALIASES="aliases"
421 elif [ -d "/proc/device-tree/aliases@0" ] ; then
422 local ALIASES="aliases@0"
424 echo 1>&2 "$PRG: Cannot find OpenFirmware aliases directory in /proc/device-tree/"
428 local MODEL="$(cat /proc/device-tree/compatible)"
429 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: Oldworld subarch: $MODEL"
432 AAPL,7300*|AAPL,7500*|AAPL,8500*|AAPL,9500*|AAPL,\?\?\?\?*)
436 case "$SCSI_DRIVER" in
438 echo $(cat /proc/device-tree/$ALIASES/scsi-int)/sd\@$DEVICE_ID:$PARTITION
441 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
444 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
450 echo 1>&2 "$PRG: Unsupported device: /dev/$DEVNODE"
459 case "$SCSI_DRIVER" in
461 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
464 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
470 echo $(cat /proc/device-tree/$ALIASES/ata)/ATA-Disk\@0:$PARTITION
473 echo $(cat /proc/device-tree/$ALIASES/ata)/ATA-Disk\@1:$PARTITION
476 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
484 case "$SCSI_DRIVER" in
486 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
489 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
495 echo $(cat /proc/device-tree/$ALIASES/ata)/ata-disk\@0:$PARTITION
498 echo $(cat /proc/device-tree/$ALIASES/ata)/ata-disk\@1:$PARTITION
501 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
505 AAPL,Gossamer*|AAPL,PowerMac\ G3*)
509 case "$SCSI_DRIVER" in
511 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITION
514 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
520 echo $(cat /proc/device-tree/$ALIASES/ide0)/ata-disk\@0:$PARTITION
523 echo $(cat /proc/device-tree/$ALIASES/ide0)/ata-disk\@1:$PARTITION
526 echo $(cat /proc/device-tree/$ALIASES/ide1)/ata-disk\@0:$PARTITION
529 echo $(cat /proc/device-tree/$ALIASES/ide1)/ata-disk\@1:$PARTITION
532 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
537 if [ -f /proc/device-tree/$ALIASES/ata0 ] ; then
542 if [ -f /proc/device-tree/$ALIASES/ata1 ] ; then
550 case "$SCSI_DRIVER" in
552 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITON
555 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
561 echo $(cat /proc/device-tree/$ALIASES/$ATA0)/ata-disk\@0:$PARTITION
564 echo $(cat /proc/device-tree/$ALIASES/$ATA0)/ata-disk\@1:$PARTITION
567 echo $(cat /proc/device-tree/$ALIASES/$ATA1)/atapi-disk\@0:$PARTITION
570 echo $(cat /proc/device-tree/$ALIASES/$ATA1)/atapi-disk\@1:$PARTITION
573 echo 1>&2 "$PRG: Unsupported device: /dev/$DEVNODE"
582 case "$SCSI_DRIVER" in
584 echo $(cat /proc/device-tree/$ALIASES/scsi-int)/sd\@$DEVICE_ID:$PARTITON
587 echo $(cat /proc/device-tree/$ALIASES/scsi)/sd\@$DEVICE_ID:$PARTITON
590 echo 1>&2 "$PRG: Driver $SCSI_DRIVER is not supported"
596 echo $(cat /proc/device-tree/$ALIASES/ata0)/ata-disk\@0:$PARTITION
599 echo $(cat /proc/device-tree/$ALIASES/ata0)/ata-disk\@1:$PARTITION
602 echo $(cat /proc/device-tree/$ALIASES/ata1)/atapi-disk\@0:$PARTITION
605 echo $(cat /proc/device-tree/$ALIASES/ata1)/atapi-disk\@1:$PARTITION
608 echo $(cat /proc/device-tree/$ALIASES/ata2):$PARTITION
611 echo $(cat /proc/device-tree/$ALIASES/ata3):$PARTITION
614 echo 1>&2 "$PRG: Unsupported device: /dev/$DEVNODE"
620 echo 1>&2 "$PRG: This machine is not supported: $MODEL"
627 ## find OpenFirmware device path for IBM CHRP hardware (scsi only)
632 if ls -l /proc/device-tree | grep -q ^lr ; then
635 echo 1>&2 "$PRG: /proc/device-tree is broken."
639 ## use common scsiinfo function to get info we need.
642 ## now we have the data for /@$DEVID:$PARTITION
643 ## find the actual OF path.
644 scsi_ofpath || return 1
647 echo 1>&2 "$PRG: Device: /dev/$DEVNODE is not supported"
654 ## If we get lame devfs name, we need to make it foad
658 /dev/ide/*|/dev/scsi/*|/dev/discs/*)
667 ## convert devfs names into normal short ones, written by Tom Rini.
670 ## get partition number, if any
671 local PARTNUM="${1##*[a-z]}"
672 ## Find the bus type.
673 local TYPE="$(v=${1#/dev/} ; echo ${v%/host*})"
674 ## Find the host number.
675 local HOST="$(v=${1#/dev/*/host} ; echo ${v%/bus*})"
676 ## Find the bus number.
677 local BUS="$(v=${1#/dev/*/bus} ; echo ${v%/tar*})"
679 local TARGET="$(v=${1#/dev/*/target} ; echo ${v%/lun*})"
705 echo 1>&2 "$PRG: $1: Unable to translate this device, try again without devfs."
708 local DEV="${DEV}${PARTNUM}"
713 local LUN="$(v=${1#/dev/*/lun} ; echo ${v%/*})"
715 ## In this case, we need to figure out what number our device is
718 ## copy scsi file into a variable removing "Attached Devices"
719 ## which is the first line. this avoids a lot of
720 ## [incmopatible] crap later, and improves readability.
722 ## find number of lines once and recycle that number, to save
723 ## some time (linecount is a bit slow). subtract one line
724 ## to scrap Attached Devices:
726 local SCSILINES="$(($(linecount /proc/scsi/scsi) - 1))"
727 local PROCSCSI="$(cat /proc/scsi/scsi | tail -n $SCSILINES)"
729 for i in $(smallseq $(($SCSILINES / 3))) ; do
731 ## put every scsi device into one single line
732 local DEVINFO="$(echo "$PROCSCSI" | head -n $(($i * 3)) | tail -n 3)"
733 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVINFO=$DEVINFO"
735 ## cut the type field, expect "Direct-Access" later.
736 local DEVTYPE="$(v=$(echo ${DEVINFO##*Type: }) ; echo ${v%% *})"
737 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVTYPE=$DEVTYPE"
739 if [ "$DEVTYPE" = "Direct-Access" ] ; then
740 ## Lets find out some more information
741 ## get the device id.
742 local DEVID="$(v=$(echo ${DEVINFO##*Id: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
743 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVID=$DEVID"
745 ## get the device lun.
746 local DEVLUN="$(v=$(echo ${DEVINFO##*Lun: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
747 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVLUN=$DEVLUN"
749 ## get the device channel.
750 local DEVCHAN="$(v=$(echo ${DEVINFO##*Channel: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
751 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVCHAN=$DEVCHAN"
753 ## get the scsi host id.
754 local DEVHOST="$(v=$(echo ${DEVINFO##*Host: scsi}) ; echo ${v%% *})"
755 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVHOST=$DEVHOST"
757 local DEVCOUNT="$(($DEVCOUNT + 1))"
758 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVCOUNT=$DEVCOUNT"
759 if [ "$DEVHOST" = "$HOST" -a "$DEVCHAN" = "$BUS" -a \
760 "$DEVID" = "$TARGET" -a "$DEVLUN" = "$LUN" ] ; then
761 local DEV="sd$(smalltr $DEVCOUNT)${PARTNUM}"
767 echo 1>&2 "$PRG: $1: Unable to translate this device, try again without devfs."
771 echo 1>&2 "$PRG: Unknown bus $TYPE"
775 ## we should never get here
779 ## make sure that find, head and tail can be found. otherwise the
780 ## script will silently give bogus paths. these are the only /usr/*
781 ## utilities this script depends on.
784 if command -v find > /dev/null 2>&1 ; then
785 [ -x `command -v find` ] || FAIL=1 ; else FAIL=1 ; fi
786 if command -v head > /dev/null 2>&1 ; then
787 [ -x `command -v head` ] || FAIL=1 ; else FAIL=1 ; fi
788 if command -v tail > /dev/null 2>&1 ; then
789 [ -x `command -v tail` ] || FAIL=1 ; else FAIL=1 ; fi
791 if [ "$FAIL" = 1 ] ; then
792 echo 1>&2 "$PRG: \`find', \`head', or \`tail' could not be found, aborting."
799 ## parse command line switches.
800 if [ $# != 0 ] ; then
816 echo 1>&2 "$PRG: unrecognized option \`$1'"
817 echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
821 echo 1>&2 "$PRG: You must specify a filename"
822 echo 1>&2 "Try \`$PRG --help' for more information."
832 echo 1>&2 "$PRG: You must specify a /dev device"
833 echo 1>&2 "Try \`$PRG --help' for more information."
837 ## check that FILE is a block device and exists.
838 if [ ! -e "$device" ] ; then
839 echo 1>&2 "$PRG: $device: No such file or directory"
841 elif [ ! -b "$device" ] ; then
842 echo 1>&2 "$PRG: $device is not a block device"
846 ## check that we are running on a GNU/Linux system, OSX/BSD does not
847 ## have the same /proc stuff
848 if [ `uname -s` != Linux ] ; then
849 echo 1>&2 "$PRG: This utility will only work with GNU/Linux"
853 ## check for ppc, i think uname -m is safe for this...
854 if [ `uname -m` != ppc ] ; then
855 echo 1>&2 "$PRG: This utility will only work on PowerPC hardware"
859 ## ofpath cannot live without procfs
860 if [ ! -f /proc/uptime ] ; then
861 echo 1>&2 "$PRG: This utility requires the /proc filesystem"
865 ## check for retarded devfs names and tell them to foad.
866 if ckdevfs "$device" ; then
867 device="$(fixdevfs $device)" || exit 1
870 ## check for newworld mac. use cat hack due to /proc wierdness.
871 if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:[ ]})" = NewWorld ] ; then
873 elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:[ ]})" = OldWorld ] ; then
875 elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
877 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
880 echo 1>&2 "$PRG: This machine is not yet supported"
884 ## make sure /proc/device-tree exists
885 if [ ! -d /proc/device-tree ] ; then
886 echo 1>&2 "$PRG: /proc/device-tree does not exist"
887 echo 1>&2 "$PRG: Make sure you compiled your kernel with CONFIG_PROC_DEVICETREE=y"
891 ## make sure we have what we need.
894 ## get the base device node and scrap /dev/ ie /dev/hda2 -> hda
895 DEVICE="${device##*/}"
896 DEVNODE="${DEVICE%%[0-9]*}"
897 PARTITION="${DEVICE##*[a-z]}"
899 ## use appropriate search for right sub arch.