From a8cf3e07373a3b73ca64a0a9a16cab8dc74bc26f Mon Sep 17 00:00:00 2001 From: Chantara Tith Date: Sat, 23 Jul 2016 02:37:23 +0700 Subject: [PATCH] Handle LUKS inside LVM. still need to fix incorrect sectorUsed. --- src/core/lvmdevice.cpp | 59 ++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index 3a92fdf..823c7a6 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -18,6 +18,7 @@ #include "core/lvmdevice.h" #include "fs/filesystem.h" #include "fs/lvm2_pv.h" +#include "fs/luks.h" #include "fs/filesystemfactory.h" #include "core/partition.h" @@ -93,32 +94,56 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, const LvmDevice& dev, * without too many special cases. */ - qint64 startSector; - qint64 endSector; - qint64 lvSize; + qint64 lvSize = getTotalLE(lvpath); + qint64 startSector = mappedSector(lvpath, 0); + qint64 endSector = startSector + lvSize - 1; + + FileSystem::Type type = FileSystem::detectFileSystem(lvpath); + FileSystem* fs = FileSystemFactory::create(type, 0, lvSize - 1); bool mounted = isMounted(lvpath); QString mountPoint = QString(); KMountPoint::List mountPointList = KMountPoint::currentMountPoints(KMountPoint::NeedRealDeviceName); mountPointList.append(KMountPoint::possibleMountPoints(KMountPoint::NeedRealDeviceName)); - mountPoint = mountPointList.findByDevice(lvpath) ? - mountPointList.findByDevice(lvpath)->mountPoint() : - QString(); - lvSize = getTotalLE(lvpath); - startSector = mappedSector(lvpath,0); - endSector = startSector + (lvSize - 1); + PartitionRole::Roles r = PartitionRole::Lvm_Lv; - const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint); + if (type == FileSystem::Luks) { + r |= PartitionRole::Luks; + FS::luks* luksFs = dynamic_cast(fs); + QString mapperNode = FS::luks::mapperName(lvpath); + bool isCryptOpen = !mapperNode.isEmpty(); + luksFs->setCryptOpen(isCryptOpen); + luksFs->setLogicalSectorSize(dev.logicalSize()); - FileSystem* fs = FileSystemFactory::create(FileSystem::detectFileSystem(lvpath), 0, lvSize - 1); + if (isCryptOpen) { + luksFs->loadInnerFileSystem(lvpath, mapperNode); + mountPoint = mountPointList.findByDevice(mapperNode) ? + mountPointList.findByDevice(mapperNode)->mountPoint() : + QString(); + mounted = isMounted(mapperNode); + if (mounted) { + const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint); + if (freeSpaceInfo.isValid() && mountPoint != QString()) + luksFs->setSectorsUsed(freeSpaceInfo.used() / dev.logicalSize() + luksFs->getPayloadOffset(lvpath)); + } + } else { + mounted = false; + } + luksFs->setMounted(mounted); + } else { + mountPoint = mountPointList.findByDevice(lvpath) ? + mountPointList.findByDevice(lvpath)->mountPoint() : + QString(); + const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint); - //TODO: fix used space report. currently incorrect - if (mounted && freeSpaceInfo.isValid() && mountPoint != QString()) { - fs->setSectorsUsed(freeSpaceInfo.used() / logicalSize()); - } else if (fs->supportGetUsed() == FileSystem::cmdSupportFileSystem) { - fs->setSectorsUsed(fs->readUsedCapacity(lvpath) / logicalSize()); + //TODO: test used space report. probably incorrect + if (mounted && freeSpaceInfo.isValid() && mountPoint != QString()) { + fs->setSectorsUsed(freeSpaceInfo.used() / logicalSize()); + } else if (fs->supportGetUsed() == FileSystem::cmdSupportFileSystem) { + fs->setSectorsUsed(fs->readUsedCapacity(lvpath) / logicalSize()); + } } if (fs->supportGetLabel() != FileSystem::cmdSupportNone) { @@ -127,7 +152,7 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, const LvmDevice& dev, Partition* part = new Partition(pTable, dev, - PartitionRole(PartitionRole::Lvm_Lv), + PartitionRole(r), fs, startSector, endSector,