-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 | |||
@@ -5,64 +5,65 @@ | |||
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
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> |
49 | #include <qlistview.h> | 50 | #include <qlistview.h> |
50 | #include <qpushbutton.h> | 51 | #include <qpushbutton.h> |
51 | #include <qradiobutton.h> | 52 | #include <qradiobutton.h> |
52 | #include <qheader.h> | 53 | #include <qheader.h> |
53 | #include <qmessagebox.h> | 54 | #include <qmessagebox.h> |
54 | #include <qcombobox.h> | 55 | #include <qcombobox.h> |
55 | #include <qlist.h> | 56 | #include <qlist.h> |
56 | #include <qregexp.h> | 57 | #include <qregexp.h> |
57 | #include <qtextstream.h> | 58 | #include <qtextstream.h> |
58 | #include <qtextview.h> | 59 | #include <qtextview.h> |
59 | #include <qlineedit.h> | 60 | #include <qlineedit.h> |
60 | #include <qstringlist.h> | 61 | #include <qstringlist.h> |
61 | 62 | ||
62 | /* STD */ | 63 | /* STD */ |
63 | #include <errno.h> | 64 | #include <errno.h> |
64 | #include <stdlib.h> | 65 | #include <stdlib.h> |
65 | #include <unistd.h> | 66 | #include <unistd.h> |
66 | #include <sys/stat.h> | 67 | #include <sys/stat.h> |
67 | #include <dirent.h> | 68 | #include <dirent.h> |
68 | 69 | ||
@@ -250,65 +251,149 @@ void BackupAndRestore::scanForApplicationSettings() | |||
250 | const QFileInfoList *list = d.entryInfoList(); | 251 | const QFileInfoList *list = d.entryInfoList(); |
251 | QFileInfoListIterator it( *list ); | 252 | QFileInfoListIterator it( *list ); |
252 | QFileInfo *fi; | 253 | QFileInfo *fi; |
253 | while ( (fi=it.current()) ) | 254 | while ( (fi=it.current()) ) |
254 | { | 255 | { |
255 | //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; | 256 | //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; |
256 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) | 257 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) |
257 | { | 258 | { |
258 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); | 259 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); |
259 | selectItem(newItem); | 260 | selectItem(newItem); |
260 | } | 261 | } |
261 | ++it; | 262 | ++it; |
262 | } | 263 | } |
263 | } | 264 | } |
264 | 265 | ||
265 | /** | 266 | /** |
266 | * The "Backup" button has been pressed. Get a list of all of the files that | 267 | * The "Backup" button has been pressed. Get a list of all of the files that |
267 | * should be backed up. If there are no files, emit and error and exit. | 268 | * should be backed up. If there are no files, emit and error and exit. |
268 | * Determine the file name to store the backup in. Backup the file(s) using | 269 | * Determine the file name to store the backup in. Backup the file(s) using |
269 | * tar and gzip --best. Report failure or success | 270 | * tar and gzip --best. Report failure or success |
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 | ||
295 | OWait *owait = new OWait(); | 380 | OWait *owait = new OWait(); |
296 | Global::statusMessage( tr( "Backing up..." ) ); | 381 | Global::statusMessage( tr( "Backing up..." ) ); |
297 | owait->show(); | 382 | owait->show(); |
298 | qApp->processEvents(); | 383 | qApp->processEvents(); |
299 | 384 | ||
300 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 385 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
301 | 386 | ||
302 | QDateTime datetime = QDateTime::currentDateTime(); | 387 | QDateTime datetime = QDateTime::currentDateTime(); |
303 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | 388 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + |
304 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | 389 | QString::number( datetime.date().day() ).rightJustify(2, '0'); |
305 | 390 | ||
306 | outputFile += "/" + dateString; | 391 | outputFile += "/" + dateString; |
307 | 392 | ||
308 | QString t = outputFile; | 393 | QString t = outputFile; |
309 | int c = 1; | 394 | int c = 1; |
310 | while(QFile::exists(outputFile + EXTENSION)) | 395 | while(QFile::exists(outputFile + EXTENSION)) |
311 | { | 396 | { |
312 | outputFile = t + QString("%1").arg(c); | 397 | outputFile = t + QString("%1").arg(c); |
313 | c++; | 398 | c++; |
314 | } | 399 | } |