I am using libhal to detect device events. I am able to detect a device added or removed but I can not detect device's mount point. The function libhal_volume_get_mount_point(volume)
does not work.
I have a callback function to detect device add:
static void handle_device_added(LibHalContext *ctx, const char *udi) {
dbus_bool_t is_storage;
dbus_bool_t is_volume;
is_storage = libhal_device_query_capability(ctx, udi, "storage", NULL);
is_volume = libhal_device_query_capability(ctx, udi, "volume", NULL);
if (is_storage) {
drive = libhal_drive_from_udi(ctx, udi);
if (libhal_drive_is_hotpluggable(drive) || libhal_drive_uses_removable_media(drive)) {
printf("Storage device added %s model %s\n",
libhal_drive_get_device_file(drive),
libhal_drive_get_model(drive));
}
libhal_drive_free(drive);
}
if(is_volume) {
volume = libhal_volume_from_udi(ctx, udi);
printf("Mount point = %s\n", libhal_volume_get_mount_point(volume));
libhal_volume_free(volume);
}
}
libhal_volume_from_udi, returns NULL.
Do you know any suitable way to detect the mount point of a storage device in C?
UPDATE
I have managed to find mount point of the device by searching /etc/mtab
but there is still one little problem. I am assuming the device has one partition only.
How can I get the list of the partition on a storage device? So I can found mount points of each.