diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2008-03-03 18:11:15 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2008-03-03 18:11:15 +0000 |
commit | 7d8f1f74961a7494f28a732b995893a8f8916527 (patch) | |
tree | 4a835cae25e938d6cfb5d4fc3ccfc0178aaa3bdd /lib/Hal/Cdroms.pm | |
parent | 83afe6bd7586cbfc9cca510fa230884b047f6b6e (diff) | |
download | perl-Hal-Cdroms-7d8f1f74961a7494f28a732b995893a8f8916527.tar perl-Hal-Cdroms-7d8f1f74961a7494f28a732b995893a8f8916527.tar.gz perl-Hal-Cdroms-7d8f1f74961a7494f28a732b995893a8f8916527.tar.bz2 perl-Hal-Cdroms-7d8f1f74961a7494f28a732b995893a8f8916527.tar.xz perl-Hal-Cdroms-7d8f1f74961a7494f28a732b995893a8f8916527.zip |
- 0.03: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
Diffstat (limited to 'lib/Hal/Cdroms.pm')
-rw-r--r-- | lib/Hal/Cdroms.pm | 61 |
1 files changed, 55 insertions, 6 deletions
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<hal_path>. -Return the mount point associated to the C<hal_path>, or undef it cannot be mounted successfully (see $hal_cdroms->{error}) +Mount the C<hal_path> through HAL +Return the mount point associated to the C<hal_path>, 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<hal_path> through HAL or fallback to plain mount(8). +Return the mount point associated to the C<hal_path>, 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<hal_path>. 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<hal_path> 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<hal_path>. Return true on success (see $hal_cdroms->{error} on failure) |