Output reason why a mount or unmount might have failed.

Patch by Marcel Partap <mpartap@gmx.net>

CCBUG: 178708


svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=901487
This commit is contained in:
Volker Lanz 2008-12-25 16:46:40 +00:00
parent 7ebf6816ce
commit b97e5225be
3 changed files with 43 additions and 38 deletions

View File

@ -25,6 +25,7 @@
#include "fs/filesystemfactory.h"
#include "util/externalcommand.h"
#include "util/report.h"
#include <QString>
#include <QStringList>
@ -266,7 +267,7 @@ bool Partition::canUnmount() const
/** Tries to mount a Partition.
@return true on success
*/
bool Partition::mount()
bool Partition::mount(Report& report)
{
if (isMounted())
return false;
@ -279,7 +280,7 @@ bool Partition::mount()
{
foreach(const QString& mp, mountPoints())
{
ExternalCommand mountCmd("mount", QStringList() << deviceNode() << mp);
ExternalCommand mountCmd(report, "mount", QStringList() << "-v" << deviceNode() << mp);
if (mountCmd.run() && mountCmd.exitCode() == 0)
success = true;
}
@ -293,7 +294,7 @@ bool Partition::mount()
/** Tries to unmount a Partition.
@return true on success
*/
bool Partition::unmount()
bool Partition::unmount(Report& report)
{
if (!isMounted() || mountPoints().size() == 0)
return false;
@ -306,7 +307,7 @@ bool Partition::unmount()
{
foreach(const QString& mp, mountPoints())
{
ExternalCommand umountCmd("umount", QStringList() << mp);
ExternalCommand umountCmd(report, "umount", QStringList() << "-v" << mp);
if (!umountCmd.run() || umountCmd.exitCode() != 0)
success = false;
}

View File

@ -49,6 +49,8 @@ class RestoreFileSystemJob;
class FileSystem;
class Report;
class QString;
/** @brief A partition or some unallocated space on a Device.
@ -67,7 +69,7 @@ class Partition : public PartitionNode
friend class OperationStack;
friend class Device;
friend class PartitionNode;
friend class PartResizerWidget;
friend class InsertDialog;
friend class NewDialog;
@ -83,7 +85,7 @@ class Partition : public PartitionNode
friend class CreatePartitionJob;
friend class SetPartFlagsJob;
friend class RestoreFileSystemJob;
public:
/** A Partition state -- where did it come from? */
enum State
@ -112,9 +114,9 @@ class Partition : public PartitionNode
Partitions& children() { return m_Children; } /**< @return the Partition's children. empty for non-extended. */
const Partitions& children() const { return m_Children; } /**< @return the Partition's children. empty for non-extended. */
const QString& devicePath() const { return m_DevicePath; } /**< @return the Partition's device path, e.g. /dev/sdd7 */
qint64 firstSector() const { return m_FirstSector; } /**< @return the Partition's first sector on the Device */
qint64 lastSector() const { return m_LastSector; } /**< @return the Partition's last sector on the Device */
qint64 sectorsUsed() const;
@ -133,20 +135,20 @@ class Partition : public PartitionNode
const PartitionRole& roles() const { return m_Roles; } /**< @return the Partition's role(s) */
const QStringList& mountPoints() const { return m_MountPoints; } /**< @return the Partition's mount points */
PartitionTable::Flags activeFlags() const { return m_ActiveFlags; } /**< @return the flags currently set for this Partition */
PartitionTable::Flags availableFlags() const { return m_AvailableFlags; } /**< @return the flags available for this Partition */
bool isMounted() const { return m_IsMounted; } /**< @return true if Partition is mounted */
FileSystem& fileSystem() { return *m_FileSystem; } /**< @return the Partition's FileSystem */
const FileSystem& fileSystem() const { return *m_FileSystem; } /**< @return the Partition's FileSystem */
State state() const { return m_State; } /**< @return the Partition's state */
bool hasChildren() const;
bool mount();
bool unmount();
bool mount(Report& report);
bool unmount(Report& report);
bool canMount() const;
bool canUnmount() const;
@ -155,7 +157,7 @@ class Partition : public PartitionNode
void checkChildrenMounted();
static qint64 minimumPartitionSectors() { return m_MinimumPartitionSectors; } /**< @return the minimum number of sectors any Partition must be long */
protected:
void append(Partition* p) { m_Children.append(p); }
void setDevicePath(const QString& s) { m_DevicePath = s; }

View File

@ -49,6 +49,7 @@
#include "util/globallog.h"
#include "util/capacity.h"
#include "util/report.h"
#include <kapplication.h>
#include <kglobalsettings.h>
@ -101,7 +102,7 @@ MainWindow::MainWindow(QWidget* parent) :
m_ProgressDialog(new ProgressDialog(this, operationRunner()))
{
setupUi(this);
FileSystemFactory::init();
connect(GlobalLog::instance(), SIGNAL(newMessage(log::Level, const QString&)), SLOT(onNewLogMessage(log::Level, const QString&)));
@ -385,7 +386,7 @@ void MainWindow::enableActions()
const Partition* part = selectedPartition();
const bool readOnly = selectedDevice() == NULL || selectedDevice()->partitionTable().isReadOnly();
actionCollection()->action("newPartition")->setEnabled(!readOnly && NewOperation::canCreateNew(part));
const bool canResize = ResizeOperation::canGrow(part) || ResizeOperation::canShrink(part) || ResizeOperation::canMove(part);
actionCollection()->action("resizePartition")->setEnabled(!readOnly && canResize);
@ -400,7 +401,7 @@ void MainWindow::enableActions()
actionCollection()->action("mountPartition")->setText(part->isMounted() ? part->fileSystem().unmountTitle() : part->fileSystem().mountTitle() );
actionCollection()->action("checkPartition")->setEnabled(!readOnly && CheckOperation::canCheck(part));
actionCollection()->action("undoOperation")->setEnabled(operationStack().size() > 0);
actionCollection()->action("clearAllOperations")->setEnabled(operationStack().size() > 0);
actionCollection()->action("applyAllOperations")->setEnabled(operationStack().size() > 0 && geteuid() == 0);
@ -480,7 +481,7 @@ void MainWindow::updatePartitions()
treePartitions().clear();
partTableWidget().clear();
updateWindowTitle();
if (selectedDevice() == NULL)
return;
@ -557,7 +558,7 @@ Device* MainWindow::selectedDevice()
if (idx < 0 || idx >= operationStack().previewDevices().size())
return NULL;
return operationStack().previewDevices()[idx];
}
@ -610,7 +611,7 @@ void MainWindow::showPartitionContextMenu(const QPoint& pos)
{
if (selectedPartition() == NULL)
return;
KMenu partitionMenu;
partitionMenu.addAction(actionCollection()->action("newPartition"));
@ -654,7 +655,7 @@ void MainWindow::onPropertiesPartition()
{
if (dlg.newFileSystemType() != selectedPartition()->fileSystem().type() || dlg.forceRecreate())
operationStack().push(new CreateFileSystemOperation(*selectedDevice(), *selectedPartition(), dlg.newFileSystemType()));
if (dlg.newLabel() != selectedPartition()->fileSystem().label())
operationStack().push(new SetFileSystemLabelOperation(*selectedPartition(), dlg.newLabel()));
@ -671,22 +672,23 @@ void MainWindow::onPropertiesPartition()
void MainWindow::onMountPartition()
{
Partition* p = selectedPartition();
Report report(NULL);
if (p && p->canMount())
{
if (!p->mount())
KMessageBox::sorry(this, i18nc("@info", "The file system on partition <filename>%1</filename> could not be mounted.", p->deviceNode()), i18nc("@title:window", "Could not mount file system."));
if (!p->mount(report))
KMessageBox::detailedSorry(this, i18nc("@info", "The file system on partition <filename>%1</filename> could not be mounted.", p->deviceNode()), QString("<pre>%1</pre>").arg(report.toText()), i18nc("@title:window", "Could not mount file system."));
}
else if (p && p->canUnmount())
{
if (!p->unmount())
KMessageBox::sorry(this, i18nc("@info", "The file system on partition <filename>%1</filename> could not be unmounted.", p->deviceNode()), i18nc("@title:window", "Could not unmount file system."));
if (!p->unmount(report))
KMessageBox::detailedSorry(this, i18nc("@info", "The file system on partition <filename>%1</filename> could not be unmounted.", p->deviceNode()), QString("<pre>%1</pre>").arg(report.toText()), i18nc("@title:window", "Could not unmount file system."));
}
if (p->roles().has(PartitionRole::Logical))
{
Partition* parent = dynamic_cast<Partition*>(p->parent());
Q_ASSERT(parent);
if (parent != NULL)
@ -716,7 +718,7 @@ void MainWindow::onFinished()
static bool checkTooManyPartitions(QWidget* parent, const Device& d, const Partition& p)
{
if (p.roles().has(PartitionRole::Unallocated) && d.partitionTable().numPrimaries() >= d.partitionTable().maxPrimaries() && !p.roles().has(PartitionRole::Logical))
{
{
KMessageBox::sorry(parent, i18nc("@info",
"<para>There are already %1 primary partitions on this device. This is the maximum number its partition table can handle.</para>"
"<para>You cannot create, paste or restore a primary partition on it before you delete an existing one.</para>",
@ -766,7 +768,7 @@ void MainWindow::onDeletePartition()
kWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return;
}
if (selectedPartition()->roles().has(PartitionRole::Logical))
{
Q_ASSERT(selectedPartition()->parent());
@ -776,7 +778,7 @@ void MainWindow::onDeletePartition()
kWarning() << "parent of selected partition is null.";
return;
}
if (selectedPartition()->parent()->highestMountedChild() > selectedPartition()->number())
{
KMessageBox::sorry(this,
@ -789,7 +791,7 @@ void MainWindow::onDeletePartition()
return;
}
}
if (clipboardPartition() == selectedPartition())
{
if (KMessageBox::warningContinueCancel(this,
@ -800,7 +802,7 @@ void MainWindow::onDeletePartition()
KGuiItem(i18nc("@action:button", "&Delete it")),
KStandardGuiItem::cancel(), "reallyDeleteClipboardPartition") == KMessageBox::Cancel)
return;
setClipboardPartition(NULL);
}
@ -834,9 +836,9 @@ void MainWindow::onResizePartition()
if (resizedPartition.firstSector() == selectedPartition()->firstSector() && resizedPartition.lastSector() == selectedPartition()->lastSector())
log(log::information) << i18nc("@info/plain", "Partition <filename>%1</filename> has the same position and size after resize/move. Ignoring operation.", selectedPartition()->deviceNode());
else
{
{
operationStack().push(new ResizeOperation(*selectedDevice(), *selectedPartition(), resizedPartition.firstSector(), resizedPartition.lastSector()));
updatePartitions();
updateStatusBar();
updateOperations();
@ -870,7 +872,7 @@ void MainWindow::onPastePartition()
kWarning() << "selected device: " << selectedDevice() << ", selected partition: " << selectedPartition();
return;
}
if (clipboardPartition() == NULL)
{
kWarning() << "no partition in the clipboard.";
@ -1042,7 +1044,7 @@ void MainWindow::onApplyAllOperations()
operationRunner().setReport(&progressDialog().report());
partTableWidget().setUpdatesEnabled(false);
// Undo all operations so the runner has a defined starting point
for (int i = operationStack().operations().size() - 1; i >= 0; i--)
{
@ -1051,7 +1053,7 @@ void MainWindow::onApplyAllOperations()
}
updatePartitions();
operationRunner().start();
}
}
@ -1113,7 +1115,7 @@ void MainWindow::onRestorePartition()
if (checkTooManyPartitions(this, *selectedDevice(), *selectedPartition()))
return;
QString fileName = KFileDialog::getOpenFileName(KUrl("kfiledialog://backupPartition"));
// QString fileName = "/tmp/backuptest.img";
@ -1127,7 +1129,7 @@ void MainWindow::onRestorePartition()
delete restorePartition;
return;
}
if (showInsertDialog(*restorePartition, restorePartition->length()))
{
operationStack().push(new RestoreOperation(*selectedDevice(), restorePartition, fileName));