From 8265a09d202cb9c2257647e31bbe1218cde5718b Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Fri, 31 Mar 2006 14:39:29 +0000 Subject: [PATCH] - Implemented check if media (CD) is automounted or not - updated libzypp.changes --- package/libzypp.changes | 5 ++-- zypp/media/MediaCD.cc | 52 +++++++++++++++++++++++++++++++-- zypp/media/MediaCD.h | 2 ++ zypp/media/MediaHandler.cc | 73 +++++++++++++++++++++++++++++++++------------- zypp/media/MediaHandler.h | 7 +++-- 5 files changed, 112 insertions(+), 27 deletions(-) diff --git a/package/libzypp.changes b/package/libzypp.changes index 6dde66d..49fe6ea 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,9 +1,10 @@ ------------------------------------------------------------------- -Fri Mar 31 14:28:14 CEST 2006 - mt@suse.de +Fri Mar 31 16:34:51 CEST 2006 - mt@suse.de - Added disabling of the automounter while MediaManager init and restoring of the old state on exit (#154326). -- rev 2833 +- Implemented check if media (CD) is automounted or not +- rev 2840 ------------------------------------------------------------------- Fri Mar 31 13:27:09 CEST 2006 - mt@suse.de diff --git a/zypp/media/MediaCD.cc b/zypp/media/MediaCD.cc index a12b01e..6cd2698 100644 --- a/zypp/media/MediaCD.cc +++ b/zypp/media/MediaCD.cc @@ -31,8 +31,20 @@ #include +/* +** verify devices names as late as possible (while attach) +*/ #define DELAYED_VERIFY 1 + +/* +** try umount of foreign (user/automounter) media on eject +** 0 = don't force, 1 = automounted only, 2 == all +*/ #define FORCE_RELEASE_FOREIGN 1 + +/* +** if to throw exception on eject errors or ignore them +*/ #define REPORT_EJECT_ERRORS 1 using namespace std; @@ -505,7 +517,7 @@ namespace zypp { if (eject) { #if FORCE_RELEASE_FOREIGN - forceRelaseAllMedia(false); + forceRelaseAllMedia(false, FORCE_RELEASE_FOREIGN != 2); #endif if(openTray( mediaSourceName())) return; @@ -517,7 +529,7 @@ namespace zypp { if (eject) { #if FORCE_RELEASE_FOREIGN - forceRelaseAllMedia(false); + forceRelaseAllMedia(false, FORCE_RELEASE_FOREIGN != 2); #endif if( !openTray( mediaSourceName() )) { @@ -610,7 +622,7 @@ namespace zypp { if( !ret.mediaSource) { #if FORCE_RELEASE_FOREIGN - forceRelaseAllMedia(media, false); + forceRelaseAllMedia(media, false, FORCE_RELEASE_FOREIGN != 2); #endif if ( openTray( it->name ) ) { @@ -628,6 +640,40 @@ namespace zypp { } } + bool MediaCD::isAutoMountedMedia(const AttachedMedia &media) + { + bool is_automounted = false; + if( media.mediaSource && !media.mediaSource->name.empty()) + { + using namespace zypp::target::hal; + + try + { + HalContext hal(true); + + HalVolume vol = hal.getVolumeFromDeviceFile(media.mediaSource->name); + if( vol) + { + std::string udi = vol.getUDI(); + std::string key = "info.hal_mount.created_mount_point"; + std::string mnt = hal.getDevicePropertyString(udi, key); + + if(media.attachPoint->path == mnt) + is_automounted = true; + } + } + catch(const HalException &e) + { + ZYPP_CAUGHT(e); + } + } + DBG << "Media " << media.mediaSource->asString() + << " attached on " << media.attachPoint->path + << " is" << (is_automounted ? "" : " not") + << " automounted" << std::endl; + return is_automounted; + } + /////////////////////////////////////////////////////////////////// // // METHOD NAME : MediaCD::isAttached diff --git a/zypp/media/MediaCD.h b/zypp/media/MediaCD.h index 4a39e43..4f50ee6 100644 --- a/zypp/media/MediaCD.h +++ b/zypp/media/MediaCD.h @@ -47,6 +47,8 @@ namespace zypp { virtual void forceEject(); + virtual bool isAutoMountedMedia(const AttachedMedia &media); + public: MediaCD( const Url & url_r, diff --git a/zypp/media/MediaHandler.cc b/zypp/media/MediaHandler.cc index c6e2fc1..362996d 100644 --- a/zypp/media/MediaHandler.cc +++ b/zypp/media/MediaHandler.cc @@ -624,13 +624,13 @@ void MediaHandler::release( bool eject ) } catch(const MediaNotEjectedException &e) { - if( !isAttached()) - { - // not ejected because our - // attach point is busy - _mediaSource.reset(NULL); - removeAttachPoint(); - } + // not ejected because the media + // is mounted by somebody else + // (if our attach point is busy, + // we get an umount exception) + _mediaSource.reset(NULL); + removeAttachPoint(); + // OK, retrow now ZYPP_RETHROW(e); } _mediaSource.reset(NULL); @@ -655,13 +655,13 @@ void MediaHandler::release( bool eject ) } catch(const MediaNotEjectedException &e) { - if( !isAttached()) - { - // not ejected because our - // attach point is busy - _mediaSource.reset(NULL); - removeAttachPoint(); - } + // not ejected because the media + // is mounted by somebody else + // (if our attach point is busy, + // we get an umount exception) + _mediaSource.reset(NULL); + removeAttachPoint(); + // OK, retrow now ZYPP_RETHROW(e); } _mediaSource.reset(NULL); @@ -675,13 +675,20 @@ void MediaHandler::release( bool eject ) MIL << "Released: " << *this << endl; } -void MediaHandler::forceRelaseAllMedia(bool matchMountFs) +bool MediaHandler::isAutoMountedMedia(const AttachedMedia &media) { - forceRelaseAllMedia( attachedMedia().mediaSource, matchMountFs); + (void)media; + return false; +} + +void MediaHandler::forceRelaseAllMedia(bool matchMountFs, bool autoMountedOny) +{ + forceRelaseAllMedia( attachedMedia().mediaSource, matchMountFs, autoMountedOny); } void MediaHandler::forceRelaseAllMedia(const MediaSourceRef &ref, - bool matchMountFs) + bool matchMountFs, + bool autoMountedOny) { if( !ref) return; @@ -707,12 +714,25 @@ void MediaHandler::forceRelaseAllMedia(const MediaSourceRef &ref, if( ref->equals( media) && e->type != "subfs") { + if(autoMountedOny) + { + try { + AttachedMedia am(MediaSourceRef(new MediaSource(media)), + AttachPointRef(new AttachPoint(e->dir))); + if( !isAutoMountedMedia(am)) + continue; + } + catch(...) + { + continue; + } + } DBG << "Forcing release of media device " << ref->asString() << " in the mount table as " << e->src << std::endl; - Mount mount; try { + Mount mount; mount.umount(e->dir); } catch (const Exception &e) @@ -726,14 +746,27 @@ void MediaHandler::forceRelaseAllMedia(const MediaSourceRef &ref, { std::string mtype(matchMountFs ? e->type : ref->type); MediaSource media(mtype, e->src); - if( ref->equals( media) && e->type != "subfs") + if( ref->equals( media)) { + if(autoMountedOny) + { + try { + AttachedMedia am(MediaSourceRef(new MediaSource(media)), + AttachPointRef(new AttachPoint(e->dir))); + if( !isAutoMountedMedia(am)) + continue; + } + catch(...) + { + continue; + } + } DBG << "Forcing release of media name " << ref->asString() << " in the mount table as " << e->src << std::endl; - Mount mount; try { + Mount mount; mount.umount(e->dir); } catch (const Exception &e) diff --git a/zypp/media/MediaHandler.h b/zypp/media/MediaHandler.h index 3830176..ca1775f 100644 --- a/zypp/media/MediaHandler.h +++ b/zypp/media/MediaHandler.h @@ -271,9 +271,12 @@ class MediaHandler { * mount table (nfs, smb and cifs) or from mediaSource * while compare of a mount entry with mediaSource. */ - void forceRelaseAllMedia(bool matchMountFs); + void forceRelaseAllMedia(bool matchMountFs, + bool autoMountedOny=true); void forceRelaseAllMedia(const MediaSourceRef &ref, - bool matchMountFs); + bool matchMountFs, + bool autoMountedOnly=true); + virtual bool isAutoMountedMedia(const AttachedMedia &media); protected: -- 2.7.4