diff 18dd720eca74524f78f5e1c76f6a79956271fdb2 uncommitted --- a//rc/bin/fshalt +++ b//rc/bin/fshalt @@ -31,13 +31,14 @@ c=`{ls /srv/cwfs*cmd >[2]/dev/null} h=`{ls /srv/hjfs*cmd >[2]/dev/null} +s=`{awk '/^sd./ {print substr($1,3,1)}' <'#S/sdctl' >[2]/dev/null} # for scram, don't scram other systems bind -b '#P' /dev >[2]/dev/null if(! ~ $reboot yes){ - if (test -e '#P'/apm) + if(test -e '#P'/apm) scram=yes - if (test -e '#P'/acpitbls -a -e '#P'/iow) + if(test -e '#P'/acpitbls -a -e '#P'/iow) scram=yes } @@ -51,7 +52,6 @@ cp /bin/rc /tmp cp /bin/sed /tmp cp /bin/sleep /tmp -cp /bin/scram /tmp cp /bin/test /tmp if(~ $#bootf 1){ if(! cp $bootf /tmp/bootf) @@ -66,9 +66,9 @@ fn x { echo echo -n halting... - for (i in $c $h) + for(i in $c $h) echo halt >>$i - for (i in $c $h){ + for(i in $c $h){ echo -n $i... while(test -e $i) sleep 1 @@ -76,15 +76,19 @@ echo echo done halting - if (~ $reboot yes) { + # turn off disk drives + for(i in $s) + echo config spec $i switch off >>'#S/sdctl' + + if(~ $reboot yes){ echo rebooting... echo reboot $bootf >'#c/reboot' } - if not if (test -e /dev/pmctl) { - echo power off >>/dev/pmctl - } - if (~ $scram yes){ - scram + if not { + if (test -e /dev/pmctl) + echo power off >>/dev/pmctl + if (~ $scram yes) + scram echo 'It''s now safe to turn off your computer' } } --- a/sys/src/9/port/sdnvme.c +++ b/sys/src/9/port/sdnvme.c @@ -521,9 +521,16 @@ ctlr->reg[IntMs] = ~ctlr->ints; iunlock(&ctlr->intr); + /* notify normal power off */ + ctlr->reg[CCfg] = (ctlr->reg[CCfg] & ~(3<<14)) | 1<<14; + for(i = 0; i < 30; i++){ + if((ctlr->reg[CSts] & 0xc) == 0x8) + break; + tsleep(&up->sleep, return0, nil, 100); + } + /* disable controller */ ctlr->reg[CCfg] = 0; - for(i = 0; i < 10; i++){ if((ctlr->reg[CSts] & 1) == 0) break;