# NAME
Linux::AtaSmart - XS wrapper around libatasmart
# VERSION
version 1.0.1
# SYNOPSIS
use v5.10.1;
use Linux::AtaSmart;
use Linux::AtaSmart::Constants qw/:all/;
my $atasmart = Linux::AtaSmart->new('/dev/sda');
if (!$atasmart->smart_is_available) {
die "Drive not SMART capable";
}
say 'Disk size in bytes: ', $atasmart->get_size;
say 'Awake: ' . ($atasmart->check_sleep_mode ? 'YES' : 'NO');
say 'Status: ' . ($atasmart->smart_status ? 'GOOD' : 'BAD');
say 'Bad Sectors: ' . $atasmart->get_bad;
say 'Temperature °C: ' . $atasmart->get_temperature;
say "Power Cycles: " . $atasmart->get_power_cycle;
say "Powered On: " . $atasmart->get_power_on->pretty;
my $status = $atasmart->get_overall;
if ($status != OVERALL_GOOD) {
say "STATUS NOT GOOD!";
}
# all of the above and more
$atasmart->dump;
$atasmart->self_test(TEST_SHORT);
# DESCRIPTION
This is an XS wrapper around the Linux-only library, [libatasmart](
http://0pointer.de/blog/projects/being-smart.html).
To read SMART info from a drive you will need to run as root, or have CAP\_RAW\_IO
(which you will most likely have to set on your `perl` binary).
__HAVING GROUP WRITE PERMISSIONS IS NOT ENOUGH!__
# ALTERNATIVES
You may already have [udisks](
http://www.freedesktop.org/wiki/Software/udisks)
installed, which you can query via [Net::DBus](
http://search.cpan.org/perldoc?Net::DBus).
# INSTALLATION
On Debian-like systems, make sure you have `libatasmart-dev` installed.
# DIFFERENCES FROM THE C API
- I have removed the `sk_disk_` and `sk_disk_smart_` prefixes for brevity.
- The `SkDisk` item is handled inside this module, you don't need to pass it to every method.
You should create a new object to examine a different disk.
- Results are returned directly by the methods, you don't have to pass references to be filled.
- You don't have to manually call `sk_disk_smart_read_data` or `sk_disk_smart_parse_data`.
This will be handled automatically by those methods that require it.
# ERRORS
All errors will throw exceptions via `confess`
# METHODS
## `new(disk\_device)`
Creates a new `Linux::AtaSmart` object. Requires one argument, a string, identifying
the disk to exmaine, e.g. `/dev/sda`, `/dev/disk/by-label/HOME`
## `smart\_is\_available`
Boolean.
## `smart\_status`
Boolean, true is GOOD, false is BAD.
## `check\_sleep\_mode`
Boolean, true if awake, false if sleeping. Reading SMART data will wake up the disk,
so check this first if you care.
## `dump`
Prints all the available SMART info for the disk to `STDOUT`.
## `get\_bad`
Returns the number of bad sectors on the disk.
## `get\_overall`
Returns an integer corresponding to the overall status of the drive. See [Linux::AtaSmart::Constants](
http://search.cpan.org/perldoc?Linux::AtaSmart::Constants).
## `get\_power\_cycle`
Returns number of times the disk has been power cycled.
## `get\_power\_on`
Returns the total time this disk has been powered-on as a [Time::Seconds](
http://search.cpan.org/perldoc?Time::Seconds) object.
The C library actually uses milliseconds, complain if you'd prefer that.
## `get\_size`
Returns the disk capacity in bytes.
## `get\_temperature`
Returns current disk temperature in celsius.
The C library actually uses millikelvins, complain if you'd prefer that.
## `self\_test(TEST\_TYPE)`
Starts a test of TEST\_TYPE. See [Linux::AtaSmart::Constants](
http://search.cpan.org/perldoc?Linux::AtaSmart::Constants).
# SEE ALSO
- [libatasmart](
http://0pointer.de/blog/projects/being-smart.html)
- [Linux::AtaSmart::Constants](
http://search.cpan.org/perldoc?Linux::AtaSmart::Constants)
# AUTHOR
Ioan Rogers <
[email protected]>
# COPYRIGHT AND LICENSE
This software is Copyright (c) 2012 by Ioan Rogers.
This is free software, licensed under:
The GNU Lesser General Public License, Version 3, June 2007
# BUGS AND LIMITATIONS
You can make new bug reports, and view existing ones, through the
web interface at [
https://github.com/ioanrogers/Linux-AtaSmart/issues](
https://github.com/ioanrogers/Linux-AtaSmart/issues).
# SOURCE
The development version is on github at [
http://github.com/ioanrogers/Linux-AtaSmart](
http://github.com/ioanrogers/Linux-AtaSmart)
and may be cloned from [git://github.com/ioanrogers/Linux-AtaSmart.git](git://github.com/ioanrogers/Linux-AtaSmart.git)