Get HDD Activity

This is a discussion on Get HDD Activity within the C++ Programming forums, part of the General Programming Boards category; Hello everyone! I'm trying to build a simple code that scans for the HDD activity and blinks Scroll Lock LED. ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    7

    Get HDD Activity

    Hello everyone!

    I'm trying to build a simple code that scans for the HDD activity and blinks Scroll Lock LED.
    To do so I need to know a piece of code to "get" the HDD status.

    Thanks for any help!

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    You probably need more than a piece of code. You would also need some additional software that provide these functions. One to read the HDD activity and maybe one that lets you send a signal to the LED.

    What OS?

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    7
    Win32 platform
    Why need 3rd party programs if hdd state and numlock led are both low level access?

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    *lock LED is a no brainer. The hdd activity as in you want to synchronize your scroll lock blinkage with your HDD activity LED on your tower?

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    7
    yep... that's it!

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A very interesting project, if you have plenty of time and a spare PC that you don't mind re-installing the OS a few times onto. [As no doubt, you will mess up at some point or another and make the disk completely corrupt].

    If you have a lot of Windows programming experience you would realize that you need a filter driver for the hard-disk, and in that filter driver "hook" into the read/write operations, send a message (signal an event) to a service that can flash the LED on the keyboard.

    Sending messages to the keyboard is VERY slow (as in, it takes many milliseconds), so you would need to design your service process in such a way that it just ignores any activity going on in between one flash and another of the keyboard LED - since the read/write operations can be queued to the hard-disk much faster than the LED can flash.

    You can send commands to set the LED's with IOCTL_KEYBOARD_SET_INDICATORS: http://msdn.microsoft.com/en-us/library/ms791035.aspx

    Edit: http://www.codeguru.com/cpp/w-p/syst...icle.php/c2825 shows how you flash the LED lights.

    This project is far from "easy" in the sense that it is very easy for any of these operations to cause the entire machine to go wrong if you do not know EXACTLY what you are doing - and as I started out, you will most likely need to reinstall the OS a few times as you've messed something up (crashed the driver when it's in the middle of updating sosmething would be a classic).

    Another, much simpler, option would just be to twine a cable with an LED at the end to the keyboard from the machine itself and connect that cable into the LED connector on the machine.

    Edit2: You may be able to simplify the process if you use some sort of monitoring/performance counter interface in a service/process - that will not tell the EXACT behaviour at the driver level, but it will give you some idea of what is going on. This solution, combined with the codeguru code above would probably get you something within a few hours.

    --
    Mats
    Last edited by matsp; 10-07-2008 at 05:37 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    7
    Hey Mats!
    I got the picture. Actually I'm just a beginner to C++.
    I had no idea it could do any harm to HDD.
    Thanks for your explanation! It helped!

    Cheers!

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You have inspired me to take a crack at writing this sort of code. Keep in mind that the hard drive activity LED that you see on your tower is something that BIOS is doing, not your operating system. I didn't read Mats post, so I am sure he went into some of the pitfalls of trying to do this from the OS (He is a thorough guy). The biggest pitfall in my opinion is the actual blinking... That could cause some noticeable kb lag. In any event, you are going to probably want to use the PDH API for getting the HDD stats (unless you want to write your own driver or write your own controller software--which could both lead to the nice added bonus of your computer not booting properly and you needing to reinstall your OS). Though I don't know why I assumed you are even using windows. What OS?

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Actually, the HD LED on the front of the case (or wherever it is), is not a BIOS function, but rather a hardware function supported by the hard-disk controller hardware - it is simply a function of the BUSY signal from the hard-disk itself being shown as LED activity. Replacing the BIOS with a completely different set of code will still get the light flashing if you access the hard-disk.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    This may sound convoluted, and like more work than it is worth, BUT here goes. If the light is controlled by the hard-disk controller that means you could design a PCI card that simply captures the output signals and write drivers for your homemade card.

    I think this would ultimately be the least intrusive way to monitor the LED. Then we start getting into the "Gee, that sure seems like a lot of work just to keep tabs on a blinking LED." Which really is true, but hey, at least its less invasive as doing something like just running a wire staight to your KB. Which is also always an option.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by master5001 View Post
    This may sound convoluted, and like more work than it is worth, BUT here goes. If the light is controlled by the hard-disk controller that means you could design a PCI card that simply captures the output signals and write drivers for your homemade card.

    I think this would ultimately be the least intrusive way to monitor the LED. Then we start getting into the "Gee, that sure seems like a lot of work just to keep tabs on a blinking LED." Which really is true, but hey, at least its less invasive as doing something like just running a wire staight to your KB. Which is also always an option.
    No, you won't be able to "see" what the BUSY signal on the hard-disk controller is up to on the PCI bus. You could of course connect something to the actual LED connector [most simply a much longer wire with a LED on the end -otherwise you could build a little device to read the level of the connection] on the motherboard [or you could make something that posts a PCI read instructon to the status word of the PATA/SATA controller, and displays bit 7 of that register - but a PCI card is not entirely trivial to build].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I am not saying it is a simpleton's task, Mats. I am just saying it is an option. I think it would be the most robust option. I have only made very basic PCI cards in my day so I am not going to even remotely pretend like this is a quick project even for me. I think running a wire up to the keyboard is probably the best option though. It takes care of all the other issues that could be encountered doing it any other way. Because, at the end of the day the end problem will still ultimately lie with the actual keyboard I/O that will ultimately need to be done to create the blink effect.

  13. #13
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    To do so I need to know a piece of code to "get" the HDD status.
    Check out the Diskperf example in the DDK.

    EDIT: Instead of toggling the scroll lock light, you might want to put something in the tray area to indicate HDD activity. Check out Sysinternal's Diskmon utility. This utility uses Event Tracing for Windows (ETW) to monitor disk activity and can be minimized to the system tray with a graphic indicator for HDD activity.
    Last edited by BobS0327; 10-09-2008 at 07:08 PM.

  14. #14
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    That is a good idea. Or use the PDH stuff from the DDK and have your system speaker blip with each flicker of your HDD LED. Actually, for that matter, just replace the LED with a something like this.

    Annoying? Well who is to say your KB flickering away isn't equally annoying?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HDD Dead I think!
    By gsoft in forum Tech Board
    Replies: 6
    Last Post: 01-20-2005, 07:16 AM
  2. Can't boot from HDD
    By somesh in forum Tech Board
    Replies: 5
    Last Post: 06-28-2003, 03:04 AM
  3. Two Windows on two different HDD??? Question
    By Sevrin in forum Tech Board
    Replies: 6
    Last Post: 06-19-2003, 11:22 AM
  4. HDD problem
    By Prasad kulkarni in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 07-15-2002, 03:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21