1 /*
2     SPDX-FileCopyrightText: 2019 Shubham Jangra <aryan100jangid@gmail.com>
3     SPDX-FileCopyrightText: 2020 Arnaud Ferraris <arnaud.ferraris@collabora.com>
4     SPDX-FileCopyrightText: 2020 Gaël PORTAY <gael.portay@collabora.com>
5 
6     SPDX-License-Identifier: GPL-3.0-or-later
7 */
8 
9 #include "fs/minix.h"
10 
11 #include "util/capacity.h"
12 #include "util/externalcommand.h"
13 
14 #include <QString>
15 
16 namespace FS
17 {
18 FileSystem::CommandSupportType minix::m_GetLabel = FileSystem::cmdSupportNone;
19 FileSystem::CommandSupportType minix::m_GetUsed = FileSystem::cmdSupportNone;
20 FileSystem::CommandSupportType minix::m_Shrink = FileSystem::cmdSupportNone;
21 FileSystem::CommandSupportType minix::m_Move = FileSystem::cmdSupportNone;
22 FileSystem::CommandSupportType minix::m_Check = FileSystem::cmdSupportNone;
23 FileSystem::CommandSupportType minix::m_Create = FileSystem::cmdSupportNone;
24 FileSystem::CommandSupportType minix::m_Copy = FileSystem::cmdSupportNone;
25 FileSystem::CommandSupportType minix::m_Backup = FileSystem::cmdSupportNone;
26 
minix(qint64 firstsector,qint64 lastsector,qint64 sectorsused,const QString & label,const QVariantMap & features)27 minix::minix(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, const QVariantMap& features) :
28     FileSystem(firstsector, lastsector, sectorsused, label, features, FileSystem::Type::Minix)
29 {
30 }
31 
init()32 void minix::init()
33 {
34     m_Check = findExternal(QStringLiteral("fsck.minix"), {}, 16) ? cmdSupportFileSystem : cmdSupportNone;
35     m_Create = findExternal(QStringLiteral("mkfs.minix"), {}, 16) ? cmdSupportFileSystem : cmdSupportNone;
36     m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone;
37     m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone;
38     m_Backup = cmdSupportCore;
39     m_GetLabel = cmdSupportCore;
40 }
41 
supportToolFound() const42 bool minix::supportToolFound() const
43 {
44     return m_GetLabel != cmdSupportNone &&
45            m_Create != cmdSupportNone &&
46            m_Check != cmdSupportNone &&
47            m_Copy != cmdSupportNone &&
48            m_Move != cmdSupportNone &&
49            m_Backup != cmdSupportNone;
50 }
51 
supportToolName() const52 FileSystem::SupportTool minix::supportToolName() const
53 {
54     return SupportTool(QStringLiteral("util-linux"), QUrl(QStringLiteral("https://www.kernel.org/pub/linux/utils/util-linux/")));
55 }
56 
maxCapacity() const57 qint64 minix::maxCapacity() const
58 {
59     return 4 * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::GiB);
60 }
61 
maxLabelLength() const62 int minix::maxLabelLength() const
63 {
64     return 63;
65 }
66 
check(Report & report,const QString & deviceNode) const67 bool minix::check(Report& report, const QString& deviceNode) const
68 {
69     ExternalCommand cmd(report, QStringLiteral("fsck.minix"), { deviceNode });
70     return cmd.run(-1) && cmd.exitCode() == 0;
71 }
72 
create(Report & report,const QString & deviceNode)73 bool minix::create(Report& report, const QString& deviceNode)
74 {
75     ExternalCommand cmd(report, QStringLiteral("mkfs.minix"), { QStringLiteral("-3"), deviceNode });
76     return cmd.run(-1) && cmd.exitCode() == 0;
77 }
78 
79 }
80