File indexing completed on 2024-05-05 05:48:43

0001 /*
0002     SPDX-FileCopyrightText: 2008-2011 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2013-2019 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
0005     SPDX-FileCopyrightText: 2020 Arnaud Ferraris <arnaud.ferraris@collabora.com>
0006     SPDX-FileCopyrightText: 2020 Gaël PORTAY <gael.portay@collabora.com>
0007 
0008     SPDX-License-Identifier: GPL-3.0-or-later
0009 */
0010 
0011 #include "fs/fat16.h"
0012 
0013 #include "util/externalcommand.h"
0014 #include "util/capacity.h"
0015 #include "util/report.h"
0016 
0017 #include <KLocalizedString>
0018 
0019 #include <QString>
0020 #include <QStringList>
0021 
0022 #include <ctime>
0023 
0024 namespace FS
0025 {
0026 fat16::fat16(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, const QVariantMap& features, FileSystem::Type type) :
0027     fat12(firstsector, lastsector, sectorsused, label, features, type)
0028 {
0029 }
0030 
0031 void fat16::init()
0032 {
0033     m_Create = m_GetUsed = m_Check = findExternal(QStringLiteral("mkfs.fat"), {}, 1) ? cmdSupportFileSystem : cmdSupportNone;
0034     m_GetLabel = cmdSupportCore;
0035     m_SetLabel = findExternal(QStringLiteral("fatlabel")) ? cmdSupportFileSystem : cmdSupportNone;
0036     m_Move = cmdSupportCore;
0037     m_Copy = cmdSupportCore;
0038     m_Backup = cmdSupportCore;
0039     m_UpdateUUID = cmdSupportCore;
0040     m_Grow = findExternal(QStringLiteral("fatresize")) ? cmdSupportFileSystem : cmdSupportNone;
0041     m_Shrink = findExternal(QStringLiteral("fatresize")) ? cmdSupportFileSystem : cmdSupportNone;
0042     m_GetUUID = cmdSupportCore;
0043 
0044     if (m_Create == cmdSupportFileSystem) {
0045         addAvailableFeature(QStringLiteral("sector-size"));
0046         addAvailableFeature(QStringLiteral("sectors-per-cluster"));
0047     }
0048 }
0049 
0050 bool fat16::supportToolFound() const
0051 {
0052     return
0053         m_GetUsed != cmdSupportNone &&
0054         m_GetLabel != cmdSupportNone &&
0055         m_SetLabel != cmdSupportNone &&
0056         m_Create != cmdSupportNone &&
0057         m_Check != cmdSupportNone &&
0058         m_UpdateUUID != cmdSupportNone &&
0059 //          m_Grow != cmdSupportNone &&
0060 //          m_Shrink != cmdSupportNone &&
0061         m_Copy != cmdSupportNone &&
0062         m_Move != cmdSupportNone &&
0063         m_Backup != cmdSupportNone &&
0064         m_GetUUID != cmdSupportNone;
0065 }
0066 
0067 qint64 fat16::minCapacity() const
0068 {
0069     return 16 * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB);
0070 }
0071 
0072 qint64 fat16::maxCapacity() const
0073 {
0074     return 4 * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::GiB) - Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB);
0075 }
0076 
0077 bool fat16::create(Report& report, const QString& deviceNode)
0078 {
0079     return createWithFatSize(report, deviceNode, 16);
0080 }
0081 
0082 bool fat16::resize(Report& report, const QString& deviceNode, qint64 length) const
0083 {
0084     ExternalCommand cmd(report, QStringLiteral("fatresize"), { QStringLiteral("--verbose"), QStringLiteral("--size"), QString::number(length - 1), deviceNode });
0085     return cmd.run(-1) && cmd.exitCode() == 0;
0086 }
0087 
0088 }