Fix online label support.

Some filesystems require mountpoint while some deviceNode to change file system
label only. So split writeLabel action into online and offline actions.
This commit is contained in:
Andrius Štikonas 2017-04-09 17:49:55 +01:00
parent 427e37a047
commit ff714f2f0e
12 changed files with 55 additions and 2 deletions

View File

@ -23,7 +23,7 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(QT_MIN_VERSION "5.6.1")
set(VERSION_MAJOR "3")
set(VERSION_MINOR "0")
set(VERSION_RELEASE "3")
set(VERSION_RELEASE "50")
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE})
set(SOVERSION "4")
add_definitions(-D'VERSION="${VERSION}"') #"

View File

@ -182,6 +182,13 @@ bool btrfs::writeLabel(Report& report, const QString& deviceNode, const QString&
return cmd.run(-1) && cmd.exitCode() == 0;
}
bool btrfs::writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel)
{
Q_UNUSED(deviceNode)
ExternalCommand cmd(report, QStringLiteral("btrfs"), { QStringLiteral("filesystem"), QStringLiteral("label"), mountPoint, newLabel });
return cmd.run(-1) && cmd.exitCode() == 0;
}
bool btrfs::updateUUID(Report& report, const QString& deviceNode) const
{
Q_UNUSED(report);

View File

@ -49,6 +49,7 @@ public:
bool resize(Report& report, const QString& deviceNode, qint64 length) const override;
bool resizeOnline(Report& report, const QString& deviceNode, const QString& mountPoint, qint64 length) const override;
bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override;
bool writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel) override;
bool updateUUID(Report& report, const QString& deviceNode) const override;
CommandSupportType supportGetUsed() const override {

View File

@ -151,6 +151,12 @@ bool ext2::writeLabel(Report& report, const QString& deviceNode, const QString&
return cmd.run(-1) && cmd.exitCode() == 0;
}
bool ext2::writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel)
{
Q_UNUSED(mountPoint)
return writeLabel(report, deviceNode, newLabel);
}
bool ext2::updateUUID(Report& report, const QString& deviceNode) const
{
ExternalCommand cmd(report, QStringLiteral("tune2fs"), { QStringLiteral("-U"), QStringLiteral("random"), deviceNode });

View File

@ -47,6 +47,7 @@ public:
bool create(Report& report, const QString& deviceNode) override;
bool resize(Report& report, const QString& deviceNode, qint64 length) const override;
bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override;
bool writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel) override;
bool updateUUID(Report& report, const QString& deviceNode) const override;
CommandSupportType supportGetUsed() const override {

View File

@ -242,6 +242,23 @@ bool FileSystem::writeLabel(Report& report, const QString& deviceNode, const QSt
return true;
}
/** Writes a label for the FileSystem to disk
@param report Report to write status information to
@param deviceNode the device node for the Partition the FileSystem is on
@param mountPoint the mount point where FileSystem is mounted on
@param newLabel the new label for the FileSystem
@return true on success
*/
bool FileSystem::writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel)
{
Q_UNUSED(report);
Q_UNUSED(deviceNode);
Q_UNUSED(mountPoint);
Q_UNUSED(newLabel);
return true;
}
/** Copies a FileSystem from one Partition to another
@param report Report to write status information to
@param targetDeviceNode device node of the target Partition

View File

@ -116,6 +116,7 @@ public:
virtual bool resizeOnline(Report& report, const QString& deviceNode, const QString& mountPoint, qint64 newLength) const;
virtual bool move(Report& report, const QString& deviceNode, qint64 newStartSector) const;
virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel);
virtual bool writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel);
virtual bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const;
virtual bool backup(Report& report, const Device& sourceDevice, const QString& deviceNode, const QString& filename) const;
virtual bool remove(Report& report, const QString& deviceNode) const;

View File

@ -138,6 +138,12 @@ bool jfs::writeLabel(Report& report, const QString& deviceNode, const QString& n
return cmd.run(-1) && cmd.exitCode() == 0;
}
bool jfs::writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel)
{
Q_UNUSED(mountPoint)
return writeLabel(report, deviceNode, newLabel);
}
bool jfs::check(Report& report, const QString& deviceNode) const
{
ExternalCommand cmd(report, QStringLiteral("fsck.jfs"), { QStringLiteral("-f"), deviceNode });

View File

@ -48,6 +48,7 @@ public:
bool resize(Report& report, const QString& deviceNode, qint64 length) const override;
bool resizeOnline(Report& report, const QString& deviceNode, const QString& mountPoint, qint64 length) const override;
bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override;
bool writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel) override;
CommandSupportType supportGetUsed() const override {
return m_GetUsed;

View File

@ -127,6 +127,12 @@ bool linuxswap::writeLabel(Report& report, const QString& deviceNode, const QStr
return cmd.run(-1) && cmd.exitCode() == 0;
}
bool linuxswap::writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel)
{
Q_UNUSED(mountPoint)
return writeLabel(report, deviceNode, newLabel);
}
QString linuxswap::mountTitle() const
{
return xi18nc("@title:menu", "Activate swap");

View File

@ -45,6 +45,7 @@ public:
bool create(Report& report, const QString& deviceNode) override;
bool resize(Report& report, const QString& deviceNode, qint64 length) const override;
bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override;
bool writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel) override;
bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const override;
bool updateUUID(Report& report, const QString& deviceNode) const override;
qint64 readUsedCapacity(const QString& deviceNode) const override;

View File

@ -48,12 +48,18 @@ bool SetFileSystemLabelJob::run(Report& parent)
// we don't have to check for support to avoid having a failed job.
if (partition().fileSystem().supportSetLabel() == FileSystem::cmdSupportNone)
report->line() << xi18nc("@info:progress", "File system on partition <filename>%1</filename> does not support setting labels. Job ignored.", partition().deviceNode());
else if (partition().fileSystem().supportSetLabel() == FileSystem::cmdSupportFileSystem) {
else if (partition().fileSystem().supportSetLabel() == FileSystem::cmdSupportFileSystem && !partition().isMounted()) {
rval = partition().fileSystem().writeLabel(*report, partition().deviceNode(), label());
if (rval)
partition().fileSystem().setLabel(label());
}
else if (partition().fileSystem().supportSetLabelOnline() == FileSystem::cmdSupportFileSystem && partition().isMounted()) {
rval = partition().fileSystem().writeLabelOnline(*report, partition().deviceNode(), partition().mountPoint(), label());
if (rval)
partition().fileSystem().setLabel(label());
}
jobFinished(*report, rval);