Windows programming is nasty

I’ve spent two days trying to figure out how to send an ATA command directly to an IDE hard drive from Windows. I’ve finally succeeded, but with an undocumented and unsupported IOCTL call. It turns out that’s the ONLY way to do what I want, at least until Windows XP SP2 is released when the documented and supported version of a similar IOCTL will be made available.

That’s nasty.

By the way, C’T (an extremely technical German computer magazine, fortunately now with a Dutch edition as well) rules in more ways than one. If you’re looking for concrete information on how to abuse IOCTL_IDE_PASS_THROUGH, they’re the only guys who can help.

14 thoughts on “Windows programming is nasty”

  1. Nope. In my case, I’m trying to fix a really irritating spindown problem. Many ATA drives (especially laptop ones) have a built-in standby/spindown mechanism and this is *independent* of the Windows hard drive timeout.

    The symptom is that the laptop “freezes” every so often for a second or two while the drive spins up. Really irritating and not necessary when I’m on wall power.

    Windows doesn’t offer any way of disabling this, nor have *any* of the Windows lamers written a program to configure this. So *this* lamer decided to do so. It seems to work. At the moment, I have one very brave beta-tester.

    This type of built-in ATA feature can only be configured by sending ATA commands directly on the bus.

  2. I am interested in how you did this. There are some new calls (IOCTL_ATA_PASS_THROUGH), but as always the Microsoft folks have left out the details — even in the XP DDK.

    Thanks in advance!

  3. Here is the code by C’T:
    ftp://ftp.heise.de/pub/ct/listings/0207-218.zip
    I stumbled onto this *after* days of hacking up my own solution (and succeeding!)

    The comments are in German, but the code is very clear and shows how you should use IOCTL_IDE_PASS_THROUGH. Note that IOCTL_ATA_PASS_THROUGH does NOT work on Windows up to XP SP1. It might work on SP2. For now, IDE_PASS_THROUGH is your friend. :)

    What exactly are you doing?

  4. Hi,
    I get the code,it runs correctly.but if I want to writepage or readpage from my device,that failed to return the page content although the registers are corrected,any suggest?

    thanks
    BR,

  5. I’m having the same hard drive spindown issue with my laptop. hdparm -S 0 /dev/hda works great in linux, but there’s no solution for windoze. Are you willing to put a copy of your fix on your site, or the source code?

    Thanks.
    -Dang

  6. Nice utility, found this on page 9 of google results looking for an XP spin down utility. I’m not a programmer and have nothing to compile with, but how about releasing a version that allows you to select the drive and the spin down time? I want to spin down my external USB drives.

  7. Charl —

    Thank you very much for developing this little piece of code and for making it avalable. It is too bad that google hasn’t ranked your pages higher–it took me a lot of searching before I found your work.

    Unfortunately, my drive (ST9808211A) has similar symptoms (pauses, clicks, freezes system for ~2s, repeats behavior every ~2min), but hdparm -S 0 does *not* fix it.

    However, hdparm -B 255 (disable drive APM) works.

    I added some code to your hdstandby.c (ver 20050226) to also disable APM:

    http://people.csail.mit.edu/vona/hdstandby/hdstandby.diff

    I also verified that it compiles in MinGW Developer Studio 2.05, and I built a simple project file:

    http://people.csail.mit.edu/vona/hdstandby/hdstandby.mdsp

    Thanks again,
    Marty

  8. the function work fine for fisical driver, but i have a usb disk, this not work, how make the identify to read a manufactor serial number from disk in the usb

  9. On Feb 9th, 2006 at 12:41, Lars Andersson wrote:
    > I have been searching for a “hdparm” for windows!

    In case someone it still interested:
    http://hdparm-win32.dyndns.org/hdparm/
    Available as Win32 native or Cygwin release.

    Uses documented IOCTL_ATA_PASS_THROUGH if available (>= XP SP2), else undocumented IOCTL_IDE_PASS_THROUGH.

    Enjoy,
    Christian

Leave a Reply

Your email address will not be published. Required fields are marked *