1 /*
2     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
3     SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
4     SPDX-FileCopyrightText: 2016-2018 Andrius Štikonas <andrius@stikonas.eu>
5     SPDX-FileCopyrightText: 2018 Huzaifa Faruqui <huzaifafaruqui@gmail.com>
6 
7     SPDX-License-Identifier: GPL-3.0-or-later
8 */
9 
10 #ifndef KPMCORE_COPYSOURCEDEVICE_H
11 #define KPMCORE_COPYSOURCEDEVICE_H
12 
13 #include "backend/corebackenddevice.h"
14 #include "core/copysource.h"
15 #include "util/libpartitionmanagerexport.h"
16 
17 #include <memory>
18 
19 #include <QtGlobal>
20 
21 class Device;
22 class CopyTarget;
23 class CoreBackendDevice;
24 class QString;
25 
26 /** A Device to copy from.
27 
28     Represents a Device to copy from. Used to copy a Partition to somewhere on the same or
29     another Device or to backup its FileSystem to a file.
30     @author Volker Lanz <vl@fidra.de>
31  */
32 class CopySourceDevice : public CopySource
33 {
34     Q_DISABLE_COPY(CopySourceDevice)
35 
36 public:
37     CopySourceDevice(Device& d, qint64 firstbyte, qint64 lastbyte);
38 
39 public:
40     bool open() override;
41     qint64 length() const override;
42     bool overlaps(const CopyTarget& target) const override;
43 
firstByte()44     qint64 firstByte() const override {
45         return m_FirstByte;    /**< @return first byte to copy */
46     }
lastByte()47     qint64 lastByte() const override {
48         return m_LastByte;    /**< @return last byte to copy */
49     }
50 
device()51     Device& device() {
52         return m_Device;    /**< @return Device to copy from */
53     }
device()54     const Device& device() const {
55         return m_Device;    /**< @return Device to copy from */
56     }
57 
58     QString path() const override;
59 
60 protected:
61     Device& m_Device;
62     const qint64 m_FirstByte;
63     const qint64 m_LastByte;
64     std::unique_ptr<CoreBackendDevice> m_BackendDevice;
65 };
66 
67 #endif
68