aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/plugins/hdparm.py97
-rw-r--r--src/restricted-hdparm.c66
2 files changed, 163 insertions, 0 deletions
diff --git a/src/plugins/hdparm.py b/src/plugins/hdparm.py
new file mode 100644
index 0000000..bbbec18
--- /dev/null
+++ b/src/plugins/hdparm.py
@@ -0,0 +1,97 @@
+# -*- python -*-
+'''
+xpybar – xmobar replacement written in python
+Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+'''
+
+import os
+
+from util import *
+
+
+class HDParm: # TODO add output parsers
+ '''
+ Set/get SATA/IDE device parameters
+ '''
+
+
+ READAHEAD_SECTOR_COUNT = 'a'
+ HAVE_READAHEAD = 'A'
+ ADVANCED_POWER_MANAGEMENT = 'B'
+ IDE_32BIT_IO_SUPPORT = 'c'
+ POWER_MODE_STATUS = 'C'
+ GEOMETRY = 'g'
+ HITACHI_TEMPERATURE = 'H'
+ KERNEL_INFORMATION = 'i'
+ DIRECT_INFORMATION = 'I'
+ WESTERN_DIGITAL_IDLE3_TIMEOUT = 'J'
+ MULTIPLE_SECTOR_IO_SECTOR_COUNT = 'm'
+ AUTOMATIC_ACOUSTIC_MANAGEMENT = 'M'
+ MAX_VISIBLE_SECTOR_COUNT = 'N'
+ COMMAND_QUEUE_DEPTH = 'Q'
+ IS_READONLY = 'r'
+ HAVE_WRITE_READ_VERIFY = 'R'
+ IDLE_MODE = 'S'
+ HAVE_WRITE_CACHING = 'W'
+ STANDBY_MODE = 'y'
+ SLEEP_MODE = 'Y'
+ DISABLE_SEAGATE_AUTOMATIC_POWER_SAVING = 'Z'
+
+
+ def __init__(self, devices = None):
+ '''
+ Constructor
+
+ @param devices:list<str>? The devices to use, `None` for all
+ '''
+ self.devices = HDParm.get_devices() if devices is None else self.devices
+ spawn_read()
+
+
+ def get(self, action):
+ '''
+ Read information about selected devices
+
+ @param action:str The information to read
+ @return :str The read information
+ '''
+ return spawn_read('restricted-hdparm', '-%s' % action)
+
+
+ def set(self, action, value = None):
+ '''
+ Configure selected devices
+
+ @param action:str The settings to reconfigure
+ @param value:int? The value to apply, `None` if there is no value to apply
+ @return :str The read information
+ '''
+ if value is None:
+ spawn('restricted-hdparm', action)
+ else:
+ spawn('restricted-hdparm', '-%s%s' % (action, str(value)))
+
+
+ @staticmethod
+ def get_devices(self):
+ '''
+ List available devices
+
+ @param :list<str> Available devices
+ '''
+ test = lambda dev : (len(dev) == 3) and (dev[:2] in ('sd', 'hd'))
+ return filter(test, os.listdir('/dev'))
+
diff --git a/src/restricted-hdparm.c b/src/restricted-hdparm.c
new file mode 100644
index 0000000..bb4d923
--- /dev/null
+++ b/src/restricted-hdparm.c
@@ -0,0 +1,66 @@
+/**
+ * xpybar – xmobar replacement written in python
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+
+int main(int argc, char** argv)
+{
+ char* act = argv[1];
+ int i;
+
+ setuid(0);
+
+ for (i = 2; i < argc; i++)
+ if (argv[i][0] == '/')
+ return 1;
+
+ if (*act++ != '-')
+ return 1;
+
+ if (!strcmp(act, "a")) ;
+ else if (!strcmp(act, "A")) ;
+ else if ( strstr(act, "B") == act) ;
+ else if (!strcmp(act, "c")) ;
+ else if (!strcmp(act, "C")) ;
+ else if (!strcmp(act, "g")) ;
+ else if (!strcmp(act, "H")) ;
+ else if (!strcmp(act, "i")) ;
+ else if (!strcmp(act, "I")) ;
+ else if ( strstr(act, "J") == act) ;
+ else if (!strcmp(act, "m")) ;
+ else if ( strstr(act, "M") == act) ;
+ else if (!strcmp(act, "N")) ;
+ else if (!strcmp(act, "Q")) ;
+ else if (!strcmp(act, "r")) ;
+ else if (!strcmp(act, "R")) ;
+ else if ( strstr(act, "S") == act) ;
+ else if (!strcmp(act, "W")) ;
+ else if (!strcmp(act, "y")) ;
+ else if (!strcmp(act, "Y")) ;
+ else if (!strcmp(act, "Z")) ;
+ else
+ return 1;
+
+ execv("hdparm", argv);
+ perror(*argv);
+
+ return 1;
+}
+