#include <errno.h>
#include <dirent.h>
-#define DELAYED_VERIFY 1
-
-#define VOL_ID_TOOL_PATHS { "/sbin/vol_id", "/lib/udev/vol_id", NULL}
+/*
+** verify devices names as late as possible (while attach)
+*/
+#define DELAYED_VERIFY 1
using namespace std;
for(it = dlist.begin(); it != dlist.end(); ++it)
{
PathInfo vol_info(*it);
- if( vol_info.isBlk() && vol_info.major() == dev_info.major() &&
- vol_info.minor() == dev_info.minor())
+ if( vol_info.isBlk() && vol_info.devMajor() == dev_info.devMajor() &&
+ vol_info.devMinor() == dev_info.devMinor())
{
DBG << "Specified device name " << dev_name
<< " is a volume (disk/by-uuid link "
for(it = dlist.begin(); it != dlist.end(); ++it)
{
PathInfo vol_info(*it);
- if( vol_info.isBlk() && vol_info.major() == dev_info.major() &&
- vol_info.minor() == dev_info.minor())
+ if( vol_info.isBlk() && vol_info.devMajor() == dev_info.devMajor() &&
+ vol_info.devMinor() == dev_info.devMinor())
{
DBG << "Specified device name " << dev_name
<< " is a volume (disk/by-label link "
}
}
- // check if a filesystem volume using the /sbin/vol_id tool
+ // check if a filesystem volume using the 'blkid' tool
// (there is no /dev/disk link for some of them)
- for(const char *vol_id_paths[] = VOL_ID_TOOL_PATHS,
- **vol_id_path = vol_id_paths;
- vol_id_path != NULL && *vol_id_path != NULL;
- vol_id_path++)
+ ExternalProgram::Arguments args;
+ args.push_back( "blkid" );
+ args.push_back( "-p" );
+ args.push_back( dev_name.asString() );
+
+ ExternalProgram cmd( args, ExternalProgram::Stderr_To_Stdout );
+ cmd >> DBG;
+ if ( cmd.close() != 0 )
{
- PathInfo vol_id_info(*vol_id_path);
- if( !vol_id_info.isFile() || !vol_id_info.isXUsr())
- continue;
-
- const char *cmd[3];
- cmd[0] = *vol_id_path;
- cmd[1] = dev_name.asString().c_str();
- cmd[2] = NULL;
-
- ExternalProgram vol_id(cmd, ExternalProgram::Stderr_To_Stdout);
-
- std::string vol_fs_usage;
- std::string vol_fs_uuid;
- std::string vol_fs_type;
-
- for(std::string out( vol_id.receiveLine());
- out.length(); out = vol_id.receiveLine())
- {
- out = str::rtrim(out);
-
- if( out.compare(0, sizeof("ID_FS_USAGE=")-1, "ID_FS_USAGE=") == 0)
- {
- vol_fs_usage = out.substr(sizeof("ID_FS_USAGE=")-1);
- }
- else
- if( out.compare(0, sizeof("ID_FS_TYPE=")-1, "ID_FS_TYPE=") == 0)
- {
- vol_fs_type = out.substr(sizeof("ID_FS_TYPE=")-1);
- }
- else
- if( out.compare(0, sizeof("ID_FS_UUID=")-1, "ID_FS_UUID=") == 0)
- {
- vol_fs_uuid = out.substr(sizeof("ID_FS_UUID=")-1);
- }
- }
-
- if( vol_id.close() == 0)
- {
- if( vol_fs_usage == "filesystem")
- {
- if(vol_fs_type == "iso9660" || vol_fs_type == "udf")
- {
- DBG << "Specified device name " << dev_name
- << " is a CD/DVD volume (type " << vol_fs_type << ")"
- << std::endl;
- return true;
- }
- else
- if(!vol_fs_type.empty() && !vol_fs_uuid.empty())
- {
- DBG << "Specified device name " << dev_name
- << " is a volume (type " << vol_fs_type
- << ", uuid " << vol_fs_uuid << ")"
- << std::endl;
- return true;
- }
- }
- }
+ ERR << cmd.execError() << endl
+ << "Specified device name " << dev_name
+ << " is not a usable disk volume"
+ << std::endl;
+ return false;
}
-
- ERR << "Specified device name " << dev_name
- << " is not a usable disk volume"
- << std::endl;
- return false;
+ return true;
}
///////////////////////////////////////////////////////////////////
// mount /dev/<partition> /tmp_mount
// mount /tmp_mount/<dir> <to> --bind -o ro
// FIXME: try all filesystems
-
+
if(_device.empty())
ZYPP_THROW(MediaBadUrlEmptyDestinationException(url()));
-
+
PathInfo dev_info(_device);
if(!dev_info.isBlk())
ZYPP_THROW(MediaBadUrlEmptyDestinationException(url()));
ZYPP_THROW(MediaBadUrlEmptyFilesystemException(url()));
MediaSourceRef media( new MediaSource(
- "disk", _device, dev_info.major(), dev_info.minor()
+ "disk", _device, dev_info.devMajor(), dev_info.devMinor()
));
AttachedMedia ret( findAttachedMedia( media));
is_device = true;
}
- if( is_device && media->maj_nr == dev_info.major() &&
- media->min_nr == dev_info.minor())
+ if( is_device && media->maj_nr == dev_info.devMajor() &&
+ media->min_nr == dev_info.devMinor())
{
- /*
- if( _filesystem != "auto" && _filesystem != e->type)
+ AttachPointRef ap( new AttachPoint(e->dir, false));
+ AttachedMedia am( media, ap);
{
- ZYPP_THROW();
+ DBG << "Using a system mounted media "
+ << media->name
+ << " attached on "
+ << ap->path
+ << endl;
+
+ media->iown = false; // mark attachment as foreign
+
+ setMediaSource(media);
+ setAttachPoint(ap);
+ return;
}
- */
- media->bdir = e->dir;
}
}
- Mount mount;
- std::string mountpoint = attachPoint().asString();
- if( !isUseableAttachPoint(attachPoint()))
+ if( !isUseableAttachPoint( attachPoint() ) )
{
- mountpoint = createAttachPoint().asString();
- if( mountpoint.empty())
- ZYPP_THROW( MediaBadAttachPointException(url()));
- setAttachPoint( mountpoint, true);
+ setAttachPoint( createAttachPoint(), true );
}
+ std::string mountpoint( attachPoint().asString() );
+ Mount mount;
string options = _url.getQueryParam("mountoptions");
if(options.empty())
{
//
// DESCRIPTION : Asserted that media is attached.
//
- void MediaDISK::releaseFrom( bool eject )
+ void MediaDISK::releaseFrom( const std::string & ejectDev )
{
- Mount mount;
- mount.umount(attachPoint().asString());
+ AttachedMedia am( attachedMedia());
+ if(am.mediaSource && am.mediaSource->iown)
+ {
+ Mount mount;
+ mount.umount(attachPoint().asString());
+ }
}
-
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : MediaDISK::getFile
{
MediaHandler::getFile( filename );
}
-
+
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : MediaDISK::getDir
{
MediaHandler::getDir( dirname, recurse_r );
}
-
+
///////////////////////////////////////////////////////////////////
//
//
{
MediaHandler::getDirInfo( retlist, dirname, dots );
}
-
+
///////////////////////////////////////////////////////////////////
//
//
bool MediaDISK::getDoesFileExist( const Pathname & filename ) const
{
return MediaHandler::getDoesFileExist( filename );
- }
-
+ }
+
} // namespace media
} // namespace zypp
// vim: set ts=8 sts=2 sw=2 ai noet: