From 7d8f1f74961a7494f28a732b995893a8f8916527 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Mon, 3 Mar 2008 18:11:15 +0000 Subject: - 0.03: - ->mount and ->umount now work even the cdrom is listed in fstab, use ->mount_hal and ->umount_hal if you want the HAL restriction --- Changes | 5 +++++ lib/Hal/Cdroms.pm | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index 01f575f..826cc19 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,8 @@ +0.03 Mon Mar 3 19:09:06 CET 2008 + + - ->mount and ->umount now work even the cdrom is listed in fstab, + use ->mount_hal and ->umount_hal if you want the HAL restriction + 0.02 Fri Feb 29 15:28:53 CET 2008 - save error in $hal_cdroms->{error} diff --git a/lib/Hal/Cdroms.pm b/lib/Hal/Cdroms.pm index 0b7e824..1a9f0f1 100644 --- a/lib/Hal/Cdroms.pm +++ b/lib/Hal/Cdroms.pm @@ -1,6 +1,6 @@ package Hal::Cdroms; -our $VERSION = 0.02; +our $VERSION = 0.03; # Copyright (C) 2008 Mandriva # @@ -128,14 +128,15 @@ sub ensure_mounted { } -=head2 $hal_cdroms->mount($hal_path) +=head2 $hal_cdroms->mount_through_hal($hal_path) -Mount the C. -Return the mount point associated to the C, or undef it cannot be mounted successfully (see $hal_cdroms->{error}) +Mount the C through HAL +Return the mount point associated to the C, or undef it cannot be mounted successfully (see $hal_cdroms->{error}). +If the cdrom is listed in fstab, HAL will refuse to mount it. =cut -sub mount { +sub mount_hal { my ($o, $hal_path) = @_; my $device = _get_device($o, $hal_path); @@ -148,19 +149,67 @@ sub mount { eval { $device->GetProperty('volume.mount_point') }; } +=head2 $hal_cdroms->mount($hal_path) + +Mount the C through HAL or fallback to plain mount(8). +Return the mount point associated to the C, or undef it cannot be mounted successfully (see $hal_cdroms->{error}) + +=cut + +sub mount { + my ($o, $hal_path) = @_; + + my $mntpoint = mount_hal($o, $hal_path); + if (!$mntpoint) { + # this usually means HAL refused to mount a cdrom listed in fstab + my $dev = _get_device($o, $hal_path)->GetProperty('block.device'); + if (my $wanted = $dev && _rdev($dev)) { + my ($fstab_dev) = grep { $wanted == _rdev($_) } _fstab_devices(); + system("mount", $fstab_dev) == 0 + and $mntpoint = get_mount_point($o, $hal_path); + } + } + $mntpoint; +} + +sub _rdev { + my ($dev) = @_; + (stat($dev))[6]; +} +sub _fstab_devices() { + open(my $F, '<', '/etc/fstab') or return; + map { /(\S+)/ } <$F>; +} + =head2 $hal_cdroms->unmount($hal_path) Unmount the C. Return true on success (see $hal_cdroms->{error} on failure) +If the cdrom is listed in not mounted by HAL, HAL will refuse to unmount it. =cut -sub unmount { +sub unmount_hal { my ($o, $hal_path) = @_; my $volume = _get_volume($o, $hal_path); _try($o, sub { $volume->Unmount([]) }); } +=head2 $hal_cdroms->unmount($hal_path) + +Unmount the C through HAL or fallback on umount(8). +Return true on success (see $hal_cdroms->{error} on failure) + +=cut + +sub unmount { + my ($o, $hal_path) = @_; + + unmount_hal($o, $hal_path) and return 1; + + system('umount', get_mount_point($o, $hal_path)) == 0; +} + =head2 $hal_cdroms->eject($hal_path) Ejects the C. Return true on success (see $hal_cdroms->{error} on failure) -- cgit v1.2.1