# -*- shell-script -*-

# 27device_sysfs - Hardware database scanning routines and variables for sysfs.

# This file is part of the Linux lsvpd package.

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

# 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: 27device_sysfs,v 1.6 2005/06/14 04:45:01 martins Exp $

[ -n "$sysfs_dir" ] || return 0

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

sysfs_add_device_hook_common ()
{
    # Uses: bus_info, device_adapter_name
    # Sets: device_bus_dir

    device_bus_dir=""

    local adapter_bus_dir
    add_device_hook_common || return 1

    # $adapter_bus_dir points to IDE channel or SCSI host adapter, so
    # strip off the first part (of the bus address... including the
    # bus_type) and use subdirectories instead of punctuation.
    local t="${bus_info#*[:.]}"
    device_bus_dir="${adapter_bus_dir}/${t//[:.]//}"
    bus_alias_set "$bus_info" "${device_bus_dir#${db_bus_dir}/}"

    device_backlink_adapter_bus_dir "$device_bus_dir" "$adapter_bus_dir"
}

add_device_hook_DEFAULT ()
{
    # Uses: bus_info, device_adapter_name
    # Sets: device_bus_dir, yl

    local type="$1"

    sysfs_add_device_hook_common || return 1

    device_set_yl "$type"
}

device_set_yl_DEFAULT ()
{
    # Uses: bus_info, device_bus_dir
    # Sets: yl
    yl=""

    local type="$1"

    local adapter_yl
    device_set_adapter_yl "$type" "$device_bus_dir"

    [ -n "$adapter_yl" ] && yl="${adapter_yl%/*}/${bus_info#*/}"
}
