File indexing completed on 2024-05-05 05:48:48
0001 /* 0002 SPDX-FileCopyrightText: 2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2012-2018 Andrius Štikonas <andrius@stikonas.eu> 0004 SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net> 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/zfs.h" 0012 0013 #include "util/externalcommand.h" 0014 #include "util/capacity.h" 0015 #include "util/report.h" 0016 0017 #include <QString> 0018 0019 namespace FS 0020 { 0021 FileSystem::CommandSupportType zfs::m_GetUsed = FileSystem::cmdSupportNone; 0022 FileSystem::CommandSupportType zfs::m_GetLabel = FileSystem::cmdSupportNone; 0023 FileSystem::CommandSupportType zfs::m_Create = FileSystem::cmdSupportNone; 0024 FileSystem::CommandSupportType zfs::m_Grow = FileSystem::cmdSupportNone; 0025 FileSystem::CommandSupportType zfs::m_Shrink = FileSystem::cmdSupportNone; 0026 FileSystem::CommandSupportType zfs::m_Move = FileSystem::cmdSupportNone; 0027 FileSystem::CommandSupportType zfs::m_Check = FileSystem::cmdSupportNone; 0028 FileSystem::CommandSupportType zfs::m_Copy = FileSystem::cmdSupportNone; 0029 FileSystem::CommandSupportType zfs::m_Backup = FileSystem::cmdSupportNone; 0030 FileSystem::CommandSupportType zfs::m_SetLabel = FileSystem::cmdSupportNone; 0031 FileSystem::CommandSupportType zfs::m_UpdateUUID = FileSystem::cmdSupportNone; 0032 FileSystem::CommandSupportType zfs::m_GetUUID = FileSystem::cmdSupportNone; 0033 0034 zfs::zfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, const QVariantMap& features) : 0035 FileSystem(firstsector, lastsector, sectorsused, label, features, FileSystem::Type::Zfs) 0036 { 0037 } 0038 0039 void zfs::init() 0040 { 0041 m_SetLabel = findExternal(QStringLiteral("zpool"), {}, 2) ? cmdSupportFileSystem : cmdSupportNone; 0042 0043 m_GetLabel = cmdSupportCore; 0044 m_Backup = cmdSupportCore; 0045 m_GetUUID = cmdSupportCore; 0046 } 0047 0048 bool zfs::supportToolFound() const 0049 { 0050 return 0051 // m_GetUsed != cmdSupportNone && 0052 m_GetLabel != cmdSupportNone && 0053 m_SetLabel != cmdSupportNone && 0054 // m_Create != cmdSupportNone && 0055 // m_Check != cmdSupportNone && 0056 // m_UpdateUUID != cmdSupportNone && 0057 // m_Grow != cmdSupportNone && 0058 // m_Shrink != cmdSupportNone && 0059 // m_Copy != cmdSupportNone && 0060 // m_Move != cmdSupportNone && 0061 m_Backup != cmdSupportNone && 0062 m_GetUUID != cmdSupportNone; 0063 } 0064 0065 FileSystem::SupportTool zfs::supportToolName() const 0066 { 0067 return SupportTool(QStringLiteral("zfs"), QUrl(QStringLiteral("https://zfsonlinux.org/"))); 0068 } 0069 0070 qint64 zfs::minCapacity() const 0071 { 0072 return 64 * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB); 0073 } 0074 0075 qint64 zfs::maxCapacity() const 0076 { 0077 return Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::EiB); 0078 } 0079 0080 bool zfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) 0081 { 0082 Q_UNUSED(deviceNode) 0083 ExternalCommand cmd1(report, QStringLiteral("zpool"), { QStringLiteral("export"), label() }); 0084 ExternalCommand cmd2(report, QStringLiteral("zpool"), { QStringLiteral("import"), label(), newLabel }); 0085 return cmd1.run(-1) && cmd1.exitCode() == 0 && cmd2.run(-1) && cmd2.exitCode() == 0; 0086 } 0087 }