23#include <zypp-media/Mount>
26#include <zypp-media/MediaException>
43 if ( ! obj.
opts.empty() )
63 const std::string &
target,
65 const std::string & options,
68 const char *
const argv[] = {
71 "-o", options.c_str(),
80 for ( std::string output = prog.receiveLine(); output.length(); output = prog.receiveLine() ) {
81 output[output.size()-1] =
'\0';
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[] = {
128 bool doRetry =
false;
129 unsigned numRetry = 2;
133 WAR <<
"umount " << path <<
": " << exitCode <<
": " << err <<
" - retrying in 1 sec." << endl;
139 WAR <<
"umount " << path <<
": " << exitCode <<
": " << err <<
" - giving up" << endl;
145 for ( std::string output = prog.receiveLine(); output.length(); output = prog.receiveLine() ) {
147 DBG <<
"stdout: " << output << 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;
173 bool verbose =
false;
177 mtabs.push_back(
"/proc/mounts");
185 mtabs.push_back(
"/etc/mtab");
189 mtabs.push_back(mtab);
192 std::vector<std::string>::const_iterator t;
193 for( t=mtabs.begin(); t != mtabs.end(); ++t)
197 DBG <<
"Reading mount table from '" << *t <<
"'" << std::endl;
199 FILE *fp = setmntent(t->c_str(),
"re");
202 char buf[PATH_MAX * 4];
205 memset(buf, 0,
sizeof(buf));
206 memset(&ent, 0,
sizeof(ent));
208 while( getmntent_r(fp, &ent, buf,
sizeof(buf)) != NULL)
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
227 && entry.
src[entry.
src.size()-1] ==
'/' )
229 entry.
src.erase( entry.
src.size()-1 );
231 entries.push_back(entry);
233 memset(buf, 0,
sizeof(buf));
234 memset(&ent, 0,
sizeof(ent));
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'"
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
int close() override
Wait for the progamm to complete.
Wrapper class for stat/lstat.
String related utilities and Regular expression matching.
Types and functions for filesystem operations.
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 dir
file system path prefix
std::string src
name of mounted file system
bool isBlockDevice() const
Returns true if the src part points to a block device in /dev.
MountEntry(std::string source, std::string target, std::string fstype, std::string options, const int dumpfreq=0, const int passnum=0)
std::string type
filesystem / mount type
std::string opts
mount options
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.