diff --git a/src/core/raid/softwareraid.cpp b/src/core/raid/softwareraid.cpp index fb8de56..8dfd604 100644 --- a/src/core/raid/softwareraid.cpp +++ b/src/core/raid/softwareraid.cpp @@ -1,251 +1,251 @@ /************************************************************************* * Copyright (C) 2018 by Caio Carvalho * * * * 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 "softwareraid.h" #include "backend/corebackend.h" #include "backend/corebackendmanager.h" #include "core/partition.h" #include "core/volumemanagerdevice_p.h" #include "fs/filesystem.h" #include "fs/filesystemfactory.h" #include "util/externalcommand.h" #include #define d_ptr std::static_pointer_cast(d) class SoftwareRAIDPrivate : public VolumeManagerDevicePrivate { public: qint32 m_raidLevel; qint64 m_chunkSize; qint64 m_totalChunk; qint64 m_arraySize; QString m_UUID; QStringList m_devicePathList; }; SoftwareRAID::SoftwareRAID(const QString& name, const QString& iconName) : VolumeManagerDevice(std::make_shared(), name, (QStringLiteral("/dev/") + name), getChunkSize(QStringLiteral("/dev/") + name), getTotalChunk(QStringLiteral("/dev/") + name), iconName, Device::Type::SoftwareRAID_Device) { d_ptr->m_raidLevel = getRaidLevel(deviceNode()); d_ptr->m_chunkSize = logicalSize(); d_ptr->m_totalChunk = totalLogical(); d_ptr->m_arraySize = getArraySize(deviceNode()); d_ptr->m_UUID = getUUID(deviceNode()); d_ptr->m_devicePathList = getDevicePathList(deviceNode()); initPartitions(); } const QStringList SoftwareRAID::deviceNodes() const { return d_ptr->m_devicePathList; } const QStringList& SoftwareRAID::partitionNodes() const { return {}; } qint64 SoftwareRAID::partitionSize(QString &partitionPath) const { - Q_UNUSED(partitionPath); + Q_UNUSED(partitionPath) return 0; } bool SoftwareRAID::growArray(Report &report, const QStringList &devices) { - Q_UNUSED(report); - Q_UNUSED(devices); + Q_UNUSED(report) + Q_UNUSED(devices) return false; } bool SoftwareRAID::shrinkArray(Report &report, const QStringList &devices) { - Q_UNUSED(report); - Q_UNUSED(devices); + Q_UNUSED(report) + Q_UNUSED(devices) return false; } qint32 SoftwareRAID::raidLevel() const { return d_ptr->m_raidLevel; } qint64 SoftwareRAID::chunkSize() const { return d_ptr->m_chunkSize; } qint64 SoftwareRAID::totalChunk() const { return d_ptr->m_totalChunk; } qint64 SoftwareRAID::arraySize() const { return d_ptr->m_arraySize; } QString SoftwareRAID::uuid() const { return d_ptr->m_UUID; } QStringList SoftwareRAID::devicePathList() const { return d_ptr->m_devicePathList; } void SoftwareRAID::scanSoftwareRAID(QList& devices) { ExternalCommand scanRaid(QStringLiteral("cat"), { QStringLiteral("/proc/mdstat") }); if (scanRaid.run(-1) && scanRaid.exitCode() == 0) { QRegularExpression re(QStringLiteral("md(\\d+)\\s+:")); QRegularExpressionMatchIterator i = re.globalMatch(scanRaid.output()); while (i.hasNext()) { QRegularExpressionMatch reMatch = i.next(); QString deviceNode = QStringLiteral("/dev/") + QStringLiteral("md") + reMatch.captured(1).trimmed(); Device* d = CoreBackendManager::self()->backend()->scanDevice(deviceNode); if ( d ) devices << d; } } } qint32 SoftwareRAID::getRaidLevel(const QString &path) { QString output = getDetail(path); if (!output.isEmpty()) { QRegularExpression re(QStringLiteral("Raid Level :\\s+\\w+(\\d+)")); QRegularExpressionMatch reMatch = re.match(output); if (reMatch.hasMatch()) return reMatch.captured(1).toLongLong(); } return -1; } qint64 SoftwareRAID::getChunkSize(const QString &path) { QString output = getDetail(path); if (!output.isEmpty()) { QRegularExpression re(QStringLiteral("Chunk Size :\\s+(\\d+)")); QRegularExpressionMatch reMatch = re.match(output); if (reMatch.hasMatch()) return reMatch.captured(1).toLongLong(); } return -1; } qint64 SoftwareRAID::getTotalChunk(const QString &path) { return getArraySize(path) / getChunkSize(path); } qint64 SoftwareRAID::getArraySize(const QString &path) { QString output = getDetail(path); if (!output.isEmpty()) { QRegularExpression re(QStringLiteral("Array Size :\\s+(\\d+)")); QRegularExpressionMatch reMatch = re.match(output); if (reMatch.hasMatch()) return reMatch.captured(1).toLongLong() * 1024; } return -1; } QString SoftwareRAID::getUUID(const QString &path) { - Q_UNUSED(path); + Q_UNUSED(path) return QStringLiteral(); } QStringList SoftwareRAID::getDevicePathList(const QString &path) { - Q_UNUSED(path); + Q_UNUSED(path) return {}; } bool SoftwareRAID::isRaidPath(const QString &path) { return !getDetail(path).isEmpty(); } bool SoftwareRAID::createSoftwareRAID(Report &report, const QString &name, const QStringList devicePathList, const qint32 raidLevel, const qint32 chunkSize) { return false; } bool SoftwareRAID::deleteSoftwareRAID(Report &report, SoftwareRAID &raidDevice) { - Q_UNUSED(report); - Q_UNUSED(raidDevice); + Q_UNUSED(report) + Q_UNUSED(raidDevice) return false; } bool SoftwareRAID::assembleSoftwareRAID(Report &report, const SoftwareRAID &raidDevice) { - Q_UNUSED(report); - Q_UNUSED(raidDevice); + Q_UNUSED(report) + Q_UNUSED(raidDevice) return false; } bool SoftwareRAID::stopSoftwareRAID(Report &report, const SoftwareRAID &raidDevice) { - Q_UNUSED(report); - Q_UNUSED(raidDevice); + Q_UNUSED(report) + Q_UNUSED(raidDevice) return false; } void SoftwareRAID::initPartitions() { } qint64 SoftwareRAID::mappedSector(const QString &partitionPath, qint64 sector) const { return -1; } QString SoftwareRAID::getDetail(const QString &path) { ExternalCommand cmd(QStringLiteral("mdadm"), { QStringLiteral("--detail"), path }); return (cmd.run(-1) && cmd.exitCode() == 0) ? cmd.output() : QStringLiteral(); } diff --git a/src/fs/exfat.cpp b/src/fs/exfat.cpp index 1971a63..3173450 100644 --- a/src/fs/exfat.cpp +++ b/src/fs/exfat.cpp @@ -1,120 +1,120 @@ /************************************************************************* * 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 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::Type::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::Unit::Byte, Capacity::Unit::EiB); } int exfat::maxLabelLength() const { return 15; } bool exfat::check(Report& report, const QString& deviceNode) const { ExternalCommand cmd(report, QStringLiteral("exfatfsck"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool exfat::create(Report& report, const QString& 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"), { deviceNode, newLabel }); return cmd.run(-1) && cmd.exitCode() == 0; } bool exfat::updateUUID(Report& report, const QString& deviceNode) const { - Q_UNUSED(report); - Q_UNUSED(deviceNode); + Q_UNUSED(report) + Q_UNUSED(deviceNode) return false; } } diff --git a/src/fs/linuxswap.cpp b/src/fs/linuxswap.cpp index b4eebdd..e535d67 100644 --- a/src/fs/linuxswap.cpp +++ b/src/fs/linuxswap.cpp @@ -1,197 +1,197 @@ /************************************************************************* * 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 #include #include #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_GetUsed = 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::Type::LinuxSwap) { } void linuxswap::init() { m_SetLabel = m_Shrink = m_Grow = m_Create = m_UpdateUUID = (findExternal(QStringLiteral("mkswap"))) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_GetUsed = cmdSupportFileSystem; 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/"))); } int linuxswap::maxLabelLength() const { return 15; } bool linuxswap::create(Report& report, const QString& 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); + Q_UNUSED(length) const QString label = readLabel(deviceNode); const QString uuid = readUUID(deviceNode); QStringList args; if (!label.isEmpty()) args << QStringLiteral("--label") << label; if (!uuid.isEmpty()) 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("--label") << label; if (!uuid.isEmpty()) 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("swaplabel"), { QStringLiteral("--label"), newLabel, deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool linuxswap::writeLabelOnline(Report& report, const QString& deviceNode, const QString& mountPoint, const QString& newLabel) { Q_UNUSED(mountPoint) return writeLabel(report, deviceNode, newLabel); } QString linuxswap::mountTitle() const { return xi18nc("@title:menu", "Activate swap"); } QString linuxswap::unmountTitle() const { return xi18nc("@title:menu", "Deactivate swap"); } bool linuxswap::canMount(const QString& deviceNode, const QString& mountPoint) const { - Q_UNUSED(deviceNode); + Q_UNUSED(deviceNode) // linux swap doesn't require mount point to activate return mountPoint != QStringLiteral("/"); } bool linuxswap::mount(Report& report, const QString& deviceNode, const QString& mountPoint) { - Q_UNUSED(mountPoint); + Q_UNUSED(mountPoint) ExternalCommand cmd(report, QStringLiteral("swapon"), { deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool linuxswap::unmount(Report& report, const QString& deviceNode) { ExternalCommand cmd(report, 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("--label") << label; args << deviceNode; ExternalCommand cmd(report, QStringLiteral("mkswap"), args); return cmd.run(-1) && cmd.exitCode() == 0; } qint64 linuxswap::readUsedCapacity(const QString& deviceNode) const { QFile swapsFile(QStringLiteral("/proc/swaps")); if (swapsFile.open(QIODevice::ReadOnly)) { QByteArray data = swapsFile.readAll(); swapsFile.close(); QTextStream in(&data); while (!in.atEnd()) { QStringList line = in.readLine().split(QRegularExpression(QStringLiteral("\\s+"))); QFileInfo kernelPath(deviceNode); if (line[0] == kernelPath.canonicalFilePath()) return line[3].toLongLong() * 1024; } } return -1; } } diff --git a/src/fs/ntfs.cpp b/src/fs/ntfs.cpp index 8386275..043d5de 100644 --- a/src/fs/ntfs.cpp +++ b/src/fs/ntfs.cpp @@ -1,216 +1,216 @@ /************************************************************************* * 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 #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::Type::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::Unit::Byte, Capacity::Unit::MiB); } qint64 ntfs::maxCapacity() const { return 256 * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::TiB); } int ntfs::maxLabelLength() const { return 128; } qint64 ntfs::readUsedCapacity(const QString& deviceNode) const { ExternalCommand cmd(QStringLiteral("ntfsresize"), { QStringLiteral("--info"), QStringLiteral("--force"), QStringLiteral("--no-progress-bar"), deviceNode }); if (cmd.run(-1) && cmd.exitCode() == 0) { qint64 usedBytes = -1; QRegularExpression re(QStringLiteral("resize at (\\d+) bytes")); QRegularExpressionMatch reUsedBytes = re.match(cmd.output()); if (reUsedBytes.hasMatch()) usedBytes = reUsedBytes.captured(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"), { QStringLiteral("--force"), deviceNode, newLabel }, QProcess::SeparateChannels); if (!writeCmd.run(-1)) return false; return true; } bool ntfs::check(Report& report, const QString& deviceNode) const { 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) { 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"), { 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 = { QStringLiteral("--no-progress-bar"), QStringLiteral("--force"), deviceNode, QStringLiteral("--size"), QString::number(length) }; QStringList dryRunArgs = args; 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); + Q_UNUSED(report) ExternalCommand cmd(QStringLiteral("ntfslabel"), { QStringLiteral("--new-serial"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } bool ntfs::updateBootSector(Report& report, const QString& deviceNode) const { report.line() << xi18nc("@info:progress", "Updating boot sector for NTFS file system on partition %1.", deviceNode); qint64 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 ExternalCommand cmd(report, QStringLiteral("dd"), { QStringLiteral("of=") + deviceNode , QStringLiteral("bs=1"), QStringLiteral("count=4"), QStringLiteral("seek=28") }); cmd.write(QByteArray(s, sizeof(s))); if (!cmd.start()) { Log() << xi18nc("@info:progress", "Could not write new start sector to partition %1 when trying to update the NTFS boot sector.", deviceNode); return false; } cmd.waitFor(-1); // Also update backup NTFS boot sector located at the end of the partition // NOTE: this should fail if filesystem does not span the whole partition qint64 pos = (lastSector() - firstSector()) * sectorSize() + 28; ExternalCommand cmd2(report, QStringLiteral("dd"), { QStringLiteral("of=") + deviceNode , QStringLiteral("bs=1"), QStringLiteral("count=4"), QStringLiteral("seek=") + QString::number(pos) }); cmd2.write(QByteArray(s, sizeof(s))); if (!cmd2.start()) { Log() << xi18nc("@info:progress", "Could not write new start sector to partition %1 when trying to update the NTFS boot sector.", deviceNode); return false; } cmd2.waitFor(-1); Log() << xi18nc("@info:progress", "Updated NTFS boot sector for partition %1 successfully.", deviceNode); return true; } } diff --git a/src/fs/ocfs2.cpp b/src/fs/ocfs2.cpp index 1122e64..8f2e914 100644 --- a/src/fs/ocfs2.cpp +++ b/src/fs/ocfs2.cpp @@ -1,158 +1,158 @@ /************************************************************************* * 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::Type::Ocfs2) { } void ocfs2::init() { 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"), { 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::Unit::Byte, Capacity::Unit::KiB); } qint64 ocfs2::maxCapacity() const { return 4 * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::PiB); } qint64 ocfs2::readUsedCapacity(const QString& deviceNode) const { - Q_UNUSED(deviceNode); + Q_UNUSED(deviceNode) return -1; } bool ocfs2::check(Report& report, const QString& deviceNode) const { 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) { ExternalCommand cmd(report, QStringLiteral("mkfs.ocfs2"), { deviceNode }); if (cmd.write("y\n")) { cmd.start(); 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"), { QStringLiteral("--request"), QStringLiteral("stats"), deviceNode }); qint32 blockSize = -1; if (cmdBlockSize.run(-1) && cmdBlockSize.exitCode() == 0) { QRegularExpression re(QStringLiteral("Block Size Bits: (\\d+)")); QRegularExpressionMatch reBlockSizeBits = re.match(cmdBlockSize.output()); if (reBlockSizeBits.hasMatch()) blockSize = 1 << reBlockSizeBits.captured(1).toInt(); } if (blockSize == -1) return false; 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"), { 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"), { QStringLiteral("--uuid-reset"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } } diff --git a/src/plugins/dummy/dummydevice.cpp b/src/plugins/dummy/dummydevice.cpp index 0ffa283..26634a7 100644 --- a/src/plugins/dummy/dummydevice.cpp +++ b/src/plugins/dummy/dummydevice.cpp @@ -1,61 +1,61 @@ /************************************************************************* * 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 .* *************************************************************************/ #include "plugins/dummy/dummydevice.h" #include "plugins/dummy/dummypartitiontable.h" #include "core/partitiontable.h" #include "util/globallog.h" #include "util/report.h" DummyDevice::DummyDevice(const QString& deviceNode) : CoreBackendDevice(deviceNode) { } DummyDevice::~DummyDevice() { } bool DummyDevice::open() { return true; } bool DummyDevice::openExclusive() { return true; } bool DummyDevice::close() { return true; } std::unique_ptr DummyDevice::openPartitionTable() { return std::make_unique(DummyPartitionTable()); } bool DummyDevice::createPartitionTable(Report& report, const PartitionTable& ptable) { - Q_UNUSED(report); - Q_UNUSED(ptable); + Q_UNUSED(report) + Q_UNUSED(ptable) return true; }