allow setting how to identify a FS in fstab (uuid, label, device node)

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1075858
This commit is contained in:
Volker Lanz 2010-01-16 22:16:04 +00:00
parent 0ab5b8a0af
commit 14a62a236e
3 changed files with 133 additions and 44 deletions

View File

@ -41,23 +41,27 @@
struct MountEntry
{
MountEntry(const QString& n, const QString& p, const QString& t, const QStringList& o, qint32 d, qint32 pn) :
enum IdentifyType { deviceNode, uuid, label };
MountEntry(const QString& n, const QString& p, const QString& t, const QStringList& o, qint32 d, qint32 pn, IdentifyType type) :
name(n),
path(p),
type(t),
options(o),
dumpFreq(d),
passNumber(pn)
passNumber(pn),
identifyType(type)
{
}
MountEntry(struct mntent* p) :
MountEntry(struct mntent* p, IdentifyType type) :
name(p->mnt_fsname),
path(p->mnt_dir),
type(p->mnt_type),
options(QString(p->mnt_opts).split(',')),
dumpFreq(p->mnt_freq),
passNumber(p->mnt_passno)
passNumber(p->mnt_passno),
identifyType(type)
{
}
@ -67,6 +71,7 @@ struct MountEntry
QStringList options;
qint32 dumpFreq;
qint32 passNumber;
IdentifyType identifyType;
};
static QString findBlkIdDevice(const QString& token, const QString& value)
@ -89,19 +94,20 @@ static QString findBlkIdDevice(const QString& token, const QString& value)
}
EditMountPointDialogWidget::EditMountPointDialogWidget(QWidget* parent, const Partition& p) :
QWidget(parent)
QWidget(parent),
m_Partition(p)
{
readMountpoints("/etc/fstab");
setupUi(this);
labelName().setText(p.deviceNode());
labelType().setText(p.fileSystem().name());
labelName().setText(partition().deviceNode());
labelType().setText(partition().fileSystem().name());
if (mountPoints().find(p.deviceNode()) == mountPoints().end())
mountPoints()[p.deviceNode()] = new MountEntry(p.deviceNode(), QString(), p.fileSystem().name(), QStringList(), 0, 0);
if (mountPoints().find(partition().deviceNode()) == mountPoints().end())
mountPoints()[partition().deviceNode()] = new MountEntry(partition().deviceNode(), QString(), partition().fileSystem().name(), QStringList(), 0, 0, MountEntry::deviceNode);
MountEntry* entry = mountPoints()[p.deviceNode()];
MountEntry* entry = mountPoints()[partition().deviceNode()];
Q_ASSERT(entry);
@ -112,6 +118,20 @@ EditMountPointDialogWidget::EditMountPointDialogWidget(QWidget* parent, const Pa
spinDumpFreq().setValue(entry->dumpFreq);
spinPassNumber().setValue(entry->passNumber);
switch(entry->identifyType)
{
case MountEntry::uuid:
radioUUID().setChecked(true);
break;
case MountEntry::label:
radioLabel().setChecked(true);
break;
default:
radioDeviceNode().setChecked(true);
}
boxOptions()["ro"] = m_CheckReadOnly;
boxOptions()["users"] = m_CheckUsers;
boxOptions()["noauto"] = m_CheckNoAuto;
@ -123,6 +143,20 @@ EditMountPointDialogWidget::EditMountPointDialogWidget(QWidget* parent, const Pa
setupOptions(entry->options);
}
if (partition().fileSystem().uuid().isEmpty())
{
radioUUID().setEnabled(false);
if (radioUUID().isChecked())
radioDeviceNode().setChecked(true);
}
if (partition().fileSystem().label().isEmpty())
{
radioLabel().setEnabled(false);
if (radioLabel().isChecked())
radioDeviceNode().setChecked(true);
}
}
EditMountPointDialogWidget::~EditMountPointDialogWidget()
@ -183,21 +217,28 @@ bool EditMountPointDialogWidget::readMountpoints(const QString& filename)
return false;
}
struct mntent* p = NULL;
struct mntent* mnt = NULL;
while ((p = getmntent(fp)) != NULL)
while ((mnt = getmntent(fp)) != NULL)
{
QString device = p->mnt_fsname;
QString device = mnt->mnt_fsname;
MountEntry::IdentifyType type = MountEntry::deviceNode;
if (device.startsWith("UUID="))
{
type = MountEntry::uuid;
device = findBlkIdDevice("UUID", QString(device).remove("UUID="));
}
else if (device.startsWith("LABEL="))
{
type = MountEntry::label;
device = findBlkIdDevice("LABEL", QString(device).remove("LABEL="));
}
if (!device.isEmpty())
{
QString mountPoint = p->mnt_dir;
mountPoints()[device] = new MountEntry(p);
QString mountPoint = mnt->mnt_dir;
mountPoints()[device] = new MountEntry(mnt, type);
}
}
@ -214,6 +255,7 @@ static void writeEntry(QFile& output, const MountEntry* entry)
return;
QTextStream s(&output);
s << entry->name << "\t"
<< entry->path << "\t"
<< entry->type << "\t"
@ -224,7 +266,7 @@ static void writeEntry(QFile& output, const MountEntry* entry)
bool EditMountPointDialogWidget::acceptChanges()
{
MountEntry* mp = NULL;
MountEntry* entry = NULL;
if (mountPoints().find(labelName().text()) == mountPoints().end())
{
@ -233,12 +275,19 @@ bool EditMountPointDialogWidget::acceptChanges()
}
else
{
mp = mountPoints()[labelName().text()];
entry = mountPoints()[labelName().text()];
mp->dumpFreq = spinDumpFreq().value();
mp->passNumber = spinPassNumber().value();
mp->path = editPath().text();
mp->options = options();
entry->dumpFreq = spinDumpFreq().value();
entry->passNumber = spinPassNumber().value();
entry->path = editPath().text();
entry->options = options();
if (radioUUID().isChecked() && !partition().fileSystem().uuid().isEmpty())
entry->name = "UUID=" + partition().fileSystem().uuid();
else if (radioLabel().isChecked() && !partition().fileSystem().label().isEmpty())
entry->name = "LABEL=" + partition().fileSystem().label();
else
entry->name = partition().deviceNode();
}
return true;

View File

@ -36,6 +36,7 @@ class QWidget;
class QSpinBox;
class QCheckBox;
class QStringList;
class QFile;
struct MountEntry;
@ -55,6 +56,9 @@ class EditMountPointDialogWidget : public QWidget, public Ui::EditMountPointDial
QSpinBox& spinPassNumber() { return *m_SpinPassNumber; }
QLabel& labelType() { return *m_LabelTypeValue; }
QStringList options();
QRadioButton& radioUUID() { return *m_RadioUUID; }
QRadioButton& radioLabel() { return *m_RadioLabel; }
QRadioButton& radioDeviceNode() { return *m_RadioDeviceNode; }
bool acceptChanges();
bool writeMountpoints(const QString& filename);
@ -69,8 +73,10 @@ class EditMountPointDialogWidget : public QWidget, public Ui::EditMountPointDial
const QMap<QString, QCheckBox*>& boxOptions() const { return m_BoxOptions; }
bool readMountpoints(const QString& filename);
QMap<QString, MountEntry*>& mountPoints() { return m_MountPoints; }
const Partition& partition() const { return m_Partition; }
private:
const Partition& m_Partition;
QMap<QString, MountEntry*> m_MountPoints;
QString m_Options;
QMap<QString, QCheckBox*> m_BoxOptions;

View File

@ -14,7 +14,7 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="m_LabelPath">
<property name="text">
<string>Path:</string>
@ -27,7 +27,7 @@
</property>
</widget>
</item>
<item row="4" column="1" colspan="5">
<item row="5" column="1" colspan="5">
<widget class="KLineEdit" name="m_EditPath">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -37,7 +37,7 @@
</property>
</widget>
</item>
<item row="4" column="6">
<item row="5" column="6">
<widget class="KPushButton" name="m_ButtonSelect">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@ -50,7 +50,7 @@
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="m_LabelType">
<property name="text">
<string>Type:</string>
@ -60,7 +60,7 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="m_LabelOptions">
<property name="text">
<string>Options:</string>
@ -70,63 +70,63 @@
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<item row="7" column="1" colspan="2">
<widget class="QCheckBox" name="m_CheckReadOnly">
<property name="text">
<string>Read-only</string>
</property>
</widget>
</item>
<item row="6" column="3" colspan="4">
<item row="7" column="3" colspan="4">
<widget class="QCheckBox" name="m_CheckUsers">
<property name="text">
<string>Users can mount and unmount</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<item row="8" column="1" colspan="2">
<widget class="QCheckBox" name="m_CheckNoAuto">
<property name="text">
<string>No automatic mount</string>
</property>
</widget>
</item>
<item row="7" column="3" colspan="3">
<item row="8" column="3" colspan="3">
<widget class="QCheckBox" name="m_CheckNoAtime">
<property name="text">
<string>No update of file access times</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<item row="9" column="1" colspan="2">
<widget class="QCheckBox" name="m_CheckSync">
<property name="text">
<string>Synchronuous access</string>
</property>
</widget>
</item>
<item row="8" column="3" colspan="4">
<item row="9" column="3" colspan="4">
<widget class="QCheckBox" name="m_CheckNoDirAtime">
<property name="text">
<string>No update of directory access times</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="2">
<item row="10" column="1" colspan="2">
<widget class="QCheckBox" name="m_CheckNoExec">
<property name="text">
<string>No binary execution</string>
</property>
</widget>
</item>
<item row="9" column="3" colspan="4">
<item row="10" column="3" colspan="4">
<widget class="QCheckBox" name="m_CheckRelAtime">
<property name="text">
<string>Update access times relative to modification</string>
</property>
</widget>
</item>
<item row="10" column="3" colspan="3">
<item row="11" column="3" colspan="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -139,14 +139,14 @@
</property>
</spacer>
</item>
<item row="10" column="6">
<item row="11" column="6">
<widget class="KPushButton" name="m_ButtonMore">
<property name="text">
<string>More...</string>
</property>
</widget>
</item>
<item row="11" column="0">
<item row="12" column="0">
<widget class="QLabel" name="m_LabelDumpFreq">
<property name="text">
<string>Dump Frequency:</string>
@ -159,10 +159,10 @@
</property>
</widget>
</item>
<item row="11" column="1">
<item row="12" column="1">
<widget class="QSpinBox" name="m_SpinDumpFreq"/>
</item>
<item row="11" column="2">
<item row="12" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -175,7 +175,7 @@
</property>
</spacer>
</item>
<item row="11" column="3">
<item row="12" column="3">
<widget class="QLabel" name="m_LabelPassNumber">
<property name="text">
<string>Pass Number:</string>
@ -188,10 +188,10 @@
</property>
</widget>
</item>
<item row="11" column="4">
<item row="12" column="4">
<widget class="QSpinBox" name="m_SpinPassNumber"/>
</item>
<item row="11" column="5" colspan="2">
<item row="12" column="5" colspan="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -220,7 +220,7 @@
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<item row="6" column="1" colspan="2">
<widget class="QLabel" name="m_LabelTypeValue">
<property name="text">
<string/>
@ -266,7 +266,7 @@
</property>
</spacer>
</item>
<item row="12" column="0" colspan="7">
<item row="13" column="0" colspan="7">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -282,6 +282,40 @@
</property>
</spacer>
</item>
<item row="4" column="1">
<widget class="QRadioButton" name="m_RadioDeviceNode">
<property name="text">
<string>Device Node</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QRadioButton" name="m_RadioUUID">
<property name="text">
<string>UUID</string>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QRadioButton" name="m_RadioLabel">
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Identify by:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>