pub struct Disk {
pub disk: PathBuf,
/* private fields */
}
Expand description
Our ata smart disk
Fields§
§disk: PathBuf
The path in the filesystem to the hard drive
Implementations§
Source§impl Disk
impl Disk
Sourcepub fn new(disk_path: &Path) -> Result<Disk, Errno>
pub fn new(disk_path: &Path) -> Result<Disk, Errno>
This will initialize a new Disk by asking libatasmart to open it. Note that this requires root permissions usually to succeed.
Sourcepub fn refresh_smart_data(&mut self) -> Result<(), Errno>
pub fn refresh_smart_data(&mut self) -> Result<(), Errno>
Refreshes cached SMART attribute values.
SMART attribute values are read once in Disk::new and cached. Methods such as
get_temperature
use these cached values and do not access the disk. Call this method to
refresh the cached values.
Note: calling this method might cause the disk to wake up from sleep. Consider checking if
the disk is asleep using check_sleep_mode
before calling this method to avoid this.
Sourcepub fn get_disk_size(&mut self) -> Result<u64, Errno>
pub fn get_disk_size(&mut self) -> Result<u64, Errno>
Returns a u64 representing the size of the disk in bytes.
Sourcepub fn check_sleep_mode(&mut self) -> Result<bool, Errno>
pub fn check_sleep_mode(&mut self) -> Result<bool, Errno>
Returns a bool of true if sleep mode is supported, false otherwise.
Sourcepub fn get_power_on(&mut self) -> Result<u64, Errno>
pub fn get_power_on(&mut self) -> Result<u64, Errno>
Returns a u64 representing the power on time in milliseconds
Sourcepub fn get_power_cycle_count(&mut self) -> Result<u64, Errno>
pub fn get_power_cycle_count(&mut self) -> Result<u64, Errno>
Returns a u64 representing the number of power on cycles
Sourcepub fn get_bad_sectors(&mut self) -> Result<u64, Errno>
pub fn get_bad_sectors(&mut self) -> Result<u64, Errno>
Returns a u64 representing the number of bad sections on the disk
Sourcepub fn get_temperature(&mut self) -> Result<u64, Errno>
pub fn get_temperature(&mut self) -> Result<u64, Errno>
Returns a u64 representing the mkelvin of the disk
Sourcepub fn get_smart_status(&mut self) -> Result<bool, Errno>
pub fn get_smart_status(&mut self) -> Result<bool, Errno>
Returns true if the disk passed smart, false otherwise.
Sourcepub fn dump(&mut self) -> Result<(), Errno>
pub fn dump(&mut self) -> Result<(), Errno>
This will dump all available information to stdout about the drive
pub fn identify_is_available(&mut self) -> Result<bool, Errno>
Sourcepub fn smart_is_available(&mut self) -> Result<bool, Errno>
pub fn smart_is_available(&mut self) -> Result<bool, Errno>
Query the device and return whether or not smart is supported on it
Sourcepub unsafe fn parse_attributes(
&mut self,
parser_callback: extern "C" fn(*mut SkDisk, *const SkSmartAttributeParsedData, *mut c_void),
userdata: *mut c_void,
) -> Result<(), Errno>
pub unsafe fn parse_attributes( &mut self, parser_callback: extern "C" fn(*mut SkDisk, *const SkSmartAttributeParsedData, *mut c_void), userdata: *mut c_void, ) -> Result<(), Errno>
This is a lower level function that is used to build new smart functions
§Safety
This function is unsafe because it dereferences raw pointers and calls an external C function.
The caller must ensure that parser_callback
and userdata
are valid and that self.skdisk
is properly initialized.
Sourcepub fn smart_test_available(
&mut self,
test_attributes: &mut SkSmartParsedData,
test_type: SkSmartSelfTest,
) -> Result<bool, Errno>
pub fn smart_test_available( &mut self, test_attributes: &mut SkSmartParsedData, test_type: SkSmartSelfTest, ) -> Result<bool, Errno>
Query the device and return whether or not a particular smart test is supported on it
pub fn execute_smart_self_test( &mut self, test_type: SkSmartSelfTest, ) -> Result<(), Errno>
pub fn smart_get_overall(&mut self) -> Result<SkSmartOverall, Errno>
Sourcepub fn identify_parse(&mut self) -> Result<IdentifyParsedData, Errno>
pub fn identify_parse(&mut self) -> Result<IdentifyParsedData, Errno>
Get the model, firmware, and serial of the disk as a IdentifyParsedDatastruct If Errno::EINVAL gets returned there is a problem with the C string parser