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

« back to all changes in this revision

Viewing changes to src/fs/hfs.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/hfs.h"
 
21
 
 
22
#include "util/externalcommand.h"
 
23
#include "util/capacity.h"
 
24
 
 
25
#include <QStringList>
 
26
#include <QRegExp>
 
27
 
 
28
namespace FS
 
29
{
 
30
        FileSystem::SupportType hfs::m_GetUsed = FileSystem::SupportNone;
 
31
        FileSystem::SupportType hfs::m_GetLabel = FileSystem::SupportNone;
 
32
        FileSystem::SupportType hfs::m_Create = FileSystem::SupportNone;
 
33
        FileSystem::SupportType hfs::m_Shrink = FileSystem::SupportNone;
 
34
        FileSystem::SupportType hfs::m_Move = FileSystem::SupportNone;
 
35
        FileSystem::SupportType hfs::m_Check = FileSystem::SupportNone;
 
36
        FileSystem::SupportType hfs::m_Copy = FileSystem::SupportNone;
 
37
        FileSystem::SupportType hfs::m_Backup = FileSystem::SupportNone;
 
38
 
 
39
        hfs::hfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
 
40
                FileSystem(firstsector, lastsector, sectorsused, label, FileSystem::Hfs)
 
41
        {
 
42
        }
 
43
 
 
44
        void hfs::init()
 
45
        {
 
46
                m_Create = findExternal("hformat") ? SupportExternal : SupportNone;
 
47
                m_Check = m_GetLabel = findExternal("hfsck") ? SupportExternal : SupportNone;
 
48
 
 
49
                m_GetUsed = SupportLibParted;
 
50
                m_Shrink = SupportLibParted;
 
51
 
 
52
                m_Move = m_Copy = (m_Check != SupportNone) ? SupportInternal : SupportNone;
 
53
                m_Backup = SupportInternal;
 
54
        }
 
55
 
 
56
        qint64 hfs::maxCapacity() const
 
57
        {
 
58
                 return 2 * Capacity::unitFactor(Capacity::Byte, Capacity::TiB);
 
59
        }
 
60
        
 
61
        QString hfs::readLabel(const QString& deviceNode) const
 
62
        {
 
63
                ExternalCommand cmd("hfsck", QStringList() << "-v" << deviceNode);
 
64
 
 
65
                if (cmd.run())
 
66
                {
 
67
                        QRegExp rxVolumeName("drVN\\s*= \"(\\w+)\"");
 
68
 
 
69
                        if (rxVolumeName.indexIn(cmd.output()) != -1)
 
70
                                return rxVolumeName.cap(1);
 
71
                }
 
72
 
 
73
                return QString();
 
74
        }
 
75
 
 
76
        bool hfs::check(Report& report, const QString& deviceNode) const
 
77
        {
 
78
                ExternalCommand cmd(report, "hfsck", QStringList() << "-v" << deviceNode);
 
79
                return cmd.run(-1) && cmd.exitCode() == 0;
 
80
        }
 
81
 
 
82
        bool hfs::create(Report& report, const QString& deviceNode) const
 
83
        {
 
84
                return ExternalCommand(report, "hformat", QStringList() << deviceNode).run(-1);
 
85
        }
 
86
}