netstar pushed a commit to branch master.

http://git.enlightenment.org/apps/evisum.git/commit/?id=ae81aa793e7fee93c34cba3cd7bc9a9c983469b1

commit ae81aa793e7fee93c34cba3cd7bc9a9c983469b1
Author: Alastair Poole <[email protected]>
Date:   Tue Dec 1 12:43:19 2020 +0000

    disks: ugh linuxism try.
    
    This whole disk stuff was not thought out at all...oops
---
 src/bin/system/filesystems.c | 44 +++++++++++++++++++++++++++++++++++++++++---
 src/bin/system/filesystems.h |  1 +
 src/bin/ui/ui_disk.c         | 17 ++---------------
 src/bin/ui/ui_disk.h         |  1 -
 4 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/src/bin/system/filesystems.c b/src/bin/system/filesystems.c
index dac60f2..dcf12b9 100644
--- a/src/bin/system/filesystems.c
+++ b/src/bin/system/filesystems.c
@@ -1,5 +1,4 @@
 #include "filesystems.h"
-#include "disks.h"
 
 #include <stdio.h>
 #include <limits.h>
@@ -169,12 +168,51 @@ file_system_type_name(const char *mountpoint)
 Eina_List *
 file_system_info_all_get(void)
 {
+   Eina_List *list = NULL;
 # if defined(__linux__)
-   return NULL;
+
+   FILE *f;
+   char *dev, *mount, *type_name, *cp, *end;
+   struct statfs stats;
+   char buf[4096];
+
+   f = fopen("/proc/mounts", "r");
+   if (!f) return NULL;
+
+   while ((fgets(buf, sizeof(buf), f)) != NULL)
+     {
+        mount = strchr(buf, ' ') + 1;
+        if (!mount) continue;
+        dev = strndup(buf, mount - buf);
+        cp = strchr(mount, ' ');
+        if (!cp) continue;
+        end = cp;
+        *end = '\0';
+        cp++;
+        end = strchr(cp, ' ');
+        if (!end) continue;
+        type_name = strndup(cp, end - cp);
+
+        if ((strstr(cp, "nodev")) || (statfs(mount, &stats) < 0) ||
+            (stats.f_blocks == 0 && stats.f_bfree == 0))
+          {
+             free(dev);
+             free(type_name);
+             continue;
+          }
+
+        File_System *fs = calloc(1, sizeof(File_System));
+        fs->mount = strdup(mount);
+        fs->path = dev;
+        fs->type_name = type_name;
+        fs->usage.total = stats.f_bsize * stats.f_blocks;
+        fs->usage.used  = fs->usage.total - (stats.f_bsize * stats.f_bfree);
+        list = eina_list_append(list, fs);
+     }
+   fclose(f);
 # else
    struct statfs *mounts;
    int i, count;
-   Eina_List *list = NULL;
 
    count = getmntinfo(&mounts, MNT_WAIT);
    for (i = 0; i < count; i++)
diff --git a/src/bin/system/filesystems.h b/src/bin/system/filesystems.h
index 2d201ba..056206a 100644
--- a/src/bin/system/filesystems.h
+++ b/src/bin/system/filesystems.h
@@ -2,6 +2,7 @@
 #define __FILESYSTEMS_H__
 
 #include <Eina.h>
+#include "disks.h"
 
 typedef struct {
    unsigned long long total;
diff --git a/src/bin/ui/ui_disk.c b/src/bin/ui/ui_disk.c
index 1dcacd2..2c69469 100644
--- a/src/bin/ui/ui_disk.c
+++ b/src/bin/ui/ui_disk.c
@@ -1,5 +1,5 @@
 #include "ui_disk.h"
-#include "../system/disks.h"
+#include "../system/filesystems.h"
 
 typedef struct
 {
@@ -77,7 +77,7 @@ _item_create(Evas_Object *parent)
    lb = _item_column_add(table, "mount", 1);
    evas_object_size_hint_align_set(lb, 0, FILL);
    lb = _item_column_add(table, "fs", 2);
-   evas_object_size_hint_align_set(lb, 0.5, FILL);
+   evas_object_size_hint_align_set(lb, 0, FILL);
    lb = _item_column_add(table, "used", 3);
    evas_object_size_hint_align_set(lb, 0.5, FILL);
    lb = _item_column_add(table, "total", 4);
@@ -227,20 +227,7 @@ _disks_poll_timer_cb(void *data)
 
    eina_lock_take(&_lock);
 
-#if defined(__linux__)
-   char *path;
-   Eina_List *disks = disks_get();
-   EINA_LIST_FREE(disks, path)
-     {
-        fs = file_system_info_get(path);
-        if (fs)
-          mounted = eina_list_append(mounted, fs);
-
-        free(path);
-     }
-#else
    mounted = file_system_info_all_get();
-#endif
 
    if (_private_data->sort_cb)
      mounted = eina_list_sort(mounted, eina_list_count(mounted), 
_private_data->sort_cb);
diff --git a/src/bin/ui/ui_disk.h b/src/bin/ui/ui_disk.h
index afc16f3..b2c3665 100644
--- a/src/bin/ui/ui_disk.h
+++ b/src/bin/ui/ui_disk.h
@@ -2,7 +2,6 @@
 #define __UI_DISK_H__
 
 #include "ui.h"
-#include "system/disks.h"
 
 void
 ui_win_disk_add(Ui *ui);

-- 


Reply via email to