~ubuntu-branches/ubuntu/oneiric/partitionmanager/oneiric

« back to all changes in this revision

Viewing changes to src/fs/reiser4.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-01-23 17:57:36 UTC
  • Revision ID: james.westby@ubuntu.com-20090123175736-2ltrhgg3m55dokbm
Tags: upstream-1.0.0~beta1a
ImportĀ upstreamĀ versionĀ 1.0.0~beta1a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008 by Volker Lanz <vl@fidra.de>                       *
 
3
 *                                                                         *
 
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.                                   *
 
8
 *                                                                         *
 
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.                          *
 
13
 *                                                                         *
 
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
 ***************************************************************************/
 
19
 
 
20
#include "fs/reiser4.h"
 
21
 
 
22
#include "util/externalcommand.h"
 
23
 
 
24
#include <QStringList>
 
25
#include <QRegExp>
 
26
 
 
27
namespace FS
 
28
{
 
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;
 
36
 
 
37
        reiser4::reiser4(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
 
38
                FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Reiser4)
 
39
        {
 
40
        }
 
41
 
 
42
        void reiser4::init()
 
43
        {
 
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;
 
49
        }
 
50
 
 
51
        qint64 reiser4::readUsedCapacity(const QString& deviceNode) const
 
52
        {
 
53
                ExternalCommand cmd("debugfs.reiser4", QStringList() << deviceNode);
 
54
 
 
55
                if (cmd.run())
 
56
                {
 
57
                        qint64 blocks = -1;
 
58
                        QRegExp rxBlocks("blocks:\\s+(\\d+)");
 
59
 
 
60
                        if (rxBlocks.indexIn(cmd.output()) != -1)
 
61
                                blocks = rxBlocks.cap(1).toLongLong();
 
62
                        
 
63
                        qint64 blockSize = -1;
 
64
                        QRegExp rxBlockSize("blksize:\\s+(\\d+)");
 
65
 
 
66
                        if (rxBlockSize.indexIn(cmd.output()) != -1)
 
67
                                blockSize = rxBlockSize.cap(1).toLongLong();
 
68
 
 
69
                        qint64 freeBlocks = -1;
 
70
                        QRegExp rxFreeBlocks("free blocks:\\s+(\\d+)");
 
71
 
 
72
                        if (rxFreeBlocks.indexIn(cmd.output()) != -1)
 
73
                                freeBlocks = rxFreeBlocks.cap(1).toLongLong();
 
74
 
 
75
                        if (blocks > - 1 && blockSize > -1 && freeBlocks > -1)
 
76
                                return (blocks - freeBlocks) * blockSize;
 
77
                }
 
78
 
 
79
                return -1;
 
80
        }
 
81
 
 
82
        QString reiser4::readLabel(const QString& deviceNode) const
 
83
        {
 
84
                ExternalCommand cmd("debugfs.reiser4", QStringList() << deviceNode);
 
85
 
 
86
                if (cmd.run())
 
87
                {
 
88
                        QRegExp rxLabel("label:\\s+(<?\\w+>?)");
 
89
 
 
90
                        if (rxLabel.indexIn(cmd.output()) != -1 && rxLabel.cap(1) != "<none>")
 
91
                                return rxLabel.cap(1);
 
92
                }
 
93
                
 
94
                return QString();
 
95
        }
 
96
 
 
97
        bool reiser4::check(Report& report, const QString& deviceNode) const
 
98
        {
 
99
                ExternalCommand cmd(report, "fsck.reiser4", QStringList() << "--fix" << "-y" << deviceNode);
 
100
                return cmd.run(-1) && cmd.exitCode() == 0;
 
101
        }
 
102
 
 
103
        bool reiser4::create(Report& report, const QString& deviceNode) const
 
104
        {
 
105
                return ExternalCommand(report, "mkfs.reiser4", QStringList() << "--yes" << deviceNode).run(-1);
 
106
        }
 
107
}