diff --git a/src/fs/btrfs.cpp b/src/fs/btrfs.cpp --- a/src/fs/btrfs.cpp +++ b/src/fs/btrfs.cpp @@ -17,12 +17,14 @@ *************************************************************************/ #include "fs/btrfs.h" +#include "fs/filesystem.h" #include "util/externalcommand.h" #include "util/capacity.h" #include "util/report.h" #include +#include #include #include @@ -166,11 +168,13 @@ bool btrfs::resizeOnline(Report& report, const QString& deviceNode, const QString& mountPoint, qint64 length) const { - ExternalCommand resizeCmd(report, QStringLiteral("btrfs"), - { QStringLiteral("filesystem"), QStringLiteral("resize"), QString::number(length), mountPoint }); + if (!FileSystem::isReadOnly()) { + ExternalCommand resizeCmd(report, QStringLiteral("btrfs"), + { QStringLiteral("filesystem"), QStringLiteral("resize"), QString::number(length), mountPoint }); - if (resizeCmd.run(-1) && resizeCmd.exitCode() == 0) - return true; + if (resizeCmd.run(-1) && resizeCmd.exitCode() == 0) + return true; + } report.line() << xi18nc("@info:progress", "Resizing Btrfs file system on partition %1 failed: btrfs file system resize failed.", deviceNode); return false; diff --git a/src/fs/filesystem.h b/src/fs/filesystem.h --- a/src/fs/filesystem.h +++ b/src/fs/filesystem.h @@ -235,6 +235,9 @@ virtual bool mount(Report& report, const QString& deviceNode, const QString& mountPoint); virtual bool unmount(Report& report, const QString& deviceNode); + /**< @return true if the mount point where FileSystem is mounted is read only */ + bool isReadOnly() const; + /**< @return the FileSystem's first sector */ qint64 firstSector() const; @@ -282,7 +285,7 @@ /**< @param s the new UUID */ void setUUID(const QString& s); - + protected: static bool findExternal(const QString& cmdName, const QStringList& args = QStringList(), int exptectedCode = 1); diff --git a/src/fs/filesystem.cpp b/src/fs/filesystem.cpp --- a/src/fs/filesystem.cpp +++ b/src/fs/filesystem.cpp @@ -555,6 +555,19 @@ return false; } +bool FileSystem::isReadOnly() const +{ + for (const QStorageInfo& volume : QStorageInfo::mountedVolumes()) { + if (!volume.isValid() || !volume.isReady()) { + return false; + } else { + return volume.isReadOnly(); + } + } + + return true; +} + qint64 FileSystem::firstSector() const { return d->m_FirstSector;