-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index c944c6d..869c1b8 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -25,24 +25,25 @@ | |||
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "backuprestore.h" | 29 | #include "backuprestore.h" |
30 | #include "errordialog.h" | 30 | #include "errordialog.h" |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qpe/config.h> | 35 | #include <qpe/config.h> |
36 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
37 | #include <opie2/odevice.h> | ||
37 | #include <opie2/ostorageinfo.h> | 38 | #include <opie2/ostorageinfo.h> |
38 | #include <opie2/ofiledialog.h> | 39 | #include <opie2/ofiledialog.h> |
39 | #include <opie2/owait.h> | 40 | #include <opie2/owait.h> |
40 | using namespace Opie::Core; | 41 | using namespace Opie::Core; |
41 | using namespace Opie::Ui; | 42 | using namespace Opie::Ui; |
42 | 43 | ||
43 | /* QT */ | 44 | /* QT */ |
44 | #include <qapplication.h> | 45 | #include <qapplication.h> |
45 | #include <qmultilineedit.h> | 46 | #include <qmultilineedit.h> |
46 | #include <qdir.h> | 47 | #include <qdir.h> |
47 | #include <qfile.h> | 48 | #include <qfile.h> |
48 | #include <qfileinfo.h> | 49 | #include <qfileinfo.h> |
@@ -270,25 +271,109 @@ void BackupAndRestore::scanForApplicationSettings() | |||
270 | */ | 271 | */ |
271 | void BackupAndRestore::backup() | 272 | void BackupAndRestore::backup() |
272 | { | 273 | { |
273 | if ( cb_type_userdata->isChecked() ) | 274 | if ( cb_type_userdata->isChecked() ) |
274 | backupUserData(); | 275 | backupUserData(); |
275 | else | 276 | else |
276 | backupRootFs(); | 277 | backupRootFs(); |
277 | } | 278 | } |
278 | 279 | ||
279 | 280 | ||
280 | void BackupAndRestore::backupRootFs() | 281 | void BackupAndRestore::backupRootFs() |
281 | { | 282 | { |
282 | QMessageBox::critical(this, "Message", "Not Yet Implemented", "Ok" ); | 283 | //#define MDEBUG |
284 | #ifndef MDEBUG | ||
285 | QMessageBox::critical( this, "Opie-Backup", "<qt>This feature is not yet implemented.</qt>", "Bummer!" ); | ||
286 | return; | ||
287 | #endif | ||
288 | // call 'mount' and parse its output to gather the device on which the root partition is mounted | ||
289 | FILE* mountp = popen( "mount", "r" ); | ||
290 | QString device; | ||
291 | QString mountpoint; | ||
292 | { | ||
293 | QTextStream mounto( mountp, IO_ReadOnly ); | ||
294 | QString on; | ||
295 | QString type; | ||
296 | QString filesystem; | ||
297 | QString options; | ||
298 | while ( !mounto.atEnd() ) | ||
299 | { | ||
300 | mounto >> device >> on >> mountpoint >> type >> filesystem >> options; | ||
301 | if ( mountpoint == "/" ) break; | ||
302 | } | ||
303 | odebug << device << " is formatted w/ " << filesystem << " and mounted on " << mountpoint << oendl; | ||
304 | |||
305 | if ( !mountpoint.startsWith( "/dev/mtdblock" ) ) | ||
306 | { | ||
307 | QMessageBox::critical( this, "Can't backup!", QString( "<qt>unsupported rootfs %1 - needs to be /dev/mtdblockN</qt>").arg( device ), "Ok" ); | ||
308 | #ifndef MDEBUG | ||
309 | return; | ||
310 | #endif | ||
311 | } | ||
312 | } // at this point, the QTextStream has been destroy and we can close the FILE* | ||
313 | pclose( mountp ); | ||
314 | |||
315 | #ifndef MDEBUG | ||
316 | int rootmtd = device.right( 1 ).toInt(); | ||
317 | #else | ||
318 | int rootmtd = 0; | ||
319 | #endif | ||
320 | odebug << "root mtdblock seems to be '" << rootmtd << "'" << oendl; | ||
321 | |||
322 | // scan /proc/mtd to gather the size and erasesize of the root mtdblock | ||
323 | QFile procmtdf( "/proc/mtd" ); | ||
324 | if ( !procmtdf.open( IO_ReadOnly ) ) | ||
325 | { | ||
326 | QMessageBox::critical( this, "Can't backup!", "<qt>Can't open /proc/mtd</qt>", "Ok" ); | ||
327 | } | ||
328 | |||
329 | QTextStream procmtd( &procmtdf ); | ||
330 | for ( int i = 0; i <= rootmtd; ++i ) procmtd.readLine(); // skip uninteresting things | ||
331 | QString dev; | ||
332 | QString size; | ||
333 | QString erasesize; | ||
334 | QString devname; | ||
335 | procmtd >> dev >> size >> erasesize >> devname; | ||
336 | |||
337 | odebug << "device " << dev << " size = " << size << ", erase size = " << erasesize << ", name = " << devname << "\"" << oendl; | ||
338 | |||
339 | // compute pad | ||
340 | QString pad = "--pad"; | ||
341 | switch ( ODevice::inst()->model() ) | ||
342 | { | ||
343 | case Model_Zaurus_SL5000: pad = "--pad=14680064"; break; | ||
344 | case Model_Zaurus_SL5500: pad = "--pad=14680064"; break; | ||
345 | // FIXME: Add Beagle and SIMpad | ||
346 | } | ||
347 | |||
348 | // compute eraseblock | ||
349 | QString eraseblock = "--eraseblock=0x" + erasesize; | ||
350 | |||
351 | // compute output | ||
352 | QString outputFile = "--output=" + backupLocations[storeToLocation->currentText()]; | ||
353 | QDateTime datetime = QDateTime::currentDateTime(); | ||
354 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | ||
355 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | ||
356 | outputFile += "/initrd.bin-" + dateString; | ||
357 | |||
358 | // call mkfs.jffs2 to create the backup | ||
359 | QString cmdline = QString( "mkfs.jffs2 --root=/ %1 --little-endian %2 %3 -n" ).arg( outputFile ).arg( pad ).arg( eraseblock ); | ||
360 | owarn << "Calling '" << cmdline << "'" << oendl; | ||
361 | |||
362 | #ifndef MDEBUG | ||
363 | ::system( cmdline ); | ||
364 | #endif | ||
365 | |||
366 | // FIXME: Add image postprocessing for C7x0 and C8x0, for Beagle, for SIMpad | ||
367 | |||
283 | } | 368 | } |
284 | 369 | ||
285 | void BackupAndRestore::backupUserData() | 370 | void BackupAndRestore::backupUserData() |
286 | { | 371 | { |
287 | QString backupFiles; | 372 | QString backupFiles; |
288 | if(getBackupFiles(backupFiles, NULL) == 0) | 373 | if(getBackupFiles(backupFiles, NULL) == 0) |
289 | { | 374 | { |
290 | QMessageBox::critical(this, "Message", | 375 | QMessageBox::critical(this, "Message", |
291 | "No items selected.",QString("Ok") ); | 376 | "No items selected.",QString("Ok") ); |
292 | return; | 377 | return; |
293 | } | 378 | } |
294 | 379 | ||