0

I need to monitor the read/write state of optical drives efficiently in real-time, preferably using native WIN32 calls (I want to avoid WMI etc. if poss).

For physical disks, DeviceIoControl() with IOCTL_DISK_PERFORMANCE works well, but it doesn't seem to be supported for optical drives. Google has suggestions for tray status monitoring, but I also need current bytes read/written counters (or at least basic read/write activity indication).

Is there way?

gl-
  • 41
  • 3
  • Do you get reasonable bytes read counters (you can't write to optical disks in a normal way, you need specialized disc-burning software and it won't be counted as "writes") from Perfmon? If so, it is possible to read performance counters, including Disk performance counters, automatically from code. But no point writing the code until you see if the counters meet your needs. – Ben Voigt Mar 09 '21 at 20:24
  • Good point on writes - reads are mainly what I'm after. The application is an LED style activity monitor of read/(write) activity. I never use Perfmon and mine seems to be corrupted as I don't even have the Physical Disk counter entry (Win10 Pro x64), just the FileSystem Disk Activity counter that does seem to expose individual drives. Anyway, Googling does not show any way to monitor CD-ROMs this way AFAIKS. So then the question is, are there DeviceIoControl() codes that can query this information directly from the drive, or something similar? – gl- Mar 10 '21 at 00:29
  • .. I've fixed my Perfmon counters. The issue is that optical drives are handled differently than physical disks, so the physical disk methods/counters for monitoring read/write activity don't work (and there seems to be no Perfmon counter for poptical drives AFAIKS). So this may require a different approach. – gl- Mar 10 '21 at 00:55
  • `but it doesn't seem to be supported for optical drives.` Can you provide some details? When I was testing, the handle of the CD-ROM was invalid. Are you the same problem? – Strive Sun Mar 10 '21 at 06:49
  • You can check [IOCTL_STORAGE_CHECK_VERIFY](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddstor/ni-ntddstor-ioctl_storage_check_verify#output-buffer): Optionally, for disk and CD-ROM devices, Irp->AssociatedIrp.SystemBuffer points to a buffer to receive the media change count. The driver fills this buffer only if Parameters.DeviceIoControl.OutputBufferLength was nonzero and the return value is STATUS_SUCCESS. The media change count is a ULONG indicating how many times the media has changed since the driver started. – Strive Sun Mar 10 '21 at 06:50
  • And this [thread](https://stackoverflow.com/questions/48560855/how-to-get-notifications-for-file-changes-on-cd-dvd-drive). – Strive Sun Mar 10 '21 at 06:51
  • @StriveSun-MSFT: I don't see how media change count gets OP any closer to bytes/sec read from his optical drive. – Ben Voigt Mar 10 '21 at 15:47
  • Yes I do want mainly read activity. Something as simple as 'currently reading' would do though, I don't need exact byte counts. This is for a software version of the LED you find on the drive, to show read/(write) activity only. – gl- Mar 22 '21 at 00:10

0 Answers0