diff --git a/src/modules/partition/core/OsproberEntry.cpp b/src/modules/partition/core/OsproberEntry.cpp new file mode 100644 index 000000000..a1e0c2b4d --- /dev/null +++ b/src/modules/partition/core/OsproberEntry.cpp @@ -0,0 +1,90 @@ +/* === This file is part of Calamares - === + * + * Copyright 2016, Teo Mrnjavac + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#include "OsproberEntry.h" + +#include + + +QString +OsproberEntry::homePartitionPath() +{ + if ( fstab.isEmpty() ) + return QString(); + + foreach ( const FstabEntry& entry, fstab ) + { + if ( entry.mountPoint == "/home" ) + { + QProcess readlink; + QString partPath; + + if ( entry.partitionNode.startsWith( "/dev" ) ) // plain dev node + { + partPath = entry.partitionNode; + } + else if ( entry.partitionNode.startsWith( "LABEL=" ) ) + { + partPath = entry.partitionNode.mid( 6 ); + partPath.remove( "\"" ); + partPath.replace( "\\040", "\\ " ); + partPath.prepend( "/dev/disk/by-label/" ); + } + else if ( entry.partitionNode.startsWith( "UUID=" ) ) + { + partPath = entry.partitionNode.mid( 5 ); + partPath.remove( "\"" ); + partPath = partPath.toLower(); + partPath.prepend( "/dev/disk/by-uuid/" ); + } + else if ( entry.partitionNode.startsWith( "PARTLABEL=" ) ) + { + partPath = entry.partitionNode.mid( 10 ); + partPath.remove( "\"" ); + partPath.replace( "\\040", "\\ " ); + partPath.prepend( "/dev/disk/by-partlabel/" ); + } + else if ( entry.partitionNode.startsWith( "PARTUUID=" ) ) + { + partPath = entry.partitionNode.mid( 9 ); + partPath.remove( "\"" ); + partPath = partPath.toLower(); + partPath.prepend( "/dev/disk/by-partuuid/" ); + } + + // At this point we either have /dev/sda1, or /dev/disk/by-something/... + + if ( partPath.startsWith( "/dev/disk/by-" ) ) // we got a fancy node + { + readlink.start( "readlink", { "-en", partPath }); + if ( !readlink.waitForStarted( 1000 ) ) + return QString(); + if ( !readlink.waitForFinished( 1000 ) ) + return QString(); + if ( readlink.exitCode() != 0 || readlink.exitStatus() != QProcess::NormalExit ) + return QString(); + partPath = QString::fromLocal8Bit( + readlink.readAllStandardOutput() ).trimmed(); + } + + return partPath; + } + } + + return QString(); +} diff --git a/src/modules/partition/core/OsproberEntry.h b/src/modules/partition/core/OsproberEntry.h index acaa3187d..d94082289 100644 --- a/src/modules/partition/core/OsproberEntry.h +++ b/src/modules/partition/core/OsproberEntry.h @@ -40,6 +40,8 @@ struct OsproberEntry bool canBeResized; QStringList line; FstabEntryList fstab; + + QString homePartitionPath(); }; typedef QList< OsproberEntry > OsproberEntryList;