cpbotha.net

voices in my head

cpbotha.net random header image

Windows programming is nasty

January 13th, 2004 · 14 Comments · Uncategorized

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.

Related posts:

  1. Facebook Like, Share and Retweet buttons in your WordPress
  2. I hate spammers. Really.
  3. Smart Guns
  4. The American Propaganda Machine
  5. envedit Windows Environment Editor released

Tags:

14 Comments so far ↓

  • Ari

    What can you do by sending an ATA command?
    Read data files very quickly?

  • Charl P. Botha

    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.

  • aB

    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!

  • Charl P. Botha

    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?

  • iwub

    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,

  • dang

    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

  • Charl Botha

    I’ve put up the source code (and a binary) here:
    http://cpbotha.net/files/hdstandby/
    Sorry for the huge delay.

    Use this at your own risk!

  • Max Watson

    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.

  • Marty Vona

    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

  • Charl P. Botha

    Hi Marty! Thanks very much for the patch, I’ve added a link to your website and the patch on my software page ( http://cpbotha.net/Software ). One day, when either of us has some time to spare, we could clean up the code and release an hdstandby work-alike for windows. :)

  • Lars Andersson

    Hi
    I have been searching for a “hdparm” for windows!
    I would love to see this program developed more.

  • luis

    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

  • Christian Franke

    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

  • cpbotha

    Wow, very cool! Thanks for making and mentioning.

Leave a Comment