## ATA commands ATA commands — Helper routines for ATA commands |

## Functions

gboolean | udisks_ata_send_command_sync ()
gboolean | udisks_ata_get_pm_state ()
#define | UDISKS_ATA_PM_STATE_AWAKE()

## Types and Values

enum | UDisksAtaCommandProtocol
| UDisksAtaCommandInput
| UDisksAtaCommandOutput

## Description

Helper routines for sending ATA commands to a device.

## Functions

### udisks_ata_send_command_sync ()

    gboolean
    udisks_ata_send_command_sync (gint fd,
                                  gint timeout_msec,
                                  UDisksAtaCommandProtocol protocol,
                                  UDisksAtaCommandInput *input,
                                  UDisksAtaCommandOutput *output,
                                  GError **error);

Sends a command to an ATA device. Blocks the calling thread while the command is pending.

#### Parameters

fd | A file descriptor for a ATA device. |
timeout_msec | Timeout in milli-seconds for the command. Use -1 for the default (5 seconds) timeout and `G_MAXINT` for no timeout. |
protocol | The direction of the command. |
input | The input for the command. |
output | The output for the command. |
error | Return location for error or `NULL`. |

#### Returns

`TRUE` if the command succeeded, `FALSE` if `error` is set.

### udisks_ata_get_pm_state ()

    gboolean
    udisks_ata_get_pm_state (const gchar *device,
                             GError **error,
                             guchar *pm_state);

Get the current power mode state.

The format of `pm_state` is the result obtained from sending the ATA command `CHECK POWER MODE` to the drive.

Known values include:

- `0x00`: Device is in PM2: Standby state.

- `0x40`: Device is in the PM0: Active state, the NV Cache power mode is enabled, and the spindle is spun down or spinning down.

- `0x41`: Device is in the PM0: Active state, the NV Cache power mode is enabled, and the spindle is spun up or spinning up.

- `0x80`: Device is in PM1: Idle state.

- `0xff`: Device is in the PM0: Active state or PM1: Idle State.

Typically user interfaces will report "Drive is spun down" if `pm_state` is 0x00 and "Drive is spun up" otherwise.

#### Parameters

device | ATA drive block device path. |
error | Return location for error. |
pm_state | Return location for the current power state value. |

#### Returns

`TRUE` if the operation succeeded, `FALSE` if `error` is set.

### UDISKS_ATA_PM_STATE_AWAKE()

    #define UDISKS_ATA_PM_STATE_AWAKE(pm_state) (pm_state >= 0x41)

Decodes the power state value as returned by udisks_ata_get_pm_state.

#### Parameters

pm_state | The power state value. |

#### Returns

`TRUE` when the drive is awake, `FALSE` when sleeping.

## Types and Values

### enum UDisksAtaCommandProtocol

Enumeration used to specify the protocol of an ATA command

#### Members

UDISKS_ATA_COMMAND_PROTOCOL_NONE | Non-data |
UDISKS_ATA_COMMAND_PROTOCOL_DRIVE_TO_HOST | PIO Data-In |
UDISKS_ATA_COMMAND_PROTOCOL_HOST_TO_DRIVE | PIO Data-Out |

### UDisksAtaCommandInput

    typedef struct {
      guint8  command;
      guint8  feature;
      guint8  count;
      guint8  device;
      guint32 lba;
      gsize   buffer_size;
      guchar *buffer;
    } UDisksAtaCommandInput;

Struct used for input data when sending ATA commands.

#### Members

guint8 `command`; | Command |
guint8 `feature`; | Feature |
guint8 `count`; | Count |
guint8 `device`; | Device |
guint32 `lba`; | LBA |
gsize `buffer_size`; | Size of the `buffer` member or 0 |
guchar *`buffer`; | Data to send to device or `NULL` |

### UDisksAtaCommandOutput

    typedef struct {
      guint8  error;
      guint8  count;
      guint8  device;
      guint8  status;
      guint32 lba;
      gsize   buffer_size;
      guchar *buffer;
    } UDisksAtaCommandOutput;

Struct used for output data when sending ATA commands.

#### Members

guint8 `error`; | Error |
guint8 `count`; | Count |
guint8 `device`; | Device |
guint8 `status`; | Status |
guint32 `lba`; | LBA |
gsize `buffer_size`; | Size of the `buffer` member or 0 |
guchar *`buffer`; | Pointer to where to receive data from the device or `NULL` |