23#include <zypp-media/Mount>
26#include <zypp-media/MediaException>
42 str <<
obj.src <<
" on " <<
obj.dir <<
" type " <<
obj.type;
43 if ( !
obj.opts.empty() )
44 str <<
" (" <<
obj.opts <<
")";
63 const std::string & target,
64 const std::string & filesystem,
65 const std::string & options,
68 const char *
const argv[] = {
71 "-o", options.c_str(),
82 value = std::move(
output );
83 DBG <<
"stdout: " << value << endl;
85 if ( value.find(
"is already mounted on" ) != std::string::npos ) {
86 err =
"Media already mounted";
88 else if ( value.find(
"ermission denied" ) != std::string::npos ) {
89 err =
"Permission denied";
91 else if ( value.find(
"wrong fs type" ) != std::string::npos ) {
92 err =
"Invalid filesystem on media";
94 else if ( value.find(
"No medium found" ) != std::string::npos ) {
95 err =
"No medium found";
97 else if ( value.find(
"Not a directory" ) != std::string::npos ) {
99 err =
"NFS path is not a directory";
102 err =
"Unable to find directory on the media";
106 int exitCode =
prog.close();
108 if ( exitCode != 0 ) {
109 if ( err.empty() ) err =
"Mounting media failed";
110 WAR <<
"mount " << source <<
" " << target <<
": " << exitCode <<
": " << err << endl;
114 MIL <<
"mounted " << source <<
" " << target << endl;
119 const char *
const argv[] = {
133 WAR <<
"umount " << path <<
": " << exitCode <<
": " << err <<
" - retrying in 1 sec." << endl;
139 WAR <<
"umount " << path <<
": " << exitCode <<
": " << err <<
" - giving up" << endl;
149 if (
output.find (
" is busy" ) != std::string::npos ) {
150 err =
"Device is busy";
154 exitCode =
prog.close();
156 }
while( exitCode != 0 &&
doRetry );
158 if ( exitCode != 0 ) {
159 if ( err.empty() ) err =
"Unmounting media failed";
160 WAR <<
"umount " << path <<
": " << exitCode <<
": " << err << endl;
164 MIL <<
"unmounted " << path << endl;
171 MountEntries entries;
172 std::vector<std::string>
mtabs;
177 mtabs.push_back(
"/proc/mounts");
185 mtabs.push_back(
"/etc/mtab");
192 std::vector<std::string>::const_iterator
t;
197 DBG <<
"Reading mount table from '" << *
t <<
"'" << std::endl;
210 if(
ent.mnt_fsname && *
ent.mnt_fsname &&
211 ent.mnt_dir && *
ent.mnt_dir &&
212 ent.mnt_type && *
ent.mnt_type &&
213 ent.mnt_opts && *
ent.mnt_opts)
216 ent.mnt_fsname,
ent.mnt_dir,
217 ent.mnt_type,
ent.mnt_opts,
218 ent.mnt_freq,
ent.mnt_passno
226 if (
entry.src.size() > 1
231 entries.push_back(
entry);
241 WAR <<
"Unable to read any entry from the mount table '" << *
t <<
"'"
255 WAR <<
"Failed to read the mount table '" << *
t <<
"': "
269 WAR <<
"Failed to retrieve modification time of '/etc/mtab'"
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Wrapper class for stat/lstat.
String related utilities and Regular expression matching.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Easy-to use interface to the ZYPP dependency resolver.
std::string asString(const Patch::Category &obj)
A "struct mntent" like mount entry structure, but using std::strings.
std::string src
name of mounted file system
bool isBlockDevice() const
Returns true if the src part points to a block device in /dev.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.