summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-11-10 14:03:37 (UTC)
committer mickeyl <mickeyl>2004-11-10 14:03:37 (UTC)
commit9088b52d1ef7c4e70e62a53e225c69508cc8afe3 (patch) (side-by-side diff)
tree38ac61c1004edecdec8cf5b1708816e13bb643df
parentfcd9c62650dd1bb9c04bfd798d243cb894a8f393 (diff)
downloadopie-9088b52d1ef7c4e70e62a53e225c69508cc8afe3.zip
opie-9088b52d1ef7c4e70e62a53e225c69508cc8afe3.tar.gz
opie-9088b52d1ef7c4e70e62a53e225c69508cc8afe3.tar.bz2
start working on clone functionality
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
@@ -1,84 +1,85 @@
/*
                This file is part of the Opie Project
=.
             .=l. Copyright (c) 2002-2004 The Opie Team <opie-devel@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This file is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .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>
/* STD */
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>
#define HEADER_NAME 0
#define HEADER_BACKUP 1
#define BACKUP_LOCATION 2
#define EXTENSION ".bck"
const QString tempFileName = "/tmp/backup.err";
BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl)
: BackupAndRestoreBase(parent, name, fl)
{
backupList->header()->hide();
restoreList->header()->hide();
locationList->header()->hide();
connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) );
connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) );
@@ -234,97 +235,181 @@ void BackupAndRestore::selectItem(QListViewItem *currentItem)
if(currentItem->text(HEADER_BACKUP) == "B")
{
currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null"));
currentItem->setText(HEADER_BACKUP, "");
}
else
{
currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check"));
currentItem->setText(HEADER_BACKUP, "B");
}
}
void BackupAndRestore::scanForApplicationSettings()
{
QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) );
d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi=it.current()) )
{
//odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl;
if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) )
{
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;
QString t = outputFile;
int c = 1;
while(QFile::exists(outputFile + EXTENSION))
{
outputFile = t + QString("%1").arg(c);
c++;
}
// We execute tar and compressing its output with gzip..
// The error output will be written into a temp-file which could be provided
// for debugging..
odebug << "Storing file: " << outputFile.latin1() << "" << oendl;
outputFile += EXTENSION;
QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() )
.arg( getExcludeFile() )
.arg( backupFiles )
.arg( outputFile.latin1() )
.arg( tempFileName.latin1() );
odebug << commandLine << oendl;
int r = system( commandLine );