From 970a955dd371ea76b02cc618d8eb99594827ad79 Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Fri, 17 Nov 2006 11:41:14 +0000 Subject: [PATCH] - Implemented an reuse of already existing foreign CD/DVD mount points (e.g. automounted) - depends on REUSE_FOREIGN_MOUNTS flag (#220206). - Added a fallback check of the volume.mount_point HAL property to isAutoMountedMedia(); info.hal_mount.created_mount_point seems to be not avaliable in newer HAL versions (on 10.2). --- zypp/media/MediaCD.cc | 113 ++++++++++++++++++++++++++++++++++++++++------- zypp/media/MediaSource.h | 4 +- 2 files changed, 100 insertions(+), 17 deletions(-) diff --git a/zypp/media/MediaCD.cc b/zypp/media/MediaCD.cc index b1dbc06..346360b 100644 --- a/zypp/media/MediaCD.cc +++ b/zypp/media/MediaCD.cc @@ -42,7 +42,13 @@ ** try umount of foreign (user/automounter) media on eject ** 0 = don't force, 1 = automounted only, 2 == all */ -#define FORCE_RELEASE_FOREIGN 1 +#define FORCE_RELEASE_FOREIGN 2 + +/* +** Reuse foreign (user/automounter) mount points. +** 0 = don't use, 1 = automounted only, 2 = all +*/ +#define REUSE_FOREIGN_MOUNTS 2 /* ** if to throw exception on eject errors or ignore them @@ -55,6 +61,7 @@ */ #define EJECT_TOOL_PATH "/bin/eject" + using namespace std; namespace zypp { @@ -580,10 +587,56 @@ namespace zypp { mountsucceeded = true; break; } - // FIXME: hmm... we may also - // - check against hal/mtab if still mounted - // - if !ret, check if already mounted (e.g. - // by automounter) and reuse (!temp) ? + +#if REUSE_FOREIGN_MOUNTS > 0 + { + MediaManager manager; + MountEntries entries( manager.getMountEntries()); + MountEntries::const_iterator e; + for( e = entries.begin(); e != entries.end(); ++e) + { + bool is_device = false; + std::string dev_path(Pathname(e->src).asString()); + PathInfo dev_info; + + if( dev_path.compare(0, sizeof("/dev/")-1, "/dev/") == 0 && + dev_info(e->src) && dev_info.isBlk()) + { + is_device = true; + } + + if( is_device && media->maj_nr == dev_info.major() && + media->min_nr == dev_info.minor()) + { + AttachPointRef ap( new AttachPoint(e->dir, false)); + AttachedMedia am( media, ap); + // + // 1 = automounted only, 2 == all + // +#if REUSE_FOREIGN_MOUNTS == 1 + if( isAutoMountedMedia(am)) +#endif + { + DBG << "Using a system mounted media " + << media->name + << " attached on " + << ap->path + << endl; + + media->iown = false; // mark attachment as foreign + + setMediaSource(media); + setAttachPoint(ap); + _lastdev = count; + mountsucceeded = true; + break; + } + } + } + if( mountsucceeded) + break; + } +#endif // REUSE_FOREIGN_MOUNTS // close tray closeTray( it->name ); @@ -684,15 +737,18 @@ namespace zypp { { Mount mount; try { - mount.umount(attachPoint().asString()); + AttachedMedia am( attachedMedia()); + if(am.mediaSource && am.mediaSource->iown) + mount.umount(am.attachPoint->path.asString()); } catch (const Exception & excpt_r) { ZYPP_CAUGHT(excpt_r); if (eject) { -#if FORCE_RELEASE_FOREIGN - forceRelaseAllMedia(false, FORCE_RELEASE_FOREIGN != 2); +#if FORCE_RELEASE_FOREIGN > 0 + /* 1 = automounted only, 2 = all */ + forceRelaseAllMedia(false, FORCE_RELEASE_FOREIGN == 1); #endif if(openTray( mediaSourceName())) return; @@ -703,8 +759,9 @@ namespace zypp { // eject device if (eject) { -#if FORCE_RELEASE_FOREIGN - forceRelaseAllMedia(false, FORCE_RELEASE_FOREIGN != 2); +#if FORCE_RELEASE_FOREIGN > 0 + /* 1 = automounted only, 2 = all */ + forceRelaseAllMedia(false, FORCE_RELEASE_FOREIGN == 1); #endif if( !openTray( mediaSourceName() )) { @@ -796,8 +853,9 @@ namespace zypp { AttachedMedia ret( findAttachedMedia( media)); if( !ret.mediaSource) { -#if FORCE_RELEASE_FOREIGN - forceRelaseAllMedia(media, false, FORCE_RELEASE_FOREIGN != 2); +#if FORCE_RELEASE_FOREIGN > 0 + /* 1 = automounted only, 2 = all */ + forceRelaseAllMedia(media, false, FORCE_RELEASE_FOREIGN == 1); #endif if ( openTray( it->name ) ) { @@ -830,11 +888,34 @@ namespace zypp { if( vol) { std::string udi = vol.getUDI(); - std::string key = "info.hal_mount.created_mount_point"; - std::string mnt = hal.getDevicePropertyString(udi, key); + std::string key; + std::string mnt; + + try + { + key = "info.hal_mount.created_mount_point"; + mnt = hal.getDevicePropertyString(udi, key); + + if(media.attachPoint->path == mnt) + is_automounted = true; + } + catch(const HalException &e1) + { + ZYPP_CAUGHT(e1); - if(media.attachPoint->path == mnt) - is_automounted = true; + try + { + key = "volume.mount_point"; + mnt = hal.getDevicePropertyString(udi, key); + + if(media.attachPoint->path == mnt) + is_automounted = true; + } + catch(const HalException &e2) + { + ZYPP_CAUGHT(e2); + } + } } } catch(const HalException &e) diff --git a/zypp/media/MediaSource.h b/zypp/media/MediaSource.h index 5e18973..c39f0c6 100644 --- a/zypp/media/MediaSource.h +++ b/zypp/media/MediaSource.h @@ -36,12 +36,13 @@ namespace zypp { public: MediaSource(const std::string &_type, const std::string &_name, unsigned int _maj=0, unsigned int _min=0, - const std::string &_bdir=std::string()) + const std::string &_bdir=std::string(), bool _own=true) : maj_nr(_maj) , min_nr(_min) , type(_type) , name(_name) , bdir(_bdir) + , iown(_own) {} MediaSource() @@ -88,6 +89,7 @@ namespace zypp { std::string type; //!< A media handler specific source type. std::string name; //!< A media handler specific source name. std::string bdir; //!< Directory, the media may be bound to. + bool iown; //!< True, if mounted by media manager. }; -- 2.7.4