Recent

Author Topic: How to catch the activity of my hard disk to pilot a virtual led?  (Read 1237 times)

lestroso

  • Jr. Member
  • **
  • Posts: 90
    • FaSasoftware
Dear friends..... is there a simple program or simple library to catch the activity of my hard disk to pilot a virtual led? Cross compile of course....win10, mac os x, linux??

I thank you a lot again in advance,happy summer....

Lestroso  :-[
« Last Edit: August 24, 2019, 01:08:04 pm by lestroso »

winni

  • Full Member
  • ***
  • Posts: 190
Re: How to cath the activity of my hard disk to pilot a virtual led?
« Reply #1 on: August 22, 2019, 10:52:09 pm »
Hi!

We had that subject in February:

https://forum.lazarus.freepascal.org/index.php?topic=44303.0

You can search in this forum!

Winni

lestroso

  • Jr. Member
  • **
  • Posts: 90
    • FaSasoftware
Re: How to cath the activity of my hard disk to pilot a virtual led?
« Reply #2 on: August 23, 2019, 05:58:21 pm »
Dear Winni.....

That link it's not  what i need....they talk about free space disk!!! I need to read a variable hard disk on off ....only...

Can some body help me?? I need a solution cross platform please....

Best regards, Lestroso :-[

Thaddy

  • Hero Member
  • *****
  • Posts: 8680
Re: How to cath the activity of my hard disk to pilot a virtual led?
« Reply #3 on: August 23, 2019, 06:07:20 pm »
Actually, what do you need? write operations (answered) read operations too?
Most people that want to use threading should learn to patch their jeans first: use a needle.

lestroso

  • Jr. Member
  • **
  • Posts: 90
    • FaSasoftware
Re: How to cath the activity of my hard disk to pilot a virtual led?
« Reply #4 on: August 24, 2019, 01:07:01 pm »
Dear Thaddy,

i need only to read the state of the hard disk...if it is reading and turn off and on the virtual led....cross platform....win10,macosx, linux......

Best regards,

Lestroso :-[

440bx

  • Hero Member
  • *****
  • Posts: 1086
Re: How to cath the activity of my hard disk to pilot a virtual led?
« Reply #5 on: August 24, 2019, 01:44:26 pm »
i need only to read the state of the hard disk...if it is reading and turn off and on the virtual led....cross platform....win10,macosx, linux......
What you're asking for sounds simple but, it's not simple at all.  Forget about a cross platform solution because accurate disk activity can only be obtained from the OS kernel.  Therefore every solution is OS specific.

The following is a link to a program that implements what you want to do (along with a few other things) but, only for Windows.  Read the implementation section which is at the end of the page, that will give you an idea of how it's done.

https://docs.microsoft.com/en-us/sysinternals/downloads/diskmon
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 801
Re: How to cath the activity of my hard disk to pilot a virtual led?
« Reply #6 on: August 24, 2019, 07:39:42 pm »
i need only to read the state of the hard disk...if it is reading and turn off and on the virtual led....cross platform....win10,macosx, linux...
There are many open source hard disk activity monitoring tools on Linux. So you can study their source code, learn how to talk to the Linux Kernel and build your own solution:

5 Tools for Monitoring Disk Activity in Linux
Featuring iostat, iotop, dstat , atop and ioping
https://www.opsdash.com/blog/disk-monitoring-linux.html

lestroso

  • Jr. Member
  • **
  • Posts: 90
    • FaSasoftware
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #7 on: August 24, 2019, 09:32:23 pm »
Dear 440bx , dear valdir.marcos,

The first soution is only an exe that seem like a monitor, the second solution are command line tools....

Tell me how i can integrate these programs in Lazarus Pascal???

I thank you a lot in advance, but these are not a solution for  me.....can somebody help with a real soution...for Pascal Lazarus code??

Best Regards,
Lestroso  :-[

440bx

  • Hero Member
  • *****
  • Posts: 1086
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #8 on: August 24, 2019, 10:19:23 pm »
I thank you a lot in advance, but these are not a solution for  me.....can somebody help with a real soution...for Pascal Lazarus code??
I cannot say anything about how to do it under Linux because I have no idea how's it's done on that OS.

On Windows, detecting/monitoring disk read/writes as they happen, which is what is needed to implement the led you want, requires a ring 0 device driver.  The Diskmon.exe program I linked to in my previous post contains 2 device drivers (as resources) which it loads dynamically to collect disk activity.

For a device driver, forget Lazarus.  In FPC, you can specify the application type as "native" which is what you need to implement a driver but, I haven't seen anywhere the Pascal definitions (ring 0 APIs and data structures) you need to implement a driver.

IOW, while it is likely possible to implement the activity led you want using FPC, it is definitely not practical to go that route.

Under Windows, unless you are willing to write a device driver, forget implementing a led to show disk activity.

using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 1901
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #9 on: August 25, 2019, 12:04:12 am »
The closes you'll get without doing hardware that will work in Laz is this I think..

https://www.codeproject.com/Articles/4997/Spying-a-file-system

You can run that in a thread.

lestroso

  • Jr. Member
  • **
  • Posts: 90
    • FaSasoftware
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #10 on: August 25, 2019, 10:48:34 am »
Dear 440bx,
Dear jamie,

I thank you a lot for your answers, i'll try to follow your idea....thanks a lot again, best regards,

Lestroso,  :D

PascalDragon

  • Hero Member
  • *****
  • Posts: 573
  • Compiler Developer
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #11 on: August 25, 2019, 12:42:32 pm »
For a device driver, forget Lazarus.  In FPC, you can specify the application type as "native" which is what you need to implement a driver but, I haven't seen anywhere the Pascal definitions (ring 0 APIs and data structures) you need to implement a driver.
You need to use target NativeNT for that as a completely different RTL is required that does not rely on the WinAPI, but instead the kernel API. The target is still considered experimental however.

440bx

  • Hero Member
  • *****
  • Posts: 1086
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #12 on: August 25, 2019, 01:47:54 pm »
You need to use target NativeNT for that as a completely different RTL is required that does not rely on the WinAPI, but instead the kernel API. The target is still considered experimental however.
Yes.  I remembered reading the wiki article you linked to some time ago but, didn't remember the details.  Thank you for the link.  It will probably come in handy sometime, though I admit, writing a device driver is always my last choice and only if there really is no other way.

Thanks again.
« Last Edit: August 25, 2019, 01:49:28 pm by 440bx »
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

MarkMLl

  • Jr. Member
  • **
  • Posts: 76
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #13 on: August 25, 2019, 05:33:16 pm »
On unix (note: not capitalised) you could possibly use something like FAM (File Alteration Monitor) based on / but the best you'd get would be indication that a file had changed, not that it had been committed to disc.

Broadly speaking, if you're trying to put this sort of thing into an application program then You're Doing It Wrong since there are quite simply too many levels of operating system (including filesystem and hardware drivers) layered above what you're trying to monitor.

Having said which, /some/ systems have low-level monitoring facilities in the OS although they might be things that you can see rather than intercept (but do you really want to be able to insert a blocking call into your disc device driver)? As a specific example, Linux tailored for SBCs such as the Raspberry Pi allows you to set up the uncommitted LED to monitor SDCard accesses via the /sys/class/leds tree.

I could go on about the feasibility of building a custom driver and ensuring that it tracks kernel updates pushed from the OS's main repository, but that's a very long way from having an application trap this sort of thing.

MarkMLl


marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7359
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #14 on: August 25, 2019, 06:30:21 pm »
And of course it is possible that the harddisk led is just a motherboard thing (from the onboard sata/ide), without the OS inbetween at all.