File indexing completed on 2024-05-05 05:48:45

0001 /*
0002     SPDX-FileCopyrightText: 2008-2011 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2013-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/hfsplus.h"
0012 
0013 #include "util/externalcommand.h"
0014 #include "util/capacity.h"
0015 
0016 #include <QStringList>
0017 
0018 namespace FS
0019 {
0020 FileSystem::CommandSupportType hfsplus::m_GetLabel = FileSystem::cmdSupportNone;
0021 FileSystem::CommandSupportType hfsplus::m_GetUsed = FileSystem::cmdSupportNone;
0022 FileSystem::CommandSupportType hfsplus::m_Shrink = FileSystem::cmdSupportNone;
0023 FileSystem::CommandSupportType hfsplus::m_Move = FileSystem::cmdSupportNone;
0024 FileSystem::CommandSupportType hfsplus::m_Check = FileSystem::cmdSupportNone;
0025 FileSystem::CommandSupportType hfsplus::m_Create = FileSystem::cmdSupportNone;
0026 FileSystem::CommandSupportType hfsplus::m_Copy = FileSystem::cmdSupportNone;
0027 FileSystem::CommandSupportType hfsplus::m_Backup = FileSystem::cmdSupportNone;
0028 
0029 hfsplus::hfsplus(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, const QVariantMap& features) :
0030     FileSystem(firstsector, lastsector, sectorsused, label, features, FileSystem::Type::HfsPlus)
0031 {
0032 }
0033 
0034 void hfsplus::init()
0035 {
0036     m_Check = findExternal(QStringLiteral("fsck.hfsplus")) ? cmdSupportFileSystem : cmdSupportNone;
0037     m_Create = findExternal(QStringLiteral("mkfs.hfsplus")) ? cmdSupportFileSystem : cmdSupportNone;
0038     m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone;
0039     m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone;
0040     m_Backup = cmdSupportCore;
0041     m_GetLabel = cmdSupportCore;
0042 }
0043 
0044 bool hfsplus::supportToolFound() const
0045 {
0046     return
0047 //          m_GetUsed != cmdSupportNone &&
0048         m_GetLabel != cmdSupportNone &&
0049 //          m_SetLabel != cmdSupportNone &&
0050         m_Create != cmdSupportNone &&
0051         m_Check != cmdSupportNone &&
0052 //          m_UpdateUUID != cmdSupportNone &&
0053 //          m_Grow != cmdSupportNone &&
0054         m_Shrink != cmdSupportNone &&
0055         m_Copy != cmdSupportNone &&
0056         m_Move != cmdSupportNone &&
0057         m_Backup != cmdSupportNone;
0058 //         m_GetUUID != cmdSupportNone;
0059 }
0060 
0061 FileSystem::SupportTool hfsplus::supportToolName() const
0062 {
0063     return SupportTool(QStringLiteral("diskdev_cmds"), QUrl(QStringLiteral("https://opensource.apple.com/tarballs/diskdev_cmds/")));
0064 }
0065 
0066 qint64 hfsplus::maxCapacity() const
0067 {
0068     return Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::EiB);
0069 }
0070 
0071 int hfsplus::maxLabelLength() const
0072 {
0073     return 63;
0074 }
0075 
0076 bool hfsplus::check(Report& report, const QString& deviceNode) const
0077 {
0078     ExternalCommand cmd(report, QStringLiteral("fsck.hfsplus"), { deviceNode });
0079     return cmd.run(-1) && cmd.exitCode() == 0;
0080 }
0081 
0082 bool hfsplus::create(Report& report, const QString& deviceNode)
0083 {
0084     ExternalCommand cmd(report, QStringLiteral("mkfs.hfsplus"), { deviceNode });
0085     return cmd.run(-1) && cmd.exitCode() == 0;
0086 }
0087 
0088 }