Skip to content

Commit

Permalink
[systemsettings] Add a role to partition that tells whether partition…
Browse files Browse the repository at this point in the history
… is encrypted. Contributes to JB#42527

The role isCryptoDevice is true when the block device is encrypted
meaning that it has Encrypted interface but not FileSystem or if the
block has been unlocked and it has crypto backing device.
  • Loading branch information
rainemak committed Aug 31, 2018
1 parent 8ee508e commit a306fa4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/partition.cpp
Expand Up @@ -86,6 +86,11 @@ bool Partition::mountFailed() const
return d && d->mountFailed;
}

bool Partition::isCryptoDevice() const
{
return d ? d->isCryptoDevice : false;
}

Partition::StorageType Partition::storageType() const
{
return d ? d->storageType : Invalid;
Expand Down
1 change: 1 addition & 0 deletions src/partition.h
Expand Up @@ -103,6 +103,7 @@ class SYSTEMSETTINGS_EXPORT Partition

bool canMount() const;
bool mountFailed() const;
bool isCryptoDevice() const;

StorageType storageType() const;

Expand Down
2 changes: 2 additions & 0 deletions src/partition_p.h
Expand Up @@ -48,6 +48,7 @@ class PartitionPrivate : public QSharedData
, status(Partition::Unmounted)
, readOnly(true)
, canMount(false)
, isCryptoDevice(false)
, mountFailed(false)
, deviceRoot(false)
, valid(false)
Expand All @@ -74,6 +75,7 @@ class PartitionPrivate : public QSharedData
Partition::Status status;
bool readOnly;
bool canMount;
bool isCryptoDevice;
bool mountFailed;
bool deviceRoot;
// If valid, only mount status and available bytes will be checked
Expand Down
5 changes: 4 additions & 1 deletion src/partitionmodel.cpp
Expand Up @@ -267,7 +267,8 @@ QHash<int, QByteArray> PartitionModel::roleNames() const
{ BytesAvailableRole, "bytesAvailable" },
{ BytesTotalRole, "bytesTotal" },
{ BytesFreeRole, "bytesFree" },
{ PartitionModelRole, "partitionModel" }
{ PartitionModelRole, "partitionModel" },
{ IsCryptoDeviceRoles, "isCryptoDevice"},
};

return roleNames;
Expand Down Expand Up @@ -314,6 +315,8 @@ QVariant PartitionModel::data(const QModelIndex &index, int role) const
return partition.bytesFree();
case PartitionModelRole:
return QVariant::fromValue(static_cast<QObject*>(const_cast<PartitionModel*>((this))));
case IsCryptoDeviceRoles:
return partition.isCryptoDevice();
default:
return QVariant();
}
Expand Down
3 changes: 2 additions & 1 deletion src/partitionmodel.h
Expand Up @@ -61,7 +61,8 @@ class SYSTEMSETTINGS_EXPORT PartitionModel : public QAbstractListModel
BytesAvailableRole,
BytesTotalRole,
BytesFreeRole,
PartitionModelRole
PartitionModelRole,
IsCryptoDeviceRoles,
};

// For Status role
Expand Down
1 change: 1 addition & 0 deletions src/udisks2monitor.cpp
Expand Up @@ -291,6 +291,7 @@ void UDisks2::Monitor::setPartitionProperties(QExplicitlySharedDataPointer<Parti
partition->canMount = blockDevice->isMountable() && m_manager->supportedFileSystems().contains(partition->filesystemType);
partition->status = blockDevice->isEncrypted() ? Partition::Locked
: blockDevice->mountPath().isEmpty() ? Partition::Unmounted : Partition::Mounted;
partition->isCryptoDevice = blockDevice->isEncrypted() || blockDevice->hasCryptoBackingDevice();
}

void UDisks2::Monitor::updatePartitionProperties(const UDisks2::Block *blockDevice)
Expand Down

0 comments on commit a306fa4

Please sign in to comment.