~ubuntu-branches/ubuntu/trusty/gparted/trusty

« back to all changes in this revision

Viewing changes to src/btrfs.cc

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2010-10-30 11:08:59 UTC
  • mfrom: (6.3.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20101030110859-2pgeh1y8p7z8tsb6
Tags: 0.7.0-1
New upstream release
Fix gparted crash at start with glibmm-ERROR
Closes: 601818
LP: #609477, #617885
Fix crash moving more than one logical partition right
Closes: 601817
Skip move/copy action because linux swap contains no data
LP: #401228
Fix several memory leaks and valgrind errors
Remove unnecessary null pointer checks
Fix partitions moved or copied are 1 MiB larger
Insert additional translator comments
Add initial support for btrfs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2009,2010 Luca Bruno <lucab@debian.org>
 
2
 * Copyright (C) 2010 Curtis Gedak
 
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 Library 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 Free Software
 
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
 
 
20
#include "../include/btrfs.h"
 
21
 
 
22
namespace GParted
 
23
{
 
24
 
 
25
FS btrfs::get_filesystem_support()
 
26
{
 
27
        FS fs ;
 
28
        fs .filesystem = GParted::FS_BTRFS ;
 
29
 
 
30
        if ( ! Glib::find_program_in_path( "btrfs-show" ) .empty() )
 
31
        {
 
32
                fs .read = GParted::FS::EXTERNAL ;
 
33
                fs .read_label = FS::EXTERNAL ;
 
34
        }
 
35
 
 
36
        if ( ! Glib::find_program_in_path( "mkfs.btrfs" ) .empty() )
 
37
                fs .create = GParted::FS::EXTERNAL ;
 
38
 
 
39
        if ( ! Glib::find_program_in_path( "btrfsck" ) .empty() )
 
40
                fs .check = GParted::FS::EXTERNAL ;
 
41
 
 
42
        if ( fs .check )
 
43
        {
 
44
                fs .copy = GParted::FS::GPARTED ;
 
45
                fs .move = GParted::FS::GPARTED ;
 
46
        }
 
47
 
 
48
        fs .MIN = 256 * MEBIBYTE ;
 
49
 
 
50
        return fs ;
 
51
}
 
52
 
 
53
bool btrfs::create( const Partition & new_partition, OperationDetail & operationdetail )
 
54
{
 
55
        return (! execute_command( "mkfs.btrfs -L \"" + new_partition .label + "\" " + new_partition .get_path(), operationdetail ) );
 
56
}
 
57
 
 
58
bool btrfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
 
59
{
 
60
        return (! execute_command( "btrfsck " + partition .get_path(), operationdetail )) ;
 
61
}
 
62
 
 
63
void btrfs::set_used_sectors( Partition & partition )
 
64
{
 
65
        if ( ! Utils::execute_command( "btrfs-show " + partition .get_path(), output, error, true ) )
 
66
        {
 
67
                Glib::ustring size_label;
 
68
                if ( ((index = output .find( "FS bytes" )) < output .length()) &&
 
69
                          (size_label=Utils::regexp_label(output .substr( index ), "^FS bytes used (.*)B")) .length() > 0)
 
70
                {
 
71
                        gchar *suffix;
 
72
                        gdouble rawN = g_ascii_strtod (size_label.c_str(),&suffix);
 
73
                        unsigned long long mult=0;
 
74
                        switch(suffix[0]){
 
75
                                case 'K':
 
76
                                        mult=KIBIBYTE;
 
77
                                        break;
 
78
                                case 'M':
 
79
                                        mult=MEBIBYTE;
 
80
                                        break;
 
81
                                case 'G':
 
82
                                        mult=GIBIBYTE;
 
83
                                        break;
 
84
                                case 'T':
 
85
                                        mult=TEBIBYTE;
 
86
                                        break;
 
87
                                default:
 
88
                                        mult=1;
 
89
                                        break;
 
90
                                        }
 
91
                        partition .set_used( Utils::round( (rawN * mult)/ double(partition .sector_size) ) ) ;
 
92
                }
 
93
        }
 
94
        else
 
95
        {
 
96
                if ( ! output .empty() )
 
97
                        partition .messages .push_back( output ) ;
 
98
 
 
99
                if ( ! error .empty() )
 
100
                        partition .messages .push_back( error ) ;
 
101
        }
 
102
}
 
103
 
 
104
bool btrfs::write_label( const Partition & partition, OperationDetail & operationdetail )
 
105
{
 
106
// TODO
 
107
        return true ;
 
108
}
 
109
 
 
110
bool btrfs::move( const Partition & partition_new
 
111
                , const Partition & partition_old
 
112
                , OperationDetail & operationdetail
 
113
                )
 
114
{
 
115
        return true ;
 
116
}
 
117
 
 
118
bool btrfs::copy( const Glib::ustring & src_part_path,
 
119
                    const Glib::ustring & dest_part_path,
 
120
                    OperationDetail & operationdetail )
 
121
{
 
122
// TODO
 
123
        return true ;
 
124
}
 
125
 
 
126
bool btrfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
 
127
{
 
128
// TODO
 
129
        return true ;
 
130
}
 
131
 
 
132
void btrfs::read_label( Partition & partition )
 
133
{
 
134
        if ( ! Utils::execute_command( "btrfs-show " + partition .get_path(), output, error, true ) )
 
135
        {
 
136
                partition .label = Utils::regexp_label( output, "^Label ([^\n\t]*)" ) ;
 
137
        }
 
138
        else
 
139
        {
 
140
                if ( ! output .empty() )
 
141
                        partition .messages .push_back( output ) ;
 
142
 
 
143
                if ( ! error .empty() )
 
144
                        partition .messages .push_back( error ) ;
 
145
        }
 
146
 
 
147
}
 
148
 
 
149
} //GParted