Powertop2 uses debugfs. Currently it uses /bin/mount to mount
the debugfs. In Android mount command is present in system/bin.
This patch mounts the debugfs in android natively.

This patch also enables powertop to use the /data directory instead of
/var to store  powertop paramaters and results  in case of Android OS
---
 main.cpp                  |   12 ++++++++++--
 parameters/persistent.cpp |   33 +++++++++++++++++++++++++--------
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/main.cpp b/main.cpp
index 7861c37..74304c1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -262,11 +262,19 @@ int main(int argc, char **argv)
        }
        system("/sbin/modprobe cpufreq_stats > /dev/null 2>&1");
        system("/sbin/modprobe msr > /dev/null 2>&1");
-       system("/bin/mount -t debugfs debugfs /sys/kernel/debug > /dev/null 
2>&1");
+
+       if (access("/bin/mount", X_OK) == 0) {
+               system("/bin/mount -t debugfs debugfs /sys/kernel/debug > 
/dev/null 2>&1");
+       } else {
+               system("mount -t debugfs debugfs /sys/kernel/debug > /dev/null 
2>&1");
+       }
 
        srand(time(NULL));
 
-       mkdir("/var/cache/powertop", 0600);
+       if (access("/var/cache/", W_OK) == 0)
+               mkdir("/var/cache/powertop", 0600);
+       else
+               mkdir("/data/local/powertop", 0600);
 
        load_results("/var/cache/powertop/saved_results.powertop");
        load_parameters("/var/cache/powertop/saved_parameters.powertop");
diff --git a/parameters/persistent.cpp b/parameters/persistent.cpp
index 069095d..9297755 100644
--- a/parameters/persistent.cpp
+++ b/parameters/persistent.cpp
@@ -26,6 +26,7 @@
 #include <fstream>
 #include <iomanip>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "parameters.h"
 #include "../measurement/measurement.h"
@@ -37,10 +38,14 @@ void save_all_results(const char *filename)
        ofstream file;
        unsigned int i;
        struct result_bundle *bundle;
+       char* tempfilename = const_cast<char*>(filename);
 
-       file.open(filename, ios::out);
+       if (access("/var/", W_OK ) != 0)
+               sprintf(tempfilename, 
"/data/local/powertop/saved_results.powertop");
+
+       file.open(tempfilename, ios::out);
        if (!file) {
-               cout << _("Cannot save to file ") << filename << "\n";
+               cout << _("Cannot save to file ") << tempfilename << "\n";
                return;
        }
        for (i = 0; i < past_results.size(); i++) {     
@@ -66,10 +71,14 @@ void load_results(const char *filename)
        struct result_bundle *bundle;
        int first = 1;
        unsigned int count = 0;
+       char* tempfilename = const_cast<char*>(filename);
+
+       if (access("/var/", W_OK ) != 0)
+               sprintf(tempfilename, 
"/data/local/powertop/saved_results.powertop");
 
-       file.open(filename, ios::in);
+       file.open(tempfilename, ios::in);
        if (!file) {
-               cout << _("Cannot load from file ") << filename << "\n";
+               cout << _("Cannot load from file ") << tempfilename << "\n";
                return;
        }
 
@@ -119,15 +128,19 @@ void load_results(const char *filename)
 void save_parameters(const char *filename)
 {
        ofstream file;
+       char* tempfilename = const_cast<char*>(filename);
 
 //     printf("result size is %i, #parameters is %i \n", 
(int)past_results.size(), (int)all_parameters.parameters.size());
 
        if (!global_power_valid())
                return;
 
-       file.open(filename, ios::out);
+       if (access("/var/", R_OK ) != 0)
+               sprintf(tempfilename, 
"/data/local/powertop/saved_parameters.powertop");
+
+       file.open(tempfilename, ios::out);
        if (!file) {
-               cout << _("Cannot save to file ") << filename << "\n";
+               cout << _("Cannot save to file ") << tempfilename << "\n";
                return;
        }
        
@@ -146,10 +159,14 @@ void load_parameters(const char *filename)
        ifstream file;
        char line[4096];
        char *c1;
+       char* tempfilename = const_cast<char*>(filename);
+
+       if (access("/var/", R_OK ) != 0)
+               sprintf(tempfilename, 
"/data/local/powertop/saved_parameters.powertop");
 
-       file.open(filename, ios::in);
+       file.open(tempfilename, ios::in);
        if (!file) {
-               cout << _("Cannot load from file ") << filename << "\n";
+               cout << _("Cannot load from file ") << tempfilename << "\n";
                return;
        }
 
-- 
1.7.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

_______________________________________________
Power mailing list
[email protected]
https://bughost.org/mailman/listinfo/power

Reply via email to