void MenuItem::mountItem(){ //Mount the device //Create the full path to the mountpoint QString deviceName = devLabel->text(); QString mntpoint = MOUNTDIR + deviceName.replace(" ","-"); //take into account spaces in the name //Create the fileystem specific command for mounting QString tmpFileSystem; QString cmd; if(filesystem=="UNKNOWN"){ //prompt for filesystem bool selected = false; tmpFileSystem = QInputDialog::getItem(0, deviceName+"("+devType+")", tr("Mount as:"), DEVCHECK->AvailableFS(), 0, false, &selected); if( !selected || tmpFileSystem.isEmpty() ){ return; } //cancelled //Now get the mount command cmd = DEVCHECK->getMountCommand(tmpFileSystem, device, mntpoint); }else{ cmd = DEVCHECK->getMountCommand(filesystem, device, mntpoint); } //Make sure the mntpoint is available QDir mpd(mntpoint); if(mpd.exists() && !rootRequired){ //Remove the existing directory (will work only if it is empty) mpd.cdUp(); mpd.rmdir(mntpoint); } //Prepare the mount command to run //QString cmd = fstype + " " +fsopts + " " + device + " " + mntpoint; qDebug() << "Mounting device" << device << "on" << mntpoint << "("<<filesystem<<")"; if(DEBUG_MODE){ qDebug() << " - command:" << cmd; } //Generate the run script QString runscript = createRunScript( mntpoint, cmd); //Now run the script bool ok = !runscript.isEmpty(); bool tryroot = false; QStringList outL("ERROR:SCRIPT"); //Run the mounting commands if(ok && !rootRequired){ outL.clear(); outL = systemCMD(runscript); //qDebug() << "Mount return code 1:" << outL; //if it could not mount device with permissions issues - try as root if( !outL.filter("Permission denied").isEmpty() || !outL.filter("not permitted").isEmpty() ){ qDebug() << " - Permissions issue, try as root"; tryroot = true; } } if( (ok && rootRequired) || tryroot ){ outL.clear(); outL = systemCMD("pc-su "+runscript); //qDebug() << "Mount return code 2:" << outL; } //Now parse the return code QString result, title; mountedHere = true; //need to set this before running isMounted to update icons right ok = isMounted(); mountedHere = ok; //now make sure it is the proper value if( ok ){ title = tr("Success"); result = QString( tr("%1 mounted at %2") ).arg(deviceName).arg(mntpoint); if(tryroot){ rootRequired = true; } //flag this as requiring root for later }else if( !outL.filter("ERROR:MOUNTPOINT").isEmpty() ){ title = tr("Failure"); result = QString( tr("Could not create mountpoint: %1") ).arg(mntpoint); }else if( !outL.filter("ERROR:MOUNTING").isEmpty() ){ title = tr("Failure"); result = QString( tr("Could not mount device %1 on %2 (%3)") ).arg(deviceName, mntpoint, filesystem); }else{ QString tmp = outL.join(""); tmp.remove("password:"******"General Error output:" << outL; title = tr("General Error"); result = tr("Could not create/run the device mounting script"); } } qDebug() << "pc-mounttray: "<<title << result; if(DEBUG_MODE){ qDebug() << " - output:" << outL; } //Output the proper signals depending upon success if(ok){ emit itemMounted(mntpoint); mountpoint = mntpoint; if( !tmpFileSystem.isEmpty() ){ filesystem = tmpFileSystem; } //this one worked - use it in the future }else{ mountpoint.clear(); } if( !checkAutomount->isChecked() && !(title.isEmpty() && result.isEmpty()) ){ emit newMessage(title, result); //suppress the output message if it was automounted } //Now remove the runscript //if(ok) //only for testing purposes QFile::remove(runscript); }
void AtaDevice::outL(u16 reg, u32 value) { outL(_port+reg, value); }