我正在使用 libhal 来检测设备事件。我能够检测到添加或删除的设备,但无法检测到设备的挂载点。该功能libhal_volume_get_mount_point(volume)
不起作用。
我有一个回调函数来检测设备添加:
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,返回 NULL。
您知道在 C 中检测存储设备挂载点的任何合适方法吗?
更新
我已经设法通过搜索找到了设备的挂载点,/etc/mtab
但仍然存在一个小问题。我假设设备只有一个分区。
如何获取存储设备上的分区列表?所以我可以找到每个的挂载点。