On Thursday, March 22, 2012 4:59:09 PM UTC+1, minux wrote:
you can strace(1) the command line app and find out how to read these data.
Out of curiosity, I did just that, and I found that smartctl is using ioctl SG_IO to do SCSI Generic commands on the device:
4602 ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[6]=[12, 00, 00, 00, 24, 00], mx_sb_len=32, iovec_count=0, dxfer_len=36, timeout=20000, flags=0, data[36]=["\0\0\5\2[\0\0\0ATA TOSHIBA THNSNC12"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
(The request and reply are emboldened.)
If you want to make this portable, you'll need to think about making a package in Go that can do SCSI Generic commands, hiding the platform-dependent parts inside of it. Take a look at the source to the net package to see how to make one Go package that's got OS-dependent implementations of the same external API.
Then you can use your new package to talk S.M.A.R.T. with your device.
I think that project would be a very good fit for Go; at the low levels, you need control of the bits to do the ioctl, and once you get the data, you have all the niceities of Go to transform it, store it in a database, graph it, etc. Go for it!
-jeff