summaryrefslogtreecommitdiffstats
path: root/tdeioslave/media
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
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')
-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
-rw-r--r--tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp41
-rw-r--r--tdeioslave/media/mounthelper/tdeio_media_mounthelper.h2
6 files changed, 87 insertions, 46 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);
diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp
index bbfbaa6b2..706b5e13a 100644
--- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp
+++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp
@@ -29,6 +29,7 @@
#include <kurl.h>
#include <tdemessagebox.h>
#include <dcopclient.h>
+#include <dcopref.h>
#include <tqtimer.h>
#include <stdlib.h>
#include <kdebug.h>
@@ -45,7 +46,8 @@
const Medium MountHelper::findMedium(const TQString &device)
{
- DCOPReply reply = m_mediamanager.call("properties", device);
+ DCOPRef mediamanager("kded", "mediamanager");
+ DCOPReply reply = mediamanager.call("properties", device);
if (!reply.isValid())
{
m_errorStr = i18n("The TDE mediamanager is not running.\n");
@@ -57,7 +59,8 @@ const Medium MountHelper::findMedium(const TQString &device)
void MountHelper::mount(const Medium &medium)
{
- DCOPReply reply = m_mediamanager.call("mount", medium.id());
+ DCOPRef mediamanager("kded", "mediamanager");
+ DCOPReply reply = mediamanager.call("mount", medium.id());
TQStringVariantMap mountResult;
if (reply.isValid()) {
reply.get(mountResult);
@@ -70,7 +73,8 @@ void MountHelper::mount(const Medium &medium)
void MountHelper::unmount(const Medium &medium)
{
- DCOPReply reply = m_mediamanager.call("unmount", medium.id());
+ DCOPRef mediamanager("kded", "mediamanager");
+ DCOPReply reply = mediamanager.call("unmount", medium.id());
TQStringVariantMap unmountResult;
if (reply.isValid()) {
reply.get(unmountResult);
@@ -105,27 +109,8 @@ void MountHelper::unlock(const Medium &medium)
void MountHelper::lock(const Medium &medium)
{
- if (medium.id().isEmpty())
- {
- m_errorStr = i18n("Try to lock an unknown medium.");
- errorAndExit();
- }
- TQString device = medium.deviceNode();
- if (!medium.isEncrypted())
- {
- m_errorStr = i18n("%1 is not an encrypted media.").arg(device);
- errorAndExit();
- }
- if (medium.needUnlocking())
- {
- m_errorStr = i18n("%1 is already locked.").arg(device);
- errorAndExit();
- }
-
- // Release children devices
- releaseHolders(medium);
-
- DCOPReply reply = m_mediamanager.call("lock", medium.id());
+ DCOPRef mediamanager("kded", "mediamanager");
+ DCOPReply reply = mediamanager.call("lock", medium.id(), true);
TQStringVariantMap lockResult;
if (reply.isValid()) {
reply.get(lockResult);
@@ -140,7 +125,8 @@ void MountHelper::lock(const Medium &medium)
void MountHelper::eject(const Medium &medium)
{
#ifdef WITH_TDEHWLIB
- DCOPReply reply = m_mediamanager.call("eject", medium.id());
+ DCOPRef mediamanager("kded", "mediamanager");
+ DCOPReply reply = mediamanager.call("eject", medium.id());
TQStringVariantMap ejectResult;
if (reply.isValid()) {
reply.get(ejectResult);
@@ -271,7 +257,7 @@ void MountHelper::openRealFolder(const Medium &medium)
}
}
-MountHelper::MountHelper() : TDEApplication(), m_mediamanager("kded", "mediamanager")
+MountHelper::MountHelper() : TDEApplication()
{
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
m_errorStr = TQString::null;
@@ -377,7 +363,8 @@ void MountHelper::errorAndExit()
void MountHelper::slotSendPassword()
{
- DCOPReply reply = m_mediamanager.call("unlock", m_mediumId, m_dialog->getPassword());
+ DCOPRef mediamanager("kded", "mediamanager");
+ DCOPReply reply = mediamanager.call("unlock", m_mediumId, m_dialog->getPassword());
TQStringVariantMap unlockResult;
if (reply.isValid()) {
reply.get(unlockResult);
diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
index eff02b1e1..540012ce3 100644
--- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
+++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
@@ -25,7 +25,6 @@
#include <tdeapplication.h>
#include <tqstring.h>
#include <tdeio/job.h>
-#include <dcopref.h>
#include "medium.h"
@@ -44,7 +43,6 @@ private:
TQString m_errorStr;
TQString m_mediumId;
Dialog *m_dialog;
- DCOPRef m_mediamanager;
const Medium findMedium(const TQString &device);
void error();