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

« back to all changes in this revision

Viewing changes to src/fs/reiserfs.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/reiserfs.h"
 
21
 
 
22
#include "util/externalcommand.h"
 
23
#include "util/capacity.h"
 
24
 
 
25
#include <QString>
 
26
#include <QStringList>
 
27
#include <QRegExp>
 
28
 
 
29
#include <uuid/uuid.h>
 
30
 
 
31
namespace FS
 
32
{
 
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;
 
44
 
 
45
        reiserfs::reiserfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
 
46
                FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::ReiserFS)
 
47
        {
 
48
        }
 
49
 
 
50
        void reiserfs::init()
 
51
        {
 
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;
 
61
        }
 
62
 
 
63
        qint64 reiserfs::minCapacity() const
 
64
        {
 
65
                return 32 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
 
66
        }
 
67
 
 
68
        qint64 reiserfs::maxCapacity() const
 
69
        {
 
70
                return 16 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB);
 
71
        }
 
72
        
 
73
        qint64 reiserfs::readUsedCapacity(const QString& deviceNode) const
 
74
        {
 
75
                ExternalCommand cmd("debugreiserfs", QStringList() << deviceNode);
 
76
 
 
77
                if (cmd.run())
 
78
                {
 
79
                        qint64 blockCount = -1;
 
80
                        QRegExp rxBlockCount("Count of blocks[^:]+: (\\d+)");
 
81
 
 
82
                        if (rxBlockCount.indexIn(cmd.output()) != -1)
 
83
                                blockCount = rxBlockCount.cap(1).toLongLong();
 
84
                        
 
85
                        qint64 blockSize = -1;
 
86
                        QRegExp rxBlockSize("Blocksize: (\\d+)");
 
87
 
 
88
                        if (rxBlockSize.indexIn(cmd.output()) != -1)
 
89
                                blockSize = rxBlockSize.cap(1).toLongLong();
 
90
 
 
91
                        qint64 freeBlocks = -1;
 
92
                        QRegExp rxFreeBlocks("Free blocks[^:]+: (\\d+)");
 
93
 
 
94
                        if (rxFreeBlocks.indexIn(cmd.output()) != -1)
 
95
                                freeBlocks = rxFreeBlocks.cap(1).toLongLong();
 
96
 
 
97
                        if (blockCount > -1 && blockSize > -1 && freeBlocks > -1)
 
98
                                return (blockCount - freeBlocks) * blockSize;
 
99
                }
 
100
 
 
101
                return -1;
 
102
        }
 
103
 
 
104
        QString reiserfs::readLabel(const QString& deviceNode) const
 
105
        {
 
106
                ExternalCommand cmd("debugreiserfs", QStringList() << deviceNode);
 
107
 
 
108
                if (cmd.run())
 
109
                {
 
110
                        QRegExp rxLabel("LABEL: (\\w+)");
 
111
 
 
112
                        if (rxLabel.indexIn(cmd.output()) != -1)
 
113
                                return rxLabel.cap(1).simplified();
 
114
                }
 
115
 
 
116
                return QString();
 
117
        }
 
118
 
 
119
        bool reiserfs::writeLabel(Report& report, const QString& deviceNode, const QString& newLabel)
 
120
        {
 
121
                return ExternalCommand(report, "reiserfstune", QStringList() << "-l" << newLabel << deviceNode).run(-1);
 
122
        }
 
123
 
 
124
        bool reiserfs::check(Report& report, const QString& deviceNode) const
 
125
        {
 
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);
 
128
        }
 
129
 
 
130
        bool reiserfs::create(Report& report, const QString& deviceNode) const
 
131
        {
 
132
                return ExternalCommand(report, "mkfs.reiserfs", QStringList() << "-f" << deviceNode).run(-1);
 
133
        }
 
134
        
 
135
        bool reiserfs::resize(Report& report, const QString& deviceNode, qint64 length) const
 
136
        {
 
137
                ExternalCommand cmd(report, "resize_reiserfs", QStringList() << deviceNode << "-q" << "-s" << QString::number(length));
 
138
                
 
139
                bool rval = cmd.start(-1);
 
140
                
 
141
                if (!rval)
 
142
                        return false;
 
143
 
 
144
                if (cmd.write("y\n", 2) != 2)
 
145
                        return false;
 
146
                
 
147
                return cmd.waitFor(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 256);
 
148
        }
 
149
 
 
150
        bool reiserfs::updateUUID(Report& report, const QString& deviceNode) const
 
151
        {
 
152
                unsigned char uuid[16];
 
153
                uuid_generate(uuid);
 
154
                char uuid_ascii[37];
 
155
                uuid_unparse(uuid, uuid_ascii);
 
156
                
 
157
                return ExternalCommand(report, "reiserfstune", QStringList() << "-u" << uuid_ascii << deviceNode).run(-1);
 
158
        }
 
159
}