Subject: Re: testing presence of a device (was sun-lamp CVS commits)
To: Jason Thorpe <>
From: Chris G Demetriou <Chris_G_Demetriou@BALVENIE.PDL.CS.CMU.EDU>
List: current-users
Date: 10/05/1995 02:30:10
> I apparently missed this original mail...
> The point is, doing this in shell to present a list like:
> 	You can install on the following devices:
> 		sd0
> 		sd1
> 		sd3
> impractical.

I disagree.

Consider the following (short, relatively simple and self-documenting)
shell script:


echo disk type list is in: $TYPELIST
echo device directory name: $DEVDIR
echo ""

dtypes=`sed -e 's,#.*,,' dtlist`
se_devdir=`echo $DEVDIR | sed -e 's,/,\\\\/,g'`

echo disk types are: $dtypes
echo sed-escped device directory name is: $se_devdir
echo ""

for type in $dtypes; do
        echo looking for disks of type \"$type\"
        pdisks=${pdisks}\ ` \
        /bin/ls -1 ${DEVDIR}/$type[0-9]*  2> /dev/null | \
            sed -n -e "s/^${se_devdir}\/\($type[0-9][0-9]*\)c/\1/p" `
echo ""
echo possible disk devices are: $pdisks
echo ""

for disk in $pdisks; do
        echo looking for disk \"$disk\"
        if sh -c "( < /dev/${disk}c ) 2> /dev/null"; then
                vdisks="$vdisks $disk"
echo ""
echo valid disk devices are: $vdisks
echo ""

with a bit of trickyness, one could easily adapt this to deal with
multiple types of devices, too (think: 'eval' 8-).

Oh, i guess the above should use a "raw partition" variable, rather
than hardcoding 'c', for the broken ports that need a different one...

> Also, the technique of opening a device can be problematic in some 
> circumstances ... maybe the disk is there but the partition has the wrong 
> fstype, and thus the driver returns ENXIO?

Is this a problem in circumstances that will be faced when installing
a system, really?

under what circumstances is it impossible to read from the raw
partition of the disk?