2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
|
|
|
* *
|
|
|
|
* 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/fat32.h"
|
|
|
|
|
|
|
|
#include "util/externalcommand.h"
|
|
|
|
#include "util/capacity.h"
|
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
namespace FS
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
fat32::fat32(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
|
|
|
|
fat16(firstsector, lastsector, sectorsused, label, FileSystem::Fat32)
|
|
|
|
{
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
qint64 fat32::minCapacity() const
|
|
|
|
{
|
|
|
|
return 32 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
qint64 fat32::maxCapacity() const
|
|
|
|
{
|
2016-06-09 22:07:23 +01:00
|
|
|
return 16 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB) - Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
|
2015-07-13 15:16:36 +01:00
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-09-05 12:10:56 +01:00
|
|
|
bool fat32::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("-F32"), QStringLiteral("-I"), QStringLiteral("-v"), deviceNode });
|
2015-07-13 15:16:36 +01:00
|
|
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
bool fat32::updateUUID(Report& report, const QString& deviceNode) const
|
|
|
|
{
|
2015-07-22 14:48:03 +01:00
|
|
|
qint32 t = time(nullptr);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
char uuid[4];
|
2016-08-11 18:57:40 +01:00
|
|
|
for (auto &u : uuid) {
|
|
|
|
u = t & 0xff;
|
|
|
|
t >>= 8;
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-04-21 22:48:05 +01:00
|
|
|
ExternalCommand cmd(report, QStringLiteral("dd"), { QStringLiteral("of=") + deviceNode, QStringLiteral("bs=1"), QStringLiteral("count=4"), QStringLiteral("seek=67") });
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (!cmd.start())
|
|
|
|
return false;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (cmd.write(uuid, sizeof(uuid)) != sizeof(uuid))
|
|
|
|
return false;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return cmd.waitFor(-1);
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|