xref: /aosp_15_r20/external/sg3_utils/scripts/scsi_stop (revision 44704f698541f6367e81f991ef8bb54ccbf3fc18)
1*44704f69SBart Van Assche#!/bin/bash
2*44704f69SBart Van Assche
3*44704f69SBart Van Assche################################################
4*44704f69SBart Van Assche#
5*44704f69SBart Van Assche#  Spin down the given SCS disk(s).
6*44704f69SBart Van Assche#
7*44704f69SBart Van Assche#  SCSI disks (or disks that understand SCSI commands)
8*44704f69SBart Van Assche#  are assumed. By default, the immediate bit is set so the
9*44704f69SBart Van Assche#  command should return immediately. The disk however will
10*44704f69SBart Van Assche#  take 10 seconds or more to spin down. The '-w' option
11*44704f69SBart Van Assche#  causes each stop to wait until the disk reports that it
12*44704f69SBart Van Assche#  has stopped.
13*44704f69SBart Van Assche#
14*44704f69SBart Van Assche#  This script assumes the sg3_utils package is installed.
15*44704f69SBart Van Assche#
16*44704f69SBart Van Assche###############################################
17*44704f69SBart Van Assche
18*44704f69SBart Van Asscheverbose=""
19*44704f69SBart Van Asscheimmediate="-i"
20*44704f69SBart Van Assche
21*44704f69SBart Van Asscheusage()
22*44704f69SBart Van Assche{
23*44704f69SBart Van Assche  echo "Usage: scsi_stop [-h] [-v] [-w] <device>+"
24*44704f69SBart Van Assche  echo "  where:"
25*44704f69SBart Van Assche  echo "    -h, --help           print usage message"
26*44704f69SBart Van Assche  echo "    -v, --verbose        more verbose output"
27*44704f69SBart Van Assche  echo "    -w, --wait           wait for each stop to complete"
28*44704f69SBart Van Assche  echo ""
29*44704f69SBart Van Assche  echo "Send SCSI START STOP UNIT command to stop each <device>"
30*44704f69SBart Van Assche}
31*44704f69SBart Van Assche
32*44704f69SBart Van Asscheopt="$1"
33*44704f69SBart Van Asschewhile test ! -z "$opt" -a -z "${opt##-*}"; do
34*44704f69SBart Van Assche  opt=${opt#-}
35*44704f69SBart Van Assche  case "$opt" in
36*44704f69SBart Van Assche    h|-help) usage ; exit 0 ;;
37*44704f69SBart Van Assche    v|-verbose) verbose="-v" ;;
38*44704f69SBart Van Assche    w|-wait) immediate="" ;;
39*44704f69SBart Van Assche    *) echo "Unknown option: -$opt " ; exit 1 ;;
40*44704f69SBart Van Assche  esac
41*44704f69SBart Van Assche  shift
42*44704f69SBart Van Assche  opt="$1"
43*44704f69SBart Van Asschedone
44*44704f69SBart Van Assche
45*44704f69SBart Van Asscheif [ $# -lt 1 ]
46*44704f69SBart Van Assche  then
47*44704f69SBart Van Assche    usage
48*44704f69SBart Van Assche    exit 1
49*44704f69SBart Van Asschefi
50*44704f69SBart Van Assche
51*44704f69SBart Van Asschefor i
52*44704f69SBart Van Asschedo
53*44704f69SBart Van Assche# Use '-r' (read-only) otherwise using a block device node
54*44704f69SBart Van Assche# (e.g. 'sg_start 0 /dev/sdb') can result in a change of state
55*44704f69SBart Van Assche# event causing the disk to spin up again immediately.
56*44704f69SBart Van Assche        echo "sg_start -r $immediate 0 $verbose $i"
57*44704f69SBart Van Assche        sg_start -r $immediate 0 $verbose $i
58*44704f69SBart Van Asschedone
59