41 str << obj.
src <<
" on " << obj.
dir <<
" type " << obj.
type;
42 if ( ! obj.
opts.empty() )
43 str <<
" (" << obj.
opts <<
")";
56 MIL <<
"~Mount()" << endl;
63 MIL <<
"~Mount() end" << endl;
66 void Mount::mount(
const std::string & source,
67 const std::string & target,
68 const std::string & filesystem,
69 const std::string & options,
72 const char *
const argv[] = {
74 "-t", filesystem.c_str(),
75 "-o", options.c_str(),
83 this->run(argv, environment, ExternalProgram::Stderr_To_Stdout);
85 if ( process == NULL )
91 string output = process->receiveLine();
94 while ( output.length() > 0)
99 ret = output.find_first_of (
"\n" );
100 if ( ret != string::npos )
102 value.assign ( output, 0, ret );
109 DBG <<
"stdout: " << value << endl;
111 if ( value.find (
"is already mounted on" ) != string::npos )
113 err =
"Media already mounted";
115 else if ( value.find (
"ermission denied" ) != string::npos )
117 err =
"Permission denied";
119 else if ( value.find (
"wrong fs type" ) != string::npos )
121 err =
"Invalid filesystem on media";
123 else if ( value.find (
"No medium found" ) != string::npos )
125 err =
"No medium found";
127 else if ( value.find (
"Not a directory" ) != string::npos )
129 if( filesystem ==
"nfs" || filesystem ==
"nfs4" )
131 err =
"Nfs path is not a directory";
135 err =
"Unable to find directory on the media";
139 output = process->receiveLine();
149 else if ( status != 0 && err ==
"" )
151 err =
"Mounting media failed";
155 WAR <<
"mount " << source <<
" " << target <<
": " << err << endl;
158 MIL <<
"mounted " << source <<
" " << target << endl;
162 void Mount::umount(
const std::string & path )
164 const char *
const argv[] = {
172 this->run(argv, ExternalProgram::Stderr_To_Stdout);
174 if ( process == NULL )
180 string output = process->receiveLine();
183 while ( output.length() > 0)
188 ret = output.find_first_of (
"\n" );
189 if ( ret != string::npos )
191 value.assign ( output, 0, ret );
198 DBG <<
"stdout: " << value << endl;
205 if ( value.find (
"device is busy" ) != string::npos )
207 err =
"Device is busy";
210 output = process->receiveLine();
220 else if ( status != 0 && err ==
"" )
222 err =
"Unmounting media failed";
226 WAR <<
"umount " << path <<
": " << err << endl;
229 MIL <<
"unmounted " << path << endl;
233 void Mount::run(
const char *
const *argv,
const Environment& environment,
238 if ( process != NULL )
245 process =
new ExternalProgram(argv, environment, disp,
false, -1,
true);
254 if ( process == NULL )
257 exit_code = process->close();
262 DBG <<
"exit code: " << exit_code << endl;
270 if (process) process->kill();
275 Mount::getEntries(
const std::string &mtab)
277 MountEntries entries;
278 std::vector<std::string> mtabs;
279 bool verbose =
false;
283 mtabs.push_back(
"/proc/mounts");
290 if ( PathInfo(
"/etc/mtab", PathInfo::LSTAT ).isFile() )
291 mtabs.push_back(
"/etc/mtab");
295 mtabs.push_back(mtab);
298 std::vector<std::string>::const_iterator t;
299 for( t=mtabs.begin(); t != mtabs.end(); ++t)
303 DBG <<
"Reading mount table from '" << *t <<
"'" << std::endl;
305 FILE *fp = setmntent(t->c_str(),
"re");
308 char buf[PATH_MAX * 4];
311 memset(buf, 0,
sizeof(buf));
312 memset(&ent, 0,
sizeof(ent));
314 while( getmntent_r(fp, &ent, buf,
sizeof(buf)) != NULL)
316 if( ent.mnt_fsname && *ent.mnt_fsname &&
317 ent.mnt_dir && *ent.mnt_dir &&
318 ent.mnt_type && *ent.mnt_type &&
319 ent.mnt_opts && *ent.mnt_opts)
322 ent.mnt_fsname, ent.mnt_dir,
323 ent.mnt_type, ent.mnt_opts,
324 ent.mnt_freq, ent.mnt_passno
332 if ( entry.
src.size() > 1
333 && entry.
src[entry.
src.size()-1] ==
'/' )
335 entry.
src.erase( entry.
src.size()-1 );
337 entries.push_back(entry);
339 memset(buf, 0,
sizeof(buf));
340 memset(&ent, 0,
sizeof(ent));
347 WAR <<
"Unable to read any entry from the mount table '" << *t <<
"'"
361 WAR <<
"Failed to read the mount table '" << *t <<
"': "
Status
UI status Status values calculated by Selectable.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
std::string type
filesystem / mount type
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
std::ostream & operator<<(std::ostream &str, const ::_Dataiterator *obj)
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
std::string opts
mount options
A "struct mntent" like mount entry structure, but using std::strings.
std::string strerror(int errno_r)
Return string describing the error_r code.
std::string src
name of mounted file system
std::string dir
file system path prefix