]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - tools/lib/api/fs/fs.c
Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / tools / lib / api / fs / fs.c
index 8afe08a99bc66fe3a53a0767ff99de0c56a34072..459599d1b6c410b7b41333c13f248ee685c2dd4a 100644 (file)
@@ -1,5 +1,6 @@
 #include <ctype.h>
 #include <errno.h>
+#include <limits.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -11,7 +12,6 @@
 #include <unistd.h>
 #include <sys/mount.h>
 
-#include "debugfs.h"
 #include "fs.h"
 
 #define _STR(x) #x
@@ -69,7 +69,7 @@ static const char * const tracefs__known_mountpoints[] = {
 struct fs {
        const char              *name;
        const char * const      *mounts;
-       char                     path[PATH_MAX + 1];
+       char                     path[PATH_MAX];
        bool                     found;
        long                     magic;
 };
@@ -282,6 +282,50 @@ int filename__read_int(const char *filename, int *value)
        return err;
 }
 
+int filename__read_ull(const char *filename, unsigned long long *value)
+{
+       char line[64];
+       int fd = open(filename, O_RDONLY), err = -1;
+
+       if (fd < 0)
+               return -1;
+
+       if (read(fd, line, sizeof(line)) > 0) {
+               *value = strtoull(line, NULL, 10);
+               if (*value != ULLONG_MAX)
+                       err = 0;
+       }
+
+       close(fd);
+       return err;
+}
+
+int sysfs__read_ull(const char *entry, unsigned long long *value)
+{
+       char path[PATH_MAX];
+       const char *sysfs = sysfs__mountpoint();
+
+       if (!sysfs)
+               return -1;
+
+       snprintf(path, sizeof(path), "%s/%s", sysfs, entry);
+
+       return filename__read_ull(path, value);
+}
+
+int sysfs__read_int(const char *entry, int *value)
+{
+       char path[PATH_MAX];
+       const char *sysfs = sysfs__mountpoint();
+
+       if (!sysfs)
+               return -1;
+
+       snprintf(path, sizeof(path), "%s/%s", sysfs, entry);
+
+       return filename__read_int(path, value);
+}
+
 int sysctl__read_int(const char *sysctl, int *value)
 {
        char path[PATH_MAX];