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 "ops/newoperation.h"
# include "core/partition.h"
# include "core/device.h"
# include "core/partitionnode.h"
# include "jobs/createpartitionjob.h"
# include "jobs/createfilesystemjob.h"
2020-03-18 18:24:27 +00:00
# include "jobs/setpartitionlabeljob.h"
Add new job to set the GPT partition UUID
The GPT partition layout supports unique GUID partitions.
The CLI sfdisk sets the partition UUID using the option --part-uuid.
See the examples below:
$ cat <<EOF | sfdisk disk.img
label: gpt
type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, size=64M
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
EOF
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=BBE806BB-8567-A843-9FF5-9B6B35D2908E
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7DB39F08-C138-664B-B38E-ED2DEB549AA6
$ sfdisk --part-uuid disk.img 1 00000000^C000-0000-0000-000000000000
(...)
$ sfdisk --part-uuid disk.img 2 11111111-1111-1111-1111-111111111111
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=00000000-0000-0000-0000-000000000000
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=11111111-1111-1111-1111-111111111111
This commit introduces the new job set-partition-uuid that is used in
the new-operation to set the UUID of the partition. The job uses the
newly introduced method setPartitionUUID that is implemented by the
sfdisk and dummy backends.
Note: This is a copypaste of what was done for GTP partition label in
commit f585f6c (Add new job to set the GPT partition label).
2020-03-18 18:24:27 +00:00
# include "jobs/setpartitionuuidjob.h"
Add new job to set the GPT partition attributes
The GPT partition layout supports partition attributes.
The CLI sfdisk sets the partition attributes using the option
--part-attrs. See the examples below:
$ cat <<EOF | sfdisk disk.img
label: gpt
type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, size=64M
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
EOF
(...)
$ sfdisk --part-attrs disk.img 1 RequiredPartition,NoBlockIOProtocol,LegacyBIOSBootable,48
(...)
$ sfdisk --part-attrs disk.img 2 60,61,62,63
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=BBE806BB-8567-A843-9FF5-9B6B35D2908E, attrs="RequiredPartition NoBlockIOProtocol LegacyBIOSBootable GUID:48"
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7DB39F08-C138-664B-B38E-ED2DEB549AA6, attrs="GUID:60,61,62,63"
This commit introduces the new job set-partition-attributes that is used
in the new-operation to set the attributes of the partition. The job
uses the newly introduced method setPartitionAttributes that is
implemented by the sfdisk and dummy backends.
Note: This is a copypaste of what was done for GPT partition label in
commit f585f6c (Add new job to set the GPT partition label) and GPT
partition UUID in commit 1dde035 (Add new job to set the GPT partition
UUID).
Note: RequiredPartition, NoBlockIOProtocol, LegacyBIOSBootable are
key words for 0, 1 and 2.
2020-05-15 17:24:06 +01:00
# include "jobs/setpartitionattributesjob.h"
2015-06-04 01:29:22 +01:00
# include "jobs/setfilesystemlabeljob.h"
# include "jobs/setpartflagsjob.h"
# include "jobs/checkfilesystemjob.h"
# include "fs/filesystem.h"
# include "fs/filesystemfactory.h"
# include "util/capacity.h"
# include <QString>
# include <KLocalizedString>
/** Creates a new NewOperation.
2015-07-13 15:16:36 +01:00
@ param d the Device to create a new Partition on
2015-07-22 14:48:03 +01:00
@ param p pointer to the new Partition to create . May not be nullptr .
2015-06-04 01:29:22 +01:00
*/
NewOperation : : NewOperation ( Device & d , Partition * p ) :
2015-07-13 15:16:36 +01:00
Operation ( ) ,
m_TargetDevice ( d ) ,
m_NewPartition ( p ) ,
m_CreatePartitionJob ( new CreatePartitionJob ( targetDevice ( ) , newPartition ( ) ) ) ,
2020-03-18 18:24:27 +00:00
m_SetPartitionLabelJob ( nullptr ) ,
Add new job to set the GPT partition UUID
The GPT partition layout supports unique GUID partitions.
The CLI sfdisk sets the partition UUID using the option --part-uuid.
See the examples below:
$ cat <<EOF | sfdisk disk.img
label: gpt
type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, size=64M
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
EOF
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=BBE806BB-8567-A843-9FF5-9B6B35D2908E
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7DB39F08-C138-664B-B38E-ED2DEB549AA6
$ sfdisk --part-uuid disk.img 1 00000000^C000-0000-0000-000000000000
(...)
$ sfdisk --part-uuid disk.img 2 11111111-1111-1111-1111-111111111111
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=00000000-0000-0000-0000-000000000000
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=11111111-1111-1111-1111-111111111111
This commit introduces the new job set-partition-uuid that is used in
the new-operation to set the UUID of the partition. The job uses the
newly introduced method setPartitionUUID that is implemented by the
sfdisk and dummy backends.
Note: This is a copypaste of what was done for GTP partition label in
commit f585f6c (Add new job to set the GPT partition label).
2020-03-18 18:24:27 +00:00
m_SetPartitionUUIDJob ( nullptr ) ,
Add new job to set the GPT partition attributes
The GPT partition layout supports partition attributes.
The CLI sfdisk sets the partition attributes using the option
--part-attrs. See the examples below:
$ cat <<EOF | sfdisk disk.img
label: gpt
type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, size=64M
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
EOF
(...)
$ sfdisk --part-attrs disk.img 1 RequiredPartition,NoBlockIOProtocol,LegacyBIOSBootable,48
(...)
$ sfdisk --part-attrs disk.img 2 60,61,62,63
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=BBE806BB-8567-A843-9FF5-9B6B35D2908E, attrs="RequiredPartition NoBlockIOProtocol LegacyBIOSBootable GUID:48"
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7DB39F08-C138-664B-B38E-ED2DEB549AA6, attrs="GUID:60,61,62,63"
This commit introduces the new job set-partition-attributes that is used
in the new-operation to set the attributes of the partition. The job
uses the newly introduced method setPartitionAttributes that is
implemented by the sfdisk and dummy backends.
Note: This is a copypaste of what was done for GPT partition label in
commit f585f6c (Add new job to set the GPT partition label) and GPT
partition UUID in commit 1dde035 (Add new job to set the GPT partition
UUID).
Note: RequiredPartition, NoBlockIOProtocol, LegacyBIOSBootable are
key words for 0, 1 and 2.
2020-05-15 17:24:06 +01:00
m_SetPartitionAttributesJob ( nullptr ) ,
2015-07-22 14:48:03 +01:00
m_CreateFileSystemJob ( nullptr ) ,
m_SetPartFlagsJob ( nullptr ) ,
m_SetFileSystemLabelJob ( nullptr ) ,
m_CheckFileSystemJob ( nullptr )
2015-06-04 01:29:22 +01:00
{
2015-07-13 15:16:36 +01:00
addJob ( createPartitionJob ( ) ) ;
2015-06-04 01:29:22 +01:00
2020-03-18 18:24:27 +00:00
if ( ! p - > label ( ) . isEmpty ( ) ) {
m_SetPartitionLabelJob = new SetPartitionLabelJob ( targetDevice ( ) , newPartition ( ) , p - > label ( ) ) ;
addJob ( setPartitionLabelJob ( ) ) ;
}
Add new job to set the GPT partition UUID
The GPT partition layout supports unique GUID partitions.
The CLI sfdisk sets the partition UUID using the option --part-uuid.
See the examples below:
$ cat <<EOF | sfdisk disk.img
label: gpt
type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, size=64M
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
EOF
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=BBE806BB-8567-A843-9FF5-9B6B35D2908E
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7DB39F08-C138-664B-B38E-ED2DEB549AA6
$ sfdisk --part-uuid disk.img 1 00000000^C000-0000-0000-000000000000
(...)
$ sfdisk --part-uuid disk.img 2 11111111-1111-1111-1111-111111111111
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=00000000-0000-0000-0000-000000000000
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=11111111-1111-1111-1111-111111111111
This commit introduces the new job set-partition-uuid that is used in
the new-operation to set the UUID of the partition. The job uses the
newly introduced method setPartitionUUID that is implemented by the
sfdisk and dummy backends.
Note: This is a copypaste of what was done for GTP partition label in
commit f585f6c (Add new job to set the GPT partition label).
2020-03-18 18:24:27 +00:00
if ( ! p - > uuid ( ) . isEmpty ( ) ) {
m_SetPartitionUUIDJob = new SetPartitionUUIDJob ( targetDevice ( ) , newPartition ( ) , p - > uuid ( ) ) ;
addJob ( setPartitionUUIDJob ( ) ) ;
}
Add new job to set the GPT partition attributes
The GPT partition layout supports partition attributes.
The CLI sfdisk sets the partition attributes using the option
--part-attrs. See the examples below:
$ cat <<EOF | sfdisk disk.img
label: gpt
type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, size=64M
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
EOF
(...)
$ sfdisk --part-attrs disk.img 1 RequiredPartition,NoBlockIOProtocol,LegacyBIOSBootable,48
(...)
$ sfdisk --part-attrs disk.img 2 60,61,62,63
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=BBE806BB-8567-A843-9FF5-9B6B35D2908E, attrs="RequiredPartition NoBlockIOProtocol LegacyBIOSBootable GUID:48"
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7DB39F08-C138-664B-B38E-ED2DEB549AA6, attrs="GUID:60,61,62,63"
This commit introduces the new job set-partition-attributes that is used
in the new-operation to set the attributes of the partition. The job
uses the newly introduced method setPartitionAttributes that is
implemented by the sfdisk and dummy backends.
Note: This is a copypaste of what was done for GPT partition label in
commit f585f6c (Add new job to set the GPT partition label) and GPT
partition UUID in commit 1dde035 (Add new job to set the GPT partition
UUID).
Note: RequiredPartition, NoBlockIOProtocol, LegacyBIOSBootable are
key words for 0, 1 and 2.
2020-05-15 17:24:06 +01:00
if ( p - > attributes ( ) ) {
m_SetPartitionAttributesJob = new SetPartitionAttributesJob ( targetDevice ( ) , newPartition ( ) , p - > attributes ( ) ) ;
addJob ( setPartitionAttributesJob ( ) ) ;
}
2015-07-13 15:16:36 +01:00
const FileSystem & fs = newPartition ( ) . fileSystem ( ) ;
2015-06-04 01:29:22 +01:00
2018-04-07 19:54:30 +01:00
if ( fs . type ( ) ! = FileSystem : : Type : : Extended ) {
2015-07-13 15:16:36 +01:00
// It would seem tempting to skip the CreateFileSystemJob or the
// SetFileSystemLabelJob if either has nothing to do (unformatted FS or
// empty label). However, the user might later on decide to change FS or
// label. The operation stack will merge these operations with this one here
// and if the jobs don't exist things will break.
2015-06-04 01:29:22 +01:00
2017-08-18 12:45:15 +01:00
m_CreateFileSystemJob = new CreateFileSystemJob ( targetDevice ( ) , newPartition ( ) , fs . label ( ) ) ;
2015-07-13 15:16:36 +01:00
addJob ( createFileSystemJob ( ) ) ;
2015-06-04 01:29:22 +01:00
2018-04-07 19:54:30 +01:00
if ( fs . type ( ) = = FileSystem : : Type : : Lvm2_PV ) {
2019-02-09 18:04:44 +00:00
m_SetPartFlagsJob = new SetPartFlagsJob ( targetDevice ( ) , newPartition ( ) , PartitionTable : : Flag : : Lvm ) ;
2015-07-13 15:16:36 +01:00
addJob ( setPartFlagsJob ( ) ) ;
}
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
m_SetFileSystemLabelJob = new SetFileSystemLabelJob ( newPartition ( ) , fs . label ( ) ) ;
addJob ( setLabelJob ( ) ) ;
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
m_CheckFileSystemJob = new CheckFileSystemJob ( newPartition ( ) ) ;
addJob ( checkJob ( ) ) ;
}
2015-06-04 01:29:22 +01:00
}
NewOperation : : ~ NewOperation ( )
{
2015-07-13 15:16:36 +01:00
if ( status ( ) = = StatusPending )
delete m_NewPartition ;
2015-06-04 01:29:22 +01:00
}
bool NewOperation : : targets ( const Device & d ) const
{
2015-07-13 15:16:36 +01:00
return d = = targetDevice ( ) ;
2015-06-04 01:29:22 +01:00
}
bool NewOperation : : targets ( const Partition & p ) const
{
2015-07-13 15:16:36 +01:00
return p = = newPartition ( ) ;
2015-06-04 01:29:22 +01:00
}
void NewOperation : : preview ( )
{
2015-07-13 15:16:36 +01:00
insertPreviewPartition ( targetDevice ( ) , newPartition ( ) ) ;
2015-06-04 01:29:22 +01:00
}
void NewOperation : : undo ( )
{
2015-07-13 15:16:36 +01:00
removePreviewPartition ( targetDevice ( ) , newPartition ( ) ) ;
2015-06-04 01:29:22 +01:00
}
QString NewOperation : : description ( ) const
{
2016-07-17 23:41:00 +01:00
return xi18nc ( " @info:status " , " Create a new partition (%1, %2) on < filename > % 3 < / filename > " , Capacity::formatByteSize(newPartition().capacity()), newPartition().fileSystem().name(), targetDevice().deviceNode()) ;
2015-06-04 01:29:22 +01:00
}
/** Can a Partition be created somewhere?
2015-07-22 14:48:03 +01:00
@ param p the Partition where a new Partition is to be created , may be nullptr
2015-07-13 15:16:36 +01:00
@ return true if a new Partition can be created in @ p p
2015-06-04 01:29:22 +01:00
*/
bool NewOperation : : canCreateNew ( const Partition * p )
{
2015-07-22 14:48:03 +01:00
return p ! = nullptr & & p - > roles ( ) . has ( PartitionRole : : Unallocated ) ;
2015-06-04 01:29:22 +01:00
}
2015-07-13 14:28:56 +01:00
Partition * NewOperation : : createNew ( const Partition & cloneFrom ,
2015-07-13 15:16:36 +01:00
FileSystem : : Type type )
2015-06-04 01:29:22 +01:00
{
2015-07-13 15:16:36 +01:00
Partition * p = new Partition ( cloneFrom ) ;
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
p - > deleteFileSystem ( ) ;
p - > setFileSystem ( FileSystemFactory : : create ( type ,
p - > firstSector ( ) ,
2017-09-03 15:37:14 +01:00
p - > lastSector ( ) ,
p - > sectorSize ( ) ) ) ;
2018-04-09 03:46:05 +01:00
p - > setState ( Partition : : State : : New ) ;
2015-07-13 15:16:36 +01:00
p - > setPartitionPath ( QString ( ) ) ;
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
return p ;
2015-06-04 01:29:22 +01:00
}