kpmcore/src/fs/fat16.cpp

89 lines
2.8 KiB
C++
Raw Normal View History

2020-09-28 00:45:21 +01:00
/*
SPDX-FileCopyrightText: 2008-2011 Volker Lanz <vl@fidra.de>
SPDX-FileCopyrightText: 2013-2019 Andrius Štikonas <andrius@stikonas.eu>
SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
SPDX-FileCopyrightText: 2020 Arnaud Ferraris <arnaud.ferraris@collabora.com>
SPDX-FileCopyrightText: 2020 Gaël PORTAY <gael.portay@collabora.com>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "fs/fat16.h"
#include "util/externalcommand.h"
#include "util/capacity.h"
#include "util/report.h"
#include <KLocalizedString>
#include <QString>
#include <QStringList>
#include <ctime>
namespace FS
{
fat16::fat16(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, const QVariantMap& features, FileSystem::Type type) :
fat12(firstsector, lastsector, sectorsused, label, features, type)
2015-07-13 15:16:36 +01:00
{
}
void fat16::init()
{
m_Create = m_GetUsed = m_Check = findExternal(QStringLiteral("mkfs.fat"), {}, 1) ? cmdSupportFileSystem : cmdSupportNone;
2015-07-13 15:16:36 +01:00
m_GetLabel = cmdSupportCore;
m_SetLabel = findExternal(QStringLiteral("fatlabel")) ? cmdSupportFileSystem : cmdSupportNone;
m_Move = cmdSupportCore;
m_Copy = cmdSupportCore;
m_Backup = cmdSupportCore;
m_UpdateUUID = cmdSupportCore;
2017-11-09 23:14:52 +00:00
m_Grow = findExternal(QStringLiteral("fatresize")) ? cmdSupportFileSystem : cmdSupportNone;
m_Shrink = findExternal(QStringLiteral("fatresize")) ? cmdSupportFileSystem : cmdSupportNone;
2015-07-13 15:16:36 +01:00
m_GetUUID = cmdSupportCore;
if (m_Create == cmdSupportFileSystem) {
addAvailableFeature(QStringLiteral("sector-size"));
addAvailableFeature(QStringLiteral("sectors-per-cluster"));
}
2015-07-13 15:16:36 +01:00
}
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;
}
qint64 fat16::minCapacity() const
{
2018-04-09 15:14:34 +01:00
return 16 * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB);
2015-07-13 15:16:36 +01:00
}
qint64 fat16::maxCapacity() const
{
2018-04-09 15:14:34 +01:00
return 4 * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::GiB) - Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB);
2015-07-13 15:16:36 +01:00
}
2016-09-05 12:10:56 +01:00
bool fat16::create(Report& report, const QString& deviceNode)
2015-07-13 15:16:36 +01:00
{
return createWithFatSize(report, deviceNode, 16);
2015-07-13 15:16:36 +01:00
}
2017-11-09 23:14:52 +00:00
bool fat16::resize(Report& report, const QString& deviceNode, qint64 length) const
{
ExternalCommand cmd(report, QStringLiteral("fatresize"), { QStringLiteral("--verbose"), QStringLiteral("--size"), QString::number(length - 1), deviceNode });
2017-11-09 23:14:52 +00:00
return cmd.run(-1) && cmd.exitCode() == 0;
}
}