2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2012 by Volker Lanz <vl@fidra.de> *
|
2016-03-31 17:43:38 +01:00
|
|
|
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
|
2018-04-07 19:54:30 +01:00
|
|
|
* Copyright (C) 2016-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
2015-06-04 01:29:22 +01:00
|
|
|
* *
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
2018-04-07 19:54:30 +01:00
|
|
|
#ifndef KPMCORE_FILESYSTEM_H
|
2017-09-10 20:12:52 +01:00
|
|
|
#define KPMCORE_FILESYSTEM_H
|
2018-01-31 15:04:55 +00:00
|
|
|
|
2016-05-06 22:36:24 +01:00
|
|
|
#include "util/libpartitionmanagerexport.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-08-08 02:01:35 +01:00
|
|
|
#include <QList>
|
2015-06-04 01:29:22 +01:00
|
|
|
#include <QStringList>
|
|
|
|
#include <QString>
|
2016-08-08 02:01:35 +01:00
|
|
|
#include <QtGlobal>
|
2015-06-04 01:29:22 +01:00
|
|
|
#include <QUrl>
|
|
|
|
|
2018-04-08 01:46:08 +01:00
|
|
|
#include <memory>
|
2018-04-05 21:52:17 +01:00
|
|
|
#include <vector>
|
2015-07-17 12:36:23 +01:00
|
|
|
|
2018-03-31 16:30:53 +01:00
|
|
|
class QColor;
|
2017-09-05 12:52:34 +01:00
|
|
|
class QValidator;
|
2015-06-04 01:29:22 +01:00
|
|
|
class Device;
|
|
|
|
class Report;
|
2018-04-08 01:46:08 +01:00
|
|
|
struct FileSystemPrivate;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
/** Base class for all FileSystems.
|
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
Represents a file system and handles support for various types of operations that can
|
|
|
|
be performed on those.
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
@author Volker Lanz <vl@fidra.de>
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
class LIBKPMCORE_EXPORT FileSystem
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
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 */
|
2018-04-05 21:52:17 +01:00
|
|
|
enum Type : int {
|
2018-04-07 19:54:30 +01:00
|
|
|
Unknown,
|
|
|
|
Extended,
|
|
|
|
|
|
|
|
Ext2,
|
|
|
|
Ext3,
|
|
|
|
Ext4,
|
|
|
|
LinuxSwap,
|
|
|
|
Fat16,
|
|
|
|
Fat32,
|
|
|
|
Ntfs,
|
|
|
|
ReiserFS,
|
|
|
|
Reiser4,
|
|
|
|
Xfs,
|
|
|
|
Jfs,
|
|
|
|
Hfs,
|
|
|
|
HfsPlus,
|
|
|
|
Ufs,
|
|
|
|
Unformatted,
|
|
|
|
Btrfs,
|
|
|
|
Hpfs,
|
|
|
|
Luks,
|
|
|
|
Ocfs2,
|
|
|
|
Zfs,
|
|
|
|
Exfat,
|
|
|
|
Nilfs2,
|
|
|
|
Lvm2_PV,
|
|
|
|
F2fs,
|
|
|
|
Udf,
|
|
|
|
Iso9660,
|
|
|
|
Luks2,
|
|
|
|
Fat12,
|
2018-07-15 21:38:43 +01:00
|
|
|
LinuxRaidMember,
|
2019-01-13 02:24:06 +00:00
|
|
|
BitLocker,
|
2019-01-13 17:33:52 +00:00
|
|
|
Apfs,
|
2018-04-07 19:54:30 +01:00
|
|
|
|
|
|
|
__lastType
|
2015-07-13 15:16:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** 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 */
|
|
|
|
};
|
|
|
|
|
2018-04-05 21:52:17 +01:00
|
|
|
static const std::vector<QColor> defaultColorCode;
|
2015-07-17 12:36:23 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_DECLARE_FLAGS(CommandSupportTypes, CommandSupportType)
|
|
|
|
|
|
|
|
protected:
|
2018-04-08 01:46:08 +01:00
|
|
|
FileSystem(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, FileSystem::Type type);
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
public:
|
2018-04-08 01:46:08 +01:00
|
|
|
virtual ~FileSystem();
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
public:
|
2017-09-10 17:26:12 +01:00
|
|
|
virtual void init() {}
|
2016-09-04 23:32:00 +01:00
|
|
|
virtual void scan(const QString& deviceNode);
|
2015-07-13 15:16:36 +01:00
|
|
|
virtual qint64 readUsedCapacity(const QString& deviceNode) const;
|
|
|
|
virtual QString readLabel(const QString& deviceNode) const;
|
2016-09-05 12:10:56 +01:00
|
|
|
virtual bool create(Report& report, const QString& deviceNode);
|
2017-08-18 12:45:15 +01:00
|
|
|
virtual bool createWithLabel(Report& report, const QString& deviceNode, const QString& label);
|
2015-07-13 15:16:36 +01:00
|
|
|
virtual bool resize(Report& report, const QString& deviceNode, qint64 newLength) const;
|
2016-08-08 02:01:35 +01:00
|
|
|
virtual bool resizeOnline(Report& report, const QString& deviceNode, const QString& mountPoint, qint64 newLength) const;
|
2015-07-13 15:16:36 +01:00
|
|
|
virtual bool move(Report& report, const QString& deviceNode, qint64 newStartSector) const;
|
|
|
|
virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel);
|
2017-04-09 17:49:55 +01:00
|
|
|
virtual bool writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel);
|
2015-07-13 15:16:36 +01:00
|
|
|
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 */
|
|
|
|
}
|
2017-08-18 12:45:15 +01:00
|
|
|
virtual CommandSupportType supportCreateWithLabel() const {
|
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for creating */
|
|
|
|
}
|
2015-07-13 15:16:36 +01:00
|
|
|
virtual CommandSupportType supportGrow() const {
|
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for growing */
|
|
|
|
}
|
2016-08-08 02:01:35 +01:00
|
|
|
virtual CommandSupportType supportGrowOnline() const {
|
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for online growing */
|
|
|
|
}
|
2015-07-13 15:16:36 +01:00
|
|
|
virtual CommandSupportType supportShrink() const {
|
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for shrinking */
|
|
|
|
}
|
2016-08-08 02:01:35 +01:00
|
|
|
virtual CommandSupportType supportShrinkOnline() const {
|
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for shrinking */
|
|
|
|
}
|
2015-07-13 15:16:36 +01:00
|
|
|
virtual CommandSupportType supportMove() const {
|
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for moving */
|
|
|
|
}
|
|
|
|
virtual CommandSupportType supportCheck() const {
|
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for checking */
|
|
|
|
}
|
2016-10-30 01:46:38 +01:00
|
|
|
virtual CommandSupportType supportCheckOnline() const {
|
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for checking */
|
|
|
|
}
|
2015-07-13 15:16:36 +01:00
|
|
|
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 {
|
2016-08-26 18:59:33 +01:00
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for setting label */
|
|
|
|
}
|
|
|
|
virtual CommandSupportType supportSetLabelOnline() const {
|
|
|
|
return cmdSupportNone; /**< @return CommandSupportType for setting label of mounted file systems */
|
2015-07-13 15:16:36 +01:00
|
|
|
}
|
|
|
|
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;
|
2017-09-11 16:52:20 +01:00
|
|
|
virtual int maxLabelLength() const;
|
2017-09-05 12:52:34 +01:00
|
|
|
virtual QValidator* labelValidator(QObject *parent = nullptr) const;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
virtual SupportTool supportToolName() const;
|
|
|
|
virtual bool supportToolFound() const;
|
|
|
|
|
2017-09-30 16:19:36 +01:00
|
|
|
/**
|
|
|
|
* Returns the (possibly translated) name of the type of this filesystem.
|
|
|
|
* @see nameForType()
|
|
|
|
*/
|
2017-09-15 12:47:01 +01:00
|
|
|
virtual QString name(const QStringList& languages = {}) const;
|
2018-04-08 01:46:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the FileSystem's type
|
|
|
|
*/
|
|
|
|
virtual FileSystem::Type type() const;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2017-09-30 16:19:36 +01:00
|
|
|
/**
|
|
|
|
* Returns the name of the given filesystem type. If @p languages
|
|
|
|
* is an empty list, uses the translated name of the filesystem,
|
|
|
|
* in the default locale. If languages is {"C"}, an untranslated
|
|
|
|
* string is returned. Passing other lists of language identifiers
|
|
|
|
* may yield unpredicatable results -- see the documentation of
|
|
|
|
* KLocalizedString() for details on the way toString() is used.
|
|
|
|
* Returns a single QString with the name.
|
|
|
|
*/
|
2017-09-15 12:47:01 +01:00
|
|
|
static QString nameForType(FileSystem::Type t, const QStringList& languages = {});
|
2015-07-13 15:16:36 +01:00
|
|
|
static QList<FileSystem::Type> types();
|
2017-09-15 12:47:01 +01:00
|
|
|
static FileSystem::Type typeForName(const QString& s, const QStringList& languages = {});
|
2016-03-31 17:43:38 +01:00
|
|
|
static FileSystem::Type detectFileSystem(const QString& partitionPath);
|
2016-09-12 11:23:19 +01:00
|
|
|
static QString detectMountPoint(FileSystem* fs, const QString& partitionPath);
|
|
|
|
static bool detectMountStatus(FileSystem* fs, const QString& partitionPath);
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2016-05-13 17:58:05 +01:00
|
|
|
/**< @return true if this FileSystem can be mounted */
|
|
|
|
virtual bool canMount(const QString& deviceNode, const QString& mountPoint) const;
|
2015-07-13 15:16:36 +01:00
|
|
|
virtual bool canUnmount(const QString&) const {
|
2016-05-13 17:27:23 +01:00
|
|
|
return true; /**< @return true if this FileSystem can be unmounted */
|
2015-07-13 15:16:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual QString mountTitle() const;
|
|
|
|
virtual QString unmountTitle() const;
|
|
|
|
|
2016-05-13 17:58:05 +01:00
|
|
|
virtual bool mount(Report& report, const QString& deviceNode, const QString& mountPoint);
|
2016-05-13 17:27:23 +01:00
|
|
|
virtual bool unmount(Report& report, const QString& deviceNode);
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2018-04-08 01:46:08 +01:00
|
|
|
/**< @return the FileSystem's first sector */
|
|
|
|
qint64 firstSector() const;
|
|
|
|
|
|
|
|
/**< @return the FileSystem's last sector */
|
|
|
|
qint64 lastSector() const;
|
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
qint64 length() const {
|
|
|
|
return lastSector() - firstSector() + 1; /**< @return the FileSystem's length */
|
|
|
|
}
|
2017-10-26 16:20:21 +01:00
|
|
|
qint64 firstByte() const {
|
|
|
|
return firstSector() * sectorSize(); /**< @return the FileSystem's first byte */
|
|
|
|
}
|
|
|
|
qint64 lastByte() const {
|
|
|
|
return firstByte() + length() * sectorSize() - 1; /**< @return the FileSystem's last byte */
|
|
|
|
}
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2018-04-08 01:46:08 +01:00
|
|
|
/**< @param s the new first sector */
|
|
|
|
void setFirstSector(qint64 s);
|
|
|
|
|
|
|
|
/**< @param s the new last sector */
|
|
|
|
void setLastSector(qint64 s);
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
void move(qint64 newStartSector);
|
|
|
|
|
2018-04-08 01:46:08 +01:00
|
|
|
/**< @return the FileSystem's label */
|
|
|
|
const QString& label() const;
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2018-04-08 01:46:08 +01:00
|
|
|
/**< @return the sector size in the underlying Device */
|
|
|
|
qint64 sectorSize() const;
|
|
|
|
|
|
|
|
/**< @return the sectors in use on the FileSystem */
|
|
|
|
qint64 sectorsUsed() const;
|
|
|
|
|
|
|
|
/**< @return the FileSystem's UUID */
|
|
|
|
const QString& uuid() const;
|
|
|
|
|
|
|
|
/**< @param s the new value for sector size */
|
|
|
|
void setSectorSize(qint64 s);
|
|
|
|
|
|
|
|
/**< @param s the new value for sectors in use */
|
|
|
|
void setSectorsUsed(qint64 s);
|
|
|
|
|
|
|
|
/**< @param s the new label */
|
|
|
|
void setLabel(const QString& s);
|
|
|
|
|
|
|
|
/**< @param s the new UUID */
|
|
|
|
void setUUID(const QString& s);
|
2015-07-13 15:16:36 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static bool findExternal(const QString& cmdName, const QStringList& args = QStringList(), int exptectedCode = 1);
|
|
|
|
|
2018-04-08 01:46:08 +01:00
|
|
|
std::unique_ptr<FileSystemPrivate> d;
|
2015-06-04 01:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(FileSystem::CommandSupportTypes)
|
|
|
|
|
|
|
|
#endif
|