1
/***************************************************************************
2
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18
***************************************************************************/
22
#include "util/externalcommand.h"
23
#include "util/report.h"
24
#include "util/capacity.h"
26
#include <QStringList>
36
FileSystem::SupportType jfs::m_GetUsed = FileSystem::SupportNone;
37
FileSystem::SupportType jfs::m_GetLabel = FileSystem::SupportNone;
38
FileSystem::SupportType jfs::m_Create = FileSystem::SupportNone;
39
FileSystem::SupportType jfs::m_Grow = FileSystem::SupportNone;
40
FileSystem::SupportType jfs::m_Move = FileSystem::SupportNone;
41
FileSystem::SupportType jfs::m_Check = FileSystem::SupportNone;
42
FileSystem::SupportType jfs::m_Copy = FileSystem::SupportNone;
43
FileSystem::SupportType jfs::m_Backup = FileSystem::SupportNone;
44
FileSystem::SupportType jfs::m_SetLabel = FileSystem::SupportNone;
46
jfs::jfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
47
FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Jfs)
53
m_GetUsed = findExternal("jfs_debugfs") ? SupportExternal : SupportNone;
54
m_SetLabel = m_GetLabel = findExternal("jfs_tune", QStringList() << "-V") ? SupportExternal : SupportNone;
55
m_Create = findExternal("mkfs.jfs", QStringList() << "-V") ? SupportExternal : SupportNone;
56
m_Grow = m_Check = findExternal("fsck.jfs", QStringList() << "-V") ? SupportExternal : SupportNone;
57
m_Copy = m_Move = (m_Check != SupportNone) ? SupportInternal : SupportNone;
58
m_Backup = SupportInternal;
61
qint64 jfs::minCapacity() const
63
return 16 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
66
qint64 jfs::readUsedCapacity(const QString& deviceNode) const
68
ExternalCommand cmd("jfs_debugfs", QStringList() << deviceNode);
70
if (cmd.start() && cmd.write("dm") == 2 && cmd.waitFor())
72
qint64 blockSize = -1;
73
QRegExp rxBlockSize("Block Size: (\\d+)");
75
if (rxBlockSize.indexIn(cmd.output()) != -1)
76
blockSize = rxBlockSize.cap(1).toLongLong();
79
QRegExp rxnBlocks("dn_mapsize:\\s+0x([0-9a-f]+)");
82
if (rxnBlocks.indexIn(cmd.output()) != -1)
84
nBlocks = rxnBlocks.cap(1).toLongLong(&ok, 16);
90
QRegExp rxnFree("dn_nfree:\\s+0x([0-9a-f]+)");
92
if (rxnFree.indexIn(cmd.output()) != -1)
94
nFree = rxnFree.cap(1).toLongLong(&ok, 16);
99
if (nBlocks > -1 && blockSize > -1 && nFree > -1)
100
return (nBlocks - nFree) * blockSize;
106
QString jfs::readLabel(const QString& deviceNode) const
108
ExternalCommand cmd("jfs_tune", QStringList() << "-l" << deviceNode);
112
QRegExp rxLabel("Volume label:\\s+'(\\w+)'");
114
if (rxLabel.indexIn(cmd.output()) != -1)
115
return rxLabel.cap(1).simplified();
121
bool jfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel)
123
return ExternalCommand(report, "jfs_tune", QStringList() << "-L" << newLabel << deviceNode).run(-1);
126
bool jfs::check(Report& report, const QString& deviceNode) const
128
ExternalCommand cmd(report, "fsck.jfs", QStringList() << "-f" << deviceNode);
129
return cmd.run(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 1);
132
bool jfs::create(Report& report, const QString& deviceNode) const
134
return ExternalCommand(report, "mkfs.jfs", QStringList() << "-q" << deviceNode).run(-1);
137
bool jfs::resize(Report& report, const QString& deviceNode, qint64) const
140
if (!tempDir.exists())
142
report.line() << i18nc("@info/plain", "Resizing JFS file system on partition <filename>%1</filename> failed: Could not create temp dir.", deviceNode);
148
ExternalCommand mountCmd(report, "mount", QStringList() << "-v" << "-t" << "jfs" << deviceNode << tempDir.name());
150
if (mountCmd.run(-1))
152
ExternalCommand resizeMountCmd(report, "mount", QStringList() << "-v" << "-t" << "jfs" << "-o" << "remount,resize" << deviceNode << tempDir.name());
154
if (resizeMountCmd.run(-1))
157
report.line() << i18nc("@info/plain", "Resizing JFS file system on partition <filename>%1</filename> failed: Remount failed.", deviceNode);
159
ExternalCommand unmountCmd(report, "umount", QStringList() << tempDir.name());
161
if (!unmountCmd.run(-1))
162
report.line() << i18nc("@info/plain", "Warning: Resizing JFS file system on partition <filename>%1</filename>: Unmount failed.", deviceNode);
165
report.line() << i18nc("@info/plain", "Resizing JFS file system on partition <filename>%1</filename> failed: Initial mount failed.", deviceNode);