From: Shie E. <er...@us...> - 2004-09-17 17:35:20
|
Update of /cvsroot/krusader/krusader_kde3/krusader/MountMan In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12942/krusader/MountMan Modified Files: kmountman.cpp Log Message: new mountman Index: kmountman.cpp =================================================================== RCS file: /cvsroot/krusader/krusader_kde3/krusader/MountMan/kmountman.cpp,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** kmountman.cpp 17 Sep 2004 13:05:19 -0000 1.33 --- kmountman.cpp 17 Sep 2004 17:35:09 -0000 1.34 *************** *** 31,55 **** #include <time.h> #include "kmountman.h" - // QT incldues - #include <qcstring.h> - #include <qfileinfo.h> - #include <qtextstream.h> - #include <qfile.h> - #include <qtimer.h> - #include <qdir.h> // KDE includes #include <kmessagebox.h> #include <kprocess.h> ! #include <kprocctrl.h> #include <kio/job.h> #include <klocale.h> #include <kpopupmenu.h> - #if KDE_IS_VERSION(3,2,0) - #include <kmountpoint.h> - #endif - // Krusader includes - #include "../resources.h" #include "../krusader.h" #include "../Dialogs/krdialogs.h" --- 31,44 ---- #include <time.h> #include "kmountman.h" // KDE includes #include <kmessagebox.h> #include <kprocess.h> ! //#include <kprocctrl.h> ! #include <kio/jobclasses.h> #include <kio/job.h> #include <klocale.h> #include <kpopupmenu.h> // Krusader includes #include "../krusader.h" #include "../Dialogs/krdialogs.h" *************** *** 64,98 **** #endif ! #define DF_WAIT_TIME 60 ! ! bool dfStartFailed = false; ! ! KMountMan::KMountMan() : QObject(), Ready( false ), Operational( false ), ! outputBuffer( 0 ), tempFile( 0 ), mountManGui( 0 ), mtab( "" ) { ! #if KDE_IS_VERSION(3,2,0) _actions = 0L; - #endif /* KDE 3.2 */ ! filesystems.setAutoDelete( true ); ! localDf = new fsData(); // will be used to move around information ! forceUpdate(); } KMountMan::~KMountMan() {} - // find the next word delimited by 'c' - QString KMountMan::nextWord( QString &s, char c ) { - s = s.stripWhiteSpace(); - int j = s.find( c, 0 ); - if ( j == -1 ) { // if the delimiter wasn't found, return the entire - QString tmp = s; // input, clearing the original string, to indicate - s = ""; // that the whole input was taken - return tmp; - } - QString temp = s.left( j ); // find the leftmost word. - s.remove( 0, j ); - return temp; - } - void KMountMan::mainWindow() { mountManGui = new KMountManGUI(); --- 53,70 ---- #endif ! KMountMan::KMountMan() : QObject(), Operational( false ), mountManGui( 0 ) { _actions = 0L; ! // added as a precaution, although we use kde services now ! if( !KrServices::cmdExist( "df" ) || !KrServices::cmdExist( "mount" ) ) { ! Operational = false; ! } else { ! Operational = true; ! } ! } KMountMan::~KMountMan() {} void KMountMan::mainWindow() { mountManGui = new KMountManGUI(); *************** *** 101,450 **** } ! // this version find the next word, delimeted by anything from ! // comma, space, tab or newline, in this order ! QString KMountMan::nextWord( QString &s ) { ! s = s.stripWhiteSpace(); ! int j; ! j = s.find( ',', 0 ); ! if ( j == -1 ) ! j = s.find( ' ', 0 ); ! if ( j == -1 ) ! j = s.find( '\t', 0 ); ! if ( j == -1 ) ! j = s.find( '\n', 0 ); ! // one of the above must have made j>0, if something went wrong, ! // we return the entire input, clearing the original string ! if ( j == -1 ) { ! QString tmp = s; ! s = ""; ! return tmp; ! } ! QString temp = s.left( j ); // find the leftmost word. ! s.remove( 0, j ); ! ! return temp; ! } ! ! QString KMountMan::followLink( QString source ) { ! // ugly hack - disable link following because of devfs ! return source; ! ! QFileInfo temp( source ); ! // if the file doesn't exist and it contains //, it's probably a samba share ! // <patch> thanks to Cristi Dumitrescu ! if ( !temp.exists() && temp.filePath().contains( "//" ) > 0 ) ! return source; ! while ( temp.isSymLink() ) ! temp.setFile( temp.readLink() ); ! return temp.fileName(); ! } ! ! bool KMountMan::createFilesystems() { ! QString temp[ 5 ][ 100 ]; // a temporary array which allows parsing of upto 100 fs ! QString dumb; // my very-own dumb pipe: nothing goes out of it :-) ! QString s; ! int i = 0, j = 0; ! ! noOfFilesystems = 0; ! // if |filesystems|>0, than we are re-creating, delete the old list ! if ( filesystems.count() > 0 ) ! while ( filesystems.removeLast() ) ! ; ! // open the /etc/fstab file... ! QFile fstab( FSTAB ); ! if ( !fstab.open( IO_ReadOnly ) ) { ! kdWarning() << "Mt.Man: Unable to read " << QString( FSTAB ) << " !!! Shutting down. (sorry)" << endl; ! return false; ! } ! // and read it into the temporary array ! QTextStream t( &fstab ); ! //kdWarning() << "debug: createFilesystems" << endl; ! while ( !fstab.atEnd() ) { ! s = t.readLine(); ! s = s.simplifyWhiteSpace(); // remove TABs ! if ( s == QString::null || s == "" ) ! continue; // skip empty lines in fstab ! // temp[0]==name, temp[1]==type, temp[2]==mount point, temp[3]==options ! // temp[4] is reserved for special cases, right now, only for supermount ! //kdWarning() << "debug: " << s << endl; ! bool remark = false; ! ( temp[ 0 ][ i ] ) = nextWord( s, ' ' ); ! #if defined(_OS_SOLARIS_) ! ! nextWord( s, ' ' ); ! #endif ! ! ( temp[ 2 ][ i ] ) = nextWord( s, ' ' ); ! ( temp[ 1 ][ i ] ) = nextWord( s, ' ' ); ! #if !defined(_OS_SOLARIS_) ! ! ( temp[ 3 ][ i ] ) = nextWord( s, ' ' ); ! #endif ! // now, we check if a remark was inserted in the line ! for ( int cnt = 0; cnt < 3; ++cnt ) ! if ( temp[ cnt ][ i ] == "#" || temp[ cnt ][ i ].left( 1 ) == "#" ) { ! //kdDebug() << "MountMan: found a remark in fstab, skipping the line." << endl; ! remark = true; ! break; ! } ! // if the filesystem is supermount, then the whole fstab is not like ! // we expected, so alterations must be made... mucho work... ! if ( temp[ 1 ][ i ] == "supermount" ) { ! temp[ 4 ][ i ] = "supermount"; // mark the filesystem ! // temp[3][i] holds the entire 'options' string ! QString t = ( temp[ 3 ][ i ] ).mid( ( temp[ 3 ][ i ] ).find( "fs=", 0 ) + 3 ); ! temp[ 1 ][ i ] = nextWord( t ); ! t = ( temp[ 3 ][ i ] ).mid( ( temp[ 3 ][ i ] ).find( "dev=", 0 ) + 4 ); ! temp[ 0 ][ i ] = nextWord( t ); ! // now we have to cut temp[3][i] down to remove supermount info from it ! int i1 = ( temp[ 3 ][ i ] ).find( "fs=", 0 ) + 3; ! int i2 = ( temp[ 3 ][ i ] ).find( "dev=", 0 ) + 4; ! // find where the supermount info ends and the other options begin ! int i3 = ( temp[ 3 ][ i ] ).find( ',', ( i1 > i2 ? i1 : i2 ) ); ! t = ( temp[ 3 ][ i ] ).mid( i3 + 1 ); // got the entire line ... all we need to do ! ( temp[ 3 ][ i ] ) = nextWord( t, ' ' ); // is remove the '0 0' or '0 1' at the end ! ( temp[ 3 ][ i ] ).simplifyWhiteSpace(); // make sure an empty string is empty! ! } ! if ( !remark ) ! ++i; // count this as a filesystem, only if it's not a remark ! } ! --i; ! fstab.close(); // finished with it ! for ( j = 0; j <= i; ++j ) { ! if ( temp[ 0 ][ j ] == "" || temp[ 0 ][ j ] == "tmpfs" || temp[ 0 ][ j ] == "none" || temp[ 0 ][ j ] == "proc" || ! #if defined(BSD) ! temp[ 0 ][ j ] == "swap" || temp[ 1 ][ j ] == "procfs" || temp[ 1 ][ j ] == "/dev/pts" || // FreeBSD: procfs instead of proc ! #else ! temp[ 0 ][ j ] == "swap" || temp[ 1 ][ j ] == "proc" || temp[ 1 ][ j ] == "/dev/pts" || ! #endif ! temp[ 1 ][ j ] == "swap" || temp[ 4 ][ j ] == "supermount" ) ! continue; ! ++noOfFilesystems; ! } ! // now, create the main list ! QString forDebugOnly = ""; ! i = 0; ! j = 0; ! while ( i < noOfFilesystems ) { ! if ( temp[ 0 ][ j ] == "" || temp[ 1 ][ j ] == "proc" || temp[ 1 ][ j ] == "/dev/pts" || temp[ 0 ][ j ] == "tmpfs" || ! temp[ 1 ][ j ] == "swap" || temp[ 0 ][ j ] == "none" || temp[ 0 ][ j ] == "proc" || ! temp[ 0 ][ j ] == "swap" || temp[ 4 ][ j ] == "supermount" ) ! ++j; ! else { ! fsData* system = new fsData(); ! system->setName( temp[ 0 ][ j ] ); ! system->setType( temp[ 1 ][ j ] ); ! system->setMntPoint( temp[ 2 ][ j ] ); ! // remove trailing spaces (since mtab removes them) ! if ( system->mntPoint() [ system->mntPoint().length() - 1 ] == '/' && system->mntPoint() != "/" ) // also skip root! ! system->setMntPoint( system->mntPoint().left( system->mntPoint().length() - 1 ) ); ! system->supermount = ( temp[ 4 ][ j ] == "supermount" ? true : false ); ! system->options = temp[ 3 ][ j ]; ! filesystems.append( system ); ! forDebugOnly = forDebugOnly + "[" + system->name() + "] on [" + system->mntPoint() + ! "] (" + temp[ 3 ][ j ] + ")" + '\n'; ! ++i; ! ++j; ! // if not supermounted, we add the mount point to our list ! if ( !system->supermount ) ! mountPoints += system->mntPoint(); ! } ! } ! kdDebug() << "Mt.Man: found the following:\n" << forDebugOnly << "Trying DF..." << endl; ! ! #if defined(BSD) || defined(_OS_SOLARIS_) ! // FreeBSD problem: df does not retrive fs type. ! // Workaround: execute mount -p and merge result. ! ! KShellProcess proc; ! proc << KrServices::fullPathName( "mount" ) + " -p"; ! ! // connect all outputs to collectOutput, to be displayed later ! connect( &proc, SIGNAL( receivedStdout( KProcess*, char*, int ) ), ! this, SLOT( collectOutput( KProcess*, char*, int ) ) ); ! // launch ! clearOutput(); ! if ( !proc.start( KProcess::Block, KProcess::Stdout ) ) { ! kdDebug() << "Unable to execute 'mount -p' !!!" << endl; ! return true; ! } ! ! QString str = getOutput(); ! QTextStream t2( str, IO_ReadOnly ); ! //kdWarning() << "debug: mount -p" << endl; ! while ( !t2.atEnd() ) { ! s = t2.readLine(); ! s = s.simplifyWhiteSpace(); // remove TABs ! if ( s == QString::null || s == "" ) ! continue; // skip empty lines in fstab ! // temp[0]==name, temp[1]==type, temp[2]==mount point, temp[3]==options ! // temp[4] is reserved for special cases, right now, only for supermount ! //kdWarning() << "debug: " << s << endl; ! QString temp0 = nextWord( s, ' ' ); ! #ifdef _OS_SOLARIS_ ! QString temp4 = nextWord( s, ' ' ); // skip '-' column ! #endif ! ! QString temp2 = nextWord( s, ' ' ); ! QString temp1 = nextWord( s, ' ' ); ! QString temp3 = nextWord( s, ' ' ); ! if ( temp0 == "" || temp2 == "/proc" || temp2 == "/dev/pts" || ! temp2 == "swap" || temp0 == "none" || temp0 == "procfs" || ! temp0 == "swap" || location( temp0 ) ) ! continue; ! else { ! fsData* system = new fsData(); ! system->setName( temp0 ); ! system->setType( temp1 ); ! system->setMntPoint( temp2 ); ! system->supermount = false; ! #ifndef _OS_SOLARIS_ ! ! system->options = temp3; // unknown column on solaris ! #endif ! ! filesystems.append( system ); ! ++noOfFilesystems; ! kdWarning() << "Mt.Man: filesystem [" << temp0 << "] found by mount -p is unlisted in " << QString( FSTAB ) << endl; ! } ! } ! #endif ! return true; ! } ! ! // run DF process and when it finishes, catch output with "parseDfData" ! /////////////////////////////////////////////////////////////////////// ! void KMountMan::updateFilesystems() { ! getMtab(); // here we get the current state of mtab for watching it later ! // create the "df -P -T" process ! ! if ( dfStartFailed ) { ! Operational = Ready = false; // stop mountman ! return ; ! } ! ! tempFile = new KTempFile(); ! tempFile->setAutoDelete( true ); ! dfProc.clearArguments(); ! dfProc << KrServices::fullPathName( "df" ); ! #if defined(BSD) ! ! dfProc << ">" << tempFile->name(); // FreeBSD: df instead of df -T -P ! #elif defined(_OS_SOLARIS_) ! ! dfProc << "-k" << ">" << tempFile->name(); // Solaris: df -k instead of df -T -P ! #else ! ! dfProc << "-T" << "-P" << ">" << tempFile->name(); ! #endif ! ! connect( &dfProc, SIGNAL( processExited( KProcess * ) ), this, ! SLOT( finishUpdateFilesystems() ) ); ! dfProc.start( KProcess::NotifyOnExit ); ! // if 'df' doesn't return in DF_WAIT_TIME seconds, stop mountman ! QTimer::singleShot( DF_WAIT_TIME * 1000, this, SLOT( killMountMan() ) ); ! } ! ! // if df didn't return, stop mountman ! void KMountMan::killMountMan() { ! // if Operational and !Ready, than df didn't return (yet) ! if ( Operational && !Ready ) { ! dfProc.kill( SIGKILL ); // kill the process ! Operational = Ready = false; // stop mountman ! dfStartFailed = true; // problems at starting df ! } ! } ! ! // gets notified when df is finished. ! void KMountMan::finishUpdateFilesystems() { ! // call parseDfData to work on the data ! parseDfData( tempFile->name() ); ! disconnect( &dfProc, 0, 0, 0 ); ! delete tempFile; ! tempFile = 0; ! emit updated(); ! } ! ! fsData* KMountMan::location( QString name ) { ! fsData * it; ! for ( it = filesystems.first() ; ( it != 0 ) ; it = filesystems.next() ) { ! if ( followLink( it->name() ) == followLink( name ) ) ! break; ! #if defined(BSD) || defined(_OS_SOLARIS_) ! ! if ( name.left( 2 ) == "//" && !strcasecmp( followLink( it->name() ).local8Bit(), followLink( name ).local8Bit() ) ) ! break; // FreeBSD: ignore case due to smbfs mounts ! #endif ! ! } ! return it; ! } ! ! /* we cannot use collectOutput as other processes may connected to it */ ! void KMountMan::collectMtab( KProcess*, char *buffer, int buflen ) { ! // add new buffer to mtab ! for ( int i = 0; i < buflen; ++i ) ! mtab += buffer[ i ]; ! } ! ! QString KMountMan::getMtab() { ! KShellProcess proc; ! proc << KrServices::fullPathName( "mount" ); ! ! // connect all outputs by collectMtab ( collectOutput can not be used because of the watcher ) ! connect( &proc, SIGNAL( receivedStdout( KProcess*, char*, int ) ), ! this, SLOT( collectMtab( KProcess*, char*, int ) ) ); ! // launch ! mtab = ""; ! if ( !proc.start( KProcess::Block, KProcess::Stdout ) ) { ! kdDebug() << "Unable to execute 'mount' !!!" << endl; ! return ""; ! } ! ! return mtab; ! } ! ! bool KMountMan::checkMtabChanged() { ! QString LastMtab = mtab; ! return getMtab() != LastMtab; } ! QString KMountMan::devFromMtab( QString mntPoint ) { ! QString mtab = getMtab(); ! ! // and read it into the temporary array ! QTextStream t( &mtab, IO_ReadOnly ); ! while ( !t.atEnd() ) { ! QString dev, point; ! QString s = t.readLine().simplifyWhiteSpace(); ! dev = nextWord( s, ' ' ); /* device */ ! nextWord( s, ' ' ); /* on */ ! point = nextWord( s, ' ' ); /* mountpoint */ ! if ( point == mntPoint ) { ! return dev; ! } ! } ! return QString::null; } ! QString KMountMan::pointFromMtab( QString device ) { ! QString mtab = getMtab(); ! ! // and read it into the temporary array ! QTextStream t( &mtab, IO_ReadOnly ); ! while ( !t.atEnd() ) { ! QString dev, mntPoint; ! QString s = t.readLine().simplifyWhiteSpace(); ! dev = nextWord( s, ' ' ); /* device */ ! nextWord( s, ' ' ); /* on */ ! mntPoint = nextWord( s, ' ' ); /* mountpoint */ ! if ( dev == device ) { ! return mntPoint; ! } ! } ! return QString::null; } ! KMountMan::mntStatus KMountMan::getStatus( QString mntPoint ) { KMountPoint::List::iterator it; KMountPoint *m; --- 73,99 ---- } ! KMountPoint *KMountMan::findInListByMntPoint(KMountPoint::List &lst, QString value) { ! KMountPoint *m; ! for (KMountPoint::List::iterator it = lst.begin(); it != lst.end(); ++it) { ! m = *it; ! if (m->mountPoint() == value) ! return m; ! } ! ! return 0; } ! void KMountMan::mount( QString mntPoint ) { ! KMountPoint::List possible = KMountPoint::possibleMountPoints(KMountPoint::NeedMountOptions); ! KMountPoint *m = findInListByMntPoint(possible, mntPoint); ! if (!m) return; ! KIO::SimpleJob *job = KIO::mount(false, m->mountType().local8Bit(), m->mountedFrom(), m->mountPoint()); } ! void KMountMan::unmount( QString mntPoint ) { ! KIO::SimpleJob *job = KIO::unmount(mntPoint); } ! KMountMan::mntStatus KMountMan::getStatus( QString mntPoint ) { KMountPoint::List::iterator it; KMountPoint *m; *************** *** 452,469 **** // 1: is it already mounted KMountPoint::List current = KMountPoint::currentMountPoints(); ! for ( it = current.begin(); it != current.end(); ++it ) { ! m = *it; ! if (m->mountPoint() == mntPoint) ! return MOUNTED; ! } // 2: is it a mount point but not mounted? KMountPoint::List possible = KMountPoint::possibleMountPoints(); ! for ( it = possible.begin(); it != possible.end(); ++it ) { ! m = *it; ! if (m->mountPoint() == mntPoint) { ! return NOT_MOUNTED; ! } ! } // 3: unknown --- 101,113 ---- // 1: is it already mounted KMountPoint::List current = KMountPoint::currentMountPoints(); ! m = findInListByMntPoint(current, mntPoint); ! if (m) ! return MOUNTED; // 2: is it a mount point but not mounted? KMountPoint::List possible = KMountPoint::possibleMountPoints(); ! m = findInListByMntPoint(possible, mntPoint); ! if (m) ! return NOT_MOUNTED; // 3: unknown *************** *** 471,740 **** } - QString KMountMan::getDevice( QString mntPoint ) { - fsData * it; - for ( it = filesystems.first() ; ( it != 0 ) ; it = filesystems.next() ) - if ( it->mntPoint() == mntPoint ) - return it->name(); - // if we got here, the mntPoint doesn't exist in the database - return QString::null; - } - - // parseDfData assumes that DF always knows better than FSTAB about currently - // mounted filesystems. - ///////////////////////////////////////////////////////////////////////////// - void KMountMan::parseDfData( QString filename ) { - QString temp; - QFile f( filename ); - if ( !f.open( IO_ReadOnly ) || dfStartFailed ) { // error reading temp file - Operational = false; - Ready = false; - return ; // make mt.man non-operational - } - QTextStream t( &f ); // use a text stream - QString s, s2; - s = t.readLine(); // read the 1st line - it's trash for us - // now that we have a QString containing all the output of DF, let's get to work. - int countFilesystems = 0; // sucessfully found filesystems - //kdWarning() << "debug: parseDfData" << endl; - while ( !t.eof() ) { - bool newFS = false; - s2 = s = t.readLine(); // this is the important one! - //kdWarning() << "debug: " << s << endl; - temp = nextWord( s, ' ' ); - // avoid adding unwanted filesystems to the list - if ( temp == "tmpfs" ) - continue; - #if defined(BSD) - - if ( temp == "procfs" ) - continue; // FreeBSD: ignore procfs too - #elif defined(_OS_SOLARIS_) - - if ( temp == "proc" || temp == "swap" ) - continue; // Solaris: ignore procfs too - #endif - - temp = followLink( temp ); // make sure DF gives us the true device and not a link - fsData* loc = location( temp ); // where is the filesystem located in our list? - if ( loc == 0 ) { - kdWarning() << "Mt.Man: filesystem [" << temp << "] found by DF is unlisted in " << QString( FSTAB ) << endl; - loc = new fsData(); - loc->supermount = false; - filesystems.append( loc ); - if ( temp.contains( "//" ) > 0 || // if it contains '//', it's a smb share - temp.contains( ":" ) > 0 || // if it contains ':' , it's an nfs share - temp.startsWith( "/" ) ) // if it is a fullpath device name - loc->setName( temp ); // <patch> thanks to Cristi Dumitrescu - else - loc->setName( "/dev/" + temp ); - newFS = true; - } - #if !defined(BSD) && !defined(_OS_SOLARIS_) - temp = nextWord( s, ' ' ); // catch the TYPE - // is it supermounted ? - if ( temp == "supermount" ) - loc->supermount = true; - loc->setType( temp ); - if ( loc->type() != temp ) { - kdWarning() << "Mt.Man: according to DF, filesystem [" << loc->name() << - "] has a different type from what's stated in " << QString( FSTAB ) << endl; - loc->setType( temp ); // DF knows best - } - #endif - temp = nextWord( s, ' ' ); - loc->setTotalBlks( temp.toLong() ); - temp = nextWord( s, ' ' ); - temp = nextWord( s, ' ' ); // get rid of the next 2 words - loc->setFreeBlks( temp.toLong() ); - temp = nextWord( s, ' ' ); - temp = nextWord( s, '\n' ); // read the "mounted on" thing - if ( loc->mntPoint() != temp ) { - if ( !newFS ) - kdWarning() << "Mt.Man: according to DF, filesystem [" << loc->name() << - "] is mounted on " << temp << " and not on " << loc->mntPoint() << endl; - loc->setMntPoint( temp ); // DF knows best - } - loc->setMounted( true ); - ++countFilesystems; - } - - Operational = Ready = true; // we are finished here - if ( countFilesystems > 0 ) - kdDebug() << "Mt.Man: Alive and kicking. " << endl; - else { - kdWarning() << "Mt.Man: failed running DF. Shutting down (sorry)." << endl; - Operational = Ready = false; - } - } - - void KMountMan::forceUpdate() { - kdWarning() << "Mt.Man: Born, looking around to get familiar." << endl; - mountPoints.clear(); - // first create our list from /etc/fstab - if ( !createFilesystems() ) { // create the potential fs from /etc/fstab - Operational = Ready = false; - return ; // if something went wrong, bail out! - } else - Operational = true; // mountman is alive but not yet ready - updateFilesystems(); // use the output of "DF -T -P" to update data - } - - void KMountMan::collectOutput( KProcess *p, char *buffer, int buflen ) { - if ( !p ) - return ; // don't collect data from unknown/undefined processes - if ( outputBuffer == 0 ) - outputBuffer = new QString(); // create buffer if needed - - // add new buffer to the main output buffer - for ( int i = 0; i < buflen; ++i ) - ( *outputBuffer ) += buffer[ i ]; - } - - void KMountMan::clearOutput() { - if ( outputBuffer != 0 ) { - delete outputBuffer; - outputBuffer = 0; - } - } - - // this is the generic version of mount - it receives a mntPoint and try to - // mount it the usual way - via /etc/fstab - void KMountMan::mount( QString mntPoint ) { - if ( mountPoints.findIndex( mntPoint ) == -1 ) - return ; // safety measure - - if ( !KrServices::cmdExist( "mount" ) ) { - KMessageBox::error( 0, - i18n( "Can't start 'mount'! Check the 'Dependencies' page in konfigurator." ) ); - return ; - } - - KProcess mountProc; - mountProc << KrServices::fullPathName( "mount" ) << mntPoint.local8Bit(); - // connect all outputs to collectOutput, to be displayed later - connect( &mountProc, SIGNAL( receivedStderr( KProcess*, char*, int ) ), - this, SLOT( collectOutput( KProcess*, char*, int ) ) ); - // launch - clearOutput(); - if ( !mountProc.start( KProcess::Block, KProcess::Stderr ) ) { - KMessageBox::error( 0, - i18n( "Unable to execute 'mount' !!!\ncheck that /bin/mount or /sbin/mount are availble" ) ); - return ; - } - if ( mountProc.normalExit() ) - if ( mountProc.exitStatus() == 0 ) - return ; // incase of a normal exit - // on any other case,report an error - KMessageBox::sorry( 0, i18n( "Unable to complete the mount." ) + - i18n( "The error reported was:\n\n" ) + getOutput() ); - } - - // this version of mount is used strictly by the GUI - // don't call it explicitly ! - void KMountMan::mount( fsData *p ) { - // first, if the user isn't ROOT, he won't be able to mount it, unless - // the option states 'user'. if so, we'll mount the mntPoint - if ( p->options.contains( "user" ) && getuid() != 0 ) { - mount( p->mntPoint() ); // call the alternative method - return ; - } - - if ( !KrServices::cmdExist( "mount" ) ) { - KMessageBox::error( 0, - i18n( "Can't start 'mount'! Check the 'Dependencies' page in konfigurator." ) ); - return ; - } - - bool ro = ( p->type() == "iso9660" ); - KProcess mountProc; - mountProc << KrServices::fullPathName( "mount" ); - if ( ro ) - mountProc << "-r"; // read only - mountProc << "-t" << p->type().local8Bit(); // local8Bit == normal ascii - if ( !p->options.isEmpty() ) - mountProc << "-o" << p->options; // -o options - mountProc << p->name().local8Bit() << p->mntPoint().local8Bit(); - - // don't allow mounting 'supermount' filesystems - if ( p->supermount ) { - KMessageBox::information( mountManGui, i18n( "Warning: you're trying to mount a 'supermount' filesystem. Supermount filesystems are (un)mounted automatically by linux upon insert/eject. This is usually a Linux-Mandrake feature.Krusader will not allow this, as it creates unpredictable behaviour." ), i18n( "Error" ), "SupermountWarning" ); - return ; - } - // connect all outputs to collectOutput, to be displayed later - connect( &mountProc, SIGNAL( receivedStderr( KProcess*, char*, int ) ), - this, SLOT( collectOutput( KProcess*, char*, int ) ) ); - // launch - clearOutput(); - if ( !mountProc.start( KProcess::Block, KProcess::Stderr ) ) { - KMessageBox::error( 0, - i18n( "Unable to execute 'mount' !!! check that /bin/mount or /sbin/mount are availble" ) ); - return ; - } - if ( mountProc.normalExit() ) - if ( mountProc.exitStatus() == 0 ) - return ; // incase of a normal exit - // on any other case,report an error - KMessageBox::sorry( 0, i18n( "Unable to complete the mount." ) + - i18n( "The error reported was:\n\n" ) + getOutput() ); - } - - // this version of unmount is generic - it doesn't care which device is mounted - // on the mntPoint, it simply unmounts it --- used with externally mounted systems - void KMountMan::unmount( QString mntPoint ) { - fsData * tmp = new fsData(); - tmp->setMntPoint( mntPoint ); // mount-point and supermount=false is all that's - tmp->supermount = false; // needed to normally unmount - unmount( tmp ); - delete tmp; // no memory-leaks here ! - } - - // this version is used strictly by the GUI or by the unmount(QString) version - // you've got no need to call it explicitly - void KMountMan::unmount( fsData *p ) { - if ( !KrServices::cmdExist( "umount" ) ) { - KMessageBox::error( 0, - i18n( "Can't start 'umount'! Check the 'Dependencies' page in konfigurator." ) ); - return ; - } - - KProcess umountProc; - umountProc << KrServices::fullPathName( "umount" ); - umountProc << p->mntPoint().local8Bit(); - - // don't allow unmounting 'supermount' filesystems - if ( p->supermount ) { - KMessageBox::information( mountManGui, i18n( "Warning: you're trying to unmount a 'supermount' filesystem. Supermount filesystems are (un)mounted automatically by linux upon insert/eject. This is usually a Linux-Mandrake feature. Krusader will not allow this, as it creates unpredictable behaviour." ), i18n( "Error" ), "SupermountWarning" ); - return ; - } - // connect outputs to collectOutput, to be displayed later - connect( &umountProc, SIGNAL( receivedStderr( KProcess*, char*, int ) ), - this, SLOT( collectOutput( KProcess*, char*, int ) ) ); - // launch - krApp->startWaiting( i18n( "Unmounting device, please wait ..." ), 0, false ); - - clearOutput(); - if ( !umountProc.start( KProcess::Block, KProcess::Stderr ) ) { - KMessageBox::error( 0, - i18n( "Unable to execute 'umount' !!! check that /bin/umount or /sbin/umount are availble" ) ); - return ; - } else - while ( umountProc.isRunning() ) - qApp->processEvents(); - krApp->stopWait(); - if ( umountProc.normalExit() ) - if ( umountProc.exitStatus() == 0 ) - return ; // incase of a normal exit - // on any other case,report an error - KMessageBox::sorry( 0, i18n( "Unable to complete the un-mount." ) + - i18n( "The error reported was:\n\n" ) + getOutput() ); - } void KMountMan::toggleMount( QString mntPoint ) { - #if 0 - fsData * p = location( device ); - // request mountMan to (un)mount something, if he does his job (and he does) - // we will be notified by signal - ( p->mounted() ? unmount( p ) : mount( p ) ); - #endif mntStatus status = getStatus(mntPoint); switch (status) { --- 115,120 ---- *************** *** 745,757 **** mount(mntPoint); break; } } - - - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - void KMountMan::autoMount( QString path ) { if ( getStatus( path ) == NOT_MOUNTED ) --- 125,134 ---- mount(mntPoint); break; + case DOESNT_EXIST: + // do nothing: no-op to make the compiler quiet ;-) + break; } } void KMountMan::autoMount( QString path ) { if ( getStatus( path ) == NOT_MOUNTED ) *************** *** 771,781 **** #if !defined(BSD) && !defined(_OS_SOLARIS_) KMountPoint::List possible = KMountPoint::possibleMountPoints(); ! KMountPoint *m; ! for ( KMountPoint::List::iterator it = possible.begin(); it != possible.end(); ++it ) { ! m = *it; ! if (m->mountPoint() == path && ! (m->mountType()=="iso9660" || m->mountedFrom().left(7)=="/dev/cd")) return KrServices::cmdExist( "eject" ); - } #endif --- 148,154 ---- #if !defined(BSD) && !defined(_OS_SOLARIS_) KMountPoint::List possible = KMountPoint::possibleMountPoints(); ! KMountPoint *m = findInListByMntPoint(possible, path); ! if (m && (m->mountType()=="iso9660" || m->mountedFrom().left(7)=="/dev/cd")) return KrServices::cmdExist( "eject" ); #endif *************** *** 825,830 **** } - #if KDE_IS_VERSION(3,2,0) - // clear the popup menu ( ( KToolBarPopupAction* ) krMountMan ) ->popupMenu() ->clear(); --- 198,201 ---- *************** *** 866,877 **** this, SLOT( performAction( int ) ) ); - #endif /* KDE 3.2 */ - } void KMountMan::performAction( int idx ) { - - #if KDE_IS_VERSION(3,2,0) - while ( qApp->hasPendingEvents() ) qApp->processEvents(); --- 237,243 ---- *************** *** 891,898 **** _actions = 0L; disconnect( ( ( KToolBarPopupAction* ) krMountMan ) ->popupMenu(), SIGNAL( activated( int ) ), 0, 0 ); - - #endif /* KDE 3.2 */ - } - - --- 257,259 ---- |