forked from enlightenment/evisum
disks: ugh linuxism try.
This whole disk stuff was not thought out at all...oops
This commit is contained in:
parent
63953978d9
commit
ae81aa793e
|
@ -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++)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define __FILESYSTEMS_H__
|
||||
|
||||
#include <Eina.h>
|
||||
#include "disks.h"
|
||||
|
||||
typedef struct {
|
||||
unsigned long long total;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define __UI_DISK_H__
|
||||
|
||||
#include "ui.h"
|
||||
#include "system/disks.h"
|
||||
|
||||
void
|
||||
ui_win_disk_add(Ui *ui);
|
||||
|
|
Loading…
Reference in New Issue