1 /*
2 SPDX-FileCopyrightText: 2008-2011 Volker Lanz <vl@fidra.de>
3 SPDX-FileCopyrightText: 2013-2018 Andrius Štikonas <andrius@stikonas.eu>
4 SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net>
5 SPDX-FileCopyrightText: 2020 Arnaud Ferraris <arnaud.ferraris@collabora.com>
6 SPDX-FileCopyrightText: 2020 Gaël PORTAY <gael.portay@collabora.com>
7
8 SPDX-License-Identifier: GPL-3.0-or-later
9 */
10
11 #include "fs/hfsplus.h"
12
13 #include "util/externalcommand.h"
14 #include "util/capacity.h"
15
16 #include <QStringList>
17
18 namespace FS
19 {
20 FileSystem::CommandSupportType hfsplus::m_GetLabel = FileSystem::cmdSupportNone;
21 FileSystem::CommandSupportType hfsplus::m_GetUsed = FileSystem::cmdSupportNone;
22 FileSystem::CommandSupportType hfsplus::m_Shrink = FileSystem::cmdSupportNone;
23 FileSystem::CommandSupportType hfsplus::m_Move = FileSystem::cmdSupportNone;
24 FileSystem::CommandSupportType hfsplus::m_Check = FileSystem::cmdSupportNone;
25 FileSystem::CommandSupportType hfsplus::m_Create = FileSystem::cmdSupportNone;
26 FileSystem::CommandSupportType hfsplus::m_Copy = FileSystem::cmdSupportNone;
27 FileSystem::CommandSupportType hfsplus::m_Backup = FileSystem::cmdSupportNone;
28
hfsplus(qint64 firstsector,qint64 lastsector,qint64 sectorsused,const QString & label,const QVariantMap & features)29 hfsplus::hfsplus(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, const QVariantMap& features) :
30 FileSystem(firstsector, lastsector, sectorsused, label, features, FileSystem::Type::HfsPlus)
31 {
32 }
33
init()34 void hfsplus::init()
35 {
36 m_Check = findExternal(QStringLiteral("fsck.hfsplus")) ? cmdSupportFileSystem : cmdSupportNone;
37 m_Create = findExternal(QStringLiteral("mkfs.hfsplus")) ? cmdSupportFileSystem : cmdSupportNone;
38 m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone;
39 m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone;
40 m_Backup = cmdSupportCore;
41 m_GetLabel = cmdSupportCore;
42 }
43
supportToolFound() const44 bool hfsplus::supportToolFound() const
45 {
46 return
47 // m_GetUsed != cmdSupportNone &&
48 m_GetLabel != cmdSupportNone &&
49 // m_SetLabel != cmdSupportNone &&
50 m_Create != cmdSupportNone &&
51 m_Check != cmdSupportNone &&
52 // m_UpdateUUID != cmdSupportNone &&
53 // m_Grow != cmdSupportNone &&
54 m_Shrink != cmdSupportNone &&
55 m_Copy != cmdSupportNone &&
56 m_Move != cmdSupportNone &&
57 m_Backup != cmdSupportNone;
58 // m_GetUUID != cmdSupportNone;
59 }
60
supportToolName() const61 FileSystem::SupportTool hfsplus::supportToolName() const
62 {
63 return SupportTool(QStringLiteral("diskdev_cmds"), QUrl(QStringLiteral("https://opensource.apple.com/tarballs/diskdev_cmds/")));
64 }
65
maxCapacity() const66 qint64 hfsplus::maxCapacity() const
67 {
68 return Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::EiB);
69 }
70
maxLabelLength() const71 int hfsplus::maxLabelLength() const
72 {
73 return 63;
74 }
75
check(Report & report,const QString & deviceNode) const76 bool hfsplus::check(Report& report, const QString& deviceNode) const
77 {
78 ExternalCommand cmd(report, QStringLiteral("fsck.hfsplus"), { deviceNode });
79 return cmd.run(-1) && cmd.exitCode() == 0;
80 }
81
create(Report & report,const QString & deviceNode)82 bool hfsplus::create(Report& report, const QString& deviceNode)
83 {
84 ExternalCommand cmd(report, QStringLiteral("mkfs.hfsplus"), { deviceNode });
85 return cmd.run(-1) && cmd.exitCode() == 0;
86 }
87
88 }
89