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/reiser4.h"
22
#include "util/externalcommand.h"
24
#include <QStringList>
29
FileSystem::SupportType reiser4::m_GetUsed = FileSystem::SupportNone;
30
FileSystem::SupportType reiser4::m_GetLabel = FileSystem::SupportNone;
31
FileSystem::SupportType reiser4::m_Create = FileSystem::SupportNone;
32
FileSystem::SupportType reiser4::m_Move = FileSystem::SupportNone;
33
FileSystem::SupportType reiser4::m_Check = FileSystem::SupportNone;
34
FileSystem::SupportType reiser4::m_Copy = FileSystem::SupportNone;
35
FileSystem::SupportType reiser4::m_Backup = FileSystem::SupportNone;
37
reiser4::reiser4(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
38
FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Reiser4)
44
m_GetUsed = m_GetLabel = findExternal("debugfs.reiser4", QStringList(), 16) ? SupportExternal : SupportNone;
45
m_Create = findExternal("mkfs.reiser4", QStringList(), 16) ? SupportExternal : SupportNone;
46
m_Check = findExternal("fsck.reiser4", QStringList(), 16) ? SupportExternal : SupportNone;
47
m_Move = m_Copy = (m_Check != SupportNone) ? SupportInternal : SupportNone;
48
m_Backup = SupportInternal;
51
qint64 reiser4::readUsedCapacity(const QString& deviceNode) const
53
ExternalCommand cmd("debugfs.reiser4", QStringList() << deviceNode);
58
QRegExp rxBlocks("blocks:\\s+(\\d+)");
60
if (rxBlocks.indexIn(cmd.output()) != -1)
61
blocks = rxBlocks.cap(1).toLongLong();
63
qint64 blockSize = -1;
64
QRegExp rxBlockSize("blksize:\\s+(\\d+)");
66
if (rxBlockSize.indexIn(cmd.output()) != -1)
67
blockSize = rxBlockSize.cap(1).toLongLong();
69
qint64 freeBlocks = -1;
70
QRegExp rxFreeBlocks("free blocks:\\s+(\\d+)");
72
if (rxFreeBlocks.indexIn(cmd.output()) != -1)
73
freeBlocks = rxFreeBlocks.cap(1).toLongLong();
75
if (blocks > - 1 && blockSize > -1 && freeBlocks > -1)
76
return (blocks - freeBlocks) * blockSize;
82
QString reiser4::readLabel(const QString& deviceNode) const
84
ExternalCommand cmd("debugfs.reiser4", QStringList() << deviceNode);
88
QRegExp rxLabel("label:\\s+(<?\\w+>?)");
90
if (rxLabel.indexIn(cmd.output()) != -1 && rxLabel.cap(1) != "<none>")
91
return rxLabel.cap(1);
97
bool reiser4::check(Report& report, const QString& deviceNode) const
99
ExternalCommand cmd(report, "fsck.reiser4", QStringList() << "--fix" << "-y" << deviceNode);
100
return cmd.run(-1) && cmd.exitCode() == 0;
103
bool reiser4::create(Report& report, const QString& deviceNode) const
105
return ExternalCommand(report, "mkfs.reiser4", QStringList() << "--yes" << deviceNode).run(-1);