File indexing completed on 2024-04-28 05:45:44

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
0004     SPDX-FileCopyrightText: 2016-2018 Andrius Štikonas <andrius@stikonas.eu>
0005     SPDX-FileCopyrightText: 2018 Huzaifa Faruqui <huzaifafaruqui@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-3.0-or-later
0008 */
0009 
0010 #ifndef KPMCORE_COPYSOURCEDEVICE_H
0011 #define KPMCORE_COPYSOURCEDEVICE_H
0012 
0013 #include "backend/corebackenddevice.h"
0014 #include "core/copysource.h"
0015 #include "util/libpartitionmanagerexport.h"
0016 
0017 #include <memory>
0018 
0019 #include <QtGlobal>
0020 
0021 class Device;
0022 class CopyTarget;
0023 class CoreBackendDevice;
0024 class QString;
0025 
0026 /** A Device to copy from.
0027 
0028     Represents a Device to copy from. Used to copy a Partition to somewhere on the same or
0029     another Device or to backup its FileSystem to a file.
0030     @author Volker Lanz <vl@fidra.de>
0031  */
0032 class CopySourceDevice : public CopySource
0033 {
0034     Q_DISABLE_COPY(CopySourceDevice)
0035 
0036 public:
0037     CopySourceDevice(Device& d, qint64 firstbyte, qint64 lastbyte);
0038 
0039 public:
0040     bool open() override;
0041     qint64 length() const override;
0042     bool overlaps(const CopyTarget& target) const override;
0043 
0044     qint64 firstByte() const override {
0045         return m_FirstByte;    /**< @return first byte to copy */
0046     }
0047     qint64 lastByte() const override {
0048         return m_LastByte;    /**< @return last byte to copy */
0049     }
0050 
0051     Device& device() {
0052         return m_Device;    /**< @return Device to copy from */
0053     }
0054     const Device& device() const {
0055         return m_Device;    /**< @return Device to copy from */
0056     }
0057 
0058     QString path() const override;
0059 
0060 protected:
0061     Device& m_Device;
0062     const qint64 m_FirstByte;
0063     const qint64 m_LastByte;
0064     std::unique_ptr<CoreBackendDevice> m_BackendDevice;
0065 };
0066 
0067 #endif