File indexing completed on 2024-05-05 05:48:43
0001 /* 0002 SPDX-FileCopyrightText: 2012-2018 Andrius Štikonas <andrius@stikonas.eu> 0003 SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net> 0004 SPDX-FileCopyrightText: 2020 Arnaud Ferraris <arnaud.ferraris@collabora.com> 0005 SPDX-FileCopyrightText: 2020 Gaël PORTAY <gael.portay@collabora.com> 0006 0007 SPDX-License-Identifier: GPL-3.0-or-later 0008 */ 0009 0010 #include "fs/exfat.h" 0011 0012 #include "util/externalcommand.h" 0013 #include "util/capacity.h" 0014 0015 #include <QString> 0016 0017 namespace FS 0018 { 0019 FileSystem::CommandSupportType exfat::m_GetUsed = FileSystem::cmdSupportNone; 0020 FileSystem::CommandSupportType exfat::m_GetLabel = FileSystem::cmdSupportNone; 0021 FileSystem::CommandSupportType exfat::m_Create = FileSystem::cmdSupportNone; 0022 FileSystem::CommandSupportType exfat::m_Grow = FileSystem::cmdSupportNone; 0023 FileSystem::CommandSupportType exfat::m_Shrink = FileSystem::cmdSupportNone; 0024 FileSystem::CommandSupportType exfat::m_Move = FileSystem::cmdSupportNone; 0025 FileSystem::CommandSupportType exfat::m_Check = FileSystem::cmdSupportNone; 0026 FileSystem::CommandSupportType exfat::m_Copy = FileSystem::cmdSupportNone; 0027 FileSystem::CommandSupportType exfat::m_Backup = FileSystem::cmdSupportNone; 0028 FileSystem::CommandSupportType exfat::m_SetLabel = FileSystem::cmdSupportNone; 0029 FileSystem::CommandSupportType exfat::m_UpdateUUID = FileSystem::cmdSupportNone; 0030 FileSystem::CommandSupportType exfat::m_GetUUID = FileSystem::cmdSupportNone; 0031 bool exfat::exfatUtils = false; 0032 0033 exfat::exfat(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, const QVariantMap& features) : 0034 FileSystem(firstsector, lastsector, sectorsused, label, features, FileSystem::Type::Exfat) 0035 { 0036 } 0037 0038 void exfat::init() 0039 { 0040 // Check if we are using exfat-utils or exfatprogs 0041 exfatUtils = findExternal(QStringLiteral("mkexfatfs")); 0042 if (exfatUtils) { 0043 m_Create = cmdSupportFileSystem; 0044 m_Check = findExternal(QStringLiteral("fsck.exfat"), {}, 1) ? cmdSupportFileSystem : cmdSupportNone; 0045 m_SetLabel = findExternal(QStringLiteral("exfatlabel")) ? cmdSupportFileSystem : cmdSupportNone; 0046 } 0047 else { 0048 m_Create = findExternal(QStringLiteral("mkfs.exfat"), {}, 1) ? cmdSupportFileSystem : cmdSupportNone; 0049 m_Check = findExternal(QStringLiteral("fsck.exfat"), {}, 16) ? cmdSupportFileSystem : cmdSupportNone; 0050 m_SetLabel = findExternal(QStringLiteral("tune.exfat")) ? cmdSupportFileSystem : cmdSupportNone; 0051 } 0052 0053 m_GetLabel = cmdSupportCore; 0054 m_UpdateUUID = cmdSupportNone; 0055 0056 m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; 0057 m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; 0058 0059 m_GetLabel = cmdSupportCore; 0060 m_Backup = cmdSupportCore; 0061 m_GetUUID = cmdSupportCore; 0062 } 0063 0064 bool exfat::supportToolFound() const 0065 { 0066 return 0067 // m_GetUsed != cmdSupportNone && 0068 m_GetLabel != cmdSupportNone && 0069 m_SetLabel != cmdSupportNone && 0070 m_Create != cmdSupportNone && 0071 m_Check != cmdSupportNone && 0072 // m_UpdateUUID != cmdSupportNone && 0073 // m_Grow != cmdSupportNone && 0074 // m_Shrink != cmdSupportNone && 0075 m_Copy != cmdSupportNone && 0076 m_Move != cmdSupportNone && 0077 m_Backup != cmdSupportNone && 0078 m_GetUUID != cmdSupportNone; 0079 } 0080 0081 FileSystem::SupportTool exfat::supportToolName() const 0082 { 0083 return SupportTool(QStringLiteral("exfatprogs"), QUrl(QStringLiteral("https://github.com/exfatprogs/exfatprogs"))); 0084 } 0085 0086 qint64 exfat::maxCapacity() const 0087 { 0088 return Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::EiB); 0089 } 0090 0091 int exfat::maxLabelLength() const 0092 { 0093 return 15; 0094 } 0095 0096 bool exfat::check(Report& report, const QString& deviceNode) const 0097 { 0098 ExternalCommand cmd(report, QStringLiteral("fsck.exfat"), { QStringLiteral("--repair-yes"), QStringLiteral("--verbose"), deviceNode }); 0099 return cmd.run(-1) && cmd.exitCode() == 0; 0100 } 0101 0102 bool exfat::create(Report& report, const QString& deviceNode) 0103 { 0104 ExternalCommand cmd(report, QStringLiteral("mkfs.exfat"), { deviceNode }); 0105 return cmd.run(-1) && cmd.exitCode() == 0; 0106 } 0107 0108 bool exfat::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) 0109 { 0110 ExternalCommand cmd(report); 0111 if (exfatUtils) { 0112 cmd.setCommand(QStringLiteral("exfatlabel")); 0113 cmd.setArgs({ deviceNode, newLabel }); 0114 } 0115 else { 0116 cmd.setCommand(QStringLiteral("tune.exfat")); 0117 cmd.setArgs({ deviceNode, QStringLiteral("-L"), newLabel }); 0118 } 0119 0120 return cmd.run(-1) && cmd.exitCode() == 0; 0121 } 0122 0123 bool exfat::updateUUID(Report& report, const QString& deviceNode) const 0124 { 0125 Q_UNUSED(report) 0126 Q_UNUSED(deviceNode) 0127 0128 return false; 0129 } 0130 }