2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2008,2009,2011 by Volker Lanz <vl@fidra.de> *
|
2017-12-24 23:24:23 +00:00
|
|
|
* Copyright (C) 2016-2017 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/fat16.h"
|
|
|
|
|
|
|
|
#include "util/externalcommand.h"
|
|
|
|
#include "util/capacity.h"
|
|
|
|
#include "util/report.h"
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
namespace FS
|
|
|
|
{
|
2017-12-24 23:24:23 +00:00
|
|
|
fat16::fat16(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
|
2018-04-07 19:54:30 +01:00
|
|
|
fat12(firstsector, lastsector, sectorsused, label, FileSystem::Type::Fat16)
|
2017-12-24 23:24:23 +00:00
|
|
|
{
|
|
|
|
}
|
2015-07-13 15:16:36 +01:00
|
|
|
|
2017-12-24 23:24:23 +00:00
|
|
|
fat16::fat16(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, FileSystem::Type type) :
|
|
|
|
fat12(firstsector, lastsector, sectorsused, label, type)
|
2015-07-13 15:16:36 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void fat16::init()
|
|
|
|
{
|
2016-10-30 02:54:10 +00:00
|
|
|
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;
|
2018-11-29 22:32:07 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-10-28 22:07:52 +01:00
|
|
|
ExternalCommand cmd(report, QStringLiteral("mkfs.fat"), { QStringLiteral("-F16"), QStringLiteral("-I"), QStringLiteral("-v"), deviceNode });
|
2015-07-13 15:16:36 +01:00
|
|
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
|
|
|
}
|
|
|
|
|
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), deviceNode });
|
|
|
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|