KHDAPSMonitor – monitor for laptops that support the IBM Hard Drive Active Protection System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

89 lines
1.6 KiB

#include <qdir.h>
#include <kdebug.h>
#include "sysfs.h"
SysFS::SysFS()
{}
SysFS::~SysFS()
{}
bool SysFS::hasHDAPS()
{
QDir d("/sys/devices/platform/hdaps");
return d.isReadable();
}
bool SysFS::fileBool(QString path)
{
QFile file;
QTextStream stream;
file.setName(path);
if(! file.exists() || ! file.open(IO_ReadOnly))
return FALSE;
stream.setDevice(&file);
return stream.readLine().toInt(NULL, 10);
}
bool SysFS::keyboardActivity()
{
return fileBool("/sys/devices/platform/hdaps/keyboard_activity");
}
bool SysFS::mouseActivity()
{
return fileBool("/sys/devices/platform/hdaps/mouse_activity");
}
QString SysFS::position()
{
QFile file;
QTextStream stream;
file.setName("/sys/devices/platform/hdaps/position");
if(! file.exists() || ! file.open(IO_ReadOnly))
return NULL;
stream.setDevice(&file);
return stream.readLine();
}
QStringList SysFS::deviceList()
{
QDir sysBlock("/sys/block", "[hs]d*", QDir::IgnoreCase, QDir::Dirs);
if (! sysBlock.exists())
return NULL;
QStringList deviceList = sysBlock.entryList();
unsigned int i = 0;
while (i < deviceList.count())
{
if(QFile("/sys/block/" + deviceList[i] + "/device/unload_heads").exists())
i++;
else
deviceList.remove(deviceList.at(i));
}
return deviceList;
}
bool SysFS::queueProtected(QString device)
{
QFile file;
bool b = FALSE;
QTextStream stream;
file.setName("/sys/block/" + device + "/device/unload_heads");
if(! file.exists() || ! file.open(IO_ReadOnly))
return NULL;
stream.setDevice(&file);
if(stream.readLine().toInt() > 0)
b = TRUE;
return b;
}