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> *
|
2016-03-02 19:00:31 +00:00
|
|
|
* Copyright (C) 2016 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/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "fs/filesystem.h"
|
2016-09-12 11:23:19 +01:00
|
|
|
#include "fs/lvm2_pv.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-05-06 19:14:01 +01:00
|
|
|
#include "backend/corebackend.h"
|
|
|
|
#include "backend/corebackendmanager.h"
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
#include "util/externalcommand.h"
|
|
|
|
#include "util/capacity.h"
|
2016-09-12 11:23:19 +01:00
|
|
|
#include "util/helpers.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
#include <blkid/blkid.h>
|
2016-03-31 17:43:38 +01:00
|
|
|
|
2016-09-12 11:23:19 +01:00
|
|
|
#include <KMountPoint>
|
2015-06-04 01:29:22 +01:00
|
|
|
#include <KLocalizedString>
|
|
|
|
|
2016-03-31 17:43:38 +01:00
|
|
|
#include <QDebug>
|
2015-07-17 12:36:23 +01:00
|
|
|
|
|
|
|
const std::array< QColor, FileSystem::__lastType > FileSystem::defaultColorCode =
|
2016-08-24 23:01:36 +01:00
|
|
|
{
|
2015-07-17 12:36:23 +01:00
|
|
|
{
|
|
|
|
QColor( 220,205,175 ),
|
|
|
|
QColor( 187,249,207 ),
|
|
|
|
QColor( 102,121,150 ),
|
|
|
|
QColor( 122,145,180 ),
|
|
|
|
QColor( 143,170,210 ),
|
|
|
|
QColor( 155,155,130 ),
|
|
|
|
QColor( 204,179,215 ),
|
|
|
|
QColor( 229,201,240 ),
|
|
|
|
QColor( 244,214,255 ),
|
|
|
|
QColor( 216,220,135 ),
|
|
|
|
QColor( 251,255,157 ),
|
|
|
|
QColor( 200,255,254 ),
|
|
|
|
QColor( 137,200,198 ),
|
|
|
|
QColor( 210,136,142 ),
|
|
|
|
QColor( 240,165,171 ),
|
|
|
|
QColor( 151,220,134 ),
|
|
|
|
QColor( 220,205,175 ),
|
|
|
|
QColor( 173,205,255 ),
|
|
|
|
QColor( 176,155,185 ),
|
|
|
|
QColor( 170,30,77 ),
|
|
|
|
QColor( 96,140,85 ),
|
|
|
|
QColor( 33,137,108 ),
|
|
|
|
QColor( 250,230,255 ),
|
|
|
|
QColor( 242,155,104 ),
|
2016-02-25 23:29:33 +00:00
|
|
|
QColor( 160,210,180 ),
|
|
|
|
QColor( 255,170,0 )
|
2016-08-24 23:01:36 +01:00
|
|
|
}
|
2015-07-17 12:36:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
/** Creates a new FileSystem object
|
2015-07-13 15:16:36 +01:00
|
|
|
@param firstsector the first sector used by this FileSystem on the Device
|
|
|
|
@param lastsector the last sector used by this FileSystem on the Device
|
|
|
|
@param sectorsused the number of sectors in use on the FileSystem
|
|
|
|
@param l the FileSystem label
|
|
|
|
@param t the FileSystem type
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
FileSystem::FileSystem(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& l, FileSystem::Type t) :
|
2015-07-13 15:16:36 +01:00
|
|
|
m_Type(t),
|
|
|
|
m_FirstSector(firstsector),
|
|
|
|
m_LastSector(lastsector),
|
|
|
|
m_SectorsUsed(sectorsused),
|
|
|
|
m_Label(l),
|
|
|
|
m_UUID()
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Reads the capacity in use on this FileSystem
|
2015-07-13 15:16:36 +01:00
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@return the used capacity in bytes or -1 in case of an error
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
qint64 FileSystem::readUsedCapacity(const QString& deviceNode) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_UNUSED(deviceNode);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return -1;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static QString readBlkIdValue(const QString& deviceNode, const QString& tag)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
blkid_cache cache;
|
|
|
|
QString rval;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-22 14:48:03 +01:00
|
|
|
if (blkid_get_cache(&cache, nullptr) == 0) {
|
2015-07-13 15:16:36 +01:00
|
|
|
blkid_dev dev;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-22 14:48:03 +01:00
|
|
|
char* label = nullptr;
|
|
|
|
if ((dev = blkid_get_dev(cache, deviceNode.toLocal8Bit().constData(), BLKID_DEV_NORMAL)) != nullptr &&
|
2015-07-13 15:16:36 +01:00
|
|
|
(label = blkid_get_tag_value(cache, tag.toLocal8Bit().constData(), deviceNode.toLocal8Bit().constData()))) {
|
|
|
|
rval = QString::fromUtf8(label);
|
|
|
|
free(label);
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
blkid_put_cache(cache);
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return rval;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
2016-03-31 17:43:38 +01:00
|
|
|
FileSystem::Type FileSystem::detectFileSystem(const QString& partitionPath)
|
|
|
|
{
|
2016-05-06 19:14:01 +01:00
|
|
|
return CoreBackendManager::self()->backend()->detectFileSystem(partitionPath);
|
2016-03-31 17:43:38 +01:00
|
|
|
}
|
|
|
|
|
2016-09-12 11:23:19 +01:00
|
|
|
QString FileSystem::detectMountPoint(FileSystem* fs, const QString& partitionPath)
|
|
|
|
{
|
|
|
|
QString mountPoint = QString();
|
|
|
|
|
|
|
|
KMountPoint::List mountPoints = KMountPoint::currentMountPoints(KMountPoint::NeedRealDeviceName);
|
|
|
|
mountPoints.append(KMountPoint::possibleMountPoints(KMountPoint::NeedRealDeviceName));
|
|
|
|
|
|
|
|
if (fs->type() == FileSystem::Lvm2_PV) {
|
|
|
|
mountPoint = FS::lvm2_pv::getVGName(partitionPath);
|
|
|
|
} else {
|
|
|
|
mountPoint = mountPoints.findByDevice(partitionPath) ?
|
|
|
|
mountPoints.findByDevice(partitionPath)->mountPoint() :
|
|
|
|
QString();
|
|
|
|
}
|
|
|
|
return mountPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileSystem::detectMountStatus(FileSystem* fs, const QString& partitionPath)
|
|
|
|
{
|
|
|
|
bool mounted = false;
|
|
|
|
|
|
|
|
if (fs->type() == FileSystem::Lvm2_PV) {
|
2016-10-30 01:46:38 +01:00
|
|
|
mounted = FS::lvm2_pv::getVGName(partitionPath) != QString(); // FIXME: VG name is scanned twice
|
2016-09-12 11:23:19 +01:00
|
|
|
} else {
|
|
|
|
mounted = isMounted(partitionPath);
|
|
|
|
}
|
|
|
|
return mounted;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
/** Reads the label for this FileSystem
|
2015-07-13 15:16:36 +01:00
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@return the FileSystem label or an empty string in case of error
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
QString FileSystem::readLabel(const QString& deviceNode) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return readBlkIdValue(deviceNode, QStringLiteral("LABEL"));
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Creates a new FileSystem
|
2015-07-13 15:16:36 +01:00
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition to create the FileSystem on
|
|
|
|
@return true if successful
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
2016-09-05 12:10:56 +01:00
|
|
|
bool FileSystem::create(Report& report, const QString& deviceNode)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2016-10-30 01:46:38 +01:00
|
|
|
Q_UNUSED(report)
|
|
|
|
Q_UNUSED(deviceNode)
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return true;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
2016-09-04 23:32:00 +01:00
|
|
|
/** Scans a new FileSystem and load file system specific class variables.
|
|
|
|
* @param deviceNode the device node for the Partition to create the FileSystem on
|
|
|
|
*/
|
|
|
|
void FileSystem::scan(const QString& deviceNode)
|
|
|
|
{
|
|
|
|
Q_UNUSED(deviceNode);
|
|
|
|
}
|
|
|
|
|
2016-04-21 17:22:48 +01:00
|
|
|
/** Resize a FileSystem to a given new length
|
2015-07-13 15:16:36 +01:00
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@param newLength the new length for the FileSystem in bytes
|
|
|
|
@return true on success
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
bool FileSystem::resize(Report& report, const QString& deviceNode, qint64 newLength) const
|
|
|
|
{
|
2016-10-30 01:46:38 +01:00
|
|
|
Q_UNUSED(report)
|
|
|
|
Q_UNUSED(deviceNode)
|
|
|
|
Q_UNUSED(newLength)
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return true;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
2016-08-08 02:01:35 +01:00
|
|
|
/** Resize a mounted FileSystem to a given new length
|
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@param mountPoint the mount point where FileSystem is mounted on
|
|
|
|
@param newLength the new length for the FileSystem in bytes
|
|
|
|
@return true on success
|
|
|
|
*/
|
|
|
|
bool FileSystem::resizeOnline(Report& report, const QString& deviceNode, const QString& mountPoint, qint64 newLength) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(deviceNode);
|
|
|
|
Q_UNUSED(mountPoint);
|
|
|
|
Q_UNUSED(newLength);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
/** Move a FileSystem to a new start sector
|
2015-07-13 15:16:36 +01:00
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
2016-05-13 23:18:24 +01:00
|
|
|
@param newStartSector the new start sector for the FileSystem
|
2015-07-13 15:16:36 +01:00
|
|
|
@return true on success
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
bool FileSystem::move(Report& report, const QString& deviceNode, qint64 newStartSector) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(deviceNode);
|
|
|
|
Q_UNUSED(newStartSector);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return true;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Writes a label for the FileSystem to disk
|
2015-07-13 15:16:36 +01:00
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@param newLabel the new label for the FileSystem
|
|
|
|
@return true on success
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
bool FileSystem::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(deviceNode);
|
|
|
|
Q_UNUSED(newLabel);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return true;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
2017-04-09 17:49:55 +01:00
|
|
|
/** Writes a label for the FileSystem to disk
|
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@param mountPoint the mount point where FileSystem is mounted on
|
|
|
|
@param newLabel the new label for the FileSystem
|
|
|
|
@return true on success
|
|
|
|
*/
|
|
|
|
bool FileSystem::writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel)
|
|
|
|
{
|
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(deviceNode);
|
|
|
|
Q_UNUSED(mountPoint);
|
|
|
|
Q_UNUSED(newLabel);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
/** Copies a FileSystem from one Partition to another
|
2015-07-13 15:16:36 +01:00
|
|
|
@param report Report to write status information to
|
|
|
|
@param targetDeviceNode device node of the target Partition
|
|
|
|
@param sourceDeviceNode device node of the source Partition
|
|
|
|
@return true on success
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
bool FileSystem::copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(targetDeviceNode);
|
|
|
|
Q_UNUSED(sourceDeviceNode);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return true;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Backs up a FileSystem to a file
|
2015-07-13 15:16:36 +01:00
|
|
|
@param report Report to write status information to
|
|
|
|
@param sourceDevice Device the source FileSystem is on
|
|
|
|
@param deviceNode device node of the source Partition
|
|
|
|
@param filename name of the file to backup to
|
|
|
|
@return true on success
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
bool FileSystem::backup(Report& report, const Device& sourceDevice, const QString& deviceNode, const QString& filename) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(sourceDevice);
|
|
|
|
Q_UNUSED(deviceNode);
|
|
|
|
Q_UNUSED(filename);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return false;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Removes a FileSystem
|
2015-07-13 15:16:36 +01:00
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@return true if FileSystem is removed
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
bool FileSystem::remove(Report& report, const QString& deviceNode) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(deviceNode);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return true;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Checks a FileSystem for errors
|
2015-07-13 15:16:36 +01:00
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@return true if FileSystem is error-free
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
bool FileSystem::check(Report& report, const QString& deviceNode) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(deviceNode);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return true;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Updates a FileSystem UUID on disk
|
2015-07-13 15:16:36 +01:00
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@return true on success
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
bool FileSystem::updateUUID(Report& report, const QString& deviceNode) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(deviceNode);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return true;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns the FileSystem UUID by calling a FileSystem-specific helper program
|
2015-07-13 15:16:36 +01:00
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@return the UUID or an empty string if the FileSystem does not support UUIDs
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
QString FileSystem::readUUID(const QString& deviceNode) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return readBlkIdValue(deviceNode, QStringLiteral("UUID"));
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Give implementations of FileSystem a chance to update the boot sector after the
|
2015-07-13 15:16:36 +01:00
|
|
|
file system has been moved or copied.
|
|
|
|
@param report Report to write status information to
|
|
|
|
@param deviceNode the device node for the Partition the FileSystem is on
|
|
|
|
@return true on success
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
bool FileSystem::updateBootSector(Report& report, const QString& deviceNode) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_UNUSED(report);
|
|
|
|
Q_UNUSED(deviceNode);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return true;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return the minimum capacity valid for this FileSystem in bytes */
|
|
|
|
qint64 FileSystem::minCapacity() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return 8 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return the maximum capacity valid for this FileSystem in bytes */
|
|
|
|
qint64 FileSystem::maxCapacity() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return Capacity::unitFactor(Capacity::Byte, Capacity::EiB);
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return the maximum label length valid for this FileSystem */
|
|
|
|
qint64 FileSystem::maxLabelLength() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return 16;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return this FileSystem's type as printable name */
|
|
|
|
QString FileSystem::name() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return nameForType(type());
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return a pointer to a QString C array with all FileSystem names */
|
|
|
|
static const QString* typeNames()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
static const QString s[] = {
|
2016-07-17 23:41:00 +01:00
|
|
|
xi18nc("@item filesystem name", "unknown"),
|
|
|
|
xi18nc("@item filesystem name", "extended"),
|
|
|
|
|
|
|
|
xi18nc("@item filesystem name", "ext2"),
|
|
|
|
xi18nc("@item filesystem name", "ext3"),
|
|
|
|
xi18nc("@item filesystem name", "ext4"),
|
|
|
|
xi18nc("@item filesystem name", "linuxswap"),
|
|
|
|
xi18nc("@item filesystem name", "fat16"),
|
|
|
|
xi18nc("@item filesystem name", "fat32"),
|
|
|
|
xi18nc("@item filesystem name", "ntfs"),
|
|
|
|
xi18nc("@item filesystem name", "reiser"),
|
|
|
|
xi18nc("@item filesystem name", "reiser4"),
|
|
|
|
xi18nc("@item filesystem name", "xfs"),
|
|
|
|
xi18nc("@item filesystem name", "jfs"),
|
|
|
|
xi18nc("@item filesystem name", "hfs"),
|
|
|
|
xi18nc("@item filesystem name", "hfsplus"),
|
|
|
|
xi18nc("@item filesystem name", "ufs"),
|
|
|
|
xi18nc("@item filesystem name", "unformatted"),
|
|
|
|
xi18nc("@item filesystem name", "btrfs"),
|
|
|
|
xi18nc("@item filesystem name", "hpfs"),
|
|
|
|
xi18nc("@item filesystem name", "luks"),
|
|
|
|
xi18nc("@item filesystem name", "ocfs2"),
|
|
|
|
xi18nc("@item filesystem name", "zfs"),
|
|
|
|
xi18nc("@item filesystem name", "exfat"),
|
|
|
|
xi18nc("@item filesystem name", "nilfs2"),
|
|
|
|
xi18nc("@item filesystem name", "lvm2 pv"),
|
|
|
|
xi18nc("@item filesystem name", "f2fs"),
|
2015-07-13 15:16:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return s;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @param t the type to get the name for
|
2015-07-13 15:16:36 +01:00
|
|
|
@return the printable name for the given type
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
QString FileSystem::nameForType(FileSystem::Type t)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_ASSERT(t >= 0);
|
|
|
|
Q_ASSERT(t < __lastType);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return typeNames()[t];
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @param s the name to get the type for
|
2015-07-13 15:16:36 +01:00
|
|
|
@return the type for the name or FileSystem::Unknown if not found
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
FileSystem::Type FileSystem::typeForName(const QString& s)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
for (quint32 i = 0; i < __lastType; i++)
|
|
|
|
if (typeNames()[i] == s)
|
|
|
|
return static_cast<FileSystem::Type>(i);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return Unknown;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return a QList of all known types */
|
|
|
|
QList<FileSystem::Type> FileSystem::types()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
QList<FileSystem::Type> result;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
int i = Ext2; // first "real" filesystem
|
|
|
|
while (i != __lastType)
|
|
|
|
result.append(static_cast<FileSystem::Type>(i++));
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return result;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return printable menu title for mounting this FileSystem */
|
|
|
|
QString FileSystem::mountTitle() const
|
|
|
|
{
|
2016-07-17 23:41:00 +01:00
|
|
|
return xi18nc("@title:menu", "Mount");
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return printable menu title for unmounting this FileSystem */
|
|
|
|
QString FileSystem::unmountTitle() const
|
|
|
|
{
|
2016-07-17 23:41:00 +01:00
|
|
|
return xi18nc("@title:menu", "Unmount");
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Moves a FileSystem to a new start sector.
|
2015-07-13 15:16:36 +01:00
|
|
|
@param newStartSector where the FileSystem should be moved to
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
void FileSystem::move(qint64 newStartSector)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
const qint64 savedLength = length();
|
|
|
|
setFirstSector(newStartSector);
|
|
|
|
setLastSector(newStartSector + savedLength - 1);
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
2016-05-13 17:58:05 +01:00
|
|
|
bool FileSystem::canMount(const QString& deviceNode, const QString& mountPoint) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(deviceNode);
|
|
|
|
// cannot mount if we have no mount points
|
|
|
|
return !mountPoint.isEmpty();
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
/** Attempt to mount this FileSystem on a given mount point
|
2016-05-13 23:18:24 +01:00
|
|
|
@param report the report to write information to
|
|
|
|
@param deviceNode the path to the device that is to be unmounted
|
2015-07-13 15:16:36 +01:00
|
|
|
@param mountPoint the mount point to mount the FileSystem on
|
|
|
|
@return true on success
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
2016-05-13 17:58:05 +01:00
|
|
|
bool FileSystem::mount(Report& report, const QString &deviceNode, const QString &mountPoint)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2016-05-13 17:58:05 +01:00
|
|
|
ExternalCommand mountCmd( report,
|
|
|
|
QStringLiteral("mount"),
|
|
|
|
{ QStringLiteral("--verbose"),
|
|
|
|
deviceNode,
|
|
|
|
mountPoint });
|
|
|
|
if (mountCmd.run() && mountCmd.exitCode() == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-13 15:16:36 +01:00
|
|
|
return false;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Attempt to unmount this FileSystem
|
2016-05-13 23:18:24 +01:00
|
|
|
@param report the report to write information to
|
|
|
|
@param deviceNode the path to the device that is to be unmounted
|
2015-07-13 15:16:36 +01:00
|
|
|
@return true on success
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
2016-05-13 17:27:23 +01:00
|
|
|
bool FileSystem::unmount(Report& report, const QString& deviceNode)
|
|
|
|
{
|
|
|
|
ExternalCommand umountCmd( report,
|
|
|
|
QStringLiteral("umount"),
|
|
|
|
{ QStringLiteral("--verbose"),
|
2016-05-13 23:08:58 +01:00
|
|
|
QStringLiteral("--all-targets"),
|
2016-05-13 17:27:23 +01:00
|
|
|
deviceNode });
|
|
|
|
if ( umountCmd.run() && umountCmd.exitCode() == 0 )
|
|
|
|
return true;
|
2015-07-13 15:16:36 +01:00
|
|
|
return false;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileSystem::findExternal(const QString& cmdName, const QStringList& args, int expectedCode)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
ExternalCommand cmd(cmdName, args);
|
|
|
|
if (!cmd.run())
|
|
|
|
return false;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return cmd.exitCode() == 0 || cmd.exitCode() == expectedCode;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileSystem::supportToolFound() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return false;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FileSystem::SupportTool FileSystem::supportToolName() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return SupportTool();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|