move mount logic from Partition to FileSystem
This commit is contained in:
parent
b7a29bc3f6
commit
1bdafec73b
|
@ -267,16 +267,15 @@ void Partition::checkChildrenMounted()
|
||||||
bool Partition::canMount() const
|
bool Partition::canMount() const
|
||||||
{
|
{
|
||||||
// cannot mount if already mounted
|
// cannot mount if already mounted
|
||||||
if (isMounted())
|
if (isMounted()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// if the file system says we can mount without mount points, that's fine
|
if (fileSystem().canMount(deviceNode(), mountPoint())) {
|
||||||
// (this is the case for swap only, actually)
|
|
||||||
if (fileSystem().canMount(deviceNode()))
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// cannot mount if we have no mount points
|
return false;
|
||||||
return !mountPoint().isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return true if this Partition can be unmounted */
|
/** @return true if this Partition can be unmounted */
|
||||||
|
@ -295,12 +294,8 @@ bool Partition::mount(Report& report)
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
if (fileSystem().canMount(deviceNode()))
|
if (fileSystem().canMount(deviceNode(), mountPoint())) {
|
||||||
success = fileSystem().mount(deviceNode(), mountPoint());
|
success = fileSystem().mount(report, deviceNode(), mountPoint());
|
||||||
else {
|
|
||||||
ExternalCommand mountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << deviceNode() << mountPoint());
|
|
||||||
if (mountCmd.run() && mountCmd.exitCode() == 0)
|
|
||||||
success = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setMounted(success);
|
setMounted(success);
|
||||||
|
|
|
@ -393,16 +393,27 @@ void FileSystem::move(qint64 newStartSector)
|
||||||
setFirstSector(newStartSector);
|
setFirstSector(newStartSector);
|
||||||
setLastSector(newStartSector + savedLength - 1);
|
setLastSector(newStartSector + savedLength - 1);
|
||||||
}
|
}
|
||||||
|
bool FileSystem::canMount(const QString& deviceNode, const QString& mountPoint) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(deviceNode);
|
||||||
|
// cannot mount if we have no mount points
|
||||||
|
return !mountPoint.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
/** Attempt to mount this FileSystem on a given mount point
|
/** Attempt to mount this FileSystem on a given mount point
|
||||||
@param mountPoint the mount point to mount the FileSystem on
|
@param mountPoint the mount point to mount the FileSystem on
|
||||||
@return true on success
|
@return true on success
|
||||||
*/
|
*/
|
||||||
bool FileSystem::mount(const QString &deviceNode, const QString &mountPoint)
|
bool FileSystem::mount(Report& report, const QString &deviceNode, const QString &mountPoint)
|
||||||
{
|
{
|
||||||
Q_UNUSED(deviceNode);
|
ExternalCommand mountCmd( report,
|
||||||
Q_UNUSED(mountPoint);
|
QStringLiteral("mount"),
|
||||||
|
{ QStringLiteral("--verbose"),
|
||||||
|
deviceNode,
|
||||||
|
mountPoint });
|
||||||
|
if (mountCmd.run() && mountCmd.exitCode() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,9 +175,8 @@ public:
|
||||||
static FileSystem::Type typeForName(const QString& s);
|
static FileSystem::Type typeForName(const QString& s);
|
||||||
static FileSystem::Type detectFileSystem(const QString& partitionPath);
|
static FileSystem::Type detectFileSystem(const QString& partitionPath);
|
||||||
|
|
||||||
virtual bool canMount(const QString&) const {
|
/**< @return true if this FileSystem can be mounted */
|
||||||
return false; /**< @return true if this FileSystem can be mounted */
|
virtual bool canMount(const QString& deviceNode, const QString& mountPoint) const;
|
||||||
}
|
|
||||||
virtual bool canUnmount(const QString&) const {
|
virtual bool canUnmount(const QString&) const {
|
||||||
return true; /**< @return true if this FileSystem can be unmounted */
|
return true; /**< @return true if this FileSystem can be unmounted */
|
||||||
}
|
}
|
||||||
|
@ -185,7 +184,7 @@ public:
|
||||||
virtual QString mountTitle() const;
|
virtual QString mountTitle() const;
|
||||||
virtual QString unmountTitle() const;
|
virtual QString unmountTitle() const;
|
||||||
|
|
||||||
virtual bool mount(const QString& deviceNode, const QString& mountPoint);
|
virtual bool mount(Report& report, const QString& deviceNode, const QString& mountPoint);
|
||||||
virtual bool unmount(Report& report, const QString& deviceNode);
|
virtual bool unmount(Report& report, const QString& deviceNode);
|
||||||
|
|
||||||
qint64 firstSector() const {
|
qint64 firstSector() const {
|
||||||
|
|
|
@ -132,10 +132,17 @@ QString linuxswap::unmountTitle() const
|
||||||
return i18nc("@title:menu", "Deactivate swap");
|
return i18nc("@title:menu", "Deactivate swap");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool linuxswap::mount(const QString& deviceNode, const QString& mountPoint)
|
bool linuxswap::canMount(const QString& deviceNode, const QString& mountPoint) const {
|
||||||
|
Q_UNUSED(deviceNode);
|
||||||
|
Q_UNUSED(mountPoint);
|
||||||
|
// linux swap doesn't require mount point to activate
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool linuxswap::mount(Report& report, const QString& deviceNode, const QString& mountPoint)
|
||||||
{
|
{
|
||||||
Q_UNUSED(mountPoint);
|
Q_UNUSED(mountPoint);
|
||||||
ExternalCommand cmd(QStringLiteral("swapon"), { deviceNode });
|
ExternalCommand cmd(report, QStringLiteral("swapon"), { deviceNode });
|
||||||
return cmd.run(-1) && cmd.exitCode() == 0;
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,14 +48,8 @@ public:
|
||||||
virtual bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const override;
|
virtual bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const override;
|
||||||
virtual bool updateUUID(Report& report, const QString& deviceNode) const override;
|
virtual bool updateUUID(Report& report, const QString& deviceNode) const override;
|
||||||
|
|
||||||
virtual bool canMount(const QString&) const override {
|
virtual bool canMount(const QString& deviceNode, const QString& mountPoint) const override;
|
||||||
return true;
|
virtual bool mount(Report& report, const QString& deviceNode, const QString& mountPoint) override;
|
||||||
}
|
|
||||||
virtual bool canUnmount(const QString&) const override {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool mount(const QString& deviceNode, const QString& mountPoint) override;
|
|
||||||
virtual bool unmount(Report& report, const QString& deviceNode) override;
|
virtual bool unmount(Report& report, const QString& deviceNode) override;
|
||||||
|
|
||||||
virtual QString mountTitle() const override;
|
virtual QString mountTitle() const override;
|
||||||
|
|
|
@ -176,12 +176,12 @@ QString luks::passphrase() const
|
||||||
return m_passphrase;
|
return m_passphrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool luks::canMount(const QString& deviceNode) const
|
bool luks::canMount(const QString& deviceNode, const QString& mountPoint) const
|
||||||
{
|
{
|
||||||
return m_isCryptOpen &&
|
return m_isCryptOpen &&
|
||||||
!m_isMounted &&
|
!m_isMounted &&
|
||||||
m_innerFs &&
|
m_innerFs &&
|
||||||
m_innerFs->canMount(mapperName(deviceNode));
|
m_innerFs->canMount(mapperName(deviceNode), mountPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool luks::canUnmount(const QString& deviceNode) const
|
bool luks::canUnmount(const QString& deviceNode) const
|
||||||
|
@ -360,7 +360,7 @@ qint64 luks::readUsedCapacity(const QString& deviceNode) const
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool luks::mount(const QString& deviceNode, const QString& mountPoint)
|
bool luks::mount(Report& report, const QString& deviceNode, const QString& mountPoint)
|
||||||
{
|
{
|
||||||
if (!m_isCryptOpen)
|
if (!m_isCryptOpen)
|
||||||
{
|
{
|
||||||
|
@ -382,9 +382,9 @@ bool luks::mount(const QString& deviceNode, const QString& mountPoint)
|
||||||
if (mapperNode.isEmpty())
|
if (mapperNode.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_innerFs->canMount(mapperNode))
|
if (m_innerFs->canMount(mapperNode, mountPoint))
|
||||||
{
|
{
|
||||||
if (m_innerFs->mount(mapperNode, mountPoint))
|
if (m_innerFs->mount(report, mapperNode, mountPoint))
|
||||||
{
|
{
|
||||||
m_isMounted = true;
|
m_isMounted = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -392,6 +392,7 @@ bool luks::mount(const QString& deviceNode, const QString& mountPoint)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ExternalCommand mountCmd(
|
ExternalCommand mountCmd(
|
||||||
|
report,
|
||||||
QStringLiteral("mount"),
|
QStringLiteral("mount"),
|
||||||
{ QStringLiteral("-v"), mapperNode, mountPoint });
|
{ QStringLiteral("-v"), mapperNode, mountPoint });
|
||||||
if (mountCmd.run() && mountCmd.exitCode() == 0)
|
if (mountCmd.run() && mountCmd.exitCode() == 0)
|
||||||
|
|
|
@ -118,7 +118,7 @@ public:
|
||||||
void setPassphrase(const QString&);
|
void setPassphrase(const QString&);
|
||||||
QString passphrase() const;
|
QString passphrase() const;
|
||||||
|
|
||||||
virtual bool canMount(const QString&) const override;
|
virtual bool canMount(const QString&, const QString&) const override;
|
||||||
virtual bool canUnmount(const QString&) const override;
|
virtual bool canUnmount(const QString&) const override;
|
||||||
bool isMounted() const;
|
bool isMounted() const;
|
||||||
void setMounted(bool mounted);
|
void setMounted(bool mounted);
|
||||||
|
@ -134,7 +134,7 @@ public:
|
||||||
void loadInnerFileSystem(const QString& mapperNode);
|
void loadInnerFileSystem(const QString& mapperNode);
|
||||||
void createInnerFileSystem(Type type);
|
void createInnerFileSystem(Type type);
|
||||||
|
|
||||||
virtual bool mount(const QString& deviceNode, const QString& mountPoint) override;
|
virtual bool mount(Report& report, const QString& deviceNode, const QString& mountPoint) override;
|
||||||
virtual bool unmount(Report& report, const QString& deviceNode) override;
|
virtual bool unmount(Report& report, const QString& deviceNode) override;
|
||||||
|
|
||||||
virtual FileSystem::Type type() const override;
|
virtual FileSystem::Type type() const override;
|
||||||
|
|
Loading…
Reference in New Issue