7#include "fstabstorageaccess.h"
8#include "fstabwatcher.h"
10#include <solid/devices/backends/fstab/fstabdevice.h>
11#include <solid/devices/backends/fstab/fstabhandling.h>
12#include <solid/devices/backends/fstab/fstabservice.h>
20using namespace Solid::Backends::Fstab;
22FstabStorageAccess::FstabStorageAccess(Solid::Backends::Fstab::FstabDevice *device)
24 , m_fstabDevice(device)
26 QStringList currentMountPoints = FstabHandling::currentMountPoints(device->device());
27 if (currentMountPoints.
isEmpty()) {
28 QStringList mountPoints = FstabHandling::mountPoints(device->device());
29 m_filePath = mountPoints.
isEmpty() ?
QString() : mountPoints.first();
30 m_isAccessible =
false;
32 m_filePath = currentMountPoints.
first();
33 m_isAccessible =
true;
36 const bool inUserPath =
39 const bool gvfsHidden = FstabHandling::options(device->device()).contains(
QLatin1String(
"x-gvfs-hide"));
40 const bool fsIsOverlay = FstabHandling::fstype(device->device()) ==
QLatin1String(
"overlay");
42 m_isIgnored = gvfsHidden ||
44 (fsIsOverlay && m_filePath !=
QLatin1String(
"/") && !inUserPath);
46 connect(device, &FstabDevice::mtabChanged,
this, &FstabStorageAccess::onMtabChanged);
50FstabStorageAccess::~FstabStorageAccess()
54void FstabStorageAccess::connectDBusSignals()
56 m_fstabDevice->registerAction(QStringLiteral(
"setup"),
this, SLOT(slotSetupRequested()), SLOT(slotSetupDone(
int, QString)));
58 m_fstabDevice->registerAction(QStringLiteral(
"teardown"),
this, SLOT(slotTeardownRequested()), SLOT(slotTeardownDone(
int, QString)));
61const Solid::Backends::Fstab::FstabDevice *FstabStorageAccess::fstabDevice()
const
66bool FstabStorageAccess::isAccessible()
const
68 return m_isAccessible;
71QString FstabStorageAccess::filePath()
const
76bool FstabStorageAccess::isIgnored()
const
81bool FstabStorageAccess::isEncrypted()
const
83 return m_fstabDevice->isEncrypted();
86bool FstabStorageAccess::setup()
88 if (filePath().isEmpty()) {
91 m_fstabDevice->broadcastActionRequested(QStringLiteral(
"setup"));
92 return FstabHandling::callSystemCommand(QStringLiteral(
"mount"), {filePath()},
this, [
this](QProcess *process) {
93 if (process->exitCode() == 0) {
94 m_fstabDevice->broadcastActionDone(QStringLiteral(
"setup"), Solid::NoError, QString());
96 m_fstabDevice->broadcastActionDone(QStringLiteral(
"setup"),
97 Solid::UnauthorizedOperation,
103void FstabStorageAccess::slotSetupRequested()
105 Q_EMIT setupRequested(m_fstabDevice->udi());
108bool FstabStorageAccess::teardown()
110 if (filePath().isEmpty()) {
113 m_fstabDevice->broadcastActionRequested(QStringLiteral(
"teardown"));
114 return FstabHandling::callSystemCommand(QStringLiteral(
"umount"), {filePath()},
this, [
this](QProcess *process) {
115 if (process->exitCode() == 0) {
116 m_fstabDevice->broadcastActionDone(QStringLiteral(
"teardown"), Solid::NoError);
117 }
else if (process->exitCode() == EBUSY) {
118 m_fstabDevice->broadcastActionDone(QStringLiteral(
"teardown"), Solid::DeviceBusy);
119 }
else if (process->exitCode() == EPERM) {
120 m_fstabDevice->broadcastActionDone(QStringLiteral(
"teardown"),
121 Solid::UnauthorizedOperation,
124 m_fstabDevice->broadcastActionDone(QStringLiteral(
"teardown"),
125 Solid::OperationFailed,
131void FstabStorageAccess::slotTeardownRequested()
133 Q_EMIT teardownRequested(m_fstabDevice->udi());
136void FstabStorageAccess::slotSetupDone(
int error,
const QString &errorString)
138 Q_EMIT setupDone(
static_cast<Solid::ErrorType
>(error), errorString, m_fstabDevice->udi());
141void FstabStorageAccess::slotTeardownDone(
int error,
const QString &errorString)
143 Q_EMIT teardownDone(
static_cast<Solid::ErrorType
>(error), errorString, m_fstabDevice->udi());
146void FstabStorageAccess::onMtabChanged(
const QString &device)
148 QStringList currentMountPoints = FstabHandling::currentMountPoints(device);
149 if (currentMountPoints.
isEmpty()) {
151 m_filePath = FstabHandling::mountPoints(device).first();
152 if (m_isAccessible) {
153 m_isAccessible =
false;
154 Q_EMIT accessibilityChanged(
false, QStringLiteral(FSTAB_UDI_PREFIX
"/%1").arg(device));
158 m_filePath = currentMountPoints.
first();
159 if (!m_isAccessible) {
160 m_isAccessible =
true;
161 Q_EMIT accessibilityChanged(
true, QStringLiteral(FSTAB_UDI_PREFIX
"/%1").arg(device));
166#include "moc_fstabstorageaccess.cpp"
bool isEmpty() const const
QString fromUtf8(QByteArrayView str)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)