summaryrefslogtreecommitdiffstats
path: root/tdeioslave/media/mediamanager
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2022-03-23 09:56:22 +0900
committerMichele Calgaro <[email protected]>2022-03-23 11:48:38 +0900
commit40ef766f02ea0e099a3fad77ed7eec519e2d5ec8 (patch)
tree2691377174181d81f7451ce83543ab83a5b057fc /tdeioslave/media/mediamanager
parentd048506bb65a3f77102f07f54c7bfc16c80e003e (diff)
downloadtdebase-40ef766f02ea0e099a3fad77ed7eec519e2d5ec8.tar.gz
tdebase-40ef766f02ea0e099a3fad77ed7eec519e2d5ec8.zip
tdeio media: add releaseHolders parameter to lock/lockByNode dcop calls.
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'tdeioslave/media/mediamanager')
-rw-r--r--tdeioslave/media/mediamanager/mediamanager.cpp8
-rw-r--r--tdeioslave/media/mediamanager/mediamanager.h4
-rw-r--r--tdeioslave/media/mediamanager/tdehardwarebackend.cpp64
-rw-r--r--tdeioslave/media/mediamanager/tdehardwarebackend.h14
4 files changed, 73 insertions, 17 deletions
diff --git a/tdeioslave/media/mediamanager/mediamanager.cpp b/tdeioslave/media/mediamanager/mediamanager.cpp
index aad9bddf2..dba4c1150 100644
--- a/tdeioslave/media/mediamanager/mediamanager.cpp
+++ b/tdeioslave/media/mediamanager/mediamanager.cpp
@@ -260,12 +260,12 @@ TQStringVariantMap MediaManager::unlock(const TQString &uid, const TQString &pas
return result;
}
-TQStringVariantMap MediaManager::lock(const TQString &uid)
+TQStringVariantMap MediaManager::lock(const TQString &uid, bool releaseHolders)
{
#ifdef COMPILE_TDEHARDWAREBACKEND
if (m_tdebackend)
{
- return m_tdebackend->lock(uid);
+ return m_tdebackend->lock(uid, releaseHolders);
}
#endif
TQStringVariantMap result;
@@ -324,7 +324,7 @@ TQStringVariantMap MediaManager::unlockByNode(const TQString &deviceNode, const
return unlock(medium->id(), password);
}
-TQStringVariantMap MediaManager::lockByNode(const TQString &deviceNode)
+TQStringVariantMap MediaManager::lockByNode(const TQString &deviceNode, bool releaseHolders)
{
const Medium *medium = m_mediaList.findByNode(deviceNode);
if (!medium) {
@@ -333,7 +333,7 @@ TQStringVariantMap MediaManager::lockByNode(const TQString &deviceNode)
result["result"] = false;
return result;
}
- return lock(medium->id());
+ return lock(medium->id(), releaseHolders);
}
TQStringVariantMap MediaManager::ejectByNode(const TQString &deviceNode)
diff --git a/tdeioslave/media/mediamanager/mediamanager.h b/tdeioslave/media/mediamanager/mediamanager.h
index 7d5e6dc24..dfb3e577c 100644
--- a/tdeioslave/media/mediamanager/mediamanager.h
+++ b/tdeioslave/media/mediamanager/mediamanager.h
@@ -51,13 +51,13 @@ k_dcop:
TQStringVariantMap mount(const TQString &uid);
TQStringVariantMap unmount(const TQString &uid);
TQStringVariantMap unlock(const TQString &uid, const TQString &password);
- TQStringVariantMap lock(const TQString &uid);
+ TQStringVariantMap lock(const TQString &uid, bool releaseHolders);
TQStringVariantMap eject(const TQString &uid);
TQStringVariantMap mountByNode(const TQString &deviceNode);
TQStringVariantMap unmountByNode(const TQString &deviceNode);
TQStringVariantMap unlockByNode(const TQString &deviceNode, const TQString &password);
- TQStringVariantMap lockByNode(const TQString &deviceNode);
+ TQStringVariantMap lockByNode(const TQString &deviceNode, bool releaseHolders);
TQStringVariantMap ejectByNode(const TQString &deviceNode);
TQString mimeType(const TQString &name);
diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
index ba99b8c0c..2a54f6b6b 100644
--- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
+++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
@@ -1478,9 +1478,10 @@ TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &passwo
return result;
}
-TQStringVariantMap TDEBackend::lock(const TQString &id)
+TQStringVariantMap TDEBackend::lock(const TQString &id, bool releaseHolders)
{
- kdDebug(1219) << "TDEBackend::lock for id " << id << endl;
+ kdDebug(1219) << "TDEBackend::lock for id " << id << ", release holders "
+ << releaseHolders << endl;
TQStringVariantMap result;
@@ -1509,6 +1510,12 @@ TQStringVariantMap TDEBackend::lock(const TQString &id)
return result;
}
+ // Release device holders if requested
+ if (releaseHolders)
+ {
+ releaseHolderDevices(medium->deviceNode(), false);
+ }
+
TQStringVariantMap lockResult = sdevice->lockDevice();
if (lockResult["result"].toBool() == false) {
TQString qerror = i18n("<b>Unable to lock the device.</b>");
@@ -1566,6 +1573,59 @@ TQStringVariantMap TDEBackend::eject(const TQString &id)
return result;
}
+void TDEBackend::releaseHolderDevices(const TQString &deviceNode, bool handleThis)
+{
+ kdDebug(1219) << "TDEBackend::releaseHolderDevices for node " << deviceNode
+ << ", handle this " << (handleThis ? "yes" : "no") << endl;
+
+ const Medium *medium = m_mediaList.findByNode(deviceNode);
+ if (!medium)
+ {
+ return;
+ }
+
+ // Scan the holding devices and unmount/lock them if possible
+ TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
+ TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
+ if (sdevice)
+ {
+ TQStringList holdingDeviceList = sdevice->holdingDevices();
+ for (TQStringList::Iterator holdingDevIt = holdingDeviceList.begin(); holdingDevIt != holdingDeviceList.end(); ++holdingDevIt)
+ {
+ TDEGenericDevice *hwHolderDevice = hwdevices->findBySystemPath(*holdingDevIt);
+ if (hwHolderDevice->type() == TDEGenericDeviceType::Disk)
+ {
+ TDEStorageDevice *holderSDevice = static_cast<TDEStorageDevice*>(hwHolderDevice);
+ const Medium *holderMedium = m_mediaList.findByNode(holderSDevice->deviceNode());
+ if (holderMedium && !holderMedium->id().isEmpty())
+ {
+ releaseHolderDevices(holderMedium->deviceNode(), true);
+ }
+ }
+ }
+ }
+
+ if (handleThis)
+ {
+ // Unmount if necessary
+ if (medium->isMountable() && medium->isMounted())
+ {
+ unmount(medium->id());
+ // Must process udev events before continuing, to make sure all
+ // affected devices are properly updated
+ tqApp->processEvents();
+ }
+ // Lock if necessary.
+ if (medium->isEncrypted() && !medium->isLocked())
+ {
+ lock(medium->id(), false);
+ // Must process udev events before continuing, to make sure all
+ // affected devices are properly updated
+ tqApp->processEvents();
+ }
+ }
+}
+
void TDEBackend::slotResult(TDEIO::Job *job)
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.h b/tdeioslave/media/mediamanager/tdehardwarebackend.h
index ab7eeea97..e1b3a9f85 100644
--- a/tdeioslave/media/mediamanager/tdehardwarebackend.h
+++ b/tdeioslave/media/mediamanager/tdehardwarebackend.h
@@ -72,8 +72,8 @@ public:
TQStringVariantMap mount(const TQString &id);
TQStringVariantMap unmount(const TQString &id);
TQStringVariantMap unlock(const TQString &id, const TQString &password);
- TQStringVariantMap lock(const TQString &id);
- TQStringVariantMap eject(const TQString &uid);
+ TQStringVariantMap lock(const TQString &id, bool releaseHolders);
+ TQStringVariantMap eject(const TQString &id);
private:
/**
@@ -118,17 +118,13 @@ private:
*/
void ResetProperties(TDEStorageDevice * sdevice, bool allowNotification=false, bool overrideIgnoreList=false);
- /**
- * Find the medium that is concerned with device udi
- */
-// const char* findMediumUdiFromUdi(const char* udi);
-
void setVolumeProperties(Medium* medium);
bool setFloppyProperties(Medium* medium);
- void setFloppyMountState( Medium* medium );
-// bool setFstabProperties(Medium* medium);
+ void setFloppyMountState(Medium* medium);
void setCameraProperties(Medium* medium);
+ void releaseHolderDevices(const TQString &deviceNode, bool handleThis);
TQString generateName(const TQString &devNode);
+
static TQString isInFstab(const Medium *medium);
static TQString listUsingProcesses(const Medium *medium);
static TQString killUsingProcesses(const Medium *medium);