disks: small refactor
This commit is contained in:
parent
4542ad10db
commit
2a90bc465e
|
@ -58,7 +58,7 @@ disk_mount_point_get(const char *path)
|
||||||
start = &buf[0];
|
start = &buf[0];
|
||||||
end = strchr(start, ' ');
|
end = strchr(start, ' ');
|
||||||
if (!end) continue;
|
if (!end) continue;
|
||||||
*end = 0x0;
|
*end = '\0';
|
||||||
|
|
||||||
if (!strcmp(path, start))
|
if (!strcmp(path, start))
|
||||||
{
|
{
|
||||||
|
@ -66,16 +66,13 @@ disk_mount_point_get(const char *path)
|
||||||
if (!start) continue;
|
if (!start) continue;
|
||||||
end = strchr(start, ' ');
|
end = strchr(start, ' ');
|
||||||
if (!end) continue;
|
if (!end) continue;
|
||||||
*end = 0x0;
|
*end = '\0';
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return strdup(start);
|
return strdup(start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
return NULL;
|
|
||||||
#else
|
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -121,9 +118,9 @@ disks_get(void)
|
||||||
{
|
{
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
struct statfs *mounts;
|
struct statfs *mounts;
|
||||||
int i, count;
|
|
||||||
char *drives, *dev, *end;
|
char *drives, *dev, *end;
|
||||||
char buf[4096];
|
Eina_List *list = NULL;
|
||||||
|
int count;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if ((sysctlbyname("kern.disks", NULL, &len, NULL, 0)) == -1)
|
if ((sysctlbyname("kern.disks", NULL, &len, NULL, 0)) == -1)
|
||||||
|
@ -137,19 +134,15 @@ disks_get(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eina_List *list = NULL;
|
|
||||||
dev = drives;
|
dev = drives;
|
||||||
while (dev)
|
while (dev)
|
||||||
{
|
{
|
||||||
end = strchr(dev, ' ');
|
end = strchr(dev, ' ');
|
||||||
if (!end)
|
if (!end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "/dev/%s", dev);
|
list = eina_list_append(list, strdup(eina_slstr_printf("/dev/%s", dev)));
|
||||||
|
|
||||||
list = eina_list_append(list, strdup(buf));
|
|
||||||
|
|
||||||
dev = end + 1;
|
dev = end + 1;
|
||||||
}
|
}
|
||||||
|
@ -157,23 +150,18 @@ disks_get(void)
|
||||||
free(drives);
|
free(drives);
|
||||||
|
|
||||||
count = getmntinfo(&mounts, MNT_WAIT);
|
count = getmntinfo(&mounts, MNT_WAIT);
|
||||||
for (i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
list = eina_list_append(list, strdup(mounts[i].f_mntfromname));
|
list = eina_list_append(list, strdup(mounts[i].f_mntfromname));
|
||||||
}
|
}
|
||||||
|
|
||||||
list = eina_list_sort(list, eina_list_count(list), _cmp_cb);
|
|
||||||
|
|
||||||
return list;
|
|
||||||
|
|
||||||
#elif defined(__OpenBSD__) || defined(__NetBSD__)
|
#elif defined(__OpenBSD__) || defined(__NetBSD__)
|
||||||
static const int mib[] = { CTL_HW, HW_DISKNAMES };
|
static const int mib[] = { CTL_HW, HW_DISKNAMES };
|
||||||
static const unsigned int miblen = 2;
|
static const unsigned int miblen = 2;
|
||||||
struct statfs *mounts;
|
struct statfs *mounts;
|
||||||
char *drives, *dev, *end;
|
char *drives, *dev, *end;
|
||||||
char buf[4096];
|
Eina_List *list = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
int i, count;
|
int count;
|
||||||
|
|
||||||
if ((sysctl(mib, miblen, NULL, &len, NULL, 0)) == -1)
|
if ((sysctl(mib, miblen, NULL, &len, NULL, 0)) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -186,8 +174,6 @@ disks_get(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eina_List *list = NULL;
|
|
||||||
|
|
||||||
dev = drives;
|
dev = drives;
|
||||||
while (dev)
|
while (dev)
|
||||||
{
|
{
|
||||||
|
@ -199,9 +185,7 @@ disks_get(void)
|
||||||
if (dev[0] == ',')
|
if (dev[0] == ',')
|
||||||
dev++;
|
dev++;
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "/dev/%s", dev);
|
list = eina_list_append(list, strdup(eina_slstr_printf("/dev/%s", dev)));
|
||||||
|
|
||||||
list = eina_list_append(list, strdup(buf));
|
|
||||||
|
|
||||||
end++;
|
end++;
|
||||||
dev = strchr(end, ',');
|
dev = strchr(end, ',');
|
||||||
|
@ -211,14 +195,10 @@ disks_get(void)
|
||||||
free(drives);
|
free(drives);
|
||||||
|
|
||||||
count = getmntinfo(&mounts, MNT_WAIT);
|
count = getmntinfo(&mounts, MNT_WAIT);
|
||||||
for (i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
list = eina_list_append(list, strdup(mounts[i].f_mntfromname));
|
list = eina_list_append(list, strdup(mounts[i].f_mntfromname));
|
||||||
}
|
}
|
||||||
|
|
||||||
list = eina_list_sort(list, eina_list_count(list), _cmp_cb);
|
|
||||||
|
|
||||||
return list;
|
|
||||||
#elif defined(__MacOS__)
|
#elif defined(__MacOS__)
|
||||||
char *name;
|
char *name;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
@ -232,18 +212,13 @@ disks_get(void)
|
||||||
{
|
{
|
||||||
if (!strncmp(name, "disk", 4))
|
if (!strncmp(name, "disk", 4))
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "/dev/%s", name);
|
list = eina_list_append(list, strdup(eina_slstr_printf("/dev/%s", name)));
|
||||||
list = eina_list_append(list, strdup(buf));
|
|
||||||
}
|
}
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devs)
|
if (devs)
|
||||||
eina_list_free(devs);
|
eina_list_free(devs);
|
||||||
|
|
||||||
list = eina_list_sort(list, eina_list_count(list), _cmp_cb);
|
|
||||||
|
|
||||||
return list;
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
char *name;
|
char *name;
|
||||||
Eina_List *devs, *list;
|
Eina_List *devs, *list;
|
||||||
|
@ -280,13 +255,9 @@ disks_get(void)
|
||||||
|
|
||||||
if (devs)
|
if (devs)
|
||||||
eina_list_free(devs);
|
eina_list_free(devs);
|
||||||
|
#endif
|
||||||
list = eina_list_sort(list, eina_list_count(list), _cmp_cb);
|
list = eina_list_sort(list, eina_list_count(list), _cmp_cb);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
#else
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue