summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp87
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
@@ -13,48 +13,49 @@
    .i_,=:_.      -<s. This file is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
..}^=.=       =       ; Public License for more details.
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "backuprestore.h"
#include "errordialog.h"
/* OPIE */
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <opie2/odebug.h>
+#include <opie2/odevice.h>
#include <opie2/ostorageinfo.h>
#include <opie2/ofiledialog.h>
#include <opie2/owait.h>
using namespace Opie::Core;
using namespace Opie::Ui;
/* QT */
#include <qapplication.h>
#include <qmultilineedit.h>
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qlistview.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qheader.h>
#include <qmessagebox.h>
#include <qcombobox.h>
#include <qlist.h>
#include <qregexp.h>
#include <qtextstream.h>
#include <qtextview.h>
#include <qlineedit.h>
#include <qstringlist.h>
@@ -258,49 +259,133 @@ void BackupAndRestore::scanForApplicationSettings()
QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName());
selectItem(newItem);
}
++it;
}
}
/**
* The "Backup" button has been pressed. Get a list of all of the files that
* should be backed up. If there are no files, emit and error and exit.
* Determine the file name to store the backup in. Backup the file(s) using
* tar and gzip --best. Report failure or success
*/
void BackupAndRestore::backup()
{
if ( cb_type_userdata->isChecked() )
backupUserData();
else
backupRootFs();
}
void BackupAndRestore::backupRootFs()
{
- QMessageBox::critical(this, "Message", "Not Yet Implemented", "Ok" );
+//#define MDEBUG
+#ifndef MDEBUG
+ QMessageBox::critical( this, "Opie-Backup", "<qt>This feature is not yet implemented.</qt>", "Bummer!" );
+ return;
+#endif
+ // call 'mount' and parse its output to gather the device on which the root partition is mounted
+ FILE* mountp = popen( "mount", "r" );
+ QString device;
+ QString mountpoint;
+ {
+ QTextStream mounto( mountp, IO_ReadOnly );
+ QString on;
+ QString type;
+ QString filesystem;
+ QString options;
+ while ( !mounto.atEnd() )
+ {
+ mounto >> device >> on >> mountpoint >> type >> filesystem >> options;
+ if ( mountpoint == "/" ) break;
+ }
+ odebug << device << " is formatted w/ " << filesystem << " and mounted on " << mountpoint << oendl;
+
+ if ( !mountpoint.startsWith( "/dev/mtdblock" ) )
+ {
+ QMessageBox::critical( this, "Can't backup!", QString( "<qt>unsupported rootfs %1 - needs to be /dev/mtdblockN</qt>").arg( device ), "Ok" );
+#ifndef MDEBUG
+ return;
+#endif
+ }
+ } // at this point, the QTextStream has been destroy and we can close the FILE*
+ pclose( mountp );
+
+#ifndef MDEBUG
+ int rootmtd = device.right( 1 ).toInt();
+#else
+ int rootmtd = 0;
+#endif
+ odebug << "root mtdblock seems to be '" << rootmtd << "'" << oendl;
+
+ // scan /proc/mtd to gather the size and erasesize of the root mtdblock
+ QFile procmtdf( "/proc/mtd" );
+ if ( !procmtdf.open( IO_ReadOnly ) )
+ {
+ QMessageBox::critical( this, "Can't backup!", "<qt>Can't open /proc/mtd</qt>", "Ok" );
+ }
+
+ QTextStream procmtd( &procmtdf );
+ for ( int i = 0; i <= rootmtd; ++i ) procmtd.readLine(); // skip uninteresting things
+ QString dev;
+ QString size;
+ QString erasesize;
+ QString devname;
+ procmtd >> dev >> size >> erasesize >> devname;
+
+ odebug << "device " << dev << " size = " << size << ", erase size = " << erasesize << ", name = " << devname << "\"" << oendl;
+
+ // compute pad
+ QString pad = "--pad";
+ switch ( ODevice::inst()->model() )
+ {
+ case Model_Zaurus_SL5000: pad = "--pad=14680064"; break;
+ case Model_Zaurus_SL5500: pad = "--pad=14680064"; break;
+ // FIXME: Add Beagle and SIMpad
+ }
+
+ // compute eraseblock
+ QString eraseblock = "--eraseblock=0x" + erasesize;
+
+ // compute output
+ QString outputFile = "--output=" + backupLocations[storeToLocation->currentText()];
+ QDateTime datetime = QDateTime::currentDateTime();
+ QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') +
+ QString::number( datetime.date().day() ).rightJustify(2, '0');
+ outputFile += "/initrd.bin-" + dateString;
+
+ // call mkfs.jffs2 to create the backup
+ QString cmdline = QString( "mkfs.jffs2 --root=/ %1 --little-endian %2 %3 -n" ).arg( outputFile ).arg( pad ).arg( eraseblock );
+ owarn << "Calling '" << cmdline << "'" << oendl;
+
+#ifndef MDEBUG
+ ::system( cmdline );
+#endif
+
+ // FIXME: Add image postprocessing for C7x0 and C8x0, for Beagle, for SIMpad
+
}
void BackupAndRestore::backupUserData()
{
QString backupFiles;
if(getBackupFiles(backupFiles, NULL) == 0)
{
QMessageBox::critical(this, "Message",
"No items selected.",QString("Ok") );
return;
}
OWait *owait = new OWait();
Global::statusMessage( tr( "Backing up..." ) );
owait->show();
qApp->processEvents();
QString outputFile = backupLocations[storeToLocation->currentText()];
QDateTime datetime = QDateTime::currentDateTime();
QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') +
QString::number( datetime.date().day() ).rightJustify(2, '0');
outputFile += "/" + dateString;