From ff714f2f0ee650477b886f87507ccc5ee0c94247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sun, 9 Apr 2017 17:49:55 +0100 Subject: [PATCH] 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. --- CMakeLists.txt | 2 +- src/fs/btrfs.cpp | 7 +++++++ src/fs/btrfs.h | 1 + src/fs/ext2.cpp | 6 ++++++ src/fs/ext2.h | 1 + src/fs/filesystem.cpp | 17 +++++++++++++++++ src/fs/filesystem.h | 1 + src/fs/jfs.cpp | 6 ++++++ src/fs/jfs.h | 1 + src/fs/linuxswap.cpp | 6 ++++++ src/fs/linuxswap.h | 1 + src/jobs/setfilesystemlabeljob.cpp | 8 +++++++- 12 files changed, 55 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc31121..5bd84b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}"') #" diff --git a/src/fs/btrfs.cpp b/src/fs/btrfs.cpp index 7fa5d03..a715441 100644 --- a/src/fs/btrfs.cpp +++ b/src/fs/btrfs.cpp @@ -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); diff --git a/src/fs/btrfs.h b/src/fs/btrfs.h index 04552c9..9603676 100644 --- a/src/fs/btrfs.h +++ b/src/fs/btrfs.h @@ -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 { diff --git a/src/fs/ext2.cpp b/src/fs/ext2.cpp index 0ae0a11..143e41e 100644 --- a/src/fs/ext2.cpp +++ b/src/fs/ext2.cpp @@ -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 }); diff --git a/src/fs/ext2.h b/src/fs/ext2.h index a269ada..d26590c 100644 --- a/src/fs/ext2.h +++ b/src/fs/ext2.h @@ -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 { diff --git a/src/fs/filesystem.cpp b/src/fs/filesystem.cpp index f3bd927..a07ef89 100644 --- a/src/fs/filesystem.cpp +++ b/src/fs/filesystem.cpp @@ -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 diff --git a/src/fs/filesystem.h b/src/fs/filesystem.h index 92f9650..8e01f58 100644 --- a/src/fs/filesystem.h +++ b/src/fs/filesystem.h @@ -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; diff --git a/src/fs/jfs.cpp b/src/fs/jfs.cpp index bf6a906..d8fe029 100644 --- a/src/fs/jfs.cpp +++ b/src/fs/jfs.cpp @@ -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 }); diff --git a/src/fs/jfs.h b/src/fs/jfs.h index 3819049..62c861e 100644 --- a/src/fs/jfs.h +++ b/src/fs/jfs.h @@ -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; diff --git a/src/fs/linuxswap.cpp b/src/fs/linuxswap.cpp index 01a18d2..a757f6e 100644 --- a/src/fs/linuxswap.cpp +++ b/src/fs/linuxswap.cpp @@ -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"); diff --git a/src/fs/linuxswap.h b/src/fs/linuxswap.h index 028c38d..487013a 100644 --- a/src/fs/linuxswap.h +++ b/src/fs/linuxswap.h @@ -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; diff --git a/src/jobs/setfilesystemlabeljob.cpp b/src/jobs/setfilesystemlabeljob.cpp index 8c36e23..7ea7a07 100644 --- a/src/jobs/setfilesystemlabeljob.cpp +++ b/src/jobs/setfilesystemlabeljob.cpp @@ -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 %1 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);