Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Oct 1998 03:27:50 -0700 (PDT)
From:      asami@FreeBSD.ORG (Satoshi Asami)
To:        tbuswell@mediaone.net
Cc:        scsi@FreeBSD.ORG
Subject:   Re: for i in disks
Message-ID:  <199810221027.DAA21738@silvia.hip.berkeley.edu>
In-Reply-To: <13870.3656.235875.122481@tbuswell.ne.mediaone.net> (message from Ted Buswell on Wed, 21 Oct 1998 12:45:54 -0400 (EDT))

next in thread | previous in thread | raw e-mail | index | archive | help
 * I haven't been following this thread closely, but unless I'm
 * missing something, I think the Disk_Names() function from libdisk(3)
 * is what you're looking for.. [assuming compiled C code is OK].
 * -Ted
 * 
 * /* gcc x.c -ldisk */
 * extern char **Disk_Names();
 * main() {
 *   char **p = Disk_Names();
 *   while(*p) puts(*p++);
 * }

Oooh.  This is very nice and simple. :)

It works on my recent CAM system but not on my old one.  Thanks
though.

By the way, in case anyone is interested, this is what I came up
with.  I can now move disks around and still have them mounted
correctly. :)

/etc/rc.disk (called from /etc/rc, right after clean_var):

===
#
# disk setups
#
#       $Id$
#

dir=/mnt
echo "setting up disks"

found=0
for i in /dev/sd*a; do
        if ! mount -o ro $i $dir 2>/dev/null; then
                continue
        fi
        if [ -f $dir/autorun.sh ]; then
                echo "running $i's autorun script"
                found=1
                sh $dir/autorun.sh $dir $i
        fi
        if ! umount $dir; then
                echo "error unmounting $i"
                exit 1
        fi
done

if [ $found = 1 -a -f /var/run/autorun.sh ]; then
        echo "running /var/run/autorun.sh"
        sh /var/run/autorun.sh
fi

echo "done"
===

For a simple mount, this will be the autorun.sh:

===
#!/bin/sh
unit=$(/usr/bin/printf "%02x" $(echo $2 | sed -e 's./dev/sd..' -e 's/a$//'))
fsck -p /dev/dsk/sd${unit}h || exit 1
mount /dev/dsk/sd${unit}h /MOUNTPOINT
===

The black magic about unit and /dev/dsk is our peciluar setup -- I
have all disks wired to "B * 16 + I" where B is bus number and I is
SCSI ID, and have a bunch of symlinks from /dev/dsk/sd* to /dev/sd* to 
make them easier to read.  The links in /dev/dsk/sd* are named as
"sdBIP" where I is represented in hexadecimal (0-f) and P is the
partition name.

For a ccd array, use this one:

===
#!/bin/sh
unit=$(/usr/bin/printf "%02x" $(echo $2 | sed -e 's./dev/sd..' -e 's/a$//'))
echo /dev/dsk/sd${unit}h > /tmp/$(cat $1/diskid)-$(cat $1/ccdno)
cp $1/mountpoint /tmp/$(cat $1/ccdno)-mountpoint
cp $1/var-autorun.sh /var/run/autorun.sh
===

and this var-autorun.sh:

===
#!/bin/sh
for ccd in 0 1; do
        if [ $(echo $(echo /tmp/*-ccd$ccd | wc -w)) = 13 ]; then
                echo "found 13 disks, making ccd"
                echo -n "ccd$ccd 128 none " > /tmp/ccd.conf
                echo $(cat /tmp/*-ccd$ccd) >> /tmp/ccd.conf
                ccdconfig -Cv -f /tmp/ccd.conf
                fsck -p /dev/ccd${ccd}c
                mount /dev/ccd${ccd}c $(cat /tmp/ccd${ccd}-mountpoint)
                rm -f /tmp/ccd.conf /tmp/ccd${ccd}-mountpoint
                rm -f /tmp/*-ccd${ccd}
        else
                echo "error"
        fi
done
===

Obviously things like "13" and "128" should be on the disks somewhere, 
we need better error handling, but it's a start. :)

Satoshi

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-scsi" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810221027.DAA21738>