diff --git a/hacking/GlobalStorage.md b/hacking/GlobalStorage.md index e7fec1458..0e024b16c 100644 --- a/hacking/GlobalStorage.md +++ b/hacking/GlobalStorage.md @@ -17,6 +17,7 @@ A list of dictionaries, one per partition. The dictionary contains the following - `device`: path to the partition device - `fs`: the name of the file system - `mountPoint`: where the device should be mounted +- `uuid`: the UUID of the partition device ## rootMountPoint diff --git a/src/modules/partition/FillGlobalStorageJob.cpp b/src/modules/partition/FillGlobalStorageJob.cpp index 4abd20643..e6e770941 100644 --- a/src/modules/partition/FillGlobalStorageJob.cpp +++ b/src/modules/partition/FillGlobalStorageJob.cpp @@ -29,15 +29,37 @@ #include #include +// Qt #include +#include +#include + +typedef QHash UuidForPartitionHash; + +static const char* UUID_DIR = "/dev/disk/by-uuid"; + +static UuidForPartitionHash +findPartitionUuids() +{ + QDir dir( UUID_DIR ); + UuidForPartitionHash hash; + for ( auto info : dir.entryInfoList( QDir::Files ) ) + { + QString uuid = info.fileName(); + QString path = info.canonicalFilePath(); + hash.insert( path, uuid ); + } + return hash; +} static QVariant -mapForPartition( Partition* partition ) +mapForPartition( Partition* partition, const QString& uuid ) { QVariantMap map; map[ "device" ] = partition->partitionPath(); map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); map[ "fs" ] = partition->fileSystem().name(); + map[ "uuid" ] = uuid; return map; } @@ -68,10 +90,11 @@ FillGlobalStorageJob::exec() QVariant FillGlobalStorageJob::createPartitionList() { + UuidForPartitionHash hash = findPartitionUuids(); QVariantList lst; - for( auto device : m_devices ) - for( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it) - lst << mapForPartition( *it ); + for ( auto device : m_devices ) + for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it ) + lst << mapForPartition( *it, hash.value( ( *it )->partitionPath() ) ); return lst; }