diff --git a/src/backend/corebackendpartitiontable.h b/src/backend/corebackendpartitiontable.h index a0f3e6e..b4b12ca 100644 --- a/src/backend/corebackendpartitiontable.h +++ b/src/backend/corebackendpartitiontable.h @@ -1,128 +1,128 @@ /************************************************************************* * Copyright (C) 2010,2011 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(COREBACKENDPARTITIONTABLE__H) #define COREBACKENDPARTITIONTABLE__H #include "../util/libpartitionmanagerexport.h" #include "../fs/filesystem.h" -#include +#include class CoreBackendPartition; class Report; class Partition; /** * Interface class to represent a partition table in the backend. * @author Volker Lanz */ class LIBKPMCORE_EXPORT CoreBackendPartitionTable { public: virtual ~CoreBackendPartitionTable() {} public: /** * Open the partition table * @return true on success */ virtual bool open() = 0; /** * Commit changes to the partition table to disk and to the OS. * @param timeout timeout in seconds to wait for the commit to succeed * @return true on success */ virtual bool commit(quint32 timeout = 10) = 0; /** * @return pointer to the extended partition as a CoreBackendPartition or nullptr if there is none */ virtual CoreBackendPartition* getExtendedPartition() = 0; /** * @param sector sector the partition occupies * @return the CoreBackendPartition to occupy the given sector or nullptr if not found */ virtual CoreBackendPartition* getPartitionBySector(qint64 sector) = 0; /** * Delete a partition. * @param report the report to write information to * @param partition the Partition to delete * @return true on success */ virtual bool deletePartition(Report& report, const Partition& partition) = 0; /** * Delete a file system on disk so it cannot be detected anymore. * @param report the report to write information to * @param partition the Partition for which to clobber the file system * @return true on success */ virtual bool clobberFileSystem(Report& report, const Partition& partition) = 0; /** * Resize a file system to a new length. * @param report the report to write information to * @param partition the partition the FileSystem to resize is on * @param newLength the new length for the FileSystem in sectors * @return true on success */ virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) = 0; /** * Detect which FileSystem is present at a given start sector. * @param report the report to write information to * @param device the Device on which the FileSystem resides * @param sector the sector where to look for a FileSystem * @return the detected FileSystem::Type */ virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) = 0; /** * Create a new partition. * @param report the report to write information to * @param partition the new partition to create on disk * @return the new number the OS sees the partition under (e.g. 7 for "/dev/sda7") or -1 on failure */ virtual QString createPartition(Report& report, const Partition& partition) = 0; /** * Update the geometry for a partition in the partition table. * @param report the report to write information to * @param partition the partition to update the geometry for * @param sector_start the new start sector for the partition * @param sector_end the new last sector for the partition * @return true on success */ virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) = 0; /** * Set the system type (e.g. 83 for Linux) of a partition. The type to set is taken from * the partition's file system. * @param report the report to write information to * @param partition the partition to set the system type for * @return true on success */ virtual bool setPartitionSystemType(Report& report, const Partition& partition) = 0; }; #endif diff --git a/src/core/copysource.h b/src/core/copysource.h index 99995cd..dbbebf0 100644 --- a/src/core/copysource.h +++ b/src/core/copysource.h @@ -1,55 +1,55 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(COPYSOURCE__H) #define COPYSOURCE__H -#include +#include class CopyTarget; /** Base class for something to copy from. Abstract base class for all copy sources. Used in combination with CopyTarget to implement moving, copying, backing up and restoring FileSystems. @see CopyTarget @author Volker Lanz */ class CopySource { Q_DISABLE_COPY(CopySource) protected: CopySource() {} virtual ~CopySource() {} public: virtual bool open() = 0; virtual qint32 sectorSize() const = 0; virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors) = 0; virtual qint64 length() const = 0; virtual bool overlaps(const CopyTarget& target) const = 0; virtual qint64 firstSector() const = 0; virtual qint64 lastSector() const = 0; private: }; #endif diff --git a/src/core/copysourcedevice.h b/src/core/copysourcedevice.h index 9e8675b..cccfbe2 100644 --- a/src/core/copysourcedevice.h +++ b/src/core/copysourcedevice.h @@ -1,74 +1,74 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(COPYSOURCEDEVICE__H) #define COPYSOURCEDEVICE__H #include "../core/copysource.h" #include "../util/libpartitionmanagerexport.h" -#include +#include class Device; class CopyTarget; class CoreBackendDevice; /** A Device to copy from. Represents a Device to copy from. Used to copy a Partition to somewhere on the same or another Device or to backup its FileSystem to a file. @author Volker Lanz */ class LIBKPMCORE_EXPORT CopySourceDevice : public CopySource { Q_DISABLE_COPY(CopySourceDevice) public: CopySourceDevice(Device& d, qint64 firstsector, qint64 lastsector); ~CopySourceDevice(); public: virtual bool open(); virtual qint32 sectorSize() const; virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors); virtual qint64 length() const; virtual bool overlaps(const CopyTarget& target) const; virtual qint64 firstSector() const { return m_FirstSector; /**< @return first sector to copying */ } virtual qint64 lastSector() const { return m_LastSector; /**< @return last sector to copy */ } Device& device() { return m_Device; /**< @return Device to copy from */ } const Device& device() const { return m_Device; /**< @return Device to copy from */ } protected: Device& m_Device; const qint64 m_FirstSector; const qint64 m_LastSector; CoreBackendDevice* m_BackendDevice ; }; #endif diff --git a/src/core/copysourcefile.h b/src/core/copysourcefile.h index c4265bf..6d21a18 100644 --- a/src/core/copysourcefile.h +++ b/src/core/copysourcefile.h @@ -1,72 +1,72 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(COPYSOURCEFILE__H) #define COPYSOURCEFILE__H #include "../core/copysource.h" -#include +#include #include class QString; class CopyTarget; /** A file to copy from. Represents a file to copy from. Used to restore a FileSystem from a backup file. @author Volker Lanz */ class CopySourceFile : public CopySource { public: CopySourceFile(const QString& filename, qint32 sectorsize); public: virtual bool open(); virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors); virtual qint64 length() const; virtual qint32 sectorSize() const { return m_SectorSize; /**< @return the file's sector size */ } virtual bool overlaps(const CopyTarget&) const { return false; /**< @return false for file */ } virtual qint64 firstSector() const { return 0; /**< @return 0 for file */ } virtual qint64 lastSector() const { return length(); /**< @return equal to length for file. @see length() */ } protected: QFile& file() { return m_File; } const QFile& file() const { return m_File; } protected: QFile m_File; qint32 m_SectorSize; }; #endif diff --git a/src/core/copytarget.h b/src/core/copytarget.h index c5ebec5..a32573e 100644 --- a/src/core/copytarget.h +++ b/src/core/copytarget.h @@ -1,61 +1,61 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(COPYTARGET__H) #define COPYTARGET__H -#include +#include /** Base class for something to copy to. Abstract base class for all copy targets. Used together with CopySource to implement moving, copying, restoring and backing up FileSystems. @see CopySource @author Volker Lanz */ class CopyTarget { Q_DISABLE_COPY(CopyTarget) protected: CopyTarget() : m_SectorsWritten(0) {} virtual ~CopyTarget() {} public: virtual bool open() = 0; virtual qint32 sectorSize() const = 0; virtual bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors) = 0; virtual qint64 firstSector() const = 0; virtual qint64 lastSector() const = 0; qint64 sectorsWritten() const { return m_SectorsWritten; } protected: void setSectorsWritten(qint64 s) { m_SectorsWritten = s; } private: qint64 m_SectorsWritten; }; #endif diff --git a/src/core/copytargetdevice.h b/src/core/copytargetdevice.h index 1afd42e..00eb155 100644 --- a/src/core/copytargetdevice.h +++ b/src/core/copytargetdevice.h @@ -1,72 +1,72 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(COPYTARGETDEVICE__H) #define COPYTARGETDEVICE__H #include "../core/copytarget.h" #include "../util/libpartitionmanagerexport.h" -#include +#include class Device; class CoreBackendDevice; /** A Device to copy to. Represents a target Device to copy to. Used to copy a Partition to somewhere on the same or another Device or to restore a FileSystem from a file to a Partition. @see CopyTargetFile, CopySourceDevice @author Volker Lanz */ class LIBKPMCORE_EXPORT CopyTargetDevice : public CopyTarget { Q_DISABLE_COPY(CopyTargetDevice) public: CopyTargetDevice(Device& d, qint64 firstsector, qint64 lastsector); ~CopyTargetDevice(); public: virtual bool open(); virtual qint32 sectorSize() const; virtual bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors); virtual qint64 firstSector() const { return m_FirstSector; /**< @return the first sector to write to */ } virtual qint64 lastSector() const { return m_LastSector; /**< @return the last sector to write to */ } Device& device() { return m_Device; /**< @return the Device to write to */ } const Device& device() const { return m_Device; /**< @return the Device to write to */ } protected: Device& m_Device; CoreBackendDevice* m_BackendDevice; const qint64 m_FirstSector; const qint64 m_LastSector; }; #endif diff --git a/src/core/copytargetfile.h b/src/core/copytargetfile.h index 403e658..5e2e9ba 100644 --- a/src/core/copytargetfile.h +++ b/src/core/copytargetfile.h @@ -1,68 +1,68 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(COPYTARGETFILE__H) #define COPYTARGETFILE__H #include "../core/copytarget.h" -#include +#include #include class QString; /** A file to copy to. Repesents a target file to copy to. Used to back up a FileSystem to a file. @see CopySourceFile, CopyTargetDevice @author Volker Lanz */ class CopyTargetFile : public CopyTarget { public: CopyTargetFile(const QString& filename, qint32 sectorsize); public: virtual bool open(); virtual bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors); virtual qint32 sectorSize() const { return m_SectorSize; /**< @return the file's sector size */ } virtual qint64 firstSector() const { return 0; /**< @return always 0 for a file */ } virtual qint64 lastSector() const { return sectorsWritten(); /**< @return the number of sectors written so far */ } protected: QFile& file() { return m_File; } const QFile& file() const { return m_File; } protected: QFile m_File; qint32 m_SectorSize; }; #endif diff --git a/src/core/device.h b/src/core/device.h index 18fc1b1..22f9522 100644 --- a/src/core/device.h +++ b/src/core/device.h @@ -1,129 +1,129 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(DEVICE__H) #define DEVICE__H #include "../util/libpartitionmanagerexport.h" #include #include -#include +#include class PartitionTable; class CreatePartitionTableOperation; class CoreBackend; class SmartStatus; /** A device. Represents a device like /dev/sda. Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions. @see PartitionTable, Partition @author Volker Lanz */ class LIBKPMCORE_EXPORT Device : public QObject { Q_OBJECT Q_DISABLE_COPY(Device) friend class CreatePartitionTableOperation; friend class CoreBackend; public: Device(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize, const QString& iconname = QString()); ~Device(); public: bool operator==(const Device& other) const; bool operator!=(const Device& other) const; const QString& name() const { return m_Name; /**< @return the Device's name, usually some manufacturer string */ } const QString& deviceNode() const { return m_DeviceNode; /**< @return the Device's node, for example "/dev/sda" */ } PartitionTable* partitionTable() { return m_PartitionTable; /**< @return the Device's PartitionTable */ } const PartitionTable* partitionTable() const { return m_PartitionTable; /**< @return the Device's PartitionTable */ } qint32 heads() const { return m_Heads; /**< @return the number of heads on the Device in CHS notation */ } qint32 cylinders() const { return m_Cylinders; /**< @return the number of cylinders on the Device in CHS notation */ } qint32 sectorsPerTrack() const { return m_SectorsPerTrack; /**< @return the number of sectors on the Device in CHS notation */ } qint32 physicalSectorSize() const { return m_PhysicalSectorSize; /**< @return the physical sector size the Device uses or -1 if unknown */ } qint32 logicalSectorSize() const { return m_LogicalSectorSize; /**< @return the logical sector size the Device uses */ } qint64 totalSectors() const { return static_cast(heads()) * cylinders() * sectorsPerTrack(); /**< @return the total number of sectors on the device */ } qint64 capacity() const { return totalSectors() * logicalSectorSize(); /**< @return the Device's capacity in bytes */ } qint64 cylinderSize() const { return static_cast(heads()) * sectorsPerTrack(); /**< @return the size of a cylinder on this Device in sectors */ } void setIconName(const QString& name) { m_IconName = name; } const QString& iconName() const { return m_IconName; /**< @return suggested icon name for this Device */ } SmartStatus& smartStatus() { return *m_SmartStatus; } const SmartStatus& smartStatus() const { return *m_SmartStatus; } QString prettyName() const; void setPartitionTable(PartitionTable* ptable) { m_PartitionTable = ptable; } private: QString m_Name; QString m_DeviceNode; PartitionTable* m_PartitionTable; qint32 m_Heads; qint32 m_SectorsPerTrack; qint32 m_Cylinders; qint32 m_LogicalSectorSize; qint32 m_PhysicalSectorSize; QString m_IconName; SmartStatus* m_SmartStatus; }; #endif diff --git a/src/core/mountentry.h b/src/core/mountentry.h index 8272b61..bc2cc50 100644 --- a/src/core/mountentry.h +++ b/src/core/mountentry.h @@ -1,49 +1,49 @@ /************************************************************************* * Copyright (C) 2009, 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(MOUNTENTRY__H) #define MOUNTENTRY__H #include "../util/libpartitionmanagerexport.h" #include #include -#include +#include struct mntent; class LIBKPMCORE_EXPORT MountEntry { public: enum IdentifyType { deviceNode, uuid, label }; public: MountEntry(const QString& n, const QString& p, const QString& t, const QStringList& o, qint32 d, qint32 pn, IdentifyType type); MountEntry(struct mntent* p, IdentifyType type); public: QString name; QString path; QString type; QStringList options; qint32 dumpFreq; qint32 passNumber; IdentifyType identifyType; }; #endif diff --git a/src/core/operationrunner.h b/src/core/operationrunner.h index 38dd1e9..9f30107 100644 --- a/src/core/operationrunner.h +++ b/src/core/operationrunner.h @@ -1,96 +1,96 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(OPERATIONRUNNER__H) #define OPERATIONRUNNER__H #include "../util/libpartitionmanagerexport.h" #include #include -#include +#include class Operation; class OperationStack; class Report; /** Thread to run the Operations in the OperationStack. Runs the OperationStack when the user applies operations. @author Volker Lanz */ class LIBKPMCORE_EXPORT OperationRunner : public QThread { Q_OBJECT Q_DISABLE_COPY(OperationRunner) public: OperationRunner(QObject* parent, OperationStack& ostack); public: void run(); LIBKPMCORE_EXPORT qint32 numJobs() const; LIBKPMCORE_EXPORT qint32 numOperations() const; LIBKPMCORE_EXPORT qint32 numProgressSub() const; bool isCancelling() const { return m_Cancelling; /**< @return if the user has requested cancelling */ } void cancel() const { m_Cancelling = true; /**< Sets cancelling to true. */ } QMutex& suspendMutex() const { return m_SuspendMutex; /**< @return the QMutex used for syncing */ } QString description(qint32 op) const; void setReport(Report* report) { m_Report = report; /**< @param report the Report to use while running */ } Q_SIGNALS: void progressSub(int); void opStarted(int, Operation*); void opFinished(int, Operation*); void finished(); void cancelled(); void error(); protected: OperationStack& operationStack() { return m_OperationStack; } const OperationStack& operationStack() const { return m_OperationStack; } void setCancelling(bool b) { m_Cancelling = b; } Report& report() { Q_ASSERT(m_Report); return *m_Report; } private: OperationStack& m_OperationStack; Report* m_Report; mutable QMutex m_SuspendMutex; mutable volatile bool m_Cancelling; }; #endif diff --git a/src/core/operationstack.h b/src/core/operationstack.h index 52d206b..9d273e6 100644 --- a/src/core/operationstack.h +++ b/src/core/operationstack.h @@ -1,107 +1,107 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(OPERATIONSTACK__H) #define OPERATIONSTACK__H #include "../util/libpartitionmanagerexport.h" #include #include #include -#include +#include class Device; class Partition; class Operation; class DeviceScanner; /** The list of Operations the user wants to have performed. OperationStack also handles the Devices that were found on this computer and the merging of Operations, e.g., when the user first creates a Partition, then deletes it. @author Volker Lanz */ class LIBKPMCORE_EXPORT OperationStack : public QObject { Q_OBJECT Q_DISABLE_COPY(OperationStack) friend class DeviceScanner; public: typedef QList Devices; typedef QList Operations; public: OperationStack(QObject* parent = nullptr); ~OperationStack(); Q_SIGNALS: void operationsChanged(); void devicesChanged(); public: void push(Operation* o); void pop(); void clearOperations(); int size() const { return operations().size(); /**< @return number of operations */ } Devices& previewDevices() { return m_PreviewDevices; /**< @return the list of Devices */ } const Devices& previewDevices() const { return m_PreviewDevices; /**< @return the list of Devices */ } Operations& operations() { return m_Operations; /**< @return the list of operations */ } const Operations& operations() const { return m_Operations; /**< @return the list of operations */ } Device* findDeviceForPartition(const Partition* p); QReadWriteLock& lock() { return m_Lock; } protected: void clearDevices(); void addDevice(Device* d); void sortDevices(); bool mergeNewOperation(Operation*& currentOp, Operation*& pushedOp); bool mergeCopyOperation(Operation*& currentOp, Operation*& pushedOp); bool mergeRestoreOperation(Operation*& currentOp, Operation*& pushedOp); bool mergePartFlagsOperation(Operation*& currentOp, Operation*& pushedOp); bool mergePartLabelOperation(Operation*& currentOp, Operation*& pushedOp); bool mergeCreatePartitionTableOperation(Operation*& currentOp, Operation*& pushedOp); private: Operations m_Operations; mutable Devices m_PreviewDevices; QReadWriteLock m_Lock; }; #endif diff --git a/src/core/partition.h b/src/core/partition.h index 27f7bd1..0464f37 100644 --- a/src/core/partition.h +++ b/src/core/partition.h @@ -1,291 +1,291 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(PARTITION__H) #define PARTITION__H #include "../core/partitionnode.h" #include "../core/partitionrole.h" #include "../core/partitiontable.h" #include "../util/libpartitionmanagerexport.h" #include -#include +#include class Device; class OperationStack; class CoreBackendPartitionTable; class PartitionAlignment; class PartResizerWidget; class ResizeDialog; class InsertDialog; class NewDialog; class EditMountPointDialog; class PartPropsDialog; class SizeDialogBase; class CreateFileSystemOperation; class RestoreOperation; class SetPartFlagsOperation; class CopyOperation; class NewOperation; class ResizeOperation; class SetPartGeometryJob; class CreatePartitionJob; class SetPartFlagsJob; class RestoreFileSystemJob; class FileSystem; class Report; class QString; class QTextStream; /** A partition or some unallocated space on a Device. Repesent partitions in a PartitionTable on a Device. Partitions can be unallocated, thus not all instances really are partitions in the way the user would see them. Extended partitions have child objects that represent the logicals inside them. @see PartitionTable, Device, FileSystem @author Volker Lanz */ class LIBKPMCORE_EXPORT Partition : public PartitionNode { friend class PartitionTable; friend class OperationStack; friend class Device; friend class PartitionNode; friend class CoreBackendPartitionTable; friend class PartitionAlignment; friend class PartResizerWidget; friend class ResizeDialog; friend class InsertDialog; friend class NewDialog; friend class EditMountPointDialog; friend class PartPropsDialog; friend class SizeDialogBase; friend class CreateFileSystemOperation; friend class RestoreOperation; friend class SetPartFlagsOperation; friend class CopyOperation; friend class NewOperation; friend class ResizeOperation; friend class SetPartGeometryJob; friend class CreatePartitionJob; friend class SetPartFlagsJob; friend class RestoreFileSystemJob; friend QTextStream& operator<<(QTextStream& stream, const Partition& p); public: /** A Partition state -- where did it come from? */ enum State { StateNone = 0, /**< exists on disk */ StateNew = 1, /**< from a NewOperation */ StateCopy = 2, /**< from a CopyOperation */ StateRestore = 3 /**< from a RestoreOperation */ }; Partition(PartitionNode* parent, const Device& device, const PartitionRole& role, FileSystem* fs, qint64 sectorStart, qint64 sectorEnd, QString partitionPath, PartitionTable::Flags availableFlags = PartitionTable::FlagNone, const QString& mountPoint = QString(), bool mounted = false, PartitionTable::Flags activeFlags = PartitionTable::FlagNone, State state = StateNone); ~Partition(); Partition(const Partition&); Partition& operator=(const Partition&); bool operator==(const Partition& other) const; bool operator!=(const Partition& other) const; qint32 number() const { return m_Number; /**< @return the Partition's device number, e.g. 7 for /dev/sdd7 */ } bool isRoot() const { return false; /**< @return always false for Partition */ } PartitionNode* parent() { return m_Parent; /**< @return the Partition's parent PartitionNode */ } const PartitionNode* parent() const { return m_Parent; /**< @return the Partition's parent PartitionNode */ } Partitions& children() { return m_Children; /**< @return the Partition's children. empty for non-extended. */ } const Partitions& children() const { return m_Children; /**< @return the Partition's children. empty for non-extended. */ } const QString& devicePath() const { return m_DevicePath; /**< @return the Partition's device path, e.g. /dev/sdd */ } const QString& partitionPath() const { return m_PartitionPath; /**< @return the Partition's path, e.g. /dev/sdd1 */ } qint64 firstSector() const { return m_FirstSector; /**< @return the Partition's first sector on the Device */ } qint64 lastSector() const { return m_LastSector; /**< @return the Partition's last sector on the Device */ } qint64 sectorsUsed() const; qint32 sectorSize() const { return m_SectorSize; /**< @return the sector size on the Partition's Device */ } qint64 length() const { return lastSector() - firstSector() + 1; /**< @return the length of the Partition */ } qint64 capacity() const { return length() * sectorSize(); /**< @return the capacity of the Partition in bytes */ } qint64 used() const { return sectorsUsed() < 0 ? -1 : sectorsUsed() * sectorSize(); /**< @return the number of used sectors in the Partition's FileSystem */ } qint64 available() const { return sectorsUsed() < 0 ? -1 : capacity() - used(); /**< @return the number of free sectors in the Partition's FileSystem */ } qint64 minimumSectors() const; qint64 maximumSectors() const; qint64 maxFirstSector() const; qint64 minLastSector() const; QString deviceNode() const; const PartitionRole& roles() const { return m_Roles; /**< @return the Partition's role(s) */ } const QString& mountPoint() const { return m_MountPoint; /**< @return the Partition's mount point */ } PartitionTable::Flags activeFlags() const { return m_ActiveFlags; /**< @return the flags currently set for this Partition */ } PartitionTable::Flags availableFlags() const { return m_AvailableFlags; /**< @return the flags available for this Partition */ } bool isMounted() const { return m_IsMounted; /**< @return true if Partition is mounted */ } FileSystem& fileSystem() { return *m_FileSystem; /**< @return the Partition's FileSystem */ } const FileSystem& fileSystem() const { return *m_FileSystem; /**< @return the Partition's FileSystem */ } State state() const { return m_State; /**< @return the Partition's state */ } bool hasChildren() const; bool mount(Report& report); bool unmount(Report& report); bool canMount() const; bool canUnmount() const; void adjustLogicalNumbers(qint32 deletedNumber, qint32 insertedNumber); void checkChildrenMounted(); void setFirstSector(qint64 s) { m_FirstSector = s; } void setLastSector(qint64 s) { m_LastSector = s; } protected: void append(Partition* p) { m_Children.append(p); } void setDevicePath(const QString& s) { m_DevicePath = s; } void setPartitionPath(const QString& s); void setRoles(const PartitionRole& r) { m_Roles = r; } void setMountPoint(const QString& s) { m_MountPoint = s; } void setFlags(PartitionTable::Flags f) { m_ActiveFlags = f; } void setSectorSize(qint32 s) { m_SectorSize = s; } void move(qint64 newStartSector); void setMounted(bool b) { m_IsMounted = b; } void setFlag(PartitionTable::Flag f) { m_ActiveFlags |= f; } void unsetFlag(PartitionTable::Flag f) { m_ActiveFlags &= ~f; } void setParent(PartitionNode* p) { m_Parent = p; } void setFileSystem(FileSystem* fs); void setState(State s) { m_State = s; } void deleteFileSystem(); private: void setNumber(qint32 n) { m_Number = n; } qint32 m_Number; Partitions m_Children; PartitionNode* m_Parent; FileSystem* m_FileSystem; PartitionRole m_Roles; qint64 m_FirstSector; qint64 m_LastSector; QString m_DevicePath; QString m_PartitionPath; QString m_MountPoint; PartitionTable::Flags m_AvailableFlags; PartitionTable::Flags m_ActiveFlags; bool m_IsMounted; qint32 m_SectorSize; State m_State; }; QTextStream& operator<<(QTextStream& stream, const Partition& p); #endif diff --git a/src/core/partitionalignment.h b/src/core/partitionalignment.h index 8ca700f..5818508 100644 --- a/src/core/partitionalignment.h +++ b/src/core/partitionalignment.h @@ -1,63 +1,63 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(PARTITIONALIGNMENT__H) #define PARTITIONALIGNMENT__H -#include "qglobal.h" +#include "QtGlobal" #include "../util/libpartitionmanagerexport.h" class Device; class Partition; class LIBKPMCORE_EXPORT PartitionAlignment { private: PartitionAlignment(); public: static bool isAligned(const Device& d, const Partition& p, bool quiet = false); static bool isAligned(const Device& d, const Partition& p, qint64 newFirst, qint64 newLast, bool quiet); static qint64 alignedFirstSector(const Device& d, const Partition& p, qint64 s, qint64 min_first, qint64 max_first, qint64 min_length, qint64 max_length); static qint64 alignedLastSector(const Device& d, const Partition& p, qint64 s, qint64 min_last, qint64 max_last, qint64 min_length, qint64 max_length, qint64 original_length = -1, bool original_aligned = false); static qint64 sectorAlignment(const Device& d); /** Sets the sector alignment multiplier for ALL devices henceforth except * for devices that have a disklabel which aligns to cylinder boundaries. * The default is 2048. * This should probably be only set once on startup if necessary and not * changed afterwards. */ static void setSectorAlignment( int sectorAlignment ); static qint64 firstDelta(const Device& d, const Partition& p, qint64 s); static qint64 lastDelta(const Device& d, const Partition& p, qint64 s); static bool isLengthAligned(const Device& d, const Partition& p); private: static int s_sectorAlignment; }; #endif diff --git a/src/core/partitionnode.h b/src/core/partitionnode.h index ad2347b..56e158d 100644 --- a/src/core/partitionnode.h +++ b/src/core/partitionnode.h @@ -1,77 +1,77 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(PARTITIONNODE__H) #define PARTITIONNODE__H #include "../util/libpartitionmanagerexport.h" #include #include -#include +#include class Partition; class PartitionRole; /** A node in the tree of partitions. The root in this tree is the PartitionTable. The primaries are the child nodes; extended partitions again have child nodes. @see Device, PartitionTable, Partition @author Volker Lanz */ class LIBKPMCORE_EXPORT PartitionNode : public QObject { Q_OBJECT public: typedef QList Partitions; protected: PartitionNode() {} virtual ~PartitionNode() {} public: virtual bool insert(Partition* partNew); virtual Partition* predecessor(Partition& p); virtual const Partition* predecessor(const Partition& p) const; virtual Partition* successor(Partition& p); virtual const Partition* successor(const Partition& p) const; virtual bool remove(Partition* p); virtual Partition* findPartitionBySector(qint64 s, const PartitionRole& role); virtual const Partition* findPartitionBySector(qint64 s, const PartitionRole& role) const; virtual void reparent(Partition& p); virtual Partitions& children() = 0; virtual PartitionNode* parent() = 0; virtual bool isRoot() const = 0; virtual const PartitionNode* parent() const = 0; virtual const Partitions& children() const = 0; virtual void append(Partition* p) = 0; virtual qint32 highestMountedChild() const; virtual bool isChildMounted() const; protected: virtual void clearChildren(); }; #endif diff --git a/src/core/partitionrole.h b/src/core/partitionrole.h index bf366c4..4bc0e39 100644 --- a/src/core/partitionrole.h +++ b/src/core/partitionrole.h @@ -1,76 +1,76 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(PARTITIONROLE__H) #define PARTITIONROLE__H #include "../util/libpartitionmanagerexport.h" -#include +#include class QString; /** A Partition's role. Each Partition has a PartitionRole: It can be primary, extended, logical or represent unallocated space on the Device. @author Volker Lanz */ class LIBKPMCORE_EXPORT PartitionRole { public: /** A Partition's role: What kind of Partition is it? */ enum Role { None = 0, /**< None at all */ Primary = 1, /**< Primary */ Extended = 2, /**< Extended */ Logical = 4, /**< Logical inside an extended */ Unallocated = 8, /**< No real Partition, just unallocated space */ Luks = 16, /**< Encrypted partition with LUKS key management */ Any = 255 /**< In case we're looking for a Partition with a PartitionRole, any will do */ }; Q_DECLARE_FLAGS(Roles, Role) public: explicit PartitionRole(Roles r) : m_Roles(r) {} /**< Creates a new PartitionRole object */ Roles roles() const { return m_Roles; /**< @return the roles as bitfield */ } bool has(Role r) const { return roles() & r; /**< @param r the role to check @return true if the role is set */ } bool operator==(const PartitionRole& other) const { return m_Roles == other.m_Roles; /**< @param other object to compare with @return true if the same */ } bool operator!=(const PartitionRole& other) const { return !operator==(other); /**< @param other object to compare with @return true if not the same */ } QString toString() const; private: Roles m_Roles; }; Q_DECLARE_OPERATORS_FOR_FLAGS(PartitionRole::Roles) #endif diff --git a/src/core/partitiontable.h b/src/core/partitiontable.h index 70473fe..1531bc4 100644 --- a/src/core/partitiontable.h +++ b/src/core/partitiontable.h @@ -1,199 +1,199 @@ /************************************************************************* * Copyright (C) 2008, 2010 by Volker Lanz * * Copyright (C) 2016 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(PARTITIONTABLE__H) #define PARTITIONTABLE__H #include "../util/libpartitionmanagerexport.h" #include "../core/partitionnode.h" #include "../core/partitionrole.h" #include -#include +#include class Device; class Partition; class CoreBackend; class QTextStream; /** The partition table (a.k.a Disk Label) PartitionTable represents a partition table (or disk label). PartitionTable has child nodes that represent Partitions. @author Volker Lanz */ class LIBKPMCORE_EXPORT PartitionTable : public PartitionNode { Q_DISABLE_COPY(PartitionTable) friend class CoreBackend; friend LIBKPMCORE_EXPORT QTextStream& operator<<(QTextStream& stream, const PartitionTable& ptable); public: enum TableType : qint8 { unknownTableType = -1, aix, bsd, dasd, msdos, msdos_sectorbased, dvh, gpt, loop, mac, pc98, amiga, sun }; /** Partition flags */ enum Flag : qint32 { FlagNone = 0, FlagBoot = 1, FlagRoot = 2, FlagSwap = 4, FlagHidden = 8, FlagRaid = 16, FlagLvm = 32, FlagLba = 64, FlagHpService = 128, FlagPalo = 256, FlagPrep = 512, FlagMsftReserved = 1024, FlagBiosGrub = 2048, FlagAppleTvRecovery = 4096, FlagDiag = 8192, FlagLegacyBoot = 16384, FlagMsftData = 32768, FlagIrst = 65536, FlagEsp = 131072 }; Q_DECLARE_FLAGS(Flags, Flag) public: PartitionTable(TableType type, qint64 first_usable, qint64 last_usable); ~PartitionTable(); public: PartitionNode* parent() { return nullptr; /**< @return always nullptr for PartitionTable */ } const PartitionNode* parent() const { return nullptr; /**< @return always nullptr for PartitionTable */ } bool isRoot() const { return true; /**< @return always true for PartitionTable */ } bool isReadOnly() const { return tableTypeIsReadOnly(type()); /**< @return true if the PartitionTable is read only */ } Partitions& children() { return m_Children; /**< @return the children in this PartitionTable */ } const Partitions& children() const { return m_Children; /**< @return the children in this PartitionTable */ } void setType(const Device& d, TableType t); void append(Partition* partition); qint64 freeSectorsBefore(const Partition& p) const; qint64 freeSectorsAfter(const Partition& p) const; bool hasExtended() const; Partition* extended() const; PartitionRole::Roles childRoles(const Partition& p) const; int numPrimaries() const; int maxPrimaries() const { return m_MaxPrimaries; /**< @return max number of primary partitions this PartitionTable can handle */ } PartitionTable::TableType type() const { return m_Type; /**< @return the PartitionTable's type */ } const QString typeName() const { return tableTypeToName(type()); /**< @return the name of this PartitionTable type */ } qint64 firstUsable() const { return m_FirstUsable; } qint64 lastUsable() const { return m_LastUsable; } void updateUnallocated(const Device& d); void insertUnallocated(const Device& d, PartitionNode* p, qint64 start) const; bool isSectorBased(const Device& d) const; static QList flagList(); static QString flagName(Flag f); static QStringList flagNames(Flags f); static bool getUnallocatedRange(const Device& device, PartitionNode& parent, qint64& start, qint64& end); static void removeUnallocated(PartitionNode* p); void removeUnallocated(); static qint64 defaultFirstUsable(const Device& d, TableType t); static qint64 defaultLastUsable(const Device& d, TableType t); static PartitionTable::TableType nameToTableType(const QString& n); static QString tableTypeToName(TableType l); static qint64 maxPrimariesForTableType(TableType l); static bool tableTypeSupportsExtended(TableType l); static bool tableTypeIsReadOnly(TableType l); protected: void setMaxPrimaries(qint32 n) { m_MaxPrimaries = n; } void setFirstUsableSector(qint64 s) { m_FirstUsable = s; } void setLastUsableSector(qint64 s) { m_LastUsable = s; } private: Partitions m_Children; qint32 m_MaxPrimaries; TableType m_Type; qint64 m_FirstUsable; qint64 m_LastUsable; }; Q_DECLARE_OPERATORS_FOR_FLAGS(PartitionTable::Flags) QTextStream& operator<<(QTextStream& stream, const PartitionTable& ptable); #endif diff --git a/src/core/smartstatus.h b/src/core/smartstatus.h index 80332c7..d6a5a59 100644 --- a/src/core/smartstatus.h +++ b/src/core/smartstatus.h @@ -1,164 +1,164 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(SMARTSTATUS__H) #define SMARTSTATUS__H #include "../util/libpartitionmanagerexport.h" -#include +#include #include #include class SmartAttribute; struct SkSmartAttributeParsedData; struct SkDisk; class LIBKPMCORE_EXPORT SmartStatus { public: enum Overall { Good, BadPast, BadSectors, BadNow, BadSectorsMany, Bad }; enum SelfTestStatus { Success, Aborted, Interrupted, Fatal, ErrorUnknown, ErrorEletrical, ErrorServo, ErrorRead, ErrorHandling, InProgress }; public: typedef QList Attributes; public: SmartStatus(const QString& device_path); public: void update(); const QString& devicePath() const { return m_DevicePath; } bool isValid() const { return m_InitSuccess; } bool status() const { return m_Status; } const QString& modelName() const { return m_ModelName; } const QString& serial() const { return m_Serial; } const QString& firmware() const { return m_Firmware; } qint64 temp() const { return m_Temp; } qint64 badSectors() const { return m_BadSectors; } qint64 powerCycles() const { return m_PowerCycles; } qint64 poweredOn() const { return m_PoweredOn; } const Attributes& attributes() const { return m_Attributes; } Overall overall() const { return m_Overall; } SelfTestStatus selfTestStatus() const { return m_SelfTestStatus; } static QString tempToString(qint64 mkelvin); static QString overallAssessmentToString(Overall o); static QString selfTestStatusToString(SmartStatus::SelfTestStatus s); protected: void setStatus(bool s) { m_Status = s; } void setModelName(const QString& name) { m_ModelName = name; } void setSerial(const QString& s) { m_Serial = s; } void setFirmware(const QString& f) { m_Firmware = f; } void setTemp(qint64 t) { m_Temp = t; } void setInitSuccess(bool b) { m_InitSuccess = b; } void setBadSectors(qint64 s) { m_BadSectors = s; } void setPowerCycles(qint64 p) { m_PowerCycles = p; } void setPoweredOn(qint64 t) { m_PoweredOn = t; } void setOverall(Overall o) { m_Overall = o; } void setSelfTestStatus(SelfTestStatus s) { m_SelfTestStatus = s; } static void callback(SkDisk* skDisk, const SkSmartAttributeParsedData* a, void* user_data); private: const QString m_DevicePath; bool m_InitSuccess; bool m_Status; QString m_ModelName; QString m_Serial; QString m_Firmware; Overall m_Overall; SelfTestStatus m_SelfTestStatus; qint64 m_Temp; qint64 m_BadSectors; qint64 m_PowerCycles; qint64 m_PoweredOn; Attributes m_Attributes; }; #endif diff --git a/src/fs/btrfs.cpp b/src/fs/btrfs.cpp index bf3f8cf..c27472a 100644 --- a/src/fs/btrfs.cpp +++ b/src/fs/btrfs.cpp @@ -1,177 +1,179 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/btrfs.h" #include "util/externalcommand.h" #include "util/capacity.h" #include "util/report.h" #include #include #include #include namespace FS { FileSystem::CommandSupportType btrfs::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType btrfs::m_GetUUID = FileSystem::cmdSupportNone; btrfs::btrfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Btrfs) { } void btrfs::init() { m_Create = findExternal(QStringLiteral("mkfs.btrfs")) ? cmdSupportFileSystem : cmdSupportNone; m_Check = findExternal(QStringLiteral("btrfsck"), QStringList(), 1) ? cmdSupportFileSystem : cmdSupportNone; m_Grow = (m_Check != cmdSupportNone && findExternal(QStringLiteral("btrfs"))) ? cmdSupportFileSystem : cmdSupportNone; m_GetUsed = findExternal(QStringLiteral("btrfs-debug-tree")) ? cmdSupportFileSystem : cmdSupportNone; m_Shrink = (m_Grow != cmdSupportNone && m_GetUsed != cmdSupportNone) ? cmdSupportFileSystem : cmdSupportNone; m_SetLabel = findExternal(QStringLiteral("btrfs")) ? cmdSupportFileSystem : cmdSupportNone; m_UpdateUUID = cmdSupportNone; m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_GetLabel = cmdSupportCore; m_Backup = cmdSupportCore; m_GetUUID = cmdSupportCore; } bool btrfs::supportToolFound() const { return m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && // m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool btrfs::supportToolName() const { return SupportTool(QStringLiteral("btrfs-tools"), QUrl(QStringLiteral("http://btrfs.wiki.kernel.org/"))); } qint64 btrfs::minCapacity() const { return 256 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 btrfs::maxCapacity() const { return Capacity::unitFactor(Capacity::Byte, Capacity::EiB); } qint64 btrfs::maxLabelLength() const { return 255; } qint64 btrfs::readUsedCapacity(const QString& deviceNode) const { - ExternalCommand cmd(QStringLiteral("btrfs"), QStringList() << QStringLiteral("filesystem") << QStringLiteral("show") << QStringLiteral("--raw") << deviceNode); + ExternalCommand cmd(QStringLiteral("btrfs"), + { QStringLiteral("filesystem"), QStringLiteral("show"), QStringLiteral("--raw"), deviceNode }); if (cmd.run()) { QRegExp rxBytesUsed(QStringLiteral(" used (\\d+) path ") + deviceNode); if (rxBytesUsed.indexIn(cmd.output()) != -1) return rxBytesUsed.cap(1).toLongLong(); } return -1; } bool btrfs::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("btrfsck"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("btrfsck"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool btrfs::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.btrfs"), QStringList() << QStringLiteral("-f") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.btrfs"), { QStringLiteral("--force"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool btrfs::resize(Report& report, const QString& deviceNode, qint64 length) const { QTemporaryDir tempDir; if (!tempDir.isValid()) { report.line() << xi18nc("@info/plain", "Resizing Btrfs file system on partition %1 failed: Could not create temp dir.", deviceNode); return false; } bool rval = false; - ExternalCommand mountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << QStringLiteral("-t") << QStringLiteral("btrfs") << deviceNode << tempDir.path()); + ExternalCommand mountCmd(report, QStringLiteral("mount"), + { QStringLiteral("--verbose"), QStringLiteral("--types"), QStringLiteral("btrfs"), deviceNode, tempDir.path() }); if (mountCmd.run(-1) && mountCmd.exitCode() == 0) { QString len = length == -1 ? QStringLiteral("max") : QString::number(length); - ExternalCommand resizeCmd(report, QStringLiteral("btrfs"), QStringList() << QStringLiteral("filesystem") << QStringLiteral("resize") << len << tempDir.path()); + ExternalCommand resizeCmd(report, QStringLiteral("btrfs"), { QStringLiteral("filesystem"), QStringLiteral("resize"), len, tempDir.path() }); if (resizeCmd.run(-1) && resizeCmd.exitCode() == 0) rval = true; else report.line() << xi18nc("@info/plain", "Resizing Btrfs file system on partition %1 failed: btrfs file system resize failed.", deviceNode); - ExternalCommand unmountCmd(report, QStringLiteral("umount"), QStringList() << tempDir.path()); + ExternalCommand unmountCmd(report, QStringLiteral("umount"), { tempDir.path() }); if (!unmountCmd.run(-1) && unmountCmd.exitCode() == 0) report.line() << xi18nc("@info/plain", "Warning: Resizing Btrfs file system on partition %1: Unmount failed.", deviceNode); } else report.line() << xi18nc("@info/plain", "Resizing Btrfs file system on partition %1 failed: Initial mount failed.", deviceNode); return rval; } bool btrfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand cmd(report, QStringLiteral("btrfs"), QStringList() << QStringLiteral("filesystem") << QStringLiteral("label") << deviceNode << newLabel); + ExternalCommand cmd(report, QStringLiteral("btrfs"), { QStringLiteral("filesystem"), QStringLiteral("label"), deviceNode, newLabel }); return cmd.run(-1) && cmd.exitCode() == 0; } bool btrfs::updateUUID(Report& report, const QString& deviceNode) const { Q_UNUSED(report); Q_UNUSED(deviceNode); return false; } } diff --git a/src/fs/btrfs.h b/src/fs/btrfs.h index 37fcffb..45b5326 100644 --- a/src/fs/btrfs.h +++ b/src/fs/btrfs.h @@ -1,112 +1,112 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(BTRFS__H) #define BTRFS__H #include "../util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A btrfs file system. @author Andrius Štikonas */ class LIBKPMCORE_EXPORT btrfs : public FileSystem { public: btrfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/exfat.cpp b/src/fs/exfat.cpp index b3b9929..6406051 100644 --- a/src/fs/exfat.cpp +++ b/src/fs/exfat.cpp @@ -1,121 +1,121 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/exfat.h" #include "util/externalcommand.h" #include "util/capacity.h" #include #include namespace FS { FileSystem::CommandSupportType exfat::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType exfat::m_GetUUID = FileSystem::cmdSupportNone; exfat::exfat(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Exfat) { } void exfat::init() { m_Create = findExternal(QStringLiteral("mkfs.exfat")) ? cmdSupportFileSystem : cmdSupportNone; m_Check = findExternal(QStringLiteral("exfatfsck"), QStringList(), 1) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_SetLabel = findExternal(QStringLiteral("exfatlabel")) ? cmdSupportFileSystem : cmdSupportNone; m_UpdateUUID = cmdSupportNone; m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_GetLabel = cmdSupportCore; m_Backup = cmdSupportCore; m_GetUUID = cmdSupportCore; } bool exfat::supportToolFound() const { return // m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && // m_UpdateUUID != cmdSupportNone && // m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool exfat::supportToolName() const { return SupportTool(QStringLiteral("exfat-utils"), QUrl(QStringLiteral("http://code.google.com/p/exfat/"))); } qint64 exfat::maxCapacity() const { return Capacity::unitFactor(Capacity::Byte, Capacity::EiB); } qint64 exfat::maxLabelLength() const { return 15; } bool exfat::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("exfatfsck"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("exfatfsck"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool exfat::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.exfat"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.exfat"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool exfat::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand cmd(report, QStringLiteral("exfatlabel"), QStringList() << deviceNode << newLabel); + ExternalCommand cmd(report, QStringLiteral("exfatlabel"), { deviceNode, newLabel }); return cmd.run(-1) && cmd.exitCode() == 0; } bool exfat::updateUUID(Report& report, const QString& deviceNode) const { Q_UNUSED(report); Q_UNUSED(deviceNode); return false; } } diff --git a/src/fs/exfat.h b/src/fs/exfat.h index b614219..16dd6e7 100644 --- a/src/fs/exfat.h +++ b/src/fs/exfat.h @@ -1,111 +1,111 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(EXFAT__H) #define EXFAT__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** An exfat file system. @author Andrius Štikonas */ class LIBKPMCORE_EXPORT exfat : public FileSystem { public: exfat(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); // virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; // virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } // virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/ext2.cpp b/src/fs/ext2.cpp index 6c9603f..260a2a2 100644 --- a/src/fs/ext2.cpp +++ b/src/fs/ext2.cpp @@ -1,157 +1,157 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/ext2.h" #include "util/externalcommand.h" #include "util/capacity.h" #include #include namespace FS { FileSystem::CommandSupportType ext2::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ext2::m_GetUUID = FileSystem::cmdSupportNone; ext2::ext2(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, FileSystem::Type t) : FileSystem(firstsector, lastsector, sectorsused, label, t) { } void ext2::init() { m_GetUsed = findExternal(QStringLiteral("dumpe2fs")) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_SetLabel = findExternal(QStringLiteral("e2label")) ? cmdSupportFileSystem : cmdSupportNone; m_Create = findExternal(QStringLiteral("mkfs.ext2")) ? cmdSupportFileSystem : cmdSupportNone; - m_Check = findExternal(QStringLiteral("e2fsck"), QStringList() << QStringLiteral("-V")) ? cmdSupportFileSystem : cmdSupportNone; + m_Check = findExternal(QStringLiteral("e2fsck"), { QStringLiteral("-V") }) ? cmdSupportFileSystem : cmdSupportNone; m_UpdateUUID = findExternal(QStringLiteral("tune2fs")) ? cmdSupportFileSystem : cmdSupportNone; m_Grow = (m_Check != cmdSupportNone && findExternal(QStringLiteral("resize2fs"))) ? cmdSupportFileSystem : cmdSupportNone; m_Shrink = (m_Grow != cmdSupportNone && m_GetUsed) != cmdSupportNone ? cmdSupportFileSystem : cmdSupportNone; m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Backup = cmdSupportCore; m_GetUUID = cmdSupportCore; } bool ext2::supportToolFound() const { return m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool ext2::supportToolName() const { return SupportTool(QStringLiteral("e2fsprogs"), QUrl(QStringLiteral("http://e2fsprogs.sf.net"))); } qint64 ext2::maxCapacity() const { return 32 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB); } qint64 ext2::maxLabelLength() const { return 16; } qint64 ext2::readUsedCapacity(const QString& deviceNode) const { - ExternalCommand cmd(QStringLiteral("dumpe2fs"), QStringList() << QStringLiteral("-h") << deviceNode); + ExternalCommand cmd(QStringLiteral("dumpe2fs"), { QStringLiteral("-h"), deviceNode }); if (cmd.run()) { qint64 blockCount = -1; QRegExp rxBlockCount(QStringLiteral("Block count:\\s*(\\d+)")); if (rxBlockCount.indexIn(cmd.output()) != -1) blockCount = rxBlockCount.cap(1).toLongLong(); qint64 freeBlocks = -1; QRegExp rxFreeBlocks(QStringLiteral("Free blocks:\\s*(\\d+)")); if (rxFreeBlocks.indexIn(cmd.output()) != -1) freeBlocks = rxFreeBlocks.cap(1).toLongLong(); qint64 blockSize = -1; QRegExp rxBlockSize(QStringLiteral("Block size:\\s*(\\d+)")); if (rxBlockSize.indexIn(cmd.output()) != -1) blockSize = rxBlockSize.cap(1).toLongLong(); if (blockCount > -1 && freeBlocks > -1 && blockSize > -1) return (blockCount - freeBlocks) * blockSize; } return -1; } bool ext2::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("e2fsck"), QStringList() << QStringLiteral("-f") << QStringLiteral("-y") << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("e2fsck"), { QStringLiteral("-f"), QStringLiteral("-y"), QStringLiteral("-v"), deviceNode }); return cmd.run(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 1 || cmd.exitCode() == 2 || cmd.exitCode() == 256); } bool ext2::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.ext2"), QStringList() << QStringLiteral("-qF") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.ext2"), { QStringLiteral("-qF"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool ext2::resize(Report& report, const QString& deviceNode, qint64 length) const { const QString len = QString::number(length / 512) + QStringLiteral("s"); - const QStringList command = length == -1 ? QStringList() << deviceNode : QStringList() << deviceNode << len; + const QStringList command = length == -1 ? QStringList() << deviceNode : QStringList() << deviceNode << len; ExternalCommand cmd(report, QStringLiteral("resize2fs"), command); return cmd.run(-1) && cmd.exitCode() == 0; } bool ext2::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand cmd(report, QStringLiteral("e2label"), QStringList() << deviceNode << newLabel); + ExternalCommand cmd(report, QStringLiteral("e2label"), { deviceNode, newLabel }); return cmd.run(-1) && cmd.exitCode() == 0; } bool ext2::updateUUID(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("tune2fs"), QStringList() << QStringLiteral("-U") << QStringLiteral("random") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("tune2fs"), { QStringLiteral("-U"), QStringLiteral("random"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/ext2.h b/src/fs/ext2.h index a8b8490..1c37b53 100644 --- a/src/fs/ext2.h +++ b/src/fs/ext2.h @@ -1,110 +1,110 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(EXT2__H) #define EXT2__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** An ext2 file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT ext2 : public FileSystem { public: ext2(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, FileSystem::Type t = FileSystem::Ext2); public: static void init(); virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/ext3.h b/src/fs/ext3.h index 158c04b..8a34b4f 100644 --- a/src/fs/ext3.h +++ b/src/fs/ext3.h @@ -1,52 +1,52 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(EXT3__H) #define EXT3__H #include "util/libpartitionmanagerexport.h" #include "fs/ext2.h" -#include +#include class Report; class QString; namespace FS { /** An ext3 file system. Basically the same as ext2. @author Volker Lanz */ class LIBKPMCORE_EXPORT ext3 : public ext2 { public: ext3(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init() {} virtual bool create(Report& report, const QString& deviceNode) const; virtual qint64 maxCapacity() const; }; } #endif diff --git a/src/fs/ext4.h b/src/fs/ext4.h index 056a0d8..7f971f0 100644 --- a/src/fs/ext4.h +++ b/src/fs/ext4.h @@ -1,52 +1,52 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(EXT4__H) #define EXT4__H #include "util/libpartitionmanagerexport.h" #include "fs/ext2.h" -#include +#include class Report; class QString; namespace FS { /** An ext4 file system. Basically the same as ext2. @author Volker Lanz */ class LIBKPMCORE_EXPORT ext4 : public ext2 { public: ext4(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init() {} virtual bool create(Report& report, const QString& deviceNode) const; virtual qint64 maxCapacity() const; }; } #endif diff --git a/src/fs/extended.h b/src/fs/extended.h index 8381498..571bc52 100644 --- a/src/fs/extended.h +++ b/src/fs/extended.h @@ -1,75 +1,75 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(EXTENDED__H) #define EXTENDED__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class QString; namespace FS { /** An extended file system. A FileSystem for an extended Partition. Of course, extended partitions do not actually have a file system, but we need this to be able to create, grow, shrink or move them. @author Volker Lanz */ class LIBKPMCORE_EXPORT extended : public FileSystem { public: extended(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init() {} virtual bool create(Report&, const QString&) const; virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual bool supportToolFound() const { return true; } public: static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; }; } #endif diff --git a/src/fs/f2fs.cpp b/src/fs/f2fs.cpp index 490b1b1..634e75d 100644 --- a/src/fs/f2fs.cpp +++ b/src/fs/f2fs.cpp @@ -1,122 +1,122 @@ /************************************************************************* * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/f2fs.h" #include "util/externalcommand.h" #include "util/capacity.h" #include "util/report.h" #include #include #include #include #include namespace FS { FileSystem::CommandSupportType f2fs::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType f2fs::m_GetUUID = FileSystem::cmdSupportNone; f2fs::f2fs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::F2fs) { } void f2fs::init() { m_Create = findExternal(QStringLiteral("mkfs.f2fs")) ? cmdSupportFileSystem : cmdSupportNone; m_Check = findExternal(QStringLiteral("fsck.f2fs")) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; // m_SetLabel = findExternal(QStringLiteral("nilfs-tune")) ? cmdSupportFileSystem : cmdSupportNone; // m_UpdateUUID = findExternal(QStringLiteral("nilfs-tune")) ? cmdSupportFileSystem : cmdSupportNone; // m_Grow = (m_Check != cmdSupportNone && findExternal(QStringLiteral("nilfs-resize"))) ? cmdSupportFileSystem : cmdSupportNone; // m_GetUsed = findExternal(QStringLiteral("nilfs-tune")) ? cmdSupportFileSystem : cmdSupportNone; // m_Shrink = (m_Grow != cmdSupportNone && m_GetUsed != cmdSupportNone) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_GetLabel = cmdSupportCore; m_Backup = cmdSupportCore; m_GetUUID = cmdSupportCore; } bool f2fs::supportToolFound() const { return // m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && // m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && // m_UpdateUUID != cmdSupportNone && // m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool f2fs::supportToolName() const { return SupportTool(QStringLiteral("f2fs-tools"), QUrl(QStringLiteral("https://git.kernel.org/cgit/linux/kernel/git/jaegeuk/f2fs-tools.git"))); } qint64 f2fs::minCapacity() const { return 128 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); // FIXME } qint64 f2fs::maxCapacity() const { return 16 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB); } qint64 f2fs::maxLabelLength() const { return 80; } bool f2fs::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("fsck.f2fs"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("fsck.f2fs"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool f2fs::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.f2fs"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.f2fs"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/f2fs.h b/src/fs/f2fs.h index 3b6f09e..021a18e 100644 --- a/src/fs/f2fs.h +++ b/src/fs/f2fs.h @@ -1,112 +1,112 @@ /************************************************************************* * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(F2FS__H) #define F2FS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A f2fs file system. @author Andrius Štikonas */ class LIBKPMCORE_EXPORT f2fs : public FileSystem { public: f2fs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); // virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; // virtual qint64 readUsedCapacity(const QString& deviceNode) const; // virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; // virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); // virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/fat16.cpp b/src/fs/fat16.cpp index 39374e3..459c75b 100644 --- a/src/fs/fat16.cpp +++ b/src/fs/fat16.cpp @@ -1,168 +1,168 @@ /************************************************************************* * Copyright (C) 2008,2009,2011 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/fat16.h" #include "util/externalcommand.h" #include "util/capacity.h" #include "util/report.h" #include #include #include #include #include namespace FS { FileSystem::CommandSupportType fat16::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType fat16::m_GetUUID = FileSystem::cmdSupportNone; fat16::fat16(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, FileSystem::Type t) : FileSystem(firstsector, lastsector, sectorsused, label, t) { } void fat16::init() { m_Create = findExternal(QStringLiteral("mkfs.msdos")) ? cmdSupportFileSystem : cmdSupportNone; - m_GetUsed = m_Check = findExternal(QStringLiteral("fsck.msdos"), QStringList(), 2) ? cmdSupportFileSystem : cmdSupportNone; + m_GetUsed = m_Check = findExternal(QStringLiteral("fsck.msdos"), {}, 2) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_SetLabel = findExternal(QStringLiteral("fatlabel")) ? cmdSupportFileSystem : cmdSupportNone; m_Move = cmdSupportCore; m_Copy = cmdSupportCore; m_Backup = cmdSupportCore; m_UpdateUUID = findExternal(QStringLiteral("dd")) ? cmdSupportFileSystem : cmdSupportNone; m_GetUUID = cmdSupportCore; } bool fat16::supportToolFound() const { return m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && // m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool fat16::supportToolName() const { // also, dd for updating the UUID, but let's assume it's there ;-) return SupportTool(QStringLiteral("dosfstools"), QUrl(QStringLiteral("http://www.daniel-baumann.ch/software/dosfstools/"))); } qint64 fat16::minCapacity() const { return 16 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 fat16::maxCapacity() const { return 4 * Capacity::unitFactor(Capacity::Byte, Capacity::GiB); } qint64 fat16::maxLabelLength() const { return 11; } qint64 fat16::readUsedCapacity(const QString& deviceNode) const { - ExternalCommand cmd(QStringLiteral("fsck.msdos"), QStringList() << QStringLiteral("-n") << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(QStringLiteral("fsck.msdos"), { QStringLiteral("-n"), QStringLiteral("-v"), deviceNode }); if (cmd.run()) { qint64 usedClusters = -1; QRegExp rxClusters(QStringLiteral("files, (\\d+)/\\d+ ")); if (rxClusters.indexIn(cmd.output()) != -1) usedClusters = rxClusters.cap(1).toLongLong(); qint64 clusterSize = -1; QRegExp rxClusterSize(QStringLiteral("(\\d+) bytes per cluster")); if (rxClusterSize.indexIn(cmd.output()) != -1) clusterSize = rxClusterSize.cap(1).toLongLong(); if (usedClusters > -1 && clusterSize > -1) return usedClusters * clusterSize; } return -1; } bool fat16::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { report.line() << xi18nc("@info/plain", "Setting label for partition %1 to %2", deviceNode, newLabel); - ExternalCommand cmd(report, QStringLiteral("fatlabel"), QStringList() << deviceNode << newLabel); + ExternalCommand cmd(report, QStringLiteral("fatlabel"), { deviceNode, newLabel }); return cmd.run(-1) && cmd.exitCode() == 0; } bool fat16::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("fsck.msdos"), QStringList() << QStringLiteral("-a") << QStringLiteral("-w") << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("fsck.msdos"), { QStringLiteral("-a"), QStringLiteral("-w"), QStringLiteral("-v"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool fat16::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.msdos"), QStringList() << QStringLiteral("-F16") << QStringLiteral("-I") << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.msdos"), { QStringLiteral("-F16"), QStringLiteral("-I"), QStringLiteral("-v"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool fat16::updateUUID(Report& report, const QString& deviceNode) const { qint32 t = time(nullptr); char uuid[4]; for (quint32 i = 0; i < sizeof(uuid); i++, t >>= 8) uuid[i] = t & 0xff; - ExternalCommand cmd(report, QStringLiteral("dd"), QStringList() << QStringLiteral("of=") + deviceNode << QStringLiteral("bs=1") << QStringLiteral("count=4") << QStringLiteral("seek=39")); + ExternalCommand cmd(report, QStringLiteral("dd"), { QStringLiteral("of=") + deviceNode , QStringLiteral("bs=1"), QStringLiteral("count=4"), QStringLiteral("seek=39") }); if (!cmd.start()) return false; if (cmd.write(uuid, sizeof(uuid)) != sizeof(uuid)) return false; return cmd.waitFor(-1); } } diff --git a/src/fs/fat16.h b/src/fs/fat16.h index b388b00..94bb093 100644 --- a/src/fs/fat16.h +++ b/src/fs/fat16.h @@ -1,110 +1,110 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(FAT16__H) #define FAT16__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A fat16 file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT fat16 : public FileSystem { public: fat16(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, FileSystem::Type t = FileSystem::Fat16); public: static void init(); virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_SetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/fat32.cpp b/src/fs/fat32.cpp index 38b855c..8ab35b5 100644 --- a/src/fs/fat32.cpp +++ b/src/fs/fat32.cpp @@ -1,67 +1,67 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/fat32.h" #include "util/externalcommand.h" #include "util/capacity.h" #include #include namespace FS { fat32::fat32(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : fat16(firstsector, lastsector, sectorsused, label, FileSystem::Fat32) { } qint64 fat32::minCapacity() const { return 32 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 fat32::maxCapacity() const { return 16 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB); } bool fat32::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.msdos"), QStringList() << QStringLiteral("-F32") << QStringLiteral("-I") << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.msdos"), { QStringLiteral("-F32"), QStringLiteral("-I"), QStringLiteral("-v"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool fat32::updateUUID(Report& report, const QString& deviceNode) const { qint32 t = time(nullptr); char uuid[4]; for (quint32 i = 0; i < sizeof(uuid); i++, t >>= 8) uuid[i] = t & 0xff; - ExternalCommand cmd(report, QStringLiteral("dd"), QStringList() << QStringLiteral("of=") + deviceNode << QStringLiteral("bs=1") << QStringLiteral("count=4") << QStringLiteral("seek=67")); + ExternalCommand cmd(report, QStringLiteral("dd"), { QStringLiteral("of=") + deviceNode, QStringLiteral("bs=1"), QStringLiteral("count=4"), QStringLiteral("seek=67") }); if (!cmd.start()) return false; if (cmd.write(uuid, sizeof(uuid)) != sizeof(uuid)) return false; return cmd.waitFor(-1); } } diff --git a/src/fs/fat32.h b/src/fs/fat32.h index c57f5b2..2999836 100644 --- a/src/fs/fat32.h +++ b/src/fs/fat32.h @@ -1,56 +1,56 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(FAT32__H) #define FAT32__H #include "util/libpartitionmanagerexport.h" #include "fs/fat16.h" -#include +#include class Report; class QString; namespace FS { /** A fat32 file system. Basically the same as a fat16 file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT fat32 : public fat16 { public: fat32(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init() {} virtual bool create(Report& report, const QString& deviceNode) const; virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; }; } #endif diff --git a/src/fs/filesystem.h b/src/fs/filesystem.h index 28a8324..be495a8 100644 --- a/src/fs/filesystem.h +++ b/src/fs/filesystem.h @@ -1,244 +1,244 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2015 by Teo Mrnjavac * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(FILESYSTEM__H) #define FILESYSTEM__H #include "../util/libpartitionmanagerexport.h" -#include +#include #include #include #include #include #include #include class Device; class Report; /** Base class for all FileSystems. Represents a file system and handles support for various types of operations that can be performed on those. @author Volker Lanz */ class LIBKPMCORE_EXPORT FileSystem { Q_DISABLE_COPY(FileSystem) public: class SupportTool { public: explicit SupportTool(const QString& n = QString(), const QUrl& u = QUrl()) : name(n), url(u) {} const QString name; const QUrl url; }; /** Supported FileSystem types */ enum Type { Unknown = 0, Extended = 1, Ext2 = 2, Ext3 = 3, Ext4 = 4, LinuxSwap = 5, Fat16 = 6, Fat32 = 7, Ntfs = 8, ReiserFS = 9, Reiser4 = 10, Xfs = 11, Jfs = 12, Hfs = 13, HfsPlus = 14, Ufs = 15, Unformatted = 16, Btrfs = 17, Hpfs = 18, Luks = 19, Ocfs2 = 20, Zfs = 21, Exfat = 22, Nilfs2 = 23, Lvm2_PV = 24, F2fs = 25, __lastType = 26 }; /** The type of support for a given FileSystem action */ enum CommandSupportType { cmdSupportNone = 0, /**< no support */ cmdSupportCore = 1, /**< internal support */ cmdSupportFileSystem = 2, /**< supported by some external command */ cmdSupportBackend = 4 /**< supported by the backend */ }; static const std::array< QColor, __lastType > defaultColorCode; Q_DECLARE_FLAGS(CommandSupportTypes, CommandSupportType) protected: FileSystem(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, FileSystem::Type t); public: virtual ~FileSystem() {} public: virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual QString readLabel(const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 newLength) const; virtual bool move(Report& report, const QString& deviceNode, qint64 newStartSector) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const; virtual bool backup(Report& report, const Device& sourceDevice, const QString& deviceNode, const QString& filename) const; virtual bool remove(Report& report, const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual QString readUUID(const QString& deviceNode) const; virtual bool updateBootSector(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return cmdSupportNone; /**< @return CommandSupportType for getting used capacity */ } virtual CommandSupportType supportGetLabel() const { return cmdSupportNone; /**< @return CommandSupportType for reading label*/ } virtual CommandSupportType supportCreate() const { return cmdSupportNone; /**< @return CommandSupportType for creating */ } virtual CommandSupportType supportGrow() const { return cmdSupportNone; /**< @return CommandSupportType for growing */ } virtual CommandSupportType supportShrink() const { return cmdSupportNone; /**< @return CommandSupportType for shrinking */ } virtual CommandSupportType supportMove() const { return cmdSupportNone; /**< @return CommandSupportType for moving */ } virtual CommandSupportType supportCheck() const { return cmdSupportNone; /**< @return CommandSupportType for checking */ } virtual CommandSupportType supportCopy() const { return cmdSupportNone; /**< @return CommandSupportType for copying */ } virtual CommandSupportType supportBackup() const { return cmdSupportNone; /**< @return CommandSupportType for backing up */ } virtual CommandSupportType supportSetLabel() const { return cmdSupportNone; /**< @return CommandSupportType for setting label*/ } virtual CommandSupportType supportUpdateUUID() const { return cmdSupportNone; /**< @return CommandSupportType for updating the UUID */ } virtual CommandSupportType supportGetUUID() const { return cmdSupportNone; /**< @return CommandSupportType for reading the UUID */ } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; virtual QString name() const; virtual FileSystem::Type type() const { return m_Type; /**< @return the FileSystem's type */ } static QString nameForType(FileSystem::Type t); static QList types(); static FileSystem::Type typeForName(const QString& s); static FileSystem::Type detectFileSystem(const QString& partitionPath); virtual bool canMount(const QString&) const { return false; /**< @return true if this FileSystem can be mounted */ } virtual bool canUnmount(const QString&) const { return false; /**< @return true if this FileSystem can be unmounted */ } virtual QString mountTitle() const; virtual QString unmountTitle() const; virtual bool mount(const QString& deviceNode, const QString& mountPoint); virtual bool unmount(const QString& deviceNode); qint64 firstSector() const { return m_FirstSector; /**< @return the FileSystem's first sector */ } qint64 lastSector() const { return m_LastSector; /**< @return the FileSystem's last sector */ } qint64 length() const { return lastSector() - firstSector() + 1; /**< @return the FileSystem's length */ } void setFirstSector(qint64 s) { m_FirstSector = s; /**< @param s the new first sector */ } void setLastSector(qint64 s) { m_LastSector = s; /**< @param s the new last sector */ } void move(qint64 newStartSector); const QString& label() const { return m_Label; /**< @return the FileSystem's label */ } qint64 sectorsUsed() const { return m_SectorsUsed; /**< @return the sectors in use on the FileSystem */ } const QString& uuid() const { return m_UUID; /**< @return the FileSystem's UUID */ } void setSectorsUsed(qint64 s) { m_SectorsUsed = s; /**< @param s the new value for sectors in use */ } void setLabel(const QString& s) { m_Label = s; /**< @param s the new label */ } void setUUID(const QString& s) { m_UUID = s; /**< @param s the new UUID */ } protected: static bool findExternal(const QString& cmdName, const QStringList& args = QStringList(), int exptectedCode = 1); protected: FileSystem::Type m_Type; qint64 m_FirstSector; qint64 m_LastSector; qint64 m_SectorsUsed; QString m_Label; QString m_UUID; }; Q_DECLARE_OPERATORS_FOR_FLAGS(FileSystem::CommandSupportTypes) #endif diff --git a/src/fs/filesystemfactory.h b/src/fs/filesystemfactory.h index 6506fa9..2963a7c 100644 --- a/src/fs/filesystemfactory.h +++ b/src/fs/filesystemfactory.h @@ -1,54 +1,54 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(FILESYSTEMFACTORY__H) #define FILESYSTEMFACTORY__H #include "../fs/filesystem.h" #include "../util/libpartitionmanagerexport.h" #include -#include +#include class QString; /** Factory to create instances of FileSystem. @author Volker Lanz */ class LIBKPMCORE_EXPORT FileSystemFactory { public: /** map of FileSystem::Types to pointers of FileSystem */ typedef QMap FileSystems; private: FileSystemFactory(); public: static void init(); static FileSystem* create(FileSystem::Type t, qint64 firstsector, qint64 lastsector, qint64 sectorsused = -1, const QString& label = QString(), const QString& uuid = QString()); static FileSystem* create(const FileSystem& other); static FileSystem* cloneWithNewType(FileSystem::Type newType, const FileSystem& other); static const FileSystems& map(); private: static FileSystems m_FileSystems; }; #endif diff --git a/src/fs/hfs.cpp b/src/fs/hfs.cpp index 2da9637..715738d 100644 --- a/src/fs/hfs.cpp +++ b/src/fs/hfs.cpp @@ -1,96 +1,96 @@ /************************************************************************* * Copyright (C) 2008,2011 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/hfs.h" #include "util/externalcommand.h" #include "util/capacity.h" #include #include namespace FS { FileSystem::CommandSupportType hfs::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfs::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfs::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfs::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfs::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfs::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfs::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfs::m_Backup = FileSystem::cmdSupportNone; hfs::hfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Hfs) { } void hfs::init() { m_GetLabel = cmdSupportCore; m_Create = findExternal(QStringLiteral("hformat")) ? cmdSupportFileSystem : cmdSupportNone; m_Check = findExternal(QStringLiteral("hfsck")) ? cmdSupportFileSystem : cmdSupportNone; m_Move = m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Backup = cmdSupportCore; } bool hfs::supportToolFound() const { return // m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && // m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && // m_UpdateUUID != cmdSupportNone && // m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone; // m_GetUUID != cmdSupportNone; } FileSystem::SupportTool hfs::supportToolName() const { return SupportTool(QStringLiteral("hfsutils"), QUrl(QStringLiteral("http://www.mars.org/home/rob/proj/hfs/"))); } qint64 hfs::maxCapacity() const { return 2 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB); } qint64 hfs::maxLabelLength() const { return 27; } bool hfs::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("hfsck"), QStringList() << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("hfsck"), { QStringLiteral("-v"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool hfs::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("hformat"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("hformat"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/hfs.h b/src/fs/hfs.h index 1a75cf1..fa28d2e 100644 --- a/src/fs/hfs.h +++ b/src/fs/hfs.h @@ -1,90 +1,90 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(HFS__H) #define HFS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** An hfs file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT hfs : public FileSystem { public: hfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; }; } #endif diff --git a/src/fs/hfsplus.cpp b/src/fs/hfsplus.cpp index 3f21941..ff70c19 100644 --- a/src/fs/hfsplus.cpp +++ b/src/fs/hfsplus.cpp @@ -1,85 +1,85 @@ /************************************************************************* * Copyright (C) 2008,2011 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/hfsplus.h" #include "util/externalcommand.h" #include "util/capacity.h" #include namespace FS { FileSystem::CommandSupportType hfsplus::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfsplus::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfsplus::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfsplus::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfsplus::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType hfsplus::m_Backup = FileSystem::cmdSupportNone; hfsplus::hfsplus(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::HfsPlus) { } void hfsplus::init() { m_Check = findExternal(QStringLiteral("hpfsck")) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Backup = cmdSupportCore; } bool hfsplus::supportToolFound() const { return // m_GetUsed != cmdSupportNone && // m_GetLabel != cmdSupportNone && // m_SetLabel != cmdSupportNone && // m_Create != cmdSupportNone && m_Check != cmdSupportNone && // m_UpdateUUID != cmdSupportNone && // m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone; // m_GetUUID != cmdSupportNone; } FileSystem::SupportTool hfsplus::supportToolName() const { return SupportTool(QStringLiteral("hfsplus"), QUrl()); } qint64 hfsplus::maxCapacity() const { return 8 * Capacity::unitFactor(Capacity::Byte, Capacity::EiB); } qint64 hfsplus::maxLabelLength() const { return 63; } bool hfsplus::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("hpfsck"), QStringList() << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("hpfsck"), { QStringLiteral("-v"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/hfsplus.h b/src/fs/hfsplus.h index f65a9b3..8166b0f 100644 --- a/src/fs/hfsplus.h +++ b/src/fs/hfsplus.h @@ -1,81 +1,81 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(HFSPLUS__H) #define HFSPLUS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** An hfsplus file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT hfsplus : public FileSystem { public: hfsplus(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual bool check(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; }; } #endif diff --git a/src/fs/hpfs.h b/src/fs/hpfs.h index 984dbc2..59f783b 100644 --- a/src/fs/hpfs.h +++ b/src/fs/hpfs.h @@ -1,103 +1,103 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(HPFS__H) #define HPFS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A hpfs file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT hpfs : public FileSystem { public: hpfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 maxCapacity() const; virtual bool supportToolFound() const { return true; } public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/jfs.cpp b/src/fs/jfs.cpp index d9fc2cc..0e664d1 100644 --- a/src/fs/jfs.cpp +++ b/src/fs/jfs.cpp @@ -1,181 +1,181 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/jfs.h" #include "util/externalcommand.h" #include "util/report.h" #include "util/capacity.h" #include #include #include #include #include namespace FS { FileSystem::CommandSupportType jfs::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType jfs::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType jfs::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType jfs::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType jfs::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType jfs::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType jfs::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType jfs::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType jfs::m_SetLabel = FileSystem::cmdSupportNone; jfs::jfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Jfs) { } void jfs::init() { m_GetUsed = findExternal(QStringLiteral("jfs_debugfs")) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; - m_SetLabel = findExternal(QStringLiteral("jfs_tune"), QStringList() << QStringLiteral("-V")) ? cmdSupportFileSystem : cmdSupportNone; - m_Create = findExternal(QStringLiteral("mkfs.jfs"), QStringList() << QStringLiteral("-V")) ? cmdSupportFileSystem : cmdSupportNone; - m_Grow = m_Check = findExternal(QStringLiteral("fsck.jfs"), QStringList() << QStringLiteral("-V")) ? cmdSupportFileSystem : cmdSupportNone; + m_SetLabel = findExternal(QStringLiteral("jfs_tune"), { QStringLiteral("-V") }) ? cmdSupportFileSystem : cmdSupportNone; + m_Create = findExternal(QStringLiteral("mkfs.jfs"),{ QStringLiteral("-V") }) ? cmdSupportFileSystem : cmdSupportNone; + m_Grow = m_Check = findExternal(QStringLiteral("fsck.jfs"), { QStringLiteral("-V") }) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Backup = cmdSupportCore; } bool jfs::supportToolFound() const { return m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && // m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone; // m_GetUUID != cmdSupportNone; } FileSystem::SupportTool jfs::supportToolName() const { return SupportTool(QStringLiteral("jfsutils"), QUrl(QStringLiteral("http://jfs.sourceforge.net/"))); } qint64 jfs::minCapacity() const { return 16 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 jfs::maxCapacity() const { return 32 * Capacity::unitFactor(Capacity::Byte, Capacity::PiB); } qint64 jfs::maxLabelLength() const { return 11; } qint64 jfs::readUsedCapacity(const QString& deviceNode) const { ExternalCommand cmd(QStringLiteral("jfs_debugfs"), QStringList() << deviceNode); if (cmd.start() && cmd.write("dm") == 2 && cmd.waitFor()) { qint64 blockSize = -1; QRegExp rxBlockSize(QStringLiteral("Block Size: (\\d+)")); if (rxBlockSize.indexIn(cmd.output()) != -1) blockSize = rxBlockSize.cap(1).toLongLong(); qint64 nBlocks = -1; QRegExp rxnBlocks(QStringLiteral("dn_mapsize:\\s+0x([0-9a-f]+)")); bool ok = false; if (rxnBlocks.indexIn(cmd.output()) != -1) { nBlocks = rxnBlocks.cap(1).toLongLong(&ok, 16); if (!ok) nBlocks = -1; } qint64 nFree = -1; QRegExp rxnFree(QStringLiteral("dn_nfree:\\s+0x([0-9a-f]+)")); if (rxnFree.indexIn(cmd.output()) != -1) { nFree = rxnFree.cap(1).toLongLong(&ok, 16); if (!ok) nFree = -1; } if (nBlocks > -1 && blockSize > -1 && nFree > -1) return (nBlocks - nFree) * blockSize; } return -1; } bool jfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand cmd(report, QStringLiteral("jfs_tune"), QStringList() << QStringLiteral("-L") << newLabel << deviceNode); + ExternalCommand cmd(report, QStringLiteral("jfs_tune"), { QStringLiteral("-L"), newLabel, deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool jfs::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("fsck.jfs"), QStringList() << QStringLiteral("-f") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("fsck.jfs"), { QStringLiteral("-f"), deviceNode }); return cmd.run(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 1); } bool jfs::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.jfs"), QStringList() << QStringLiteral("-q") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.jfs"), { QStringLiteral("-q"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool jfs::resize(Report& report, const QString& deviceNode, qint64) const { QTemporaryDir tempDir; if (!tempDir.isValid()) { report.line() << xi18nc("@info/plain", "Resizing JFS file system on partition %1 failed: Could not create temp dir.", deviceNode); return false; } bool rval = false; - ExternalCommand mountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << QStringLiteral("-t") << QStringLiteral("jfs") << deviceNode << tempDir.path()); + ExternalCommand mountCmd(report, QStringLiteral("mount"), { QStringLiteral("-v"), QStringLiteral("-t"), QStringLiteral("jfs"), deviceNode, tempDir.path() }); if (mountCmd.run(-1)) { - ExternalCommand resizeMountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << QStringLiteral("-t") << QStringLiteral("jfs") << QStringLiteral("-o") << QStringLiteral("remount,resize") << deviceNode << tempDir.path()); + ExternalCommand resizeMountCmd(report, QStringLiteral("mount"), { QStringLiteral("-v"), QStringLiteral("-t"), QStringLiteral("jfs"), QStringLiteral("-o"), QStringLiteral("remount,resize"), deviceNode, tempDir.path() }); if (resizeMountCmd.run(-1)) rval = true; else report.line() << xi18nc("@info/plain", "Resizing JFS file system on partition %1 failed: Remount failed.", deviceNode); - ExternalCommand unmountCmd(report, QStringLiteral("umount"), QStringList() << tempDir.path()); + ExternalCommand unmountCmd(report, QStringLiteral("umount"), { tempDir.path() }); if (!unmountCmd.run(-1)) report.line() << xi18nc("@info/plain", "Warning: Resizing JFS file system on partition %1: Unmount failed.", deviceNode); } else report.line() << xi18nc("@info/plain", "Resizing JFS file system on partition %1 failed: Initial mount failed.", deviceNode); return rval; } } diff --git a/src/fs/jfs.h b/src/fs/jfs.h index 0d3bc85..6b338e8 100644 --- a/src/fs/jfs.h +++ b/src/fs/jfs.h @@ -1,98 +1,98 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(JFS__H) #define JFS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A JFS file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT jfs : public FileSystem { public: jfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; }; } #endif diff --git a/src/fs/linuxswap.cpp b/src/fs/linuxswap.cpp index 29674da..9645d6b 100644 --- a/src/fs/linuxswap.cpp +++ b/src/fs/linuxswap.cpp @@ -1,162 +1,161 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/linuxswap.h" #include "util/externalcommand.h" #include namespace FS { FileSystem::CommandSupportType linuxswap::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType linuxswap::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType linuxswap::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType linuxswap::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType linuxswap::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType linuxswap::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType linuxswap::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType linuxswap::m_GetUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType linuxswap::m_UpdateUUID = FileSystem::cmdSupportNone; linuxswap::linuxswap(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::LinuxSwap) { } void linuxswap::init() { m_SetLabel = m_Shrink = m_Grow = m_Create = m_UpdateUUID = (findExternal(QStringLiteral("mkswap"))) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_Copy = cmdSupportFileSystem; m_Move = cmdSupportCore; m_GetUUID = cmdSupportCore; } bool linuxswap::supportToolFound() const { return // m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && // m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && // m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool linuxswap::supportToolName() const { return SupportTool(QStringLiteral("util-linux"), QUrl(QStringLiteral("http://www.kernel.org/pub/linux/utils/util-linux-ng/"))); } qint64 linuxswap::maxLabelLength() const { return 15; } bool linuxswap::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkswap"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkswap"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool linuxswap::resize(Report& report, const QString& deviceNode, qint64 length) const { Q_UNUSED(length); const QString label = readLabel(deviceNode); const QString uuid = readUUID(deviceNode); QStringList args; if (!label.isEmpty()) - args << QStringLiteral("-L") << label; + args << QStringLiteral("--label") << label; if (!uuid.isEmpty()) - args << QStringLiteral("-U") << uuid; + args << QStringLiteral("--uuid") << uuid; args << deviceNode; ExternalCommand cmd(report, QStringLiteral("mkswap"), args); return cmd.run(-1) && cmd.exitCode() == 0; } bool linuxswap::copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const { const QString label = readLabel(sourceDeviceNode); const QString uuid = readUUID(sourceDeviceNode); QStringList args; if (!label.isEmpty()) - args << QStringLiteral("-L") << label; + args << QStringLiteral("--label") << label; if (!uuid.isEmpty()) - args << QStringLiteral("-U") << uuid; + args << QStringLiteral("--uuid") << uuid; args << targetDeviceNode; ExternalCommand cmd(report, QStringLiteral("mkswap"), args); return cmd.run(-1) && cmd.exitCode() == 0; } bool linuxswap::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand cmd(report, QStringLiteral("mkswap"), QStringList() << QStringLiteral("-L") << newLabel << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkswap"), { QStringLiteral("--label"), newLabel, deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } QString linuxswap::mountTitle() const { return i18nc("@title:menu", "Activate swap"); } QString linuxswap::unmountTitle() const { return i18nc("@title:menu", "Deactivate swap"); } bool linuxswap::mount(const QString& deviceNode, const QString& mountPoint) { Q_UNUSED(mountPoint); - - ExternalCommand cmd(QStringLiteral("swapon"), QStringList() << deviceNode); + ExternalCommand cmd(QStringLiteral("swapon"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool linuxswap::unmount(const QString& deviceNode) { - ExternalCommand cmd(QStringLiteral("swapoff"), QStringList() << deviceNode); + ExternalCommand cmd(QStringLiteral("swapoff"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool linuxswap::updateUUID(Report& report, const QString& deviceNode) const { const QString label = readLabel(deviceNode); QStringList args; if (!label.isEmpty()) - args << QStringLiteral("-L") << label; + args << QStringLiteral("--label") << label; args << deviceNode; ExternalCommand cmd(report, QStringLiteral("mkswap"), args); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/linuxswap.h b/src/fs/linuxswap.h index e7010df..545aae2 100644 --- a/src/fs/linuxswap.h +++ b/src/fs/linuxswap.h @@ -1,109 +1,109 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(LINUXSWAP__H) #define LINUXSWAP__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A linux swap pseudo file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT linuxswap : public FileSystem { public: linuxswap(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual bool create(Report& report, const QString& deviceNode) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const; virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual bool canMount(const QString&) const { return true; } virtual bool canUnmount(const QString&) const { return true; } virtual bool mount(const QString& deviceNode, const QString& mountPoint) override; virtual bool unmount(const QString& deviceNode) override; virtual QString mountTitle() const override; virtual QString unmountTitle() const override; virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Copy; static CommandSupportType m_SetLabel; static CommandSupportType m_GetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index 5f3de48..d08b0fd 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -1,588 +1,588 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2013 by Andrius Štikonas * * Copyright (C) 2015-2016 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/luks.h" #include "fs/filesystemfactory.h" #include "gui/decryptluksdialog.h" #include "util/capacity.h" #include "util/externalcommand.h" #include "util/report.h" #include #include #include #include #include #include namespace FS { FileSystem::CommandSupportType luks::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType luks::m_GetUUID = FileSystem::cmdSupportNone; luks::luks(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Luks) , m_innerFs(nullptr) , m_isCryptOpen(false) , m_isMounted(false) { } luks::~luks() { delete m_innerFs; } void luks::init() { m_Create = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone; m_SetLabel = cmdSupportFileSystem; m_GetLabel = cmdSupportFileSystem; m_UpdateUUID = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone; m_Grow = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = cmdSupportCore; m_Move = cmdSupportCore; m_Backup = cmdSupportCore; m_GetUUID = findExternal(QStringLiteral("cryptsetup")) ? cmdSupportFileSystem : cmdSupportNone; } bool luks::create(Report& report, const QString& deviceNode) const { Q_ASSERT(m_innerFs); Q_ASSERT(!m_passphrase.isEmpty()); std::vector commands; commands.push_back(QStringLiteral("echo")); commands.push_back(QStringLiteral("cryptsetup")); std::vector args; args.push_back({ m_passphrase }); args.push_back({ QStringLiteral("-s"), QStringLiteral("512"), QStringLiteral("luksFormat"), deviceNode }); ExternalCommand createCmd(commands, args); if (!(createCmd.run(-1) && createCmd.exitCode() == 0)) return false; commands.clear(); commands.push_back(QStringLiteral("echo")); commands.push_back(QStringLiteral("cryptsetup")); args.clear(); args.push_back({ m_passphrase }); args.push_back({ QStringLiteral("luksOpen"), deviceNode, QStringLiteral("luks-") + readUUID(deviceNode) }); ExternalCommand openCmd(commands, args); if (!(openCmd.run(-1) && openCmd.exitCode() == 0)) return false; QString mapperNode = mapperName(deviceNode); if (mapperNode.isEmpty()) return false; m_innerFs->create(report, mapperNode); m_isCryptOpen = (m_innerFs != nullptr); if (m_isCryptOpen) return true; return false; } bool luks::supportToolFound() const { return // m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && // m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool luks::supportToolName() const { return SupportTool(QStringLiteral("cryptsetup"), QUrl(QStringLiteral("https://code.google.com/p/cryptsetup/"))); } qint64 luks::minCapacity() const { return 3 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } QString luks::mountTitle() const { return i18nc("@title:menu", "Mount"); } QString luks::unmountTitle() const { return i18nc("@title:menu", "Unmount"); } QString luks::cryptOpenTitle() const { return i18nc("@title:menu", "Decrypt"); } QString luks::cryptCloseTitle() const { return i18nc("@title:menu", "Deactivate"); } void luks::setPassphrase(const QString& passphrase) { m_passphrase = passphrase; } bool luks::canMount(const QString& deviceNode) const { return m_isCryptOpen && !m_isMounted && m_innerFs && m_innerFs->canMount(mapperName(deviceNode)); } bool luks::canUnmount(const QString& deviceNode) const { return m_isCryptOpen && m_isMounted && m_innerFs && m_innerFs->canUnmount(mapperName(deviceNode)); } bool luks::isMounted() const { return m_isCryptOpen && m_isMounted; } void luks::setMounted(bool mounted) { m_isMounted = mounted; } bool luks::canCryptOpen(const QString&) const { return !m_isCryptOpen && !m_isMounted; } bool luks::canCryptClose(const QString&) const { return m_isCryptOpen && !m_isMounted; } bool luks::isCryptOpen() const { return m_isCryptOpen; } void luks::setCryptOpen(bool cryptOpen) { m_isCryptOpen = cryptOpen; } bool luks::cryptOpen(const QString& deviceNode) { if (m_isCryptOpen) { if (!mapperName(deviceNode).isEmpty()) { qWarning() << "LUKS device" << deviceNode << "already decrypted." << "Cannot decrypt again."; return false; } else { qWarning() << "LUKS device" << deviceNode << "reportedly decrypted but mapper node not found." << "Marking device as NOT decrypted and trying to " "decrypt again anyway."; m_isCryptOpen = false; } } QPointer dlg = new DecryptLuksDialog(0, deviceNode); //TODO: parent widget instead of 0 if (dlg->exec() != QDialog::Accepted) { delete dlg; return false; } QString passphrase = dlg->luksPassphrase().text(); std::vector commands; commands.push_back(QStringLiteral("echo")); commands.push_back(QStringLiteral("cryptsetup")); std::vector args; args.push_back({ passphrase }); args.push_back({ QStringLiteral("luksOpen"), deviceNode, QStringLiteral("luks-") + readUUID(deviceNode) }); delete dlg; ExternalCommand cmd(commands, args); if (!(cmd.run(-1) && cmd.exitCode() == 0)) return false; if (m_innerFs) { delete m_innerFs; m_innerFs = nullptr; } QString mapperNode = mapperName(deviceNode); if (mapperNode.isEmpty()) return false; loadInnerFileSystem(mapperNode); m_isCryptOpen = (m_innerFs != nullptr); if (m_isCryptOpen) { m_passphrase = passphrase; return true; } return false; } bool luks::cryptClose(const QString& deviceNode) { if (!m_isCryptOpen) { qWarning() << "Cannot close LUKS device" << deviceNode << "because it's not open."; return false; } if (m_isMounted) { qWarning() << "Cannot close LUKS device" << deviceNode << "because the filesystem is mounted."; return false; } ExternalCommand cmd(QStringLiteral("cryptsetup"), { QStringLiteral("luksClose"), mapperName(deviceNode) }); if (!(cmd.run(-1) && cmd.exitCode() == 0)) return false; delete m_innerFs; m_innerFs = nullptr; m_passphrase.clear(); m_isCryptOpen = (m_innerFs != nullptr); if (!m_isCryptOpen) return true; return false; } void luks::loadInnerFileSystem(const QString& mapperNode) { Q_ASSERT(!m_innerFs); FileSystem::Type innerFsType = detectFileSystem(mapperNode); m_innerFs = FileSystemFactory::cloneWithNewType(innerFsType, *this); } void luks::createInnerFileSystem(FileSystem::Type type) { Q_ASSERT(!m_innerFs); m_innerFs = FileSystemFactory::cloneWithNewType(type, *this); } bool luks::mount(const QString& deviceNode, const QString& mountPoint) { if (!m_isCryptOpen) { qWarning() << "Cannot mount device" << deviceNode << "before decrypting it first."; return false; } if (m_isMounted) { qWarning() << "Cannot mount device" << deviceNode << "because it's already mounted."; return false; } Q_ASSERT(m_innerFs); QString mapperNode = mapperName(deviceNode); if (mapperNode.isEmpty()) return false; if (m_innerFs->canMount(mapperNode)) { if (m_innerFs->mount(mapperNode, mountPoint)) { m_isMounted = true; return true; } } else { ExternalCommand mountCmd( QStringLiteral("mount"), { QStringLiteral("-v"), mapperNode, mountPoint }); if (mountCmd.run() && mountCmd.exitCode() == 0) { m_isMounted = true; return true; } } return false; } bool luks::unmount(const QString& deviceNode) { if (!m_isCryptOpen) { qWarning() << "Cannot unmount device" << deviceNode << "before decrypting it first."; return false; } if (!m_isMounted) { qWarning() << "Cannot unmount device" << deviceNode << "because it's not mounted."; return false; } Q_ASSERT(m_innerFs); QString mapperNode = mapperName(deviceNode); if (mapperNode.isEmpty()) return false; if (m_innerFs->canUnmount(mapperNode)) { if (m_innerFs->unmount(mapperNode)) { m_isMounted = false; return true; } } else { ExternalCommand unmountCmd( QStringLiteral("mount"), { QStringLiteral("-v"), QStringLiteral("-A"), mapperNode }); if (unmountCmd.run() && unmountCmd.exitCode() == 0) { m_isMounted = false; return true; } } return false; } FileSystem::Type luks::type() const { if (m_isCryptOpen && m_innerFs) return m_innerFs->type(); return FileSystem::Luks; } QString luks::readLabel(const QString& deviceNode) const { if (m_isCryptOpen && m_innerFs) return m_innerFs->readLabel(mapperName(deviceNode)); return QStringLiteral(); } bool luks::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { Q_ASSERT(m_innerFs); return m_innerFs->writeLabel(report, mapperName(deviceNode), newLabel); } bool luks::resize(Report& report, const QString& deviceNode, qint64) const { Q_ASSERT(m_innerFs); QString mapperNode = mapperName(deviceNode); if (mapperNode.isEmpty()) return false; - ExternalCommand cryptResizeCmd(report, QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("resize") << mapperNode); + ExternalCommand cryptResizeCmd(report, QStringLiteral("cryptsetup"), { QStringLiteral("resize"), mapperNode }); report.line() << xi18nc("@info/plain", "Resizing LUKS crypt on partition %1.", deviceNode); bool rval = false; if (cryptResizeCmd.run(-1)) { rval = m_innerFs->resize(report, mapperNode, -1); } else report.line() << xi18nc("@info/plain", "Resizing encrypted file system on partition %1 failed.", deviceNode); return rval; } QString luks::readUUID(const QString& deviceNode) const { ExternalCommand cmd(QStringLiteral("cryptsetup"), { QStringLiteral("luksUUID"), deviceNode }); if (cmd.run()) { return cmd.output().simplified(); } return QStringLiteral("---"); } bool luks::updateUUID(Report& report, const QString& deviceNode) const { QUuid uuid = QUuid::createUuid(); ExternalCommand cmd(report, QStringLiteral("cryptsetup"), { QStringLiteral("luksUUID"), deviceNode, QStringLiteral("--uuid"), uuid.toString() }); return cmd.run(-1) && cmd.exitCode() == 0; } QString luks::mapperName(const QString& deviceNode) { ExternalCommand cmd(QStringLiteral("find"), { QStringLiteral("/dev/mapper/"), QStringLiteral("-exec"), QStringLiteral("cryptsetup"), QStringLiteral("status"), QStringLiteral("{}"), QStringLiteral(";") }); if (cmd.run()) { QRegExp rxDeviceName(QStringLiteral("(/dev/mapper/[A-Za-z0-9-/]+) is " "active[A-Za-z0-9- \\.\n]+[A-Za-z0-9-: \n]+") + deviceNode); if (rxDeviceName.indexIn(cmd.output()) > -1) return rxDeviceName.cap(1); } return QString(); } QString luks::getCipherName(const QString& deviceNode) { ExternalCommand cmd(QStringLiteral("cryptsetup"), { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxCipherName(QStringLiteral("(?:Cipher name:\\s+)([A-Za-z0-9-]+)")); if (rxCipherName.indexIn(cmd.output()) > -1) return rxCipherName.cap(1); } return QStringLiteral("---"); } QString luks::getCipherMode(const QString& deviceNode) { ExternalCommand cmd(QStringLiteral("cryptsetup"), { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxCipherMode(QStringLiteral("(?:Cipher mode:\\s+)([A-Za-z0-9-]+)")); if (rxCipherMode.indexIn(cmd.output()) > -1) return rxCipherMode.cap(1); } return QStringLiteral("---"); } QString luks::getHashName(const QString& deviceNode) { ExternalCommand cmd(QStringLiteral("cryptsetup"), { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxHash(QStringLiteral("(?:Hash spec:\\s+)([A-Za-z0-9-]+)")); if (rxHash.indexIn(cmd.output()) > -1) return rxHash.cap(1); } return QStringLiteral("---"); } QString luks::getKeySize(const QString& deviceNode) { ExternalCommand cmd(QStringLiteral("cryptsetup"), { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxKeySize(QStringLiteral("(?:MK bits:\\s+)(\\d+)")); if (rxKeySize.indexIn(cmd.output()) > -1) return rxKeySize.cap(1); } return QStringLiteral("---"); } QString luks::getPayloadOffset(const QString& deviceNode) { ExternalCommand cmd(QStringLiteral("cryptsetup"), { QStringLiteral("luksDump"), deviceNode }); if (cmd.run()) { QRegExp rxPayloadOffset(QStringLiteral("(?:Payload offset:\\s+)(\\d+)")); if (rxPayloadOffset.indexIn(cmd.output()) > -1) return rxPayloadOffset.cap(1); } return QStringLiteral("---"); } bool luks::canEncryptType(FileSystem::Type type) { switch (type) { case Ext2: case Ext3: case Ext4: case LinuxSwap: case ReiserFS: case Reiser4: case Xfs: case Jfs: case Btrfs: case Zfs: case Lvm2_PV: return true; default: return false; } } } diff --git a/src/fs/lvm2_pv.cpp b/src/fs/lvm2_pv.cpp index f4d22f5..5af3c7c 100644 --- a/src/fs/lvm2_pv.cpp +++ b/src/fs/lvm2_pv.cpp @@ -1,113 +1,113 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/lvm2_pv.h" #include "util/externalcommand.h" #include "util/capacity.h" #include namespace FS { FileSystem::CommandSupportType lvm2_pv::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType lvm2_pv::m_GetUUID = FileSystem::cmdSupportNone; lvm2_pv::lvm2_pv(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Lvm2_PV) { } void lvm2_pv::init() { m_Create = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone; m_Check = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_UpdateUUID = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = cmdSupportNone; // Copying PV can confuse LVM m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_GetLabel = cmdSupportNone; m_Backup = cmdSupportCore; m_GetUUID = cmdSupportCore; } bool lvm2_pv::supportToolFound() const { return // m_GetUsed != cmdSupportNone && // m_GetLabel != cmdSupportNone && // m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && // m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && // m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool lvm2_pv::supportToolName() const { return SupportTool(QStringLiteral("lvm2"), QUrl(QStringLiteral("http://sourceware.org/lvm2/"))); } qint64 lvm2_pv::maxCapacity() const { return Capacity::unitFactor(Capacity::Byte, Capacity::EiB); } bool lvm2_pv::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("lvm"), QStringList() << QStringLiteral("pvck") << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvck"), QStringLiteral("--verbose"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool lvm2_pv::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("lvm"), QStringList() << QStringLiteral("pvcreate") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvcreate"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool lvm2_pv::remove(Report& report, const QString& deviceNode) const { // TODO: check if PV is a member of an exported VG - ExternalCommand cmd(report, QStringLiteral("lvm"), QStringList() << QStringLiteral("pvremove") << QStringLiteral("-ffy") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvremove"), QStringLiteral("--force"), QStringLiteral("--force"), QStringLiteral("--yes"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool lvm2_pv::updateUUID(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("lvm"), QStringList() << QStringLiteral("pvchange") << QStringLiteral("-u") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvchange"), QStringLiteral("--uuid"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/lvm2_pv.h b/src/fs/lvm2_pv.h index c4aa784..700548d 100644 --- a/src/fs/lvm2_pv.h +++ b/src/fs/lvm2_pv.h @@ -1,111 +1,111 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(LVM2_PV__H) #define LVM2_PV__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** LVM2 physical volume. @author Andrius Štikonas */ class LIBKPMCORE_EXPORT lvm2_pv : public FileSystem { public: lvm2_pv(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); // virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool remove(Report& report, const QString& deviceNode) const; // virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; // virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 maxCapacity() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/nilfs2.cpp b/src/fs/nilfs2.cpp index 9f61a17..38da68f 100644 --- a/src/fs/nilfs2.cpp +++ b/src/fs/nilfs2.cpp @@ -1,180 +1,180 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/nilfs2.h" #include "util/externalcommand.h" #include "util/capacity.h" #include "util/report.h" #include #include #include #include #include namespace FS { FileSystem::CommandSupportType nilfs2::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType nilfs2::m_GetUUID = FileSystem::cmdSupportNone; nilfs2::nilfs2(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Nilfs2) { } void nilfs2::init() { m_Create = findExternal(QStringLiteral("mkfs.nilfs2")) ? cmdSupportFileSystem : cmdSupportNone; m_Check = findExternal(QStringLiteral("fsck.nilfs2")) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_SetLabel = findExternal(QStringLiteral("nilfs-tune")) ? cmdSupportFileSystem : cmdSupportNone; m_UpdateUUID = findExternal(QStringLiteral("nilfs-tune")) ? cmdSupportFileSystem : cmdSupportNone; m_Grow = (m_Check != cmdSupportNone && findExternal(QStringLiteral("nilfs-resize"))) ? cmdSupportFileSystem : cmdSupportNone; m_GetUsed = findExternal(QStringLiteral("nilfs-tune")) ? cmdSupportFileSystem : cmdSupportNone; m_Shrink = (m_Grow != cmdSupportNone && m_GetUsed != cmdSupportNone) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_GetLabel = cmdSupportCore; m_Backup = cmdSupportCore; m_GetUUID = cmdSupportCore; } bool nilfs2::supportToolFound() const { return m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool nilfs2::supportToolName() const { return SupportTool(QStringLiteral("nilfs2-utils"), QUrl(QStringLiteral("http://code.google.com/p/nilfs2/"))); } qint64 nilfs2::minCapacity() const { return 128 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 nilfs2::maxCapacity() const { return Capacity::unitFactor(Capacity::Byte, Capacity::EiB); } qint64 nilfs2::maxLabelLength() const { return 80; } bool nilfs2::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("fsck.nilfs2"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("fsck.nilfs2"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool nilfs2::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.nilfs2"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.nilfs2"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } qint64 nilfs2::readUsedCapacity(const QString& deviceNode) const { - ExternalCommand cmd(QStringLiteral("nilfs-tune"), QStringList() << QStringLiteral("-l") << deviceNode); + ExternalCommand cmd(QStringLiteral("nilfs-tune"), { QStringLiteral("-l"), deviceNode }); if (cmd.run()) { QRegExp rxBlockSize(QStringLiteral("(?:Block size:\\s+)(\\d+)")); QRegExp rxDeviceSize(QStringLiteral("(?:Device size:\\s+)(\\d+)")); QRegExp rxFreeBlocks(QStringLiteral("(?:Free blocks count:\\s+)(\\d+)")); if (rxBlockSize.indexIn(cmd.output()) != -1 && rxDeviceSize.indexIn(cmd.output()) != -1 && rxFreeBlocks.indexIn(cmd.output()) != -1) return rxDeviceSize.cap(1).toLongLong() - rxBlockSize.cap(1).toLongLong() * rxFreeBlocks.cap(1).toLongLong(); } return -1; } bool nilfs2::resize(Report& report, const QString& deviceNode, qint64 length) const { QTemporaryDir tempDir; if (!tempDir.isValid()) { report.line() << xi18nc("@info/plain", "Resizing NILFS2 file system on partition %1 failed: Could not create temp dir.", deviceNode); return false; } bool rval = false; - ExternalCommand mountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << QStringLiteral("-t") << QStringLiteral("nilfs2") << deviceNode << tempDir.path()); + ExternalCommand mountCmd(report, QStringLiteral("mount"), { QStringLiteral("--verbose"), QStringLiteral("--types"), QStringLiteral("nilfs2"), deviceNode, tempDir.path() }); if (mountCmd.run(-1) && mountCmd.exitCode() == 0) { - ExternalCommand resizeCmd(report, QStringLiteral("nilfs-resize"), QStringList() << QStringLiteral("-v") << QStringLiteral("-y") << deviceNode << QString::number(length)); + ExternalCommand resizeCmd(report, QStringLiteral("nilfs-resize"), { QStringLiteral("--verbose"), QStringLiteral("--assume-yes"), deviceNode, QString::number(length) }); if (resizeCmd.run(-1) && resizeCmd.exitCode() == 0) rval = true; else report.line() << xi18nc("@info/plain", "Resizing NILFS2 file system on partition %1 failed: NILFS2 file system resize failed.", deviceNode); - ExternalCommand unmountCmd(report, QStringLiteral("umount"), QStringList() << tempDir.path()); + ExternalCommand unmountCmd(report, QStringLiteral("umount"), { tempDir.path() }); if (!unmountCmd.run(-1) && unmountCmd.exitCode() == 0) report.line() << xi18nc("@info/plain", "Warning: Resizing NILFS2 file system on partition %1: Unmount failed.", deviceNode); } else report.line() << xi18nc("@info/plain", "Resizing NILFS2 file system on partition %1 failed: Initial mount failed.", deviceNode); return rval; } bool nilfs2::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand cmd(report, QStringLiteral("nilfs-tune"), QStringList() << QStringLiteral("-l") << newLabel << deviceNode); + ExternalCommand cmd(report, QStringLiteral("nilfs-tune"), { QStringLiteral("-l"), newLabel, deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool nilfs2::updateUUID(Report& report, const QString& deviceNode) const { QUuid uuid = QUuid::createUuid(); - ExternalCommand cmd(report, QStringLiteral("nilfs-tune"), QStringList() << QStringLiteral("-U") << uuid.toString() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("nilfs-tune"), { QStringLiteral("-U"), uuid.toString(), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/nilfs2.h b/src/fs/nilfs2.h index b987eba..04e40a2 100644 --- a/src/fs/nilfs2.h +++ b/src/fs/nilfs2.h @@ -1,113 +1,113 @@ /************************************************************************* * Copyright (C) 2012 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(NILFS2__H) #define NILFS2__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A nilfs2 file system. @author Andrius Štikonas */ class LIBKPMCORE_EXPORT nilfs2 : public FileSystem { public: nilfs2(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); // virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/ntfs.cpp b/src/fs/ntfs.cpp index 8e0f96d..80f512a 100644 --- a/src/fs/ntfs.cpp +++ b/src/fs/ntfs.cpp @@ -1,234 +1,234 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/ntfs.h" #include "util/externalcommand.h" #include "util/capacity.h" #include "util/report.h" #include "util/globallog.h" #include #include #include #include #include #include #include namespace FS { FileSystem::CommandSupportType ntfs::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ntfs::m_GetUUID = FileSystem::cmdSupportNone; ntfs::ntfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Ntfs) { } void ntfs::init() { m_Shrink = m_Grow = m_Check = m_GetUsed = findExternal(QStringLiteral("ntfsresize")) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_SetLabel = findExternal(QStringLiteral("ntfslabel")) ? cmdSupportFileSystem : cmdSupportNone; m_Create = findExternal(QStringLiteral("mkfs.ntfs")) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = findExternal(QStringLiteral("ntfsclone")) ? cmdSupportFileSystem : cmdSupportNone; m_Backup = cmdSupportCore; m_UpdateUUID = cmdSupportCore; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_GetUUID = cmdSupportCore; } bool ntfs::supportToolFound() const { return m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool ntfs::supportToolName() const { return SupportTool(QStringLiteral("ntfs-3g"), QUrl(QStringLiteral("http://www.tuxera.com/community/ntfs-3g-download/"))); } qint64 ntfs::minCapacity() const { return 2 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 ntfs::maxCapacity() const { return 256 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB); } qint64 ntfs::maxLabelLength() const { return 128; } qint64 ntfs::readUsedCapacity(const QString& deviceNode) const { - ExternalCommand cmd(QStringLiteral("ntfsresize"), QStringList() << QStringLiteral("--info") << QStringLiteral("--force") << QStringLiteral("--no-progress-bar") << deviceNode); + ExternalCommand cmd(QStringLiteral("ntfsresize"), { QStringLiteral("--info"), QStringLiteral("--force"), QStringLiteral("--no-progress-bar"), deviceNode }); if (cmd.run()) { qint64 usedBytes = -1; QRegExp rxUsedBytes(QStringLiteral("resize at (\\d+) bytes")); if (rxUsedBytes.indexIn(cmd.output()) != -1) usedBytes = rxUsedBytes.cap(1).toLongLong(); if (usedBytes > -1) return usedBytes; } return -1; } bool ntfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand writeCmd(report, QStringLiteral("ntfslabel"), QStringList() << QStringLiteral("--force") << deviceNode << newLabel.simplified()); + ExternalCommand writeCmd(report, QStringLiteral("ntfslabel"), { QStringLiteral("--force"), deviceNode, newLabel.simplified() }); writeCmd.setProcessChannelMode(QProcess::SeparateChannels); if (!writeCmd.run(-1)) return false; - ExternalCommand testCmd(QStringLiteral("ntfslabel"), QStringList() << QStringLiteral("--force") << deviceNode); + ExternalCommand testCmd(QStringLiteral("ntfslabel"), { QStringLiteral("--force"), deviceNode }); testCmd.setProcessChannelMode(QProcess::SeparateChannels); if (!testCmd.run(-1)) return false; return testCmd.output().simplified() == newLabel.simplified(); } bool ntfs::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("ntfsresize"), QStringList() << QStringLiteral("-P") << QStringLiteral("-i") << QStringLiteral("-f") << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("ntfsresize"), { QStringLiteral("--no-progress-bar"), QStringLiteral("--info"), QStringLiteral("--force"), QStringLiteral("--verbose"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool ntfs::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.ntfs"), QStringList() << QStringLiteral("-f") << QStringLiteral("-vv") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.ntfs"), { QStringLiteral("--quick"), QStringLiteral("--verbose"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool ntfs::copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const { - ExternalCommand cmd(report, QStringLiteral("ntfsclone"), QStringList() << QStringLiteral("-f") << QStringLiteral("--overwrite") << targetDeviceNode << sourceDeviceNode); + ExternalCommand cmd(report, QStringLiteral("ntfsclone"), { QStringLiteral("--force"), QStringLiteral("--overwrite"), targetDeviceNode, sourceDeviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool ntfs::resize(Report& report, const QString& deviceNode, qint64 length) const { - QStringList args; - args << QStringLiteral("-P") << QStringLiteral("-f") << deviceNode << QStringLiteral("-s") << QString::number(length); + QStringList args = { QStringLiteral("--no-progress-bar"), QStringLiteral("--force"), deviceNode, QStringLiteral("--size"), QString::number(length) }; QStringList dryRunArgs = args; - dryRunArgs << QStringLiteral("-n"); + dryRunArgs << QStringLiteral("--no-action"); ExternalCommand cmdDryRun(QStringLiteral("ntfsresize"), dryRunArgs); if (cmdDryRun.run(-1) && cmdDryRun.exitCode() == 0) { ExternalCommand cmd(report, QStringLiteral("ntfsresize"), args); return cmd.run(-1) && cmd.exitCode() == 0; } return false; } bool ntfs::updateUUID(Report& report, const QString& deviceNode) const { + Q_UNUSED(report); QUuid uuid = QUuid::createUuid(); char* s = reinterpret_cast(&uuid.data4[0]); QFile device(deviceNode); if (!device.open(QFile::ReadWrite | QFile::Unbuffered)) { Log() << xi18nc("@info/plain", "Could not open partition %1 for writing when trying to update the NTFS serial number.", deviceNode); return false; } if (!device.seek(0x48)) { Log() << xi18nc("@info/plain", "Could not seek to position 0x48 on partition %1 when trying to update the NTFS serial number.", deviceNode); return false; } if (device.write(s, 8) != 8) { Log() << xi18nc("@info/plain", "Could not write new NTFS serial number to partition %1.", deviceNode); return false; } Log() << xi18nc("@info/plain", "Updated NTFS serial number for partition %1 successfully.", deviceNode); return true; } bool ntfs::updateBootSector(Report& report, const QString& deviceNode) const { report.line() << xi18nc("@info/plain", "Updating boot sector for NTFS file system on partition %1.", deviceNode); quint32 n = firstSector(); char* s = reinterpret_cast(&n); #if Q_BYTE_ORDER == Q_BIG_ENDIAN std::swap(s[0], s[3]); std::swap(s[1], s[2]); #endif QFile device(deviceNode); if (!device.open(QFile::ReadWrite | QFile::Unbuffered)) { Log() << xi18nc("@info/plain", "Could not open partition %1 for writing when trying to update the NTFS boot sector.", deviceNode); return false; } if (!device.seek(0x1c)) { Log() << xi18nc("@info/plain", "Could not seek to position 0x1c on partition %1 when trying to update the NTFS boot sector.", deviceNode); return false; } if (device.write(s, 4) != 4) { Log() << xi18nc("@info/plain", "Could not write new start sector to partition %1 when trying to update the NTFS boot sector.", deviceNode); return false; } Log() << xi18nc("@info/plain", "Updated NTFS boot sector for partition %1 successfully.", deviceNode); return true; } } diff --git a/src/fs/ntfs.h b/src/fs/ntfs.h index bab7d14..6c6f8a0 100644 --- a/src/fs/ntfs.h +++ b/src/fs/ntfs.h @@ -1,113 +1,113 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(NTFS__H) #define NTFS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** An NTFS file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT ntfs : public FileSystem { public: ntfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual bool updateBootSector(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/ocfs2.cpp b/src/fs/ocfs2.cpp index 53bf527..53c25f8 100644 --- a/src/fs/ocfs2.cpp +++ b/src/fs/ocfs2.cpp @@ -1,157 +1,157 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/ocfs2.h" #include "util/externalcommand.h" #include "util/capacity.h" #include #include namespace FS { FileSystem::CommandSupportType ocfs2::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType ocfs2::m_GetUUID = FileSystem::cmdSupportNone; ocfs2::ocfs2(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Ocfs2) { } void ocfs2::init() { - m_Create = findExternal(QStringLiteral("mkfs.ocfs2"), QStringList() << QStringLiteral("-V")) ? cmdSupportFileSystem : cmdSupportNone; - m_Check = findExternal(QStringLiteral("fsck.ocfs2"), QStringList(), 16) ? cmdSupportFileSystem : cmdSupportNone; - m_Grow = (m_Check != cmdSupportNone && findExternal(QStringLiteral("tunefs.ocfs2"), QStringList() << QStringLiteral("-V")) && findExternal(QStringLiteral("debugfs.ocfs2"), QStringList() << QStringLiteral("-V"))) ? cmdSupportFileSystem : cmdSupportNone; + m_Create = findExternal(QStringLiteral("mkfs.ocfs2"), { QStringLiteral("--version") }) ? cmdSupportFileSystem : cmdSupportNone; + m_Check = findExternal(QStringLiteral("fsck.ocfs2"), {}, 16) ? cmdSupportFileSystem : cmdSupportNone; + m_Grow = (m_Check != cmdSupportNone && findExternal(QStringLiteral("tunefs.ocfs2"), { QStringLiteral("--version") }) && findExternal(QStringLiteral("debugfs.ocfs2"), { QStringLiteral("--version") })) ? cmdSupportFileSystem : cmdSupportNone; m_Shrink = cmdSupportNone; // TODO: it seems there's no way to get the FS usage with ocfs2 m_GetUsed = cmdSupportNone; - m_SetLabel = findExternal(QStringLiteral("tunefs.ocfs2"), QStringList() << QStringLiteral("-V")) ? cmdSupportFileSystem : cmdSupportNone; - m_UpdateUUID = findExternal(QStringLiteral("tunefs.ocfs2"), QStringList() << QStringLiteral("-V")) ? cmdSupportFileSystem : cmdSupportNone; + m_SetLabel = findExternal(QStringLiteral("tunefs.ocfs2"), { QStringLiteral("--version") }) ? cmdSupportFileSystem : cmdSupportNone; + m_UpdateUUID = findExternal(QStringLiteral("tunefs.ocfs2"), { QStringLiteral("--version") }) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_GetLabel = cmdSupportCore; m_Backup = cmdSupportCore; m_GetUUID = cmdSupportCore; } bool ocfs2::supportToolFound() const { return // m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool ocfs2::supportToolName() const { return SupportTool(QStringLiteral("ocfs2-tools"), QUrl(QStringLiteral("http://oss.oracle.com/projects/ocfs2-tools/"))); } qint64 ocfs2::minCapacity() const { return 14000 * Capacity::unitFactor(Capacity::Byte, Capacity::KiB); } qint64 ocfs2::maxCapacity() const { return 4 * Capacity::unitFactor(Capacity::Byte, Capacity::PiB); } qint64 ocfs2::readUsedCapacity(const QString& deviceNode) const { Q_UNUSED(deviceNode); return -1; } bool ocfs2::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("fsck.ocfs2"), QStringList() << QStringLiteral("-f") << QStringLiteral("-y") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("fsck.ocfs2"), { QStringLiteral("-f"), QStringLiteral("-y"), deviceNode }); return cmd.run(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 1 || cmd.exitCode() == 2); } bool ocfs2::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.ocfs2"), QStringList() << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.ocfs2"), { deviceNode }); if (cmd.start()) { cmd.write("y\n"); cmd.waitFor(-1); return cmd.exitCode() == 0; } else return false; } bool ocfs2::resize(Report& report, const QString& deviceNode, qint64 length) const { - ExternalCommand cmdBlockSize(QStringLiteral("debugfs.ocfs2"), QStringList() << QStringLiteral("-R") << QStringLiteral("stats") << deviceNode); + ExternalCommand cmdBlockSize(QStringLiteral("debugfs.ocfs2"), { QStringLiteral("--request"), QStringLiteral("stats"), deviceNode }); qint32 blockSize = -1; if (cmdBlockSize.run()) { QRegExp rxBlockSizeBits(QStringLiteral("Block Size Bits: (\\d+)")); if (rxBlockSizeBits.indexIn(cmdBlockSize.output()) != -1) blockSize = 1 << rxBlockSizeBits.cap(1).toInt(); } if (blockSize == -1) return false; - ExternalCommand cmd(report, QStringLiteral("tunefs.ocfs2"), QStringList() << QStringLiteral("-y") << QStringLiteral("-S") << deviceNode << QString::number(length / blockSize)); + ExternalCommand cmd(report, QStringLiteral("tunefs.ocfs2"), { QStringLiteral("--yes"), QStringLiteral("--volume-size"), deviceNode, QString::number(length / blockSize) }); return cmd.run(-1) && cmd.exitCode() == 0; } bool ocfs2::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand cmd(report, QStringLiteral("tunefs.ocfs2"), QStringList() << QStringLiteral("-L") << newLabel << deviceNode); + ExternalCommand cmd(report, QStringLiteral("tunefs.ocfs2"), { QStringLiteral("--label"), newLabel, deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool ocfs2::updateUUID(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("tunefs.ocfs2"), QStringList() << QStringLiteral("-U") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("tunefs.ocfs2"), { QStringLiteral("--uuid-reset"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/ocfs2.h b/src/fs/ocfs2.h index 2a5740f..4f477be 100644 --- a/src/fs/ocfs2.h +++ b/src/fs/ocfs2.h @@ -1,110 +1,110 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(OCFS2__H) #define OCFS2__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A ocfs2 file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT ocfs2 : public FileSystem { public: ocfs2(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/reiser4.cpp b/src/fs/reiser4.cpp index cab2ab0..ce70981 100644 --- a/src/fs/reiser4.cpp +++ b/src/fs/reiser4.cpp @@ -1,127 +1,127 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/reiser4.h" #include "util/capacity.h" #include "util/externalcommand.h" #include #include namespace FS { FileSystem::CommandSupportType reiser4::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiser4::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiser4::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiser4::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiser4::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiser4::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiser4::m_Backup = FileSystem::cmdSupportNone; reiser4::reiser4(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Reiser4) { } void reiser4::init() { m_GetLabel = cmdSupportCore; - m_GetUsed = findExternal(QStringLiteral("debugfs.reiser4"), QStringList(), 16) ? cmdSupportFileSystem : cmdSupportNone; - m_Create = findExternal(QStringLiteral("mkfs.reiser4"), QStringList(), 16) ? cmdSupportFileSystem : cmdSupportNone; - m_Check = findExternal(QStringLiteral("fsck.reiser4"), QStringList(), 16) ? cmdSupportFileSystem : cmdSupportNone; + m_GetUsed = findExternal(QStringLiteral("debugfs.reiser4"), {}, 16) ? cmdSupportFileSystem : cmdSupportNone; + m_Create = findExternal(QStringLiteral("mkfs.reiser4"), {}, 16) ? cmdSupportFileSystem : cmdSupportNone; + m_Check = findExternal(QStringLiteral("fsck.reiser4"), {}, 16) ? cmdSupportFileSystem : cmdSupportNone; m_Move = m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Backup = cmdSupportCore; } bool reiser4::supportToolFound() const { return m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && // m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && // m_UpdateUUID != cmdSupportNone && // m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone; // m_GetUUID != cmdSupportNone; } FileSystem::SupportTool reiser4::supportToolName() const { return SupportTool(QStringLiteral("reiser4progs"), QUrl(QStringLiteral("http://www.kernel.org/pub/linux/utils/fs/reiser4/reiser4progs/"))); } qint64 reiser4::maxCapacity() const { // looks like it's actually unknown. see // http://en.wikipedia.org/wiki/Comparison_of_file_systems return Capacity::unitFactor(Capacity::Byte, Capacity::EiB); } qint64 reiser4::maxLabelLength() const { return 16; } qint64 reiser4::readUsedCapacity(const QString& deviceNode) const { - ExternalCommand cmd(QStringLiteral("debugfs.reiser4"), QStringList() << deviceNode); + ExternalCommand cmd(QStringLiteral("debugfs.reiser4"), { deviceNode }); if (cmd.run()) { qint64 blocks = -1; QRegExp rxBlocks(QStringLiteral("blocks:\\s+(\\d+)")); if (rxBlocks.indexIn(cmd.output()) != -1) blocks = rxBlocks.cap(1).toLongLong(); qint64 blockSize = -1; QRegExp rxBlockSize(QStringLiteral("blksize:\\s+(\\d+)")); if (rxBlockSize.indexIn(cmd.output()) != -1) blockSize = rxBlockSize.cap(1).toLongLong(); qint64 freeBlocks = -1; QRegExp rxFreeBlocks(QStringLiteral("free blocks:\\s+(\\d+)")); if (rxFreeBlocks.indexIn(cmd.output()) != -1) freeBlocks = rxFreeBlocks.cap(1).toLongLong(); if (blocks > - 1 && blockSize > -1 && freeBlocks > -1) return (blocks - freeBlocks) * blockSize; } return -1; } bool reiser4::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("fsck.reiser4"), QStringList() << QStringLiteral("--fix") << QStringLiteral("-y") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("fsck.reiser4"), { QStringLiteral("--yes"), QStringLiteral("--fix"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool reiser4::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.reiser4"), QStringList() << QStringLiteral("--yes") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.reiser4"), { QStringLiteral("--yes"), QStringLiteral("--force"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/reiser4.h b/src/fs/reiser4.h index 232c11a..f5edc14 100644 --- a/src/fs/reiser4.h +++ b/src/fs/reiser4.h @@ -1,87 +1,87 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(REISER4__H) #define REISER4__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A Reiser4 file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT reiser4 : public FileSystem { public: reiser4(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; }; } #endif diff --git a/src/fs/reiserfs.cpp b/src/fs/reiserfs.cpp index 0f61230..337969c 100644 --- a/src/fs/reiserfs.cpp +++ b/src/fs/reiserfs.cpp @@ -1,170 +1,170 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/reiserfs.h" #include "util/externalcommand.h" #include "util/capacity.h" #include #include #include #include namespace FS { FileSystem::CommandSupportType reiserfs::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType reiserfs::m_GetUUID = FileSystem::cmdSupportNone; reiserfs::reiserfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::ReiserFS) { } void reiserfs::init() { m_GetLabel = cmdSupportCore; - m_GetUsed = findExternal(QStringLiteral("debugreiserfs"), QStringList(), 16) ? cmdSupportFileSystem : cmdSupportNone; + m_GetUsed = findExternal(QStringLiteral("debugreiserfs"), {}, 16) ? cmdSupportFileSystem : cmdSupportNone; m_SetLabel = findExternal(QStringLiteral("reiserfstune")) ? cmdSupportFileSystem : cmdSupportNone; m_Create = findExternal(QStringLiteral("mkfs.reiserfs")) ? cmdSupportFileSystem : cmdSupportNone; m_Check = findExternal(QStringLiteral("fsck.reiserfs")) ? cmdSupportFileSystem : cmdSupportNone; m_Move = m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; - m_Grow = findExternal(QStringLiteral("resize_reiserfs"), QStringList(), 16) ? cmdSupportFileSystem : cmdSupportNone; + m_Grow = findExternal(QStringLiteral("resize_reiserfs"), {}, 16) ? cmdSupportFileSystem : cmdSupportNone; m_Shrink = (m_GetUsed != cmdSupportNone && m_Grow != cmdSupportNone) ? cmdSupportFileSystem : cmdSupportNone; m_Backup = cmdSupportCore; m_UpdateUUID = findExternal(QStringLiteral("reiserfstune")) ? cmdSupportFileSystem : cmdSupportNone; m_GetUUID = cmdSupportCore; } bool reiserfs::supportToolFound() const { return m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool reiserfs::supportToolName() const { return SupportTool(QStringLiteral("reiserfsprogs"), QUrl(QStringLiteral("http://www.kernel.org/pub/linux/utils/fs/reiserfs/"))); } qint64 reiserfs::minCapacity() const { return 32 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 reiserfs::maxCapacity() const { return 16 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB); } qint64 reiserfs::maxLabelLength() const { return 16; } qint64 reiserfs::readUsedCapacity(const QString& deviceNode) const { - ExternalCommand cmd(QStringLiteral("debugreiserfs"), QStringList() << deviceNode); + ExternalCommand cmd(QStringLiteral("debugreiserfs"), { deviceNode }); if (cmd.run()) { qint64 blockCount = -1; QRegExp rxBlockCount(QStringLiteral("Count of blocks[^:]+: (\\d+)")); if (rxBlockCount.indexIn(cmd.output()) != -1) blockCount = rxBlockCount.cap(1).toLongLong(); qint64 blockSize = -1; QRegExp rxBlockSize(QStringLiteral("Blocksize: (\\d+)")); if (rxBlockSize.indexIn(cmd.output()) != -1) blockSize = rxBlockSize.cap(1).toLongLong(); qint64 freeBlocks = -1; QRegExp rxFreeBlocks(QStringLiteral("Free blocks[^:]+: (\\d+)")); if (rxFreeBlocks.indexIn(cmd.output()) != -1) freeBlocks = rxFreeBlocks.cap(1).toLongLong(); if (blockCount > -1 && blockSize > -1 && freeBlocks > -1) return (blockCount - freeBlocks) * blockSize; } return -1; } bool reiserfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand cmd(report, QStringLiteral("reiserfstune"), QStringList() << QStringLiteral("-l") << newLabel << deviceNode); + ExternalCommand cmd(report, QStringLiteral("reiserfstune"), { QStringLiteral("--label"), newLabel, deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool reiserfs::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("fsck.reiserfs"), QStringList() << QStringLiteral("--fix-fixable") << QStringLiteral("-q") << QStringLiteral("-y") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("fsck.reiserfs"), { QStringLiteral("--fix-fixable"), QStringLiteral("--quiet"), QStringLiteral("--yes"), deviceNode }); return cmd.run(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 1 || cmd.exitCode() == 256); } bool reiserfs::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.reiserfs"), QStringList() << QStringLiteral("-f") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.reiserfs"), { QStringLiteral("-f"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool reiserfs::resize(Report& report, const QString& deviceNode, qint64 length) const { - ExternalCommand cmd(report, QStringLiteral("resize_reiserfs"), QStringList() << deviceNode << QStringLiteral("-q") << QStringLiteral("-s") << QString::number(length)); + ExternalCommand cmd(report, QStringLiteral("resize_reiserfs"), { deviceNode, QStringLiteral("-q"), QStringLiteral("-s"), QString::number(length) }); bool rval = cmd.start(-1); if (!rval) return false; if (cmd.write("y\n", 2) != 2) return false; return cmd.waitFor(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 256); } bool reiserfs::updateUUID(Report& report, const QString& deviceNode) const { const QString uuid = QUuid::createUuid().toString().remove(QRegExp(QStringLiteral("\\{|\\}"))); - ExternalCommand cmd(report, QStringLiteral("reiserfstune"), QStringList() << QStringLiteral("-u") << uuid << deviceNode); + ExternalCommand cmd(report, QStringLiteral("reiserfstune"), { QStringLiteral("--uuid"), uuid, deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/fs/reiserfs.h b/src/fs/reiserfs.h index 8f66cbf..aa5ed60 100644 --- a/src/fs/reiserfs.h +++ b/src/fs/reiserfs.h @@ -1,113 +1,113 @@ /************************************************************************* * Copyright (C) 2008,2009 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(REISERFS__H) #define REISERFS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" #include "util/capacity.h" -#include +#include class Report; class QString; namespace FS { /** A ReiserFS file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT reiserfs : public FileSystem { public: reiserfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual bool updateUUID(Report& report, const QString& deviceNode) const; virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/fs/ufs.h b/src/fs/ufs.h index 57e5349..b07f0ed 100644 --- a/src/fs/ufs.h +++ b/src/fs/ufs.h @@ -1,64 +1,64 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(UFS__H) #define UFS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class QString; namespace FS { /** A UFS file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT ufs : public FileSystem { public: ufs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init() {} virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual bool supportToolFound() const { return true; } public: static CommandSupportType m_Move; static CommandSupportType m_Copy; static CommandSupportType m_Backup; }; } #endif diff --git a/src/fs/unformatted.h b/src/fs/unformatted.h index 36a8588..d38283a 100644 --- a/src/fs/unformatted.h +++ b/src/fs/unformatted.h @@ -1,60 +1,60 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(UNFORMATTED__H) #define UNFORMATTED__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A pseudo file system for unformatted partitions. @author Volker Lanz */ class LIBKPMCORE_EXPORT unformatted : public FileSystem { public: unformatted(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init() {} virtual bool create(Report&, const QString&) const; virtual CommandSupportType supportCreate() const { return m_Create; } virtual bool supportToolFound() const { return true; } public: static CommandSupportType m_Create; }; } #endif diff --git a/src/fs/unknown.h b/src/fs/unknown.h index 2653dce..6cc0cde 100644 --- a/src/fs/unknown.h +++ b/src/fs/unknown.h @@ -1,46 +1,46 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(UNKNOWN__H) #define UNKNOWN__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include namespace FS { /** A pseudo file system for partitions whose file system we cannot determine. @author Volker Lanz */ class LIBKPMCORE_EXPORT unknown : public FileSystem { public: unknown(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init() {} virtual bool supportToolFound() const { return true; } }; } #endif diff --git a/src/fs/xfs.cpp b/src/fs/xfs.cpp index 4d0e366..949d280 100644 --- a/src/fs/xfs.cpp +++ b/src/fs/xfs.cpp @@ -1,191 +1,191 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/xfs.h" #include "util/externalcommand.h" #include "util/capacity.h" #include "util/report.h" #include #include #include #include #include #include namespace FS { FileSystem::CommandSupportType xfs::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType xfs::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType xfs::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType xfs::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType xfs::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType xfs::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType xfs::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType xfs::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType xfs::m_SetLabel = FileSystem::cmdSupportNone; xfs::xfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Xfs) { } void xfs::init() { m_GetLabel = cmdSupportCore; m_SetLabel = m_GetUsed = findExternal(QStringLiteral("xfs_db")) ? cmdSupportFileSystem : cmdSupportNone; m_Create = findExternal(QStringLiteral("mkfs.xfs")) ? cmdSupportFileSystem : cmdSupportNone; m_Check = findExternal(QStringLiteral("xfs_repair")) ? cmdSupportFileSystem : cmdSupportNone; - m_Grow = (findExternal(QStringLiteral("xfs_growfs"), QStringList() << QStringLiteral("-V")) && m_Check != cmdSupportNone) ? cmdSupportFileSystem : cmdSupportNone; + m_Grow = (findExternal(QStringLiteral("xfs_growfs"), { QStringLiteral("-V") }) && m_Check != cmdSupportNone) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = findExternal(QStringLiteral("xfs_copy")) ? cmdSupportFileSystem : cmdSupportNone; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Backup = cmdSupportCore; } bool xfs::supportToolFound() const { return m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && m_Create != cmdSupportNone && m_Check != cmdSupportNone && // m_UpdateUUID != cmdSupportNone && m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone; // m_GetUUID != cmdSupportNone; } FileSystem::SupportTool xfs::supportToolName() const { return SupportTool(QStringLiteral("xfsprogs"), QUrl(QStringLiteral("http://oss.sgi.com/projects/xfs/"))); } qint64 xfs::minCapacity() const { return 32 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 xfs::maxCapacity() const { return Capacity::unitFactor(Capacity::Byte, Capacity::EiB); } qint64 xfs::maxLabelLength() const { return 12; } qint64 xfs::readUsedCapacity(const QString& deviceNode) const { - ExternalCommand cmd(QStringLiteral("xfs_db"), QStringList() << QStringLiteral("-c") << QStringLiteral("sb 0") << QStringLiteral("-c") << QStringLiteral("print") << deviceNode); + ExternalCommand cmd(QStringLiteral("xfs_db"), { QStringLiteral("-c"), QStringLiteral("sb 0"), QStringLiteral("-c"), QStringLiteral("print"), deviceNode }); if (cmd.run()) { qint64 dBlocks = -1; QRegExp rxDBlocks(QStringLiteral("dblocks = (\\d+)")); if (rxDBlocks.indexIn(cmd.output()) != -1) dBlocks = rxDBlocks.cap(1).toLongLong(); qint64 blockSize = -1; QRegExp rxBlockSize(QStringLiteral("blocksize = (\\d+)")); if (rxBlockSize.indexIn(cmd.output()) != -1) blockSize = rxBlockSize.cap(1).toLongLong(); qint64 fdBlocks = -1; QRegExp rxFdBlocks(QStringLiteral("fdblocks = (\\d+)")); if (rxFdBlocks.indexIn(cmd.output()) != -1) fdBlocks = rxFdBlocks.cap(1).toLongLong(); if (dBlocks > -1 && blockSize > -1 && fdBlocks > -1) return (dBlocks - fdBlocks) * blockSize; } return -1; } bool xfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { - ExternalCommand cmd(report, QStringLiteral("xfs_db"), QStringList() << QStringLiteral("-x") << QStringLiteral("-c") << QStringLiteral("sb 0") << QStringLiteral("-c") << QStringLiteral("label ") + newLabel << deviceNode); + ExternalCommand cmd(report, QStringLiteral("xfs_db"), { QStringLiteral("-x"), QStringLiteral("-c"), QStringLiteral("sb 0"), QStringLiteral("-c"), QStringLiteral("label ") + newLabel, deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool xfs::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("xfs_repair"), QStringList() << QStringLiteral("-v") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("xfs_repair"), { QStringLiteral("-v"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool xfs::create(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("mkfs.xfs"), QStringList() << QStringLiteral("-f") << deviceNode); + ExternalCommand cmd(report, QStringLiteral("mkfs.xfs"), { QStringLiteral("-f"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool xfs::copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const { - ExternalCommand cmd(report, QStringLiteral("xfs_copy"), QStringList() << sourceDeviceNode << targetDeviceNode); + ExternalCommand cmd(report, QStringLiteral("xfs_copy"), { sourceDeviceNode, targetDeviceNode }); // xfs_copy behaves a little strangely. It apparently kills itself at the end of main, causing QProcess // to report that it crashed. // See http://oss.sgi.com/archives/xfs/2004-11/msg00169.html // So we cannot rely on QProcess::exitStatus() and thus not on ExternalCommand::run() returning true. cmd.run(-1); return cmd.exitCode() == 0; } bool xfs::resize(Report& report, const QString& deviceNode, qint64) const { QTemporaryDir tempDir; if (!tempDir.isValid()) { report.line() << xi18nc("@info/plain", "Resizing XFS file system on partition %1 failed: Could not create temp dir.", deviceNode); return false; } bool rval = false; - ExternalCommand mountCmd(report, QStringLiteral("mount"), QStringList() << QStringLiteral("-v") << QStringLiteral("-t") << QStringLiteral("xfs") << deviceNode << tempDir.path()); + ExternalCommand mountCmd(report, QStringLiteral("mount"), { QStringLiteral("--verbose"), QStringLiteral("--types"), QStringLiteral("xfs"), deviceNode, tempDir.path() }); if (mountCmd.run(-1)) { - ExternalCommand resizeCmd(report, QStringLiteral("xfs_growfs"), QStringList() << tempDir.path()); + ExternalCommand resizeCmd(report, QStringLiteral("xfs_growfs"), { tempDir.path() }); if (resizeCmd.run(-1)) rval = true; else report.line() << xi18nc("@info/plain", "Resizing XFS file system on partition %1 failed: xfs_growfs failed.", deviceNode); - ExternalCommand unmountCmd(report, QStringLiteral("umount"), QStringList() << tempDir.path()); + ExternalCommand unmountCmd(report, QStringLiteral("umount"), { tempDir.path() }); if (!unmountCmd.run(-1)) report.line() << xi18nc("@info/plain", "Warning: Resizing XFS file system on partition %1: Unmount failed.", deviceNode); } else report.line() << xi18nc("@info/plain", "Resizing XFS file system on partition %1 failed: Initial mount failed.", deviceNode); return rval; } } diff --git a/src/fs/xfs.h b/src/fs/xfs.h index 1c2d6f0..520a33c 100644 --- a/src/fs/xfs.h +++ b/src/fs/xfs.h @@ -1,99 +1,99 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(XFS__H) #define XFS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** An XFS file system. @author Volker Lanz */ class LIBKPMCORE_EXPORT xfs : public FileSystem { public: xfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual qint64 readUsedCapacity(const QString& deviceNode) const; virtual bool check(Report& report, const QString& deviceNode) const; virtual bool create(Report& report, const QString& deviceNode) const; virtual bool copy(Report& report, const QString&, const QString&) const; virtual bool resize(Report& report, const QString& deviceNode, qint64 length) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual qint64 maxLabelLength() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; }; } #endif diff --git a/src/fs/zfs.cpp b/src/fs/zfs.cpp index 32d6093..fccf00a 100644 --- a/src/fs/zfs.cpp +++ b/src/fs/zfs.cpp @@ -1,103 +1,102 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "fs/zfs.h" #include "util/externalcommand.h" #include "util/capacity.h" #include "util/report.h" #include namespace FS { FileSystem::CommandSupportType zfs::m_GetUsed = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_GetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_Create = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_Grow = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_Shrink = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_Move = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_Check = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_Copy = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_Backup = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_SetLabel = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_UpdateUUID = FileSystem::cmdSupportNone; FileSystem::CommandSupportType zfs::m_GetUUID = FileSystem::cmdSupportNone; zfs::zfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) : FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Zfs) { } void zfs::init() { - m_SetLabel = findExternal(QStringLiteral("zpool"), QStringList(), 2) ? cmdSupportFileSystem : cmdSupportNone; + m_SetLabel = findExternal(QStringLiteral("zpool"), {}, 2) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_Backup = cmdSupportCore; m_GetUUID = cmdSupportCore; } bool zfs::supportToolFound() const { return // m_GetUsed != cmdSupportNone && m_GetLabel != cmdSupportNone && m_SetLabel != cmdSupportNone && // m_Create != cmdSupportNone && // m_Check != cmdSupportNone && // m_UpdateUUID != cmdSupportNone && // m_Grow != cmdSupportNone && // m_Shrink != cmdSupportNone && // m_Copy != cmdSupportNone && // m_Move != cmdSupportNone && m_Backup != cmdSupportNone && m_GetUUID != cmdSupportNone; } FileSystem::SupportTool zfs::supportToolName() const { return SupportTool(QStringLiteral("zfs"), QUrl(QStringLiteral("http://zfsonlinux.org/"))); } qint64 zfs::minCapacity() const { return 64 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB); } qint64 zfs::maxCapacity() const { return Capacity::unitFactor(Capacity::Byte, Capacity::EiB); } bool zfs::remove(Report& report, const QString& deviceNode) const { Q_UNUSED(deviceNode) -// TODO: check if -f option is needed - ExternalCommand cmd(report, QStringLiteral("zpool"), QStringList() << QStringLiteral("destroy") << QStringLiteral("-f") << this->label()); + ExternalCommand cmd(report, QStringLiteral("zpool"), { QStringLiteral("destroy"), QStringLiteral("-f"), label() }); return cmd.run(-1) && cmd.exitCode() == 0; } bool zfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) { Q_UNUSED(deviceNode) - ExternalCommand cmd1(report, QStringLiteral("zpool"), QStringList() << QStringLiteral("export") << this->label()); - ExternalCommand cmd2(report, QStringLiteral("zpool"), QStringList() << QStringLiteral("import") << this->label() << newLabel); + ExternalCommand cmd1(report, QStringLiteral("zpool"), { QStringLiteral("export"), label() }); + ExternalCommand cmd2(report, QStringLiteral("zpool"), { QStringLiteral("import"), label(), newLabel }); return cmd1.run(-1) && cmd1.exitCode() == 0 && cmd2.run(-1) && cmd2.exitCode() == 0; } } diff --git a/src/fs/zfs.h b/src/fs/zfs.h index 19fecad..b9d7845 100644 --- a/src/fs/zfs.h +++ b/src/fs/zfs.h @@ -1,107 +1,107 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(ZFS__H) #define ZFS__H #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" -#include +#include class Report; class QString; namespace FS { /** A zfs file system. @author Andrius Štikonas */ class LIBKPMCORE_EXPORT zfs : public FileSystem { public: zfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); public: static void init(); virtual bool remove(Report& report, const QString& deviceNode) const; virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel); virtual CommandSupportType supportGetUsed() const { return m_GetUsed; } virtual CommandSupportType supportGetLabel() const { return m_GetLabel; } virtual CommandSupportType supportCreate() const { return m_Create; } virtual CommandSupportType supportGrow() const { return m_Grow; } virtual CommandSupportType supportShrink() const { return m_Shrink; } virtual CommandSupportType supportMove() const { return m_Move; } virtual CommandSupportType supportCheck() const { return m_Check; } virtual CommandSupportType supportCopy() const { return m_Copy; } virtual CommandSupportType supportBackup() const { return m_Backup; } virtual CommandSupportType supportSetLabel() const { return m_SetLabel; } virtual CommandSupportType supportUpdateUUID() const { return m_UpdateUUID; } virtual CommandSupportType supportGetUUID() const { return m_GetUUID; } virtual qint64 minCapacity() const; virtual qint64 maxCapacity() const; virtual SupportTool supportToolName() const; virtual bool supportToolFound() const; public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; static CommandSupportType m_Create; static CommandSupportType m_Grow; static CommandSupportType m_Shrink; static CommandSupportType m_Move; static CommandSupportType m_Check; static CommandSupportType m_Copy; static CommandSupportType m_Backup; static CommandSupportType m_SetLabel; static CommandSupportType m_UpdateUUID; static CommandSupportType m_GetUUID; }; } #endif diff --git a/src/jobs/copyfilesystemjob.h b/src/jobs/copyfilesystemjob.h index 3d28a04..dd4b39f 100644 --- a/src/jobs/copyfilesystemjob.h +++ b/src/jobs/copyfilesystemjob.h @@ -1,84 +1,84 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(COPYFILESYSTEMJOB__H) #define COPYFILESYSTEMJOB__H #include "jobs/job.h" -#include +#include class Partition; class Device; class Report; class QString; /** Copy a FileSystem. Copy a FileSystem on a given Partition and Device to another Partition on a (possibly other) Device. @author Volker Lanz */ class CopyFileSystemJob : public Job { public: CopyFileSystemJob(Device& targetdevice, Partition& targetpartition, Device& sourcedevice, Partition& sourcepartition); public: virtual bool run(Report& parent); virtual qint32 numSteps() const; virtual QString description() const; protected: Partition& targetPartition() { return m_TargetPartition; } const Partition& targetPartition() const { return m_TargetPartition; } Device& targetDevice() { return m_TargetDevice; } const Device& targetDevice() const { return m_TargetDevice; } Partition& sourcePartition() { return m_SourcePartition; } const Partition& sourcePartition() const { return m_SourcePartition; } Device& sourceDevice() { return m_SourceDevice; } const Device& sourceDevice() const { return m_SourceDevice; } private: Device& m_TargetDevice; Partition& m_TargetPartition; Device& m_SourceDevice; Partition& m_SourcePartition; }; #endif diff --git a/src/jobs/job.h b/src/jobs/job.h index 30ccbe7..821e713 100644 --- a/src/jobs/job.h +++ b/src/jobs/job.h @@ -1,100 +1,100 @@ /************************************************************************* * Copyright (C) 2008, 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(JOB__H) #define JOB__H #include "../fs/filesystem.h" #include "../util/libpartitionmanagerexport.h" #include -#include +#include class QString; class QIcon; class CopySource; class CopyTarget; class Report; /** Base class for all Jobs. Each Operation is made up of one or more Jobs. Usually, an Operation will run each Job it is made up of and only complete successfully if each Job could be run without error. Jobs are all-or-nothing and try to be as atomic as possible: A Job is either successfully run or not, there is no case where a Job finishes with a warning. @author Volker Lanz */ class LIBKPMCORE_EXPORT Job : public QObject { Q_OBJECT Q_DISABLE_COPY(Job) public: /** Status of this Job */ enum JobStatus { Pending = 0, /**< Pending, not yet run */ Success, /**< Successfully run */ Error /**< Running generated an error */ }; protected: Job(); public: virtual ~Job() {} Q_SIGNALS: void started(); void progress(int); void finished(); public: virtual qint32 numSteps() const { return 1; /**< @return the number of steps the job takes to complete */ } virtual QString description() const = 0; /**< @return the Job's description */ virtual bool run(Report& parent) = 0; /**< @param parent parent Report to add new child to for this Job @return true if successfully run */ virtual QIcon statusIcon() const; virtual QString statusText() const; JobStatus status() const { return m_Status; /**< @return the Job's current status */ } void emitProgress(int i); protected: bool copyBlocks(Report& report, CopyTarget& target, CopySource& source); bool rollbackCopyBlocks(Report& report, CopyTarget& origTarget, CopySource& origSource); Report* jobStarted(Report& parent); void jobFinished(Report& report, bool b); void setStatus(JobStatus s) { m_Status = s; } private: JobStatus m_Status; }; #endif diff --git a/src/jobs/setpartgeometryjob.h b/src/jobs/setpartgeometryjob.h index 2dad7e9..08ec789 100644 --- a/src/jobs/setpartgeometryjob.h +++ b/src/jobs/setpartgeometryjob.h @@ -1,78 +1,78 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(SETPARTGEOMETRYJOB__H) #define SETPARTGEOMETRYJOB__H #include "jobs/job.h" -#include +#include class Partition; class Device; class Report; class QString; /** Set a Partition's geometry. Sets the geometry for a given Partition on a given Device to a new start sector and/or a new length. This does not move the FileSystem, it only updates the partition table entry for the Partition and is usually run together with MoveFileSystemJob or ResizeFileSystemJob for that reason. @author Volker Lanz */ class SetPartGeometryJob : public Job { public: SetPartGeometryJob(Device& d, Partition& p, qint64 newstart, qint64 newlength); public: virtual bool run(Report& parent); virtual QString description() const; protected: Partition& partition() { return m_Partition; } const Partition& partition() const { return m_Partition; } Device& device() { return m_Device; } const Device& device() const { return m_Device; } qint64 newStart() const { return m_NewStart; } qint64 newLength() const { return m_NewLength; } private: Device& m_Device; Partition& m_Partition; qint64 m_NewStart; qint64 m_NewLength; }; #endif diff --git a/src/ops/operation.h b/src/ops/operation.h index 847a3e6..d8d36c9 100644 --- a/src/ops/operation.h +++ b/src/ops/operation.h @@ -1,153 +1,153 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(OPERATION__H) #define OPERATION__H #include "../util/libpartitionmanagerexport.h" #include #include -#include +#include class Partition; class Device; class OperationStack; class Job; class OperationRunner; class Report; class QString; class QIcon; /** Base class of all Operations. An Operation serves two purposes: It is responsible for modifying the device preview to show the user a state as if the Operation had already been applied and it is made up of Jobs to actually perform what the Operation is supposed to do. Most Operations just run a list of Jobs and for that reason do not even overwrite Operation::execute(). The more complex Operations, however, need to perform some extra tasks in between running Jobs (most notably RestoreOperation and CopyOperation). These do overwrite Operation::execute(). Operations own the objects they deal with in most cases, usually Partitions. But as soon as an Operation has been successfully executed, it no longer owns anything, because the OperationStack then takes over ownership. Some rules for creating new operations that inherit the Operation class:
  1. Don't modify anything in the ctor. The ctor runs before merging operations. If you modify anything there, undo and merging will break. Just remember what you're supposed to do in the ctor and perform modifications in preview().
  2. Do not access the preview partitions and devices in description(). If you do, the operation descriptions will be wrong.
  3. Don't create or delete objects in preview() or undo() since these will be called more than once. Create and delete objects in the ctor and dtor.
@author Volker Lanz */ class LIBKPMCORE_EXPORT Operation : public QObject { Q_OBJECT Q_DISABLE_COPY(Operation) friend class OperationStack; friend class OperationRunner; public: /** Status of this Operation */ enum OperationStatus { StatusNone = 0, /**< None yet, can be merged */ StatusPending, /**< Pending, can be undone */ StatusRunning, /**< Currently running */ StatusFinishedSuccess, /**< Successfully finished */ StatusFinishedWarning, /**< Finished with warnings */ StatusError /**< Finished with errors */ }; protected: Operation(); virtual ~Operation(); Q_SIGNALS: int progress(int); void jobStarted(Job*, Operation*); void jobFinished(Job*, Operation*); public: virtual QString iconName() const = 0; /**< @return name of the icon for the Operation */ virtual QString description() const = 0; /**< @return the Operation's description */ virtual void preview() = 0; /**< Apply the Operation to the current preview */ virtual void undo() = 0; /**< Undo applying the Operation to the current preview */ virtual bool execute(Report& parent); virtual bool targets(const Device&) const = 0; virtual bool targets(const Partition&) const = 0; virtual OperationStatus status() const { return m_Status; /**< @return the current status */ } virtual QString statusText() const; virtual QIcon statusIcon() const; virtual void setStatus(OperationStatus s) { m_Status = s; /**< @param s the new status */ } LIBKPMCORE_EXPORT qint32 totalProgress() const; protected Q_SLOTS: void onJobStarted(); void onJobFinished(); protected: void insertPreviewPartition(Device& targetDevice, Partition& newPartition); void removePreviewPartition(Device& device, Partition& p); void addJob(Job* job); QList& jobs() { return m_Jobs; } const QList& jobs() const { return m_Jobs; } void setProgressBase(qint32 i) { m_ProgressBase = i; } qint32 progressBase() const { return m_ProgressBase; } private: OperationStatus m_Status; QList m_Jobs; qint32 m_ProgressBase; }; #endif diff --git a/src/plugins/dummy/dummydevice.h b/src/plugins/dummy/dummydevice.h index 9ec5026..f374a07 100644 --- a/src/plugins/dummy/dummydevice.h +++ b/src/plugins/dummy/dummydevice.h @@ -1,52 +1,52 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(DUMMYDEVICE__H) #define DUMMYDEVICE__H #include "backend/corebackenddevice.h" -#include +#include class Partition; class PartitionTable; class Report; class CoreBackendPartitionTable; class DummyDevice : public CoreBackendDevice { Q_DISABLE_COPY(DummyDevice); public: DummyDevice(const QString& device_node); ~DummyDevice(); public: virtual bool open(); virtual bool openExclusive(); virtual bool close(); virtual CoreBackendPartitionTable* openPartitionTable(); virtual bool createPartitionTable(Report& report, const PartitionTable& ptable); virtual bool readSectors(void* buffer, qint64 offset, qint64 numSectors); virtual bool writeSectors(void* buffer, qint64 offset, qint64 numSectors); }; #endif diff --git a/src/plugins/dummy/dummypartitiontable.h b/src/plugins/dummy/dummypartitiontable.h index addc580..90a1179 100644 --- a/src/plugins/dummy/dummypartitiontable.h +++ b/src/plugins/dummy/dummypartitiontable.h @@ -1,55 +1,55 @@ /************************************************************************* * Copyright (C) 2010, 2012 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(DUMMYPARTITIONTABLE__H) #define DUMMYPARTITIONTABLE__H #include "backend/corebackendpartitiontable.h" #include "fs/filesystem.h" -#include +#include class CoreBackendPartition; class Report; class Partition; class DummyPartitionTable : public CoreBackendPartitionTable { public: DummyPartitionTable(); ~DummyPartitionTable(); public: virtual bool open(); virtual bool commit(quint32 timeout = 10); virtual CoreBackendPartition* getExtendedPartition(); virtual CoreBackendPartition* getPartitionBySector(qint64 sector); virtual QString createPartition(Report& report, const Partition& partition); virtual bool deletePartition(Report& report, const Partition& partition); virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end); virtual bool clobberFileSystem(Report& report, const Partition& partition); virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength); virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector); virtual bool setPartitionSystemType(Report& report, const Partition& partition); }; #endif diff --git a/src/plugins/libparted/libpartedbackend.h b/src/plugins/libparted/libpartedbackend.h index f4853af..2131e5c 100644 --- a/src/plugins/libparted/libpartedbackend.h +++ b/src/plugins/libparted/libpartedbackend.h @@ -1,78 +1,78 @@ /************************************************************************* * Copyright (C) 2008, 2010 by Volker Lanz * * Copyright (C) 2015 by Teo Mrnjavac * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(LIBPARTED__H) #define LIBPARTED__H #include "backend/corebackend.h" #include "core/partitiontable.h" #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" #include #include #include -#include +#include class LibPartedDevice; class LibPartedPartitionTable; class LibPartedPartition; class OperationStack; class Device; class KPluginFactory; class QString; /** Backend plugin for libparted. @author Volker Lanz */ class LibPartedBackend : public CoreBackend { friend class KPluginFactory; friend class LibPartedPartition; friend class LibPartedDevice; friend class LibPartedPartitionTable; Q_DISABLE_COPY(LibPartedBackend) private: LibPartedBackend(QObject* parent, const QList& args); public: virtual void initFSSupport(); virtual CoreBackendDevice* openDevice(const QString& device_node) override; virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node) override; virtual bool closeDevice(CoreBackendDevice* core_device) override; virtual Device* scanDevice(const QString& device_node) override; virtual QList scanDevices(bool excludeReadOnly = false) override; static QString lastPartedExceptionMessage(); private: static FileSystem::Type detectFileSystem(PedPartition* pedPartition); static PedPartitionFlag getPedFlag(PartitionTable::Flag flag); static void scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDisk); }; #endif diff --git a/src/plugins/libparted/libparteddevice.h b/src/plugins/libparted/libparteddevice.h index 4b14c17..2a5a10d 100644 --- a/src/plugins/libparted/libparteddevice.h +++ b/src/plugins/libparted/libparteddevice.h @@ -1,62 +1,62 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(LIBPARTEDDEVICE__H) #define LIBPARTEDDEVICE__H #include "backend/corebackenddevice.h" -#include +#include #include class Partition; class PartitionTable; class Report; class CoreBackendPartitionTable; class LibPartedDevice : public CoreBackendDevice { Q_DISABLE_COPY(LibPartedDevice); public: LibPartedDevice(const QString& device_node); ~LibPartedDevice(); public: virtual bool open(); virtual bool openExclusive(); virtual bool close(); virtual CoreBackendPartitionTable* openPartitionTable(); virtual bool createPartitionTable(Report& report, const PartitionTable& ptable); virtual bool readSectors(void* buffer, qint64 offset, qint64 numSectors); virtual bool writeSectors(void* buffer, qint64 offset, qint64 numSectors); protected: PedDevice* pedDevice() { return m_PedDevice; } private: PedDevice* m_PedDevice; }; #endif diff --git a/src/plugins/libparted/libpartedpartitiontable.cpp b/src/plugins/libparted/libpartedpartitiontable.cpp index 5b56a51..6cc2421 100644 --- a/src/plugins/libparted/libpartedpartitiontable.cpp +++ b/src/plugins/libparted/libpartedpartitiontable.cpp @@ -1,340 +1,341 @@ /************************************************************************* * Copyright (C) 2010, 2011, 2012 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "plugins/libparted/libpartedpartitiontable.h" #include "plugins/libparted/libpartedpartition.h" #include "plugins/libparted/libpartedbackend.h" #include "backend/corebackend.h" #include "backend/corebackendmanager.h" #include "core/partition.h" #include "core/device.h" #include "fs/filesystem.h" #include "util/report.h" #include "util/externalcommand.h" #include #include LibPartedPartitionTable::LibPartedPartitionTable(PedDevice* device) : CoreBackendPartitionTable(), m_PedDevice(device), m_PedDisk(nullptr) { } LibPartedPartitionTable::~LibPartedPartitionTable() { if (m_PedDisk != nullptr) ped_disk_destroy(m_PedDisk); } bool LibPartedPartitionTable::open() { m_PedDisk = ped_disk_new(pedDevice()); return m_PedDisk != nullptr; } bool LibPartedPartitionTable::commit(quint32 timeout) { return commit(pedDisk(), timeout); } bool LibPartedPartitionTable::commit(PedDisk* pd, quint32 timeout) { if (pd == nullptr) return false; bool rval = ped_disk_commit_to_dev(pd); // The GParted authors have found a bug in libparted that causes it to intermittently // not commit changes to the Linux kernel, probably a race. Until this is fixed in // libparted, the following patch should help alleviate the consequences by just re-trying // committing to the OS if it fails the first time after a short pause. // See: http://git.gnome.org/browse/gparted/commit/?id=bf86fd3f9ceb0096dfe87a8c9a38403c13b13f00 if (rval) { rval = ped_disk_commit_to_os(pd); if (!rval) { sleep(1); rval = ped_disk_commit_to_os(pd); } } if (!ExternalCommand(QStringLiteral("udevadm"), QStringList() << QStringLiteral("settle") << QStringLiteral("--timeout=") + QString::number(timeout)).run() && !ExternalCommand(QStringLiteral("udevsettle"), QStringList() << QStringLiteral("--timeout=") + QString::number(timeout)).run()) sleep(timeout); return rval; } CoreBackendPartition* LibPartedPartitionTable::getExtendedPartition() { PedPartition* pedPartition = ped_disk_extended_partition(pedDisk()); if (pedPartition == nullptr) return nullptr; return new LibPartedPartition(pedPartition); } CoreBackendPartition* LibPartedPartitionTable::getPartitionBySector(qint64 sector) { PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk(), sector); if (pedPartition == nullptr) return nullptr; return new LibPartedPartition(pedPartition); } static const struct { FileSystem::Type type; QString name; } mapFileSystemTypeToLibPartedName[] = { { FileSystem::Btrfs, QStringLiteral("btrfs") }, { FileSystem::Ext2, QStringLiteral("ext2") }, { FileSystem::Ext3, QStringLiteral("ext3") }, { FileSystem::Ext4, QStringLiteral("ext4") }, { FileSystem::LinuxSwap, QStringLiteral("linux-swap") }, { FileSystem::Fat16, QStringLiteral("fat16") }, { FileSystem::Fat32, QStringLiteral("fat32") }, { FileSystem::Nilfs2, QStringLiteral("nilfs2") }, { FileSystem::Ntfs, QStringLiteral("ntfs") }, { FileSystem::Exfat, QStringLiteral("ntfs") }, { FileSystem::ReiserFS, QStringLiteral("reiserfs") }, - { FileSystem::Reiser4, QStringLiteral("reiser4") }, + { FileSystem::Reiser4, QStringLiteral("reiserfs") }, { FileSystem::Xfs, QStringLiteral("xfs") }, { FileSystem::Jfs, QStringLiteral("jfs") }, { FileSystem::Hfs, QStringLiteral("hfs") }, { FileSystem::HfsPlus, QStringLiteral("hfs+") }, { FileSystem::Ufs, QStringLiteral("ufs") } }; static PedFileSystemType* getPedFileSystemType(FileSystem::Type t) { for (quint32 i = 0; i < sizeof(mapFileSystemTypeToLibPartedName) / sizeof(mapFileSystemTypeToLibPartedName[0]); i++) if (mapFileSystemTypeToLibPartedName[i].type == t) return ped_file_system_type_get(mapFileSystemTypeToLibPartedName[i].name.toLatin1().constData()); // if we didn't find anything, go with ext2 as a safe fallback return ped_file_system_type_get("ext2"); } QString LibPartedPartitionTable::createPartition(Report& report, const Partition& partition) { Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path)); QString rval = QString(); // According to libParted docs, PedPartitionType can be "nullptr if unknown". That's obviously wrong, // it's a typedef for an enum. So let's use something the libparted devs will hopefully never // use... PedPartitionType pedType = static_cast(0xffffffff); if (partition.roles().has(PartitionRole::Extended)) pedType = PED_PARTITION_EXTENDED; else if (partition.roles().has(PartitionRole::Logical)) pedType = PED_PARTITION_LOGICAL; else if (partition.roles().has(PartitionRole::Primary)) pedType = PED_PARTITION_NORMAL; if (pedType == static_cast(0xffffffff)) { report.line() << xi18nc("@info/plain", "Unknown partition role for new partition %1 (roles: %2)", partition.deviceNode(), partition.roles().toString()); return QString(); } PedFileSystemType* pedFsType = (partition.roles().has(PartitionRole::Extended) || partition.fileSystem().type() == FileSystem::Unformatted) ? nullptr : getPedFileSystemType(partition.fileSystem().type()); PedPartition* pedPartition = ped_partition_new(pedDisk(), pedType, pedFsType, partition.firstSector(), partition.lastSector()); if (pedPartition == nullptr) { report.line() << xi18nc("@info/plain", "Failed to create new partition %1.", partition.deviceNode()); return QString(); } PedConstraint* pedConstraint = nullptr; PedGeometry* pedGeometry = ped_geometry_new(pedDevice(), partition.firstSector(), partition.length()); if (pedGeometry) pedConstraint = ped_constraint_exact(pedGeometry); if (pedConstraint == nullptr) { report.line() << i18nc("@info/plain", "Failed to create a new partition: could not get geometry for constraint."); return QString(); } if (ped_disk_add_partition(pedDisk(), pedPartition, pedConstraint)) rval = QString::fromUtf8(ped_partition_get_path(pedPartition)); else { report.line() << xi18nc("@info/plain", "Failed to add partition %1 to device %2.", partition.deviceNode(), QString::fromUtf8(pedDisk()->dev->path)); report.line() << LibPartedBackend::lastPartedExceptionMessage(); } ped_constraint_destroy(pedConstraint); return rval; } bool LibPartedPartitionTable::deletePartition(Report& report, const Partition& partition) { Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path)); bool rval = false; PedPartition* pedPartition = partition.roles().has(PartitionRole::Extended) ? ped_disk_extended_partition(pedDisk()) : ped_disk_get_partition_by_sector(pedDisk(), partition.firstSector()); if (pedPartition) { rval = ped_disk_delete_partition(pedDisk(), pedPartition); if (!rval) report.line() << xi18nc("@info/plain", "Could not delete partition %1.", partition.deviceNode()); } else report.line() << xi18nc("@info/plain", "Deleting partition failed: Partition to delete (%1) not found on disk.", partition.deviceNode()); return rval; } bool LibPartedPartitionTable::updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) { Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path)); bool rval = false; PedPartition* pedPartition = (partition.roles().has(PartitionRole::Extended)) ? ped_disk_extended_partition(pedDisk()) : ped_disk_get_partition_by_sector(pedDisk(), partition.firstSector()); if (pedPartition) { if (PedGeometry* pedGeometry = ped_geometry_new(pedDevice(), sector_start, sector_end - sector_start + 1)) { if (PedConstraint* pedConstraint = ped_constraint_exact(pedGeometry)) { if (ped_disk_set_partition_geom(pedDisk(), pedPartition, pedConstraint, sector_start, sector_end)) rval = true; else report.line() << xi18nc("@info/plain", "Could not set geometry for partition %1 while trying to resize/move it.", partition.deviceNode()); } else report.line() << xi18nc("@info/plain", "Could not get constraint for partition %1 while trying to resize/move it.", partition.deviceNode()); } else report.line() << xi18nc("@info/plain", "Could not get geometry for partition %1 while trying to resize/move it.", partition.deviceNode()); } else report.line() << xi18nc("@info/plain", "Could not open partition %1 while trying to resize/move it.", partition.deviceNode()); return rval; } bool LibPartedPartitionTable::clobberFileSystem(Report& report, const Partition& partition) { bool rval = false; if (PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk(), partition.firstSector())) { if (pedPartition->type == PED_PARTITION_NORMAL || pedPartition->type == PED_PARTITION_LOGICAL) { if (ped_device_open(pedDevice())) { //reiser4 stores "ReIsEr4" at sector 128 with a sector size of 512 bytes - rval = ped_geometry_write(&pedPartition->geom, "0000000", 65536 / pedDevice()->sector_size, 1); + char zeroes[pedDevice()->sector_size*129] = {0}; + rval = ped_geometry_write(&pedPartition->geom, zeroes, 0, 129); if (!rval) report.line() << xi18nc("@info/plain", "Failed to erase filesystem signature on partition %1.", partition.deviceNode()); ped_device_close(pedDevice()); } } else rval = true; } else report.line() << xi18nc("@info/plain", "Could not delete file system on partition %1: Failed to get partition.", partition.deviceNode()); return rval; } #if defined LIBPARTED_FS_RESIZE_LIBRARY_SUPPORT static void pedTimerHandler(PedTimer* pedTimer, void*) { CoreBackendManager::self()->backend()->emitProgress(pedTimer->frac * 100); } #endif bool LibPartedPartitionTable::resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) { bool rval = false; #if defined LIBPARTED_FS_RESIZE_LIBRARY_SUPPORT if (PedGeometry* originalGeometry = ped_geometry_new(pedDevice(), partition.fileSystem().firstSector(), partition.fileSystem().length())) { if (PedFileSystem* pedFileSystem = ped_file_system_open(originalGeometry)) { if (PedGeometry* resizedGeometry = ped_geometry_new(pedDevice(), partition.fileSystem().firstSector(), newLength)) { PedTimer* pedTimer = ped_timer_new(pedTimerHandler, nullptr); rval = ped_file_system_resize(pedFileSystem, resizedGeometry, pedTimer); ped_timer_destroy(pedTimer); if (!rval) report.line() << xi18nc("@info/plain", "Could not resize file system on partition %1.", partition.deviceNode()); } else report.line() << xi18nc("@info/plain", "Could not get geometry for resized partition %1 while trying to resize the file system.", partition.deviceNode()); ped_file_system_close(pedFileSystem); } else report.line() << xi18nc("@info/plain", "Could not open partition %1 while trying to resize the file system.", partition.deviceNode()); } else report.line() << xi18nc("@info/plain", "Could not read geometry for partition %1 while trying to resize the file system.", partition.deviceNode()); #else Q_UNUSED(report); Q_UNUSED(partition); Q_UNUSED(newLength); #endif return rval; } FileSystem::Type LibPartedPartitionTable::detectFileSystemBySector(Report& report, const Device& device, qint64 sector) { PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk(), sector); FileSystem::Type rval = FileSystem::Unknown; if (pedPartition) rval = LibPartedBackend::detectFileSystem(pedPartition); else report.line() << xi18nc("@info/plain", "Could not determine file system of partition at sector %1 on device %2.", sector, device.deviceNode()); return rval; } bool LibPartedPartitionTable::setPartitionSystemType(Report& report, const Partition& partition) { PedFileSystemType* pedFsType = (partition.roles().has(PartitionRole::Extended) || partition.fileSystem().type() == FileSystem::Unformatted) ? nullptr : getPedFileSystemType(partition.fileSystem().type()); if (pedFsType == nullptr) { report.line() << xi18nc("@info/plain", "Could not update the system type for partition %1.", partition.deviceNode()); report.line() << xi18nc("@info/plain", "No file system defined."); return false; } PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk(), partition.firstSector()); if (pedPartition == nullptr) { report.line() << xi18nc("@info/plain", "Could not update the system type for partition %1.", partition.deviceNode()); report.line() << xi18nc("@info/plain", "No partition found at sector %1.", partition.firstSector()); return false; } return ped_partition_set_system(pedPartition, pedFsType) != 0; } diff --git a/src/plugins/libparted/libpartedpartitiontable.h b/src/plugins/libparted/libpartedpartitiontable.h index bc1a619..c41e45e 100644 --- a/src/plugins/libparted/libpartedpartitiontable.h +++ b/src/plugins/libparted/libpartedpartitiontable.h @@ -1,70 +1,70 @@ /************************************************************************* * Copyright (C) 2010, 2011 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(LIBPARTEDPARTITIONTABLE__H) #define LIBPARTEDPARTITIONTABLE__H #include "backend/corebackendpartitiontable.h" #include "fs/filesystem.h" -#include +#include #include class CoreBackendPartition; class Report; class Partition; class LibPartedPartitionTable : public CoreBackendPartitionTable { public: LibPartedPartitionTable(PedDevice* device); ~LibPartedPartitionTable(); public: virtual bool open(); virtual bool commit(quint32 timeout = 10); static bool commit(PedDisk* pd, quint32 timeout = 10); virtual CoreBackendPartition* getExtendedPartition(); virtual CoreBackendPartition* getPartitionBySector(qint64 sector); virtual QString createPartition(Report& report, const Partition& partition); virtual bool deletePartition(Report& report, const Partition& partition); virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end); virtual bool clobberFileSystem(Report& report, const Partition& partition); virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength); virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector); virtual bool setPartitionSystemType(Report& report, const Partition& partition); private: PedDevice* pedDevice() { return m_PedDevice; } PedDisk* pedDisk() { return m_PedDisk; } private: PedDevice* m_PedDevice; PedDisk* m_PedDisk; }; #endif diff --git a/src/util/capacity.h b/src/util/capacity.h index 97c1c84..f35d59a 100644 --- a/src/util/capacity.h +++ b/src/util/capacity.h @@ -1,90 +1,90 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(CAPACITY__H) #define CAPACITY__H #include "../util/libpartitionmanagerexport.h" class Partition; class Device; -#include +#include /** Represent any kind of capacity. Any kind of capacity that can be expressed in units of Byte, KiB, MiB and so on. Also prints capacities in nicely formatted ways. @author Volker Lanz */ class LIBKPMCORE_EXPORT Capacity { public: /** Units we can deal with */ enum Unit { Byte, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB }; /** Type of capacity to print */ enum Type { Used, Available, Total }; /** Flags for printing */ enum Flag { NoFlags = 0, AppendUnit = 1, AppendBytes = 2 }; Q_DECLARE_FLAGS(Flags, Flag) public: explicit Capacity(qint64 size); explicit Capacity(const Partition& p, Type t = Total); Capacity(const Device& d); public: bool operator==(const Capacity& other) const { return other.m_Size == m_Size; } bool operator!=(const Capacity& other) const { return other.m_Size != m_Size; } bool operator>(const Capacity& other) const { return other.m_Size > m_Size; } bool operator<(const Capacity& other) const { return other.m_Size < m_Size; } bool operator>=(const Capacity& other) const { return other.m_Size >= m_Size; } bool operator<=(const Capacity& other) const { return other.m_Size <= m_Size; } qint64 toInt(Unit u) const; double toDouble(Unit u) const; bool isValid() const; static QString formatByteSize(double size, int precision = 2); static const QString& invalidString() { return m_InvalidString; /**< @return string representing an invalid capacity */ } static QString unitName(Unit u, qint64 val = 1); static qint64 unitFactor(Unit from, Unit to); private: qint64 m_Size; static const QString m_InvalidString; }; Q_DECLARE_OPERATORS_FOR_FLAGS(Capacity::Flags) #endif diff --git a/src/util/externalcommand.h b/src/util/externalcommand.h index 758c8c8..8522e1c 100644 --- a/src/util/externalcommand.h +++ b/src/util/externalcommand.h @@ -1,108 +1,108 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(EXTERNALCOMMAND__H) #define EXTERNALCOMMAND__H #include "../util/libpartitionmanagerexport.h" #include #include #include #include -#include +#include class Report; /** An external command. Runs an external command as a child process. @author Volker Lanz @author Andrius Štikonas */ class LIBKPMCORE_EXPORT ExternalCommand : public QProcess { Q_OBJECT Q_DISABLE_COPY(ExternalCommand) public: explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList()); explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList()); explicit ExternalCommand(const std::vector cmd, const std::vector args); explicit ExternalCommand(Report& report, const std::vector cmd, const std::vector args); ~ExternalCommand(); public: void setCommand(const std::vector cmd) { m_Command = cmd; /**< @param cmd the command to run */ } const std::vector command() const { return m_Command; /**< @return the command to run */ } /** @param s the argument to add @param i the command to which the argument is added */ void addArg(const QString& s, const int i = 0) { m_Args[i] << s; } const std::vector args() const { return m_Args; /**< @return the arguments */ } void setArgs(const std::vector args) { m_Args = args; /**< @param args the new arguments */ } bool start(int timeout = 30000); bool waitFor(int timeout = 30000); bool run(int timeout = 30000); int exitCode() const { return m_ExitCode; /**< @return the exit code */ } const QString& output() const { return m_Output; /**< @return the command output */ } Report* report() { return m_Report; /**< @return pointer to the Report or nullptr */ } protected: void setExitCode(int i) { m_ExitCode = i; } void setup(); protected Q_SLOTS: void onFinished(int exitCode); void onReadOutput(); private: QProcess *processes; Report *m_Report; std::vector m_Command; std::vector m_Args; int m_ExitCode; QString m_Output; }; #endif diff --git a/src/util/globallog.h b/src/util/globallog.h index 1b6594c..99eae5c 100644 --- a/src/util/globallog.h +++ b/src/util/globallog.h @@ -1,91 +1,91 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(GLOBALLOG__H) #define GLOBALLOG__H #include "../util/libpartitionmanagerexport.h" #include #include -#include +#include class LIBKPMCORE_EXPORT Log { public: enum Level { debug = 0, information = 1, warning = 2, error = 3 }; public: Log(Level lev = information) : ref(1), level(lev) {} ~Log(); Log(const Log& other) : ref(other.ref + 1), level(other.level) {} private: quint32 ref; Level level; }; /** Global logging. @author Volker Lanz */ class LIBKPMCORE_EXPORT GlobalLog : public QObject { Q_OBJECT Q_DISABLE_COPY(GlobalLog) friend class Log; friend Log operator<<(Log l, const QString& s); friend Log operator<<(Log l, qint64 i); private: GlobalLog() : msg() {} Q_SIGNALS: void newMessage(Log::Level, const QString&); public: static GlobalLog* instance(); private: void append(const QString& s) { msg += s; } void flush(Log::Level level); private: QString msg; }; inline Log operator<<(Log l, const QString& s) { GlobalLog::instance()->append(s); return l; } inline Log operator<<(Log l, qint64 i) { GlobalLog::instance()->append(QString::number(i)); return l; } #endif diff --git a/src/util/htmlreport.cpp b/src/util/htmlreport.cpp index 877a05f..a95fff8 100644 --- a/src/util/htmlreport.cpp +++ b/src/util/htmlreport.cpp @@ -1,95 +1,95 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "util/htmlreport.h" #include "../backend/corebackend.h" #include "../backend/corebackendmanager.h" #include #include #include #include #include #include #include -#include +#include #include #include QString HtmlReport::tableLine(const QString& label, const QString contents) { QString rval; QTextStream s(&rval); s << "\n" << QStringLiteral("%1\n").arg(QString(label).toHtmlEscaped()) << QStringLiteral("%1\n").arg(QString(contents).toHtmlEscaped()) << "\n"; s.flush(); return rval; } QString HtmlReport::header() { QString rval; QTextStream s(&rval); s << "\n" "\n" "\n" " " << i18n("%1: SMART Status Report", QGuiApplication::applicationDisplayName().toHtmlEscaped()) << "\n" " \n" "\n\n" "\n"; s << "

" << i18n("%1: SMART Status Report", QGuiApplication::applicationDisplayName().toHtmlEscaped()) << "

\n\n"; struct utsname info; uname(&info); const QString unameString = QString::fromUtf8(info.sysname) + QStringLiteral(" ") + QString::fromUtf8(info.nodename) + QStringLiteral(" ") + QString::fromUtf8(info.release) + QStringLiteral(" ") + QString::fromUtf8(info.version) + QStringLiteral(" ") + QString::fromUtf8(info.machine); s << "\n" << tableLine(i18n("Date:"), QLocale().toString(QDateTime::currentDateTime(), QLocale::ShortFormat)) << tableLine(i18n("Program version:"), QCoreApplication::applicationVersion()) << tableLine(i18n("Backend:"), QStringLiteral("%1 (%2)").arg(CoreBackendManager::self()->backend()->id()).arg(CoreBackendManager::self()->backend()->version())) - << tableLine(i18n("KDE Frameworks version:"), QStringLiteral(KXMLGUI_VERSION_STRING)) + << tableLine(i18n("KDE Frameworks version:"), QStringLiteral(KIO_VERSION_STRING)) << tableLine(i18n("Machine:"), unameString) << "
\n
\n"; s << "\n"; s.flush(); return rval; } QString HtmlReport::footer() { return QStringLiteral("\n\n\n\n"); } diff --git a/src/util/report.h b/src/util/report.h index cd29abe..507b490 100644 --- a/src/util/report.h +++ b/src/util/report.h @@ -1,154 +1,154 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(REPORT__H) #define REPORT__H #include "../util/libpartitionmanagerexport.h" #include #include #include -#include +#include class ReportLine; /** Report details about running Operations and Jobs. Gather information for the report shown in the ProgressDialog's detail view. @author Volker Lanz */ class LIBKPMCORE_EXPORT Report : public QObject { Q_OBJECT Q_DISABLE_COPY(Report) friend Report& operator<<(Report& report, const QString& s); friend Report& operator<<(Report& report, qint64 i); public: explicit Report(Report* p, const QString& cmd = QString()); ~Report(); Q_SIGNALS: void outputChanged(); public: Report* newChild(const QString& cmd = QString()); const QList& children() const { return m_Children; /**< @return the list of this Report's children */ } Report* parent() { return m_Parent; /**< @return pointer to this Reports parent. May be nullptr if this is the root Report */ } const Report* parent() const { return m_Parent; /**< @return pointer to this Reports parent. May be nullptr if this is the root Report */ } Report* root(); const Report* root() const; const QString& command() const { return m_Command; /**< @return the command */ } const QString& output() const { return m_Output; /**< @return the output */ } const QString& status() const { return m_Status; /**< @return the status line */ } void setCommand(const QString& s) { m_Command = s; /**< @param s the new command */ } void setStatus(const QString& s) { m_Status = s; /**< @param s the new status */ } void addOutput(const QString& s); QString toHtml() const; QString toText() const; ReportLine line(); static QString htmlHeader(); static QString htmlFooter(); protected: void emitOutputChanged(); private: Report* m_Parent; QList m_Children; QString m_Command; QString m_Output; QString m_Status; }; inline Report& operator<<(Report& report, const QString& s) { report.addOutput(s); return report; } inline Report& operator<<(Report& report, qint64 i) { report.addOutput(QString::number(i)); return report; } class ReportLine { friend ReportLine operator<<(ReportLine reportLine, const QString& s); friend ReportLine operator<<(ReportLine reportLine, qint64 i); friend class Report; protected: ReportLine(Report& r) : ref(1), report(r.newChild()) {} public: ~ReportLine() { if (--ref == 0) *report << QStringLiteral("\n"); } ReportLine(const ReportLine& other) : ref(other.ref + 1), report(other.report) {} private: ReportLine& operator=(const ReportLine&); private: qint32 ref; Report* report; }; inline ReportLine operator<<(ReportLine reportLine, const QString& s) { *reportLine.report << s; return reportLine; } inline ReportLine operator<<(ReportLine reportLine, qint64 i) { *reportLine.report << i; return reportLine; } #endif