[podsleuth] Do the bare minimum to get working with DeviceKit
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [podsleuth] Do the bare minimum to get working with DeviceKit
- Date: Wed, 9 Dec 2009 02:20:20 +0000 (UTC)
commit 8c1dda626d331b0b7e40ef21e7a828dfc195dd25
Author: Gabriel Burt <gabriel burt gmail com>
Date: Tue Dec 8 18:09:15 2009 -0800
Do the bare minimum to get working with DeviceKit
Is not fully ported to DeviceKit; still relies on HAL extensively.
But makes podsleuth work where DeviceKit is actually mounting the
drive but HAL still is running. The problem was podsleuth was reading
HAL's volume.is_mounted property, which was false since DK had mounted
it.
src/PodSleuth.Hal/PodSleuth.HalFrontend/DkDisk.cs | 88 ++++++++++++++++++++
.../PodSleuth.HalFrontend/HalClient.cs | 44 +++++++++-
.../PodSleuth.HalFrontend/HalPopulator.cs | 7 +-
3 files changed, 133 insertions(+), 6 deletions(-)
---
diff --git a/src/PodSleuth.Hal/PodSleuth.HalFrontend/DkDisk.cs b/src/PodSleuth.Hal/PodSleuth.HalFrontend/DkDisk.cs
new file mode 100644
index 0000000..16d05f7
--- /dev/null
+++ b/src/PodSleuth.Hal/PodSleuth.HalFrontend/DkDisk.cs
@@ -0,0 +1,88 @@
+using System;
+
+using NDesk.DBus;
+
+namespace PodSleuth.HalFrontend
+{
+ public class DkDisk
+ {
+ public static DkDisk FindByDevice (string device_path)
+ {
+ if (device_path == null)
+ return null;
+
+ if (disks == null)
+ return null;
+
+
+ string disk_path = null;
+ try {
+ disk_path = disks.FindDeviceByDeviceFile (device_path);
+ } catch {}
+
+ if (disk_path == null)
+ return null;
+
+ try {
+ return new DkDisk (disk_path);
+ } catch {}
+
+ return null;
+ }
+
+ private IDkDisk disk;
+ private org.freedesktop.DBus.Properties props;
+
+ private DkDisk (string obj_path)
+ {
+ disk = Bus.System.GetObject<IDkDisk>("org.freedesktop.DeviceKit.Disks",
+ new ObjectPath(obj_path));
+
+ props = Bus.System.GetObject<org.freedesktop.DBus.Properties>("org.freedesktop.DeviceKit.Disks",
+ new ObjectPath(obj_path));
+ }
+
+ public bool IsMounted {
+ get {
+ return (bool) props.Get ("org.freedesktop.DeviceKit.Disks.Device", "DeviceIsMounted");
+ }
+ }
+
+ public bool IsReadOnly {
+ get {
+ return (bool) props.Get ("org.freedesktop.DeviceKit.Disks.Device", "DeviceIsReadOnly");
+ }
+ }
+
+ public string MountPoint {
+ get {
+ var ary = (string[])props.Get ("org.freedesktop.DeviceKit.Disks.Device", "DeviceMountPaths");
+ return ary != null && ary.Length > 0 ? ary[0] : null;
+ }
+ }
+
+ private static IDkDisks disks;
+
+ static DkDisk ()
+ {
+ try {
+ disks = Bus.System.GetObject<IDkDisks>("org.freedesktop.DeviceKit.Disks",
+ new ObjectPath("/org/freedesktop/DeviceKit/Disks"));
+ } catch {}
+ }
+
+ [Interface("org.freedesktop.DeviceKit.Disks")]
+ internal interface IDkDisks
+ {
+ string FindDeviceByDeviceFile (string deviceFile);
+ }
+
+ }
+
+ [Interface("org.freedesktop.DeviceKit.Disks.Device")]
+ public interface IDkDisk
+ {
+ bool DeviceIsMounted { get; }
+ string [] DeviceMountPaths { get; }
+ }
+}
diff --git a/src/PodSleuth.Hal/PodSleuth.HalFrontend/HalClient.cs b/src/PodSleuth.Hal/PodSleuth.HalFrontend/HalClient.cs
index ce83f27..aebb742 100644
--- a/src/PodSleuth.Hal/PodSleuth.HalFrontend/HalClient.cs
+++ b/src/PodSleuth.Hal/PodSleuth.HalFrontend/HalClient.cs
@@ -85,9 +85,8 @@ namespace PodSleuth.HalFrontend
foreach(Hal.Device ipod in manager.FindDeviceByStringMatchAsDevice("info.product", "iPod")) {
foreach(Hal.Device volume in ipod.GetChildrenAsDevice(manager)) {
if(!volume.IsVolume ||
- !volume.PropertyExists("volume.is_mounted") ||
+ !IsVolumeMounted (volume) ||
!volume.PropertyExists("volume.fsusage") ||
- !volume.GetPropertyBoolean("volume.is_mounted") ||
volume.GetPropertyString("volume.fsusage") != "filesystem") {
continue;
}
@@ -132,7 +131,7 @@ namespace PodSleuth.HalFrontend
Console.WriteLine(" Error: {0}* properties are missing", HalNamespace);
Console.WriteLine(" UDI: {0}", volume.Udi);
Console.WriteLine(" Block Device: {0}", volume.GetPropertyString("block.device"));
- Console.WriteLine(" Mount Point: {0}", volume.GetPropertyString("volume.mount_point"));
+ Console.WriteLine(" Mount Point: {0}", MountPoint (volume));
Console.WriteLine();
Console.WriteLine(" Cause: PodSleuth may not be installed properly, the HAL daemon may need");
Console.WriteLine(" to be restarted and/or the device needs to be refreshed.");
@@ -150,9 +149,46 @@ namespace PodSleuth.HalFrontend
DumpSleuthableIpod(volume);
}
+
+ private static bool IsVolumeMounted(Hal.Device volume)
+ {
+ bool is_mounted = false;
+
+ var dk_disk = DkDisk.FindByDevice (volume["block.device"] as string);
+ if (dk_disk != null) {
+ is_mounted = dk_disk.IsMounted;
+ }
+
+ if (!is_mounted && volume.PropertyExists("volume.is_mounted")) {
+ is_mounted = volume.GetPropertyBoolean("volume.is_mounted");
+ }
+
+ return is_mounted;
+ }
+
+ private static string MountPoint (Hal.Device volume)
+ {
+ string mount_point = null;
+
+ var dk_disk = DkDisk.FindByDevice (volume["block.device"] as string);
+ if (dk_disk != null) {
+ mount_point = dk_disk.MountPoint;
+ }
+
+ if (mount_point == null) {
+ mount_point = volume["volume.mount_point"];
+ }
+
+ return mount_point;
+ }
private static bool IsVolumeReadOnly(Hal.Volume volume)
{
+ var dk_disk = DkDisk.FindByDevice (volume["block.device"] as string);
+ if (dk_disk != null) {
+ return dk_disk.IsReadOnly;
+ }
+
if(volume.PropertyExists("volume.is_mounted_read_only")) {
return volume.GetPropertyBoolean("volume.is_mounted_read_only");
}
@@ -222,7 +258,7 @@ namespace PodSleuth.HalFrontend
Console.WriteLine("iPod Found [{0}]", volume.Udi);
Console.WriteLine(" * Generic Device Properties");
Console.WriteLine(" - Block Device: {0}", volume["block.device"]);
- Console.WriteLine(" - Mount Point: {0}", volume["volume.mount_point"]);
+ Console.WriteLine(" - Mount Point: {0}", MountPoint (volume));
Console.WriteLine(" - Read Only: {0}", IsVolumeReadOnly(volume));
Console.WriteLine(" - Volume Size: {0}", GetVolumeSizeString(volume));
Console.WriteLine(" * General iPod Properties");
diff --git a/src/PodSleuth.Hal/PodSleuth.HalFrontend/HalPopulator.cs b/src/PodSleuth.Hal/PodSleuth.HalFrontend/HalPopulator.cs
index 72e3787..13a393b 100644
--- a/src/PodSleuth.Hal/PodSleuth.HalFrontend/HalPopulator.cs
+++ b/src/PodSleuth.Hal/PodSleuth.HalFrontend/HalPopulator.cs
@@ -14,6 +14,7 @@ namespace PodSleuth.HalFrontend
private const string HalNamespace = "org.podsleuth.";
private static Hal.Device hal_device;
+ private static DkDisk dk_disk;
private static PodSleuth.Device pod_device;
private static string mount_point;
private static string fs_type;
@@ -52,15 +53,17 @@ namespace PodSleuth.HalFrontend
}
hal_device = new Hal.Device(HalEnvironment.Udi);
+
+ dk_disk = DkDisk.FindByDevice (HalEnvironment.BlockDevice ?? hal_device["block.device"]);
- bool private_mount = !hal_device.GetPropertyBoolean("volume.is_mounted");
+ bool private_mount = !(hal_device.GetPropertyBoolean("volume.is_mounted") || (dk_disk != null && dk_disk.IsMounted));
if(private_mount) {
mount_point = LowLevelMount.GenerateMountPoint();
fs_type = hal_device["volume.fstype"];
LowLevelMount.Mount(HalEnvironment.BlockDevice, mount_point, fs_type, true);
} else {
- mount_point = hal_device["volume.mount_point"];
+ mount_point = dk_disk == null ? hal_device["volume.mount_point"] : dk_disk.MountPoint;
}
pod_device = new PodSleuth.Device(HalEnvironment.BlockDevice, mount_point);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]