forked from enlightenment/efl
add helper udev function to browse children devices, use helper functions to get properties when not found in current disk device
SVN revision: 59566
This commit is contained in:
parent
924bddfc83
commit
e1e525ae19
|
@ -14,22 +14,54 @@ Eina_List *_eeze_disks = NULL;
|
||||||
static Eeze_Disk_Type
|
static Eeze_Disk_Type
|
||||||
_eeze_disk_type_find(Eeze_Disk *disk)
|
_eeze_disk_type_find(Eeze_Disk *disk)
|
||||||
{
|
{
|
||||||
const char *bus;
|
const char *test;
|
||||||
bus = udev_device_get_property_value(disk->device, "ID_BUS");
|
Eeze_Disk_Type ret;
|
||||||
if (!bus)
|
Eina_Bool filesystem = EINA_FALSE; /* this will have no children */
|
||||||
return EEZE_DISK_TYPE_UNKNOWN;
|
|
||||||
|
|
||||||
if (!strcmp(bus, "ata") || !strcmp(bus, "scsi"))
|
if (udev_device_get_property_value(disk->device, "ID_CDROM"))
|
||||||
{ /* FIXME: I think some other types of devices fall into this, check later */
|
return EEZE_DISK_TYPE_CDROM;
|
||||||
if (udev_device_get_property_value(disk->device, "ID_CDROM"))
|
test = udev_device_get_property_value(disk->device, "ID_FS_USAGE");
|
||||||
return EEZE_DISK_TYPE_CDROM;
|
if ((!test) || strcmp(test, "filesystem"))
|
||||||
else
|
{
|
||||||
return EEZE_DISK_TYPE_INTERNAL;
|
test = _walk_children_get_attr(disk->syspath, "ID_CDROM", "block", EINA_TRUE);
|
||||||
|
if (test)
|
||||||
|
{
|
||||||
|
eina_stringshare_del(test);
|
||||||
|
return EEZE_DISK_TYPE_CDROM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!strcmp(bus, "usb"))
|
else
|
||||||
return EEZE_DISK_TYPE_USB;
|
filesystem = EINA_TRUE;
|
||||||
|
if (udev_device_get_property_value(disk->device, "ID_ATA"))
|
||||||
|
return EEZE_DISK_TYPE_INTERNAL;
|
||||||
|
if (!filesystem)
|
||||||
|
{
|
||||||
|
test = _walk_children_get_attr(disk->syspath, "ID_ATA", "block", EINA_TRUE);
|
||||||
|
if (test)
|
||||||
|
{
|
||||||
|
eina_stringshare_del(test);
|
||||||
|
return EEZE_DISK_TYPE_INTERNAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
test = udev_device_get_property_value(disk->device, "ID_BUS");
|
||||||
|
if (test)
|
||||||
|
{
|
||||||
|
if (!strcmp(test, "ata")) return EEZE_DISK_TYPE_INTERNAL;
|
||||||
|
if (!strcmp(test, "usb")) return EEZE_DISK_TYPE_USB;
|
||||||
|
return EEZE_DISK_TYPE_UNKNOWN; /* FIXME */
|
||||||
|
}
|
||||||
|
if ((!test) && (!filesystem))
|
||||||
|
test = _walk_children_get_attr(disk->syspath, "ID_BUS", "block", EINA_TRUE);
|
||||||
|
if (!test)
|
||||||
|
return EEZE_DISK_TYPE_UNKNOWN; /* FIXME */
|
||||||
|
|
||||||
return EEZE_DISK_TYPE_UNKNOWN;
|
if (!strcmp(test, "ata")) ret = EEZE_DISK_TYPE_INTERNAL;
|
||||||
|
else if (!strcmp(test, "usb")) ret = EEZE_DISK_TYPE_USB;
|
||||||
|
else ret = EEZE_DISK_TYPE_UNKNOWN;
|
||||||
|
|
||||||
|
eina_stringshare_del(test);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static _udev_device *
|
static _udev_device *
|
||||||
|
@ -209,6 +241,7 @@ eeze_disk_free(Eeze_Disk *disk)
|
||||||
EAPI void
|
EAPI void
|
||||||
eeze_disk_scan(Eeze_Disk *disk)
|
eeze_disk_scan(Eeze_Disk *disk)
|
||||||
{
|
{
|
||||||
|
const char *test;
|
||||||
EINA_SAFETY_ON_NULL_RETURN(disk);
|
EINA_SAFETY_ON_NULL_RETURN(disk);
|
||||||
/* never rescan; if these values change then something is seriously wrong */
|
/* never rescan; if these values change then something is seriously wrong */
|
||||||
if (disk->cache.filled) return;
|
if (disk->cache.filled) return;
|
||||||
|
@ -229,7 +262,15 @@ eeze_disk_scan(Eeze_Disk *disk)
|
||||||
disk->cache.type = _eeze_disk_type_find(disk);
|
disk->cache.type = _eeze_disk_type_find(disk);
|
||||||
if (!disk->cache.label)
|
if (!disk->cache.label)
|
||||||
disk->cache.label = udev_device_get_property_value(disk->device, "ID_FS_LABEL");
|
disk->cache.label = udev_device_get_property_value(disk->device, "ID_FS_LABEL");
|
||||||
disk->cache.removable = !!strtol(udev_device_get_sysattr_value(disk->device, "removable"), NULL, 10);
|
test = udev_device_get_sysattr_value(disk->device, "removable");
|
||||||
|
if (test) disk->cache.removable = !!strtol(test, NULL, 10);
|
||||||
|
else
|
||||||
|
test = _walk_children_get_attr(disk->syspath, "removable", "block", EINA_FALSE);
|
||||||
|
if (test)
|
||||||
|
{
|
||||||
|
disk->cache.removable = !!strtol(test, NULL, 10);
|
||||||
|
eina_stringshare_del(test);
|
||||||
|
}
|
||||||
|
|
||||||
disk->cache.filled = EINA_TRUE;
|
disk->cache.filled = EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -350,11 +391,20 @@ eeze_disk_type_get(Eeze_Disk *disk)
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
eeze_disk_removable_get(Eeze_Disk *disk)
|
eeze_disk_removable_get(Eeze_Disk *disk)
|
||||||
{
|
{
|
||||||
|
const char *test;
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EINA_FALSE);
|
||||||
|
|
||||||
if (disk->cache.filled)
|
if (disk->cache.filled)
|
||||||
return disk->cache.removable;
|
return disk->cache.removable;
|
||||||
|
|
||||||
disk->cache.removable = !!strtol(udev_device_get_sysattr_value(disk->device, "removable"), NULL, 10);
|
test = udev_device_get_sysattr_value(disk->device, "removable");
|
||||||
|
if (test) disk->cache.removable = !!strtol(test, NULL, 10);
|
||||||
|
else
|
||||||
|
test = _walk_children_get_attr(disk->syspath, "removable", "block", EINA_FALSE);
|
||||||
|
if (test)
|
||||||
|
{
|
||||||
|
disk->cache.removable = !!strtol(test, NULL, 10);
|
||||||
|
eina_stringshare_del(test);
|
||||||
|
}
|
||||||
return disk->cache.removable;
|
return disk->cache.removable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,25 +77,76 @@ _walk_parents_test_attr(_udev_device *device,
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
_walk_parents_get_attr(_udev_device *device,
|
_walk_parents_get_attr(_udev_device *device,
|
||||||
const char *sysattr)
|
const char *sysattr,
|
||||||
|
Eina_Bool property)
|
||||||
{
|
{
|
||||||
_udev_device *parent, *child = device;
|
_udev_device *parent, *child = device;
|
||||||
const char *test;
|
const char *test;
|
||||||
|
|
||||||
if ((test = udev_device_get_sysattr_value(device, sysattr)))
|
if (property)
|
||||||
return eina_stringshare_add(test);
|
test = udev_device_get_property_value(device, sysattr);
|
||||||
|
else
|
||||||
|
test = udev_device_get_sysattr_value(device, sysattr);
|
||||||
|
if (test) return eina_stringshare_add(test);
|
||||||
|
|
||||||
parent = udev_device_get_parent(child);
|
parent = udev_device_get_parent(child);
|
||||||
|
|
||||||
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
||||||
{
|
{
|
||||||
if ((test = udev_device_get_sysattr_value(parent, sysattr)))
|
if (property)
|
||||||
return eina_stringshare_add(test);
|
test = udev_device_get_property_value(parent, sysattr);
|
||||||
|
else
|
||||||
|
test = udev_device_get_sysattr_value(parent, sysattr);
|
||||||
|
if (test) return eina_stringshare_add(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
_walk_children_get_attr(const char *syspath,
|
||||||
|
const char *sysattr,
|
||||||
|
const char *subsystem,
|
||||||
|
Eina_Bool property)
|
||||||
|
{
|
||||||
|
char buf[PATH_MAX];
|
||||||
|
const char *path, *ret = NULL;
|
||||||
|
_udev_enumerate *en;
|
||||||
|
_udev_list_entry *devs, *cur;
|
||||||
|
|
||||||
|
en = udev_enumerate_new((udev));
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN_VAL(en, NULL);
|
||||||
|
path = strrchr(syspath, '/');
|
||||||
|
if (path) path++;
|
||||||
|
else path = syspath;
|
||||||
|
snprintf(buf, sizeof(buf), "%s*", path);
|
||||||
|
udev_enumerate_add_match_sysname(en, buf);
|
||||||
|
if (subsystem) udev_enumerate_add_match_subsystem(en, subsystem);
|
||||||
|
udev_enumerate_scan_devices(en);
|
||||||
|
devs = udev_enumerate_get_list_entry(en);
|
||||||
|
udev_list_entry_foreach(cur, devs)
|
||||||
|
{
|
||||||
|
const char *devname, *test;
|
||||||
|
_udev_device *device;
|
||||||
|
|
||||||
|
devname = udev_list_entry_get_name(cur);
|
||||||
|
device = _new_device(devname);
|
||||||
|
if (property)
|
||||||
|
test = udev_device_get_property_value(device, sysattr);
|
||||||
|
else
|
||||||
|
test = udev_device_get_sysattr_value(device, sysattr);
|
||||||
|
if (test)
|
||||||
|
{
|
||||||
|
ret = eina_stringshare_add(test);
|
||||||
|
udev_device_unref(device);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
udev_device_unref(device);
|
||||||
|
}
|
||||||
|
udev_enumerate_unref(en);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check a list for all parents of a device,
|
* check a list for all parents of a device,
|
||||||
* stringshare adding all devices that are not in the list
|
* stringshare adding all devices that are not in the list
|
||||||
|
|
|
@ -34,8 +34,9 @@ typedef struct udev_monitor _udev_monitor;
|
||||||
extern _udev *udev;
|
extern _udev *udev;
|
||||||
|
|
||||||
_udev_device *_new_device(const char *syspath);
|
_udev_device *_new_device(const char *syspath);
|
||||||
|
const char *_walk_children_get_attr(const char *syspath, const char *sysattr, const char *subsystem, Eina_Bool property);
|
||||||
Eina_Bool _walk_parents_test_attr(_udev_device *device, const char *sysattr, const char* value);
|
Eina_Bool _walk_parents_test_attr(_udev_device *device, const char *sysattr, const char* value);
|
||||||
const char *_walk_parents_get_attr(_udev_device *device, const char *sysattr);
|
const char *_walk_parents_get_attr(_udev_device *device, const char *sysattr, Eina_Bool property);
|
||||||
Eina_List *_get_unlisted_parents(Eina_List *list, _udev_device *device);
|
Eina_List *_get_unlisted_parents(Eina_List *list, _udev_device *device);
|
||||||
_udev_device *_copy_device(_udev_device *device);
|
_udev_device *_copy_device(_udev_device *device);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue