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