Warning, file /system/kpmcore/src/core/copysourcedevice.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
0004     SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
0005     SPDX-FileCopyrightText: 2017-2018 Andrius Štikonas <andrius@stikonas.eu>
0006     SPDX-FileCopyrightText: 2018 Huzaifa Faruqui <huzaifafaruqui@gmail.com>
0007 
0008     SPDX-License-Identifier: GPL-3.0-or-later
0009 */
0010 
0011 #include "core/copysourcedevice.h"
0012 
0013 #include "backend/corebackend.h"
0014 #include "backend/corebackendmanager.h"
0015 
0016 #include "core/copytarget.h"
0017 #include "core/copytargetdevice.h"
0018 #include "core/device.h"
0019 
0020 /** Constructs a CopySource on the given Device
0021     @param d Device from which to copy
0022     @param firstbyte the first byte that will be copied
0023     @param lastbyte the last byte that will be copied
0024 */
0025 CopySourceDevice::CopySourceDevice(Device& d, qint64 firstbyte, qint64 lastbyte) :
0026     CopySource(),
0027     m_Device(d),
0028     m_FirstByte(firstbyte),
0029     m_LastByte(lastbyte),
0030     m_BackendDevice(nullptr)
0031 {
0032 }
0033 
0034 /** Opens the Device
0035     @return true if the Device could be successfully opened
0036 */
0037 bool CopySourceDevice::open()
0038 {
0039     m_BackendDevice = CoreBackendManager::self()->backend()->openDeviceExclusive(device());
0040     return m_BackendDevice != nullptr;
0041 }
0042 
0043 /** Returns the length of this CopySource
0044     @return length of the copy source
0045 */
0046 qint64 CopySourceDevice::length() const
0047 {
0048     return lastByte() - firstByte() + 1;
0049 }
0050 
0051 /** Checks if this CopySourceDevice overlaps with the given CopyTarget
0052     @param target the CopyTarget to check overlapping with
0053     @return true if overlaps
0054 */
0055 bool CopySourceDevice::overlaps(const CopyTarget& target) const
0056 {
0057     try {
0058         const CopyTargetDevice& t = dynamic_cast<const CopyTargetDevice&>(target);
0059 
0060         if (device().deviceNode() != t.device().deviceNode())
0061             return false;
0062 
0063         // overlapping at the front?
0064         if (firstByte() <= t.firstByte() && lastByte() >= t.firstByte())
0065             return true;
0066 
0067         // overlapping at the back?
0068         if (firstByte() <= t.lastByte() && lastByte() >= t.lastByte())
0069             return true;
0070     } catch (...) {
0071     }
0072 
0073     return false;
0074 }
0075 
0076 QString CopySourceDevice::path() const
0077 {
0078     return m_Device.deviceNode();
0079 }