我在安装 smb:// 连接时具有此功能。如果有一个不属于我的情况的错误怎么办。有没有更好的方法来确定挂载是否成功?我使用的是 ubuntu 11.04 和 qt 4.7.3
bool mwDM::mountFolder()
{
QString smbUsername,smbPassword,serverPath,mountPath;
QProcess connectSamba;
QString terminalCommand,linuxPassword;
QDir dir("/mnt/backup");
smbUsername=ReadINIStr(iniPath,"Server","Username","");
smbPassword=ReadINIStr(iniPath,"Server","Password","");
serverPath=ReadINIStr(iniPath,"Server","Hostname","");
serverPath="//" + serverPath;
mountPath="/mnt/backup";
linuxPassword=ReadINIStr(iniPath,"Server","AdminPassword","");
terminalCommand="echo "+linuxPassword+" | sudo -S mount -t cifs -o username="+smbUsername+",password="+smbPassword+" "+serverPath+ " "+mountPath;
connectSamba.start("sh",QStringList() << "-c" << terminalCommand );
if(!connectSamba.waitForStarted())
{
LogWrite("Failed to start mount command", Qt::red);
}
if(!connectSamba.waitForFinished() )
{
LogWrite("Failed to finish mount command", Qt::red);
}
QString connectSamba_stderr = connectSamba.readAllStandardError();
qDebug() << "connectSamba_stderr" << connectSamba_stderr;
if(connectSamba_stderr.contains("is not a valid block device"))
{
LogWrite("Hostname is invalid", Qt::red);
return false;
}
else if(connectSamba_stderr.contains("3 incorrect password attempts"))
{
LogWrite("Admin password is incorrect", Qt::red);
return false;
}
else if(connectSamba_stderr.contains("wrong fs type, bad option, bad superblock on"))
{
LogWrite("Hostname is invalid", Qt::red);
return false;
}
else if(connectSamba_stderr.contains("Invalid argument"))
{
LogWrite("Mount error(22): Invalid argument", Qt::red);
return false;
}
else if(!dir.exists())
{
LogWrite("Directory doesn't exists", Qt::red);
return false;
}
else
{
return true;
}
}