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

View File

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

View File

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