# -*- shell-script -*-

# 07device_scsi_sg_scan - SCSI device listing support using sg3_utils.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2002, 2003, 2004

# Maintained by Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 07device_scsi_sg_scan,v 1.10 2004/04/16 01:31:03 martins Exp $

sg_map=$(type -p sg_map)
[ -n "$sg_map" ] || return 0

######################################################################

device_setup_scsi ()
{
    # First ensure there's the maximum number of available sg device nodes.
    local i=0
    while [ $i -lt 256 ] ; do
	node="/dev/sg$i"
	[ -c "$node" ] || mknod "$node" "c" 21 $i
	i=$(($i + 1))
    done

    debug_cmd "$sg_map" -x | grep -v '^#' >"${db_misc_dir}/sg_map-x"
}

list_devices_scsi ()
{
    local num='\([0-9][0-9]*\)'
    local x="^/dev/[^ ]*  *${num} ${num} ${num} ${num} .*"
    local y="\1:\2:\3:\4"
    sed -n -e "s@${x}@${y}@p" "${db_misc_dir}/sg_map-x"
}
