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
***************************************************************************/
20
#include "fs/reiserfs.h"
22
#include "util/externalcommand.h"
23
#include "util/capacity.h"
26
#include <QStringList>
29
#include <uuid/uuid.h>
33
FileSystem::SupportType reiserfs::m_GetUsed = FileSystem::SupportNone;
34
FileSystem::SupportType reiserfs::m_GetLabel = FileSystem::SupportNone;
35
FileSystem::SupportType reiserfs::m_Create = FileSystem::SupportNone;
36
FileSystem::SupportType reiserfs::m_Grow = FileSystem::SupportNone;
37
FileSystem::SupportType reiserfs::m_Shrink = FileSystem::SupportNone;
38
FileSystem::SupportType reiserfs::m_Move = FileSystem::SupportNone;
39
FileSystem::SupportType reiserfs::m_Check = FileSystem::SupportNone;
40
FileSystem::SupportType reiserfs::m_Copy = FileSystem::SupportNone;
41
FileSystem::SupportType reiserfs::m_Backup = FileSystem::SupportNone;
42
FileSystem::SupportType reiserfs::m_SetLabel = FileSystem::SupportNone;
43
FileSystem::SupportType reiserfs::m_UpdateUUID = FileSystem::SupportNone;
45
reiserfs::reiserfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
46
FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::ReiserFS)
52
m_GetLabel = m_GetUsed = findExternal("debugreiserfs", QStringList(), 16) ? SupportExternal : SupportNone;
53
m_SetLabel = findExternal("reiserfstune") ? SupportExternal : SupportNone;
54
m_Create = findExternal("mkfs.reiserfs") ? SupportExternal : SupportNone;
55
m_Check = findExternal("fsck.reiserfs") ? SupportExternal : SupportNone;
56
m_Move = m_Copy = (m_Check != SupportNone) ? SupportInternal : SupportNone;
57
m_Grow = findExternal("resize_reiserfs", QStringList(), 16) ? SupportExternal : SupportNone;
58
m_Shrink = (m_GetUsed != SupportNone && m_Grow != SupportNone) ? SupportExternal : SupportNone;
59
m_Backup = SupportInternal;
60
m_UpdateUUID = findExternal("reiserfstune") ? SupportExternal : SupportNone;
63
qint64 reiserfs::minCapacity() const
65
return 32 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
68
qint64 reiserfs::maxCapacity() const
70
return 16 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB);
73
qint64 reiserfs::readUsedCapacity(const QString& deviceNode) const
75
ExternalCommand cmd("debugreiserfs", QStringList() << deviceNode);
79
qint64 blockCount = -1;
80
QRegExp rxBlockCount("Count of blocks[^:]+: (\\d+)");
82
if (rxBlockCount.indexIn(cmd.output()) != -1)
83
blockCount = rxBlockCount.cap(1).toLongLong();
85
qint64 blockSize = -1;
86
QRegExp rxBlockSize("Blocksize: (\\d+)");
88
if (rxBlockSize.indexIn(cmd.output()) != -1)
89
blockSize = rxBlockSize.cap(1).toLongLong();
91
qint64 freeBlocks = -1;
92
QRegExp rxFreeBlocks("Free blocks[^:]+: (\\d+)");
94
if (rxFreeBlocks.indexIn(cmd.output()) != -1)
95
freeBlocks = rxFreeBlocks.cap(1).toLongLong();
97
if (blockCount > -1 && blockSize > -1 && freeBlocks > -1)
98
return (blockCount - freeBlocks) * blockSize;
104
QString reiserfs::readLabel(const QString& deviceNode) const
106
ExternalCommand cmd("debugreiserfs", QStringList() << deviceNode);
110
QRegExp rxLabel("LABEL: (\\w+)");
112
if (rxLabel.indexIn(cmd.output()) != -1)
113
return rxLabel.cap(1).simplified();
119
bool reiserfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel)
121
return ExternalCommand(report, "reiserfstune", QStringList() << "-l" << newLabel << deviceNode).run(-1);
124
bool reiserfs::check(Report& report, const QString& deviceNode) const
126
ExternalCommand cmd(report, "fsck.reiserfs", QStringList() << "--fix-fixable" << "-q" << "-y" << deviceNode);
127
return cmd.run(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 1 || cmd.exitCode() == 256);
130
bool reiserfs::create(Report& report, const QString& deviceNode) const
132
return ExternalCommand(report, "mkfs.reiserfs", QStringList() << "-f" << deviceNode).run(-1);
135
bool reiserfs::resize(Report& report, const QString& deviceNode, qint64 length) const
137
ExternalCommand cmd(report, "resize_reiserfs", QStringList() << deviceNode << "-q" << "-s" << QString::number(length));
139
bool rval = cmd.start(-1);
144
if (cmd.write("y\n", 2) != 2)
147
return cmd.waitFor(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 256);
150
bool reiserfs::updateUUID(Report& report, const QString& deviceNode) const
152
unsigned char uuid[16];
155
uuid_unparse(uuid, uuid_ascii);
157
return ExternalCommand(report, "reiserfstune", QStringList() << "-u" << uuid_ascii << deviceNode).run(-1);