Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

By code, how can I send a hard disk drive to sleep

I have lots of hard disk drives in my computer (7).

When they are not used the power option send them to sleep after a while. But because everything makes a lot of noise I would like to send them to sleep when I want, not just after the default system timeout.

On Windows (XP and up), preferably in C#,

How can I send a disk to sleep by code?

Thanks a lot in advance for your help...

like image 787
Jonx Avatar asked May 13 '09 23:05

Jonx


4 Answers

I do not know of the API to do this directly but there are tools that can do it. One that I have seen is Hard Disk Sleeper. I have not used it on my own machines so I cannot speak to its quality or effectiveness.

like image 111
Jack Bolding Avatar answered Oct 17 '22 01:10

Jack Bolding


It is possible to do this if you send ATA commands directly to a drive using IOCTL_ATA_PASS_THROUGH. You will need to pass the SLEEP command.

I don't think that this is a project for C# though.

like image 37
Dave Ganger Avatar answered Oct 17 '22 02:10

Dave Ganger


AFAIK, this is an ATA command that sets the *spin down time8 - meaning it's the drive itself that shuts down. You could use IOCTL_ATA_PASS_THROUGH to send commands directly to the drive - but I'm afraid you'd do no better than just setting it to some min value (which I don't know what it is, but it should be in the ATA specs).

Edit: Looks like the venerable hdparm supports it, so it must be in the ATA spec:

-y Force an IDE drive to immediately enter the low power consumption standby mode, usually causing it to spin down.

-Y Force an IDE drive to immediately enter the lowest power consumption sleep mode, causing it to shut down completely. A hard or soft reset is required before the drive can be accessed again (the Linux IDE driver will automatically handle issuing a reset if/when needed).

Since hdparm (and the underlying Linux kernel it uses to communicate with the drive) is GPL - you should be able to crib the specifics from there if you don't have an ATA spec handy.

Or, just use the win32 port.

like image 42
Mark Brackett Avatar answered Oct 17 '22 03:10

Mark Brackett


On windows you can simply use "GetDevicePowerState" function returning FALSE if the drive is sleeping (not rotating).

https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getdevicepowerstate

like image 27
Lothar Avatar answered Oct 17 '22 02:10

Lothar