Author Topic: HD temperature  (Read 801 times)

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 888
  • Liked:
  • Likes Given: 10
HD temperature
« on: March 15, 2022, 12:45:34 PM »
Is it possible to read the HD temperature in a C++ program?

Offline robespierre

  • Enthusiast Member (25+ Posts)
  • ***
  • Posts: 31
  • New Member
  • Liked:
  • Likes Given: 5
Re: HD temperature
« Reply #1 on: March 15, 2022, 02:02:11 PM »
If you have something like a SPI3 CAM interface it should be pretty simple. Send a LOG SENSE command for either page $2F (informational exceptions) or page $0D (temperature), and parse the receive data buffer for the 1-byte temperature in °C. It is always at offset +10 in log page $2F, and offset +9 in log page $0D.

Offline Daniel

  • Gold Member (200+ Posts)
  • *****
  • Posts: 311
  • Programmer, Hacker, Thinker
  • Liked:
  • Likes Given: 8
Re: HD temperature
« Reply #2 on: March 16, 2022, 03:23:49 AM »
MacOS does let you send arbitrary ATA and/or SCSI commands to any connected disk. The type of command that gets temperature might not even interfere with ongoing data operations. I just have no clue what ATA and/or SCSI commands to use and if there are any vendor differences between disks for those commands or the data returned.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 888
  • Liked:
  • Likes Given: 10
Re: HD temperature
« Reply #3 on: March 17, 2022, 12:24:42 PM »
I copied the source code of hddtemp for Linux to see how they do it.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 888
  • Liked:
  • Likes Given: 10
Re: HD temperature
« Reply #4 on: March 18, 2022, 11:29:57 AM »
It uses ioctl.h. This is included in Symantec C++. But I don't see an implementation or library that contains the ioctl function. How do I link this?

Offline robespierre

  • Enthusiast Member (25+ Posts)
  • ***
  • Posts: 31
  • New Member
  • Liked:
  • Likes Given: 5
Re: HD temperature
« Reply #5 on: March 18, 2022, 06:51:37 PM »
ioctl() is a Unix system call.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 888
  • Liked:
  • Likes Given: 10
Re: HD temperature
« Reply #6 on: March 21, 2022, 10:22:07 AM »
The ioctl function is in ROM (CStdLib). It has only basic functionality. I don't think that this can be used to get the SMART values. I tried it but I got -1 and done.

Offline Daniel

  • Gold Member (200+ Posts)
  • *****
  • Posts: 311
  • Programmer, Hacker, Thinker
  • Liked:
  • Likes Given: 8
Re: HD temperature
« Reply #7 on: March 23, 2022, 02:44:54 PM »
MacOS doesn't have any easy way to do this. The disk driver is stored on the disk itself, and some drivers go back to the Mac Plus. Some drivers might have the capability to do this (with vendor-specific control calls), but most probably don't.

If you want to do this you will have to use the Old SCSI Manager, SCSI Manager 4.3, ATA Manager, or FireWire Manager to talk to the disk itself and ask it what it's temperature is. Even getting to the point where you know which Manager to talk to the disk with is tricky. You have to go from a volume reference number to a drive number, to a driver reference number. If the driver reference number is from -33 to -40 (inclusive), it is an Old SCSI Manager driver, and you can use the exact value to determine what SCSI ID the disk is (the SCSI ID is what the Old SCSI Manager uses to talk to one particular SCSI device). Otherwise you have to ask the SCSI Manager 4.3, ATA Manager, and FireWire Manager if that driver reference number is registered with them, and get the info that that Manager uses to talk to one of their devices. Each Manager might not actually be installed, so be sure to use the Gestalt Manager to see what is present

Once you know which Manager to use and have the ID of that particular disk, you have to actually ask the disk what it's temperature is. How you do that is bus-specific, and possibly disk-vendor-specific. I have no idea how to do it. But I also know that some SATA cards actually pretend to be SCSI cards, and might or might not have a way to send the right ATA commands to the disks that it pretends are SCSI disks.

Good luck.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 888
  • Liked:
  • Likes Given: 10
Re: HD temperature
« Reply #8 on: March 26, 2022, 12:14:13 PM »
My idea was to get the S.M.A.R.T. values, which is a block of 512 bytes and search the temperature here, but it’s not standard among all manufacturers. It has very little chance to succeed.

 


SimplePortal 2.3.6 © 2008-2014, SimplePortal