1

I would like to send ATA command (ultimately, any supported ATA command) to my HDD (it is a SATA drive) from user space application using libata (this is possible, right?). What I would be happy for the beginning is to preform ATA command Identify Device and printf out this data. Unfortunately I do not find out any such example. In libata [exactly in file libata-core.c (linux-2.6.39/drivers/ata/)] there is a function ata_dev_read_id [line 1860, at less in my source code] which seams to do what I want. The problem is that it take as one of the argument pointer to ata_device and I have no idea how to initialize it. I read some of the libATA Developer's Guide (http://www.hep.by/gnu/kernel/libata/index.html), but it didn't clear things for me. I think the example source code will help me more. Can anyone provide such example (the core source will be enough, no need for error checking and such things). Practically what I want is a source code that will do something like this http://www.tldp.org/HOWTO/SCSI-Generic-HOWTO/pexample.html but instead of using sg.h ioctl I would like to use libata. I am aware that I could use a SCSI command ATA Pass-Through. Or instead example maybe someone know any open source tool, application that use libATA and I could see how it is used there?

2 Answers2

2

The open source tool SmartMonTools does a lot of low-level ATA handling. Perhaps that could point you in the right direction. http://sourceforge.net/apps/trac/smartmontools/wiki

faffaffaff
  • 3,429
  • 16
  • 27
  • 4
    Actually, `hdparm` (http://hdparm.sourceforge.net/) is probably an easier starting point. Its `-I` option uses the Identify Device command, and reports the results, for example. In particular, see `sgio.c` in the hdparm sources (and `identify.c` for details parsing the response). – Nominal Animal Jun 28 '13 at 16:56
0

LibATA is implemented in Kernel mode for handling different functionality related to ATA Drives.

If you want to use the libATA functionality you have to write your own kernel module and then expose ioctl methods to the user space.

Better approach will be to use ATA Passthrough related api's to send command to ATA drives, same methods are getting used by Smart Mon Tools and hdparam.