~ubuntu-branches/ubuntu/intrepid/gparted/intrepid

« back to all changes in this revision

Viewing changes to src/jfs.cc

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-18 09:24:46 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070518092446-qog6ipxs9ah78q0c
Tags: 0.3.3-2ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/control:
    - Maintainer: Ubuntu Core Developers
      <ubuntu-devel-discuss@lists.ubuntu.com> 
    - don't depend on menu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        if ( ! Glib::find_program_in_path( "jfs_debugfs" ) .empty() )
32
32
                fs .read = GParted::FS::EXTERNAL ;
33
33
        
 
34
        if ( ! Glib::find_program_in_path( "jfs_tune" ) .empty() )
 
35
                fs .get_label = FS::EXTERNAL ;
 
36
        
34
37
        if ( ! Glib::find_program_in_path( "mkfs.jfs" ) .empty() )
35
38
                fs .create = GParted::FS::EXTERNAL ;
36
39
        
57
60
                        input .close() ;
58
61
                }
59
62
        }
60
 
        
61
 
        if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow )
62
 
                fs .copy = GParted::FS::EXTERNAL ;
 
63
 
 
64
 
 
65
        if ( fs .check )
 
66
        {
 
67
                fs .move = GParted::FS::GPARTED ;
 
68
                fs .copy = GParted::FS::GPARTED ;
 
69
        }
63
70
        
64
71
        fs .MIN = 16 * MEBIBYTE ;
65
72
        
66
73
        return fs ;
67
74
}
68
75
 
69
 
void jfs::Set_Used_Sectors( Partition & partition ) 
 
76
void jfs::set_used_sectors( Partition & partition ) 
70
77
{
71
78
        if ( ! Utils::execute_command( "echo dm | jfs_debugfs " + partition .get_path(), output, error, true ) )
72
79
        {
86
93
                        partition .Set_Unused( Utils::round( N * ( S / 512.0 ) ) ) ;
87
94
        }
88
95
        else
89
 
                partition .error = error ;
90
 
}
91
 
 
92
 
bool jfs::Create( const Partition & new_partition, std::vector<OperationDetails> & operation_details )
93
 
{
94
 
        operation_details .push_back( OperationDetails( String::ucompose(
95
 
                                                                _("create new %1 filesystem"),
96
 
                                                                Utils::get_filesystem_string( GParted::FS_JFS ) ) ) ) ;
97
 
        
98
 
        if ( ! execute_command( "mkfs.jfs -q " + new_partition .get_path(), operation_details .back() .sub_details ) )
99
 
        {
100
 
                operation_details .back() .status = OperationDetails::SUCCES ;
101
 
                return true ;
102
 
        }
103
 
        else
104
 
        {
105
 
                operation_details .back() .status = OperationDetails::ERROR ;
106
 
                return false ;
107
 
        }
108
 
}
109
 
 
110
 
bool jfs::Resize( const Partition & partition_new,
111
 
                  std::vector<OperationDetails> & operation_details,
112
 
                  bool fill_partition )
113
 
{
114
 
        if ( fill_partition )
115
 
                operation_details .push_back( OperationDetails( _("grow filesystem to fill the partition") ) ) ;
116
 
        else
117
 
                operation_details .push_back( OperationDetails( _("resize the filesystem") ) ) ;
118
 
        
 
96
        {
 
97
                if ( ! output .empty() )
 
98
                        partition .messages .push_back( output ) ;
 
99
                
 
100
                if ( ! error .empty() )
 
101
                        partition .messages .push_back( error ) ;
 
102
        }
 
103
}
 
104
 
 
105
void jfs::get_label( Partition & partition )
 
106
{
 
107
        if ( ! Utils::execute_command( "jfs_tune -l " + partition .get_path(), output, error, true ) )
 
108
        {
 
109
                char buf[512] ;
 
110
                index = output .find( "Volume label:" ) ;
 
111
 
 
112
                if ( index < output .length() && sscanf( output .substr( index ) .c_str(), "Volume label: %512s", buf ) == 1 )
 
113
                {
 
114
                        partition .label = buf ;
 
115
 
 
116
                        //remove '' from the label..
 
117
                        if ( partition .label .size() > 0 && partition .label[0] == '\'' )
 
118
                                partition .label = partition .label .substr( 1 ) ;
 
119
 
 
120
                        if ( partition .label .size() > 0 && partition .label[ partition .label .size() -1 ] == '\'' )
 
121
                                partition .label = partition .label .substr( 0, partition .label .size() -1 ) ;
 
122
                }
 
123
        }
 
124
        else
 
125
        {
 
126
                if ( ! output .empty() )
 
127
                        partition .messages .push_back( output ) ;
 
128
                
 
129
                if ( ! error .empty() )
 
130
                        partition .messages .push_back( error ) ;
 
131
        }
 
132
}
 
133
 
 
134
bool jfs::create( const Partition & new_partition, OperationDetail & operationdetail )
 
135
{
 
136
        return ! execute_command( "mkfs.jfs -q " + new_partition .get_path(), operationdetail ) ;
 
137
}
 
138
 
 
139
bool jfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
 
140
{
119
141
        bool return_value = false ;
120
142
        Glib::ustring error ;
121
143
        Glib::ustring TEMP_MP = Glib::get_tmp_dir() + "/gparted_tmp_jfs_mountpoint" ;
122
144
        
123
145
        //create mountpoint...
124
 
        operation_details .back() .sub_details .push_back(
125
 
                OperationDetails( String::ucompose( _("create temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
 
146
        operationdetail .add_child( OperationDetail( String::ucompose( _("create temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
126
147
        if ( ! mkdir( TEMP_MP .c_str(), 0 ) )
127
148
        {
128
 
                operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
 
149
                operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
129
150
 
130
151
                //mount partition
131
 
                operation_details .back() .sub_details .push_back(
132
 
                        OperationDetails( String::ucompose( _("mount %1 on %2"), partition_new .get_path(), TEMP_MP ) ) ) ;
 
152
                operationdetail .add_child(
 
153
                        OperationDetail( String::ucompose( _("mount %1 on %2"), partition_new .get_path(), TEMP_MP ) ) ) ;
133
154
                
134
155
                if ( ! execute_command( "mount -v -t jfs " + partition_new .get_path() + " " + TEMP_MP,
135
 
                                        operation_details .back() .sub_details .back() .sub_details ) )
 
156
                                        operationdetail .get_last_child() ) )
136
157
                {
137
 
                        operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
 
158
                        operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
138
159
                        
139
160
                        //remount the partition to resize the filesystem
140
 
                        operation_details .back() .sub_details .push_back(
141
 
                                OperationDetails( String::ucompose( _("remount %1 on %2 with the 'resize' flag enabled"),
142
 
                                                        partition_new .get_path(), TEMP_MP ) ) ) ;
 
161
                        operationdetail .add_child(
 
162
                                OperationDetail( String::ucompose( _("remount %1 on %2 with the 'resize' flag enabled"),
 
163
                                                                   partition_new .get_path(),
 
164
                                                                   TEMP_MP ) ) ) ;
143
165
                        
144
 
                        if ( ! execute_command( "mount -v -t jfs -o remount,resize " + partition_new .get_path() + " " + TEMP_MP,
145
 
                                                operation_details .back() .sub_details .back() .sub_details ) )
 
166
                        if ( ! execute_command( 
 
167
                                        "mount -v -t jfs -o remount,resize " + partition_new .get_path() + " " + TEMP_MP,
 
168
                                        operationdetail .get_last_child() ) )
146
169
                        {
147
 
                                operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
 
170
                                operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
148
171
                                return_value = true ;
149
172
                        }
150
173
                        else
151
174
                        {
152
 
                                operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
 
175
                                operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
153
176
                        }
154
177
                        
155
178
                        //and unmount it...
156
 
                        operation_details .back() .sub_details .push_back(
157
 
                                OperationDetails( String::ucompose( _("unmount %1"), partition_new .get_path() ) ) ) ;
 
179
                        operationdetail .add_child(
 
180
                                OperationDetail( String::ucompose( _("unmount %1"), partition_new .get_path() ) ) ) ;
158
181
                
159
182
                        if ( ! execute_command( "umount -v " + partition_new .get_path(),
160
 
                                                operation_details .back() .sub_details .back() .sub_details ) )
 
183
                                                operationdetail .get_last_child() ) )
161
184
                        {
162
 
                                operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
 
185
                                operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
163
186
                        }
164
187
                        else
165
188
                        {
166
 
                                operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
 
189
                                operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
167
190
                                return_value = false ;
168
191
                        }
169
192
                }
170
193
                else
171
194
                {
172
 
                        operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
 
195
                        operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
173
196
                }
174
197
                
175
198
                //remove the mountpoint..
176
 
                operation_details .back() .sub_details .push_back(
177
 
                        OperationDetails( String::ucompose( _("remove temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
 
199
                operationdetail .add_child(
 
200
                        OperationDetail( String::ucompose( _("remove temporary mountpoint (%1)"), TEMP_MP ) ) ) ;
178
201
                if ( ! rmdir( TEMP_MP .c_str() ) )
179
202
                {
180
 
                        operation_details .back() .sub_details .back() .status = OperationDetails::SUCCES ;
 
203
                        operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
181
204
                }
182
205
                else
183
206
                {
184
 
                        operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
185
 
                        operation_details .back() .sub_details .back() .sub_details .push_back(
186
 
                                OperationDetails( Glib::strerror( errno ), OperationDetails::NONE ) ) ;
 
207
                        operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
 
208
                        operationdetail .get_last_child() .add_child( 
 
209
                                OperationDetail( Glib::strerror( errno ), STATUS_NONE ) ) ;
187
210
 
188
211
                        return_value = false ;
189
212
                }
190
213
        }
191
214
        else
192
215
        {
193
 
                operation_details .back() .sub_details .back() .status = OperationDetails::ERROR ;
194
 
                operation_details .back() .sub_details .back() .sub_details .push_back(
195
 
                        OperationDetails( Glib::strerror( errno ), OperationDetails::NONE ) ) ;
 
216
                operationdetail .get_last_child() .set_status( STATUS_ERROR ) ;
 
217
                operationdetail .get_last_child() .add_child( 
 
218
                        OperationDetail( Glib::strerror( errno ), STATUS_NONE ) ) ;
196
219
        }
197
220
        
198
 
        operation_details .back() .status = return_value ? OperationDetails::SUCCES : OperationDetails::ERROR ;
199
221
        return return_value ;
200
222
}
201
223
 
202
 
bool jfs::Copy( const Glib::ustring & src_part_path, 
 
224
bool jfs::copy( const Glib::ustring & src_part_path, 
203
225
                const Glib::ustring & dest_part_path,
204
 
                std::vector<OperationDetails> & operation_details )
 
226
                OperationDetail & operationdetail )
205
227
{
206
 
        operation_details .push_back( OperationDetails( 
207
 
                                String::ucompose( _("copy contents of %1 to %2"), src_part_path, dest_part_path ) ) ) ;
208
 
        
209
 
        if ( ! execute_command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path,
210
 
                                operation_details .back() .sub_details ) )
211
 
        {
212
 
                operation_details .back() .status = OperationDetails::SUCCES ;
213
 
                return true ;
214
 
                
215
 
        }
216
 
        else
217
 
        {
218
 
                operation_details .back() .status = OperationDetails::ERROR ;
219
 
                return false ;
220
 
        }
 
228
        return true ;
221
229
}
222
230
 
223
 
bool jfs::Check_Repair( const Partition & partition, std::vector<OperationDetails> & operation_details )
 
231
bool jfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
224
232
{
225
 
        operation_details .push_back( OperationDetails( 
226
 
                                String::ucompose( _("check filesystem on %1 for errors and (if possible) fix them"),
227
 
                                                  partition .get_path() ) ) ) ;
 
233
        exit_status = execute_command( "jfs_fsck -f " + partition .get_path(), operationdetail ) ;
228
234
 
229
 
        exit_status = execute_command( "jfs_fsck -f " + partition .get_path(), operation_details .back() .sub_details ) ;
230
 
        if ( exit_status == 0 || exit_status == 1 )
231
 
        {
232
 
                operation_details .back() .status = OperationDetails::SUCCES ;
233
 
                return true ;
234
 
        }
235
 
        else
236
 
        {
237
 
                operation_details .back() .status = OperationDetails::ERROR ;
238
 
                return false ;
239
 
        }
 
235
        return ( exit_status == 0 || exit_status == 1 ) ;
240
236
}
241
237
 
242
238
} //GParted