summaryrefslogtreecommitdiff
path: root/hal-automounter.pl
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2011-06-27 21:06:35 +0100
committerdakkar <dakkar@thenautilus.net>2011-06-27 21:07:03 +0100
commitd31cf7d18bd1bcccb4deab0c6256c8a37e1223fc (patch)
tree843812054c0b5d53cfdd47d14e12a11b97608773 /hal-automounter.pl
parentadd locking mechanism (diff)
downloadhal-automounter-d31cf7d18bd1bcccb4deab0c6256c8a37e1223fc.tar.gz
hal-automounter-d31cf7d18bd1bcccb4deab0c6256c8a37e1223fc.tar.bz2
hal-automounter-d31cf7d18bd1bcccb4deab0c6256c8a37e1223fc.zip
use udisks instead of HAL
Diffstat (limited to 'hal-automounter.pl')
-rwxr-xr-xhal-automounter.pl92
1 files changed, 34 insertions, 58 deletions
diff --git a/hal-automounter.pl b/hal-automounter.pl
index 22e8f6f..b26f998 100755
--- a/hal-automounter.pl
+++ b/hal-automounter.pl
@@ -85,9 +85,9 @@ sub remove_from_fstab {
}
my $bus=Net::DBus->system();
-my $hal=$bus->get_service('org.freedesktop.Hal');
+my $udisks=$bus->get_service('org.freedesktop.UDisks');
-my %ignore;my %mounted;
+my %mounted;
sub sanitize {
my ($path)=@_;
@@ -102,80 +102,55 @@ sub safe_get_property {
my ($dev,$prop)=@_;
local $@;
- return eval {$dev->GetProperty($prop)}
+ return eval { $dev->$prop };
}
sub device_added {
- my $dev=$hal->get_object($_[0],'org.freedesktop.Hal.Device');
- my $caps=safe_get_property($dev,'info.capabilities');
- return unless $caps;
- my %caps;@caps{@$caps}=();
-
- if (exists($caps{storage})) {
- my $should_automount=
- safe_get_property($dev,'storage.automount_enabled_hint');
- if (!$should_automount) {
- $ignore{$_[0]}=1;
- }
- return;
- }
+ my $dev=$udisks->get_object($_[0],'org.freedesktop.UDisks.Device');
- if (exists($caps{volume})) {
- my $parent=safe_get_property($dev,'info.parent');
+ return unless safe_get_property($dev,'IdUsage') eq 'filesystem';
+ #return unless safe_get_property($dev,'DeviceIsRemovable');
+ return unless safe_get_property($dev,'DeviceIsMediaAvailable');
+ return if safe_get_property($dev,'DeviceIsMounted');
- if ($ignore{$parent}) {
- warn "ignoring $_[0]\n";
- return;
- }
+ return if exists $mounted{$_[0]};
- if (safe_get_property($dev,'volume.ignore')) {
- warn "ignoring $_[0]\n";
- return;
- }
+ my $uuid=safe_get_property($dev,'IdUuid');
+ my $dev_path=safe_get_property($dev,'DeviceFile')
+ ||($uuid?'/dev/disk/by-uuid/'.$uuid:undef)
+ || 'unknown';
- my $uuid=safe_get_property($dev,'volume.uuid');
-
- my $dev_path=safe_get_property($dev,'linux.device_file')
- ||safe_get_property($dev,'volume.linux.device_file')
- ||($uuid?'/dev/disk/by-uuid/'.$uuid:undef)
- || 'unknown';
- if ($dev_path eq 'unknown') {
- warn "unknown path for $_[0]\n";
- return;
- }
-
- my $usage=safe_get_property($dev,'volume.fsusage');
- return unless $usage eq 'filesystem';
-
- my $label=safe_get_property($dev,'volume.label');
+ if ($dev_path eq 'unknown') {
+ warn "unknown path for $_[0]\n";
+ return;
+ }
- my $fstype=safe_get_property($dev,'volume.fstype');
+ my $label=safe_get_property($dev,'IdLabel');
+ my $fstype=safe_get_property($dev,'IdType');
- return unless defined $fstype;
+ return unless defined $fstype;
- my $mountpoint='/mnt/'.(sanitize($label)||$uuid);
+ my $mountpoint='/mnt/'.(sanitize($label)||$uuid);
- if (-e $mountpoint) {
- $mountpoint.='-0';
- while (-e $mountpoint) {++$mountpoint};
- }
+ if (-e $mountpoint) {
+ $mountpoint.='-0';
+ while (-e $mountpoint) {++$mountpoint};
+ }
- my $manual_mountpoint=add_to_fstab($dev_path,$mountpoint,$fstype,'users,noauto,noatime,nodiratime,nosuid,nodev');
+ my $manual_mountpoint=add_to_fstab($dev_path,$mountpoint,$fstype,'users,noauto,noatime,nodiratime,nosuid,nodev');
- $mountpoint=$manual_mountpoint if defined $manual_mountpoint;
+ $mountpoint=$manual_mountpoint if defined $manual_mountpoint;
- $mounted{$_[0]}=$mountpoint;
- mkdir $mountpoint;
- chown -1,scalar(getgrnam('plugdev')),$mountpoint;
- chmod 0775,$mountpoint;
- }
+ $mounted{$_[0]}=$mountpoint;
+ mkdir $mountpoint;
+ chown -1,scalar(getgrnam('plugdev')),$mountpoint;
+ chmod 0775,$mountpoint;
return;
}
sub device_removed {
- delete $ignore{$_[0]};
if (exists $mounted{$_[0]}) {
system('umount',$mounted{$_[0]});
if (remove_from_fstab($mounted{$_[0]})) {
@@ -188,10 +163,11 @@ sub device_removed {
my $reactor=Net::DBus::Reactor->main();
-my $manager = $hal->get_object('/org/freedesktop/Hal/Manager',
- 'org.freedesktop.Hal.Manager');
+my $manager = $udisks->get_object('/org/freedesktop/UDisks',
+ 'org.freedesktop.UDisks');
$manager->connect_to_signal('DeviceAdded',\&device_added);
+$manager->connect_to_signal('DeviceChanged',\&device_added);
$manager->connect_to_signal('DeviceRemoved',\&device_removed);
$reactor->run();