2015-06-04 01:29:22 +01:00
/*************************************************************************
* Copyright ( C ) 2008 by Volker Lanz < vl @ fidra . de > *
2016-03-02 19:00:31 +00:00
* Copyright ( C ) 2016 by Andrius Š tikonas < andrius @ stikonas . eu > *
2015-06-04 01:29:22 +01:00
* *
* This program is free software ; you can redistribute it and / or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation ; either version 3 of *
* the License , or ( at your option ) any later version . *
* *
* This program 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 program . If not , see < http : //www.gnu.org/licenses/>.*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "jobs/movefilesystemjob.h"
# include "core/partition.h"
# include "core/device.h"
# include "core/copysourcedevice.h"
# include "core/copytargetdevice.h"
# include "util/report.h"
# include <KLocalizedString>
/** Creates a new MoveFileSystemJob
2015-07-13 15:16:36 +01:00
@ param d the Device the Partition to move is on
@ param p the Partition to move
@ param newstart the new start sector for the Partition
2015-06-04 01:29:22 +01:00
*/
MoveFileSystemJob : : MoveFileSystemJob ( Device & d , Partition & p , qint64 newstart ) :
2015-07-13 15:16:36 +01:00
Job ( ) ,
m_Device ( d ) ,
m_Partition ( p ) ,
m_NewStart ( newstart )
2015-06-04 01:29:22 +01:00
{
}
qint32 MoveFileSystemJob : : numSteps ( ) const
{
2015-07-13 15:16:36 +01:00
return 100 ;
2015-06-04 01:29:22 +01:00
}
bool MoveFileSystemJob : : run ( Report & parent )
{
2015-07-13 15:16:36 +01:00
bool rval = false ;
Report * report = jobStarted ( parent ) ;
// A scope for moveSource and moveTarget, so CopyTargetDevice's dtor runs before we
// say we're finished: The CopyTargetDevice dtor asks the backend to close the device
// and that may take a while.
{
CopySourceDevice moveSource ( device ( ) , partition ( ) . fileSystem ( ) . firstSector ( ) , partition ( ) . fileSystem ( ) . lastSector ( ) ) ;
CopyTargetDevice moveTarget ( device ( ) , newStart ( ) , newStart ( ) + partition ( ) . fileSystem ( ) . length ( ) ) ;
if ( ! moveSource . open ( ) )
2016-07-17 23:41:00 +01:00
report - > line ( ) < < xi18nc ( " @info:progress " , " Could not open file system on partition <filename>%1</filename> for moving. " , partition ( ) . deviceNode ( ) ) ;
2015-07-13 15:16:36 +01:00
else if ( ! moveTarget . open ( ) )
2016-07-17 23:41:00 +01:00
report - > line ( ) < < xi18nc ( " @info:progress " , " Could not create target for moving file system on partition <filename>%1</filename>. " , partition ( ) . deviceNode ( ) ) ;
2015-07-13 15:16:36 +01:00
else {
rval = copyBlocks ( * report , moveTarget , moveSource ) ;
if ( rval ) {
const qint64 savedLength = partition ( ) . fileSystem ( ) . length ( ) - 1 ;
partition ( ) . fileSystem ( ) . setFirstSector ( newStart ( ) ) ;
partition ( ) . fileSystem ( ) . setLastSector ( newStart ( ) + savedLength ) ;
} else if ( ! rollbackCopyBlocks ( * report , moveTarget , moveSource ) )
2016-07-17 23:41:00 +01:00
report - > line ( ) < < xi18nc ( " @info:progress " , " Rollback for file system on partition <filename>%1</filename> failed. " , partition ( ) . deviceNode ( ) ) ;
2015-07-13 15:16:36 +01:00
2016-07-17 23:41:00 +01:00
report - > line ( ) < < xi18nc ( " @info:progress " , " Closing device. This may take a few seconds. " ) ;
2015-07-13 15:16:36 +01:00
}
}
if ( rval )
rval = partition ( ) . fileSystem ( ) . updateBootSector ( * report , partition ( ) . deviceNode ( ) ) ;
jobFinished ( * report , rval ) ;
return rval ;
2015-06-04 01:29:22 +01:00
}
QString MoveFileSystemJob : : description ( ) const
{
2016-07-17 23:41:00 +01:00
return xi18nc ( " @info:progress " , " Move the file system on partition <filename>%1</filename> to sector %2 " , partition ( ) . deviceNode ( ) , newStart ( ) ) ;
2015-06-04 01:29:22 +01:00
}