diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index b9899ff..6f21684 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -121,7 +121,7 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl qint64 endSector = startSector + lvSize - 1; FileSystem::Type type = FileSystem::detectFileSystem(lvPath); - FileSystem* fs = FileSystemFactory::create(type, 0, lvSize - 1); + FileSystem* fs = FileSystemFactory::create(type, 0, lvSize - 1, logicalSize()); fs->scan(lvPath); PartitionRole::Roles r = PartitionRole::Lvm_Lv; @@ -132,7 +132,7 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl if (fs->type() == FileSystem::Luks) { r |= PartitionRole::Luks; FS::luks* luksFs = static_cast(fs); - luksFs->initLUKS(logicalSize()); + luksFs->initLUKS(); QString mapperNode = luksFs->mapperName(); mountPoint = FileSystem::detectMountPoint(fs, mapperNode); diff --git a/src/core/partitiontable.cpp b/src/core/partitiontable.cpp index c34d367..e793bb0 100644 --- a/src/core/partitiontable.cpp +++ b/src/core/partitiontable.cpp @@ -324,7 +324,7 @@ Partition* createUnallocated(const Device& device, PartitionNode& parent, qint64 if (!PartitionTable::getUnallocatedRange(device, parent, start, end)) return nullptr; - return new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end), start, end, QString()); + return new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end, device.logicalSize()), start, end, QString()); } /** Removes all unallocated children from a PartitionNode diff --git a/src/fs/filesystem.h b/src/fs/filesystem.h index a578992..2f344f7 100644 --- a/src/fs/filesystem.h +++ b/src/fs/filesystem.h @@ -232,6 +232,9 @@ public: const QString& label() const { return m_Label; /**< @return the FileSystem's label */ } + qint64 sectorSize() const { + return m_SectorSize; /**< @return the sector size in the underlying Device */ + } qint64 sectorsUsed() const { return m_SectorsUsed; /**< @return the sectors in use on the FileSystem */ } @@ -239,6 +242,9 @@ public: return m_UUID; /**< @return the FileSystem's UUID */ } + void setSectorSize(qint64 s) { + m_SectorSize = s; /**< @param s the new value for sector size */ + } void setSectorsUsed(qint64 s) { m_SectorsUsed = s; /**< @param s the new value for sectors in use */ } @@ -256,6 +262,7 @@ protected: FileSystem::Type m_Type; qint64 m_FirstSector; qint64 m_LastSector; + qint64 m_SectorSize; qint64 m_SectorsUsed; QString m_Label; QString m_UUID; diff --git a/src/fs/filesystemfactory.cpp b/src/fs/filesystemfactory.cpp index e357657..3c7b905 100644 --- a/src/fs/filesystemfactory.cpp +++ b/src/fs/filesystemfactory.cpp @@ -100,7 +100,7 @@ void FileSystemFactory::init() @param label the FileSystem's label @return pointer to the newly created FileSystem object or nullptr if FileSystem could not be created */ -FileSystem* FileSystemFactory::create(FileSystem::Type t, qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, const QString& uuid) +FileSystem* FileSystemFactory::create(FileSystem::Type t, qint64 firstsector, qint64 lastsector, qint64 sectorSize, qint64 sectorsused, const QString& label, const QString& uuid) { FileSystem* fs = nullptr; @@ -138,6 +138,7 @@ FileSystem* FileSystemFactory::create(FileSystem::Type t, qint64 firstsector, qi if (fs != nullptr) fs->setUUID(uuid); + fs->setSectorSize(sectorSize); return fs; } @@ -146,7 +147,7 @@ FileSystem* FileSystemFactory::create(FileSystem::Type t, qint64 firstsector, qi */ FileSystem* FileSystemFactory::create(const FileSystem& other) { - return create(other.type(), other.firstSector(), other.lastSector(), other.sectorsUsed(), other.label(), other.uuid()); + return create(other.type(), other.firstSector(), other.lastSector(), other.sectorSize(), other.sectorsUsed(), other.label(), other.uuid()); } /** @return the map of FileSystems */ @@ -162,5 +163,5 @@ const FileSystemFactory::FileSystems& FileSystemFactory::map() */ FileSystem* FileSystemFactory::cloneWithNewType(FileSystem::Type newType, const FileSystem& other) { - return create(newType, other.firstSector(), other.lastSector(), other.sectorsUsed(), other.label()); + return create(newType, other.firstSector(), other.lastSector(), other.sectorSize(), other.sectorsUsed(), other.label()); } diff --git a/src/fs/filesystemfactory.h b/src/fs/filesystemfactory.h index 1cee946..78431cf 100644 --- a/src/fs/filesystemfactory.h +++ b/src/fs/filesystemfactory.h @@ -42,7 +42,7 @@ private: public: static void init(); - static FileSystem* create(FileSystem::Type t, qint64 firstsector, qint64 lastsector, qint64 sectorsused = -1, const QString& label = QString(), const QString& uuid = QString()); + static FileSystem* create(FileSystem::Type t, qint64 firstsector, qint64 lastsector, qint64 sectorSize, qint64 sectorsused = -1, const QString& label = QString(), const QString& uuid = QString()); static FileSystem* create(const FileSystem& other); static FileSystem* cloneWithNewType(FileSystem::Type newType, const FileSystem& other); static const FileSystems& map(); diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index e8ce6ba..5170f7e 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -67,7 +67,6 @@ luks::luks(qint64 firstsector, , m_isCryptOpen(false) , m_cryptsetupFound(m_Create != cmdSupportNone) , m_isMounted(false) - , m_logicalSectorSize(512) , m_KeySize(-1) , m_PayloadOffset(-1) { @@ -338,7 +337,7 @@ void luks::loadInnerFileSystem(const QString& mapperNode) setLabel(m_innerFs->readLabel(mapperNode)); setUUID(m_innerFs->readUUID(mapperNode)); if (m_innerFs->supportGetUsed() == FileSystem::cmdSupportFileSystem) - setSectorsUsed(std::ceil((m_innerFs->readUsedCapacity(mapperNode) + payloadOffset()) / static_cast(m_logicalSectorSize) )); + setSectorsUsed(std::ceil((m_innerFs->readUsedCapacity(mapperNode) + payloadOffset()) / static_cast(sectorSize()) )); m_innerFs->scan(mapperNode); } @@ -396,7 +395,7 @@ bool luks::mount(Report& report, const QString& deviceNode, const QString& mount const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint); if (freeSpaceInfo.isValid() && !mountPoint.isEmpty()) - setSectorsUsed((freeSpaceInfo.used() + payloadOffset()) / m_logicalSectorSize); + setSectorsUsed((freeSpaceInfo.used() + payloadOffset()) / sectorSize()); return true; } @@ -490,7 +489,7 @@ bool luks::resize(Report& report, const QString& deviceNode, qint64 newLength) c return false; qint64 payloadLength = newLength - payloadOffset(); - if ( newLength - length() * m_logicalSectorSize > 0 ) + if ( newLength - length() * sectorSize() > 0 ) { ExternalCommand cryptResizeCmd(report, QStringLiteral("cryptsetup"), { QStringLiteral("resize"), mapperName() }); report.line() << xi18nc("@info:progress", "Resizing LUKS crypt on partition %1.", deviceNode); @@ -664,9 +663,8 @@ bool luks::canEncryptType(FileSystem::Type type) } } -void luks::initLUKS(unsigned int sectorSize) +void luks::initLUKS() { - setLogicalSectorSize(sectorSize); QString mapperNode = mapperName(); bool isCryptOpen = !mapperNode.isEmpty(); setCryptOpen(isCryptOpen); diff --git a/src/fs/luks.h b/src/fs/luks.h index b15246a..c5ac15e 100644 --- a/src/fs/luks.h +++ b/src/fs/luks.h @@ -126,10 +126,6 @@ public: return m_GetUUID; } - void setLogicalSectorSize(unsigned int logicalSectorSize) { - m_logicalSectorSize = logicalSectorSize; - } - bool check(Report& report, const QString& deviceNode) const override; bool create(Report& report, const QString& deviceNode) override; SupportTool supportToolName() const override; @@ -186,7 +182,7 @@ public: qint64 payloadOffset() const { return m_PayloadOffset; } static bool canEncryptType(FileSystem::Type type); - void initLUKS(unsigned int sectorSize); + void initLUKS(); protected: virtual QString readOuterUUID(const QString& deviceNode) const; @@ -212,7 +208,6 @@ private: mutable bool m_cryptsetupFound; QString m_passphrase; bool m_isMounted; - unsigned int m_logicalSectorSize; QString m_MapperName; QString m_CipherName; diff --git a/src/jobs/restorefilesystemjob.cpp b/src/jobs/restorefilesystemjob.cpp index 60373dc..1387726 100644 --- a/src/jobs/restorefilesystemjob.cpp +++ b/src/jobs/restorefilesystemjob.cpp @@ -91,7 +91,7 @@ bool RestoreFileSystemJob::run(Report& parent) t = backendPartitionTable->detectFileSystemBySector(*report, targetDevice(), targetPartition().firstSector()); } - FileSystem* fs = FileSystemFactory::create(t, targetPartition().firstSector(), newLastSector); + FileSystem* fs = FileSystemFactory::create(t, targetPartition().firstSector(), newLastSector, targetPartition().sectorSize()); targetPartition().deleteFileSystem(); targetPartition().setFileSystem(fs); diff --git a/src/ops/newoperation.cpp b/src/ops/newoperation.cpp index 7814b92..89b0be3 100644 --- a/src/ops/newoperation.cpp +++ b/src/ops/newoperation.cpp @@ -126,7 +126,8 @@ Partition* NewOperation::createNew(const Partition& cloneFrom, p->deleteFileSystem(); p->setFileSystem(FileSystemFactory::create(type, p->firstSector(), - p->lastSector())); + p->lastSector(), + p->sectorSize())); p->setState(Partition::StateNew); p->setPartitionPath(QString()); diff --git a/src/ops/restoreoperation.cpp b/src/ops/restoreoperation.cpp index 8423aeb..be8c0ab 100644 --- a/src/ops/restoreoperation.cpp +++ b/src/ops/restoreoperation.cpp @@ -225,7 +225,7 @@ Partition* RestoreOperation::createRestorePartition(const Device& device, Partit return nullptr; const qint64 end = start + fileInfo.size() / device.logicalSize() - 1; - Partition* p = new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end), start, end, QString()); + Partition* p = new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end, device.logicalSize()), start, end, QString()); p->setState(Partition::StateRestore); return p; diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index 86c9a77..2fecdc9 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -336,7 +336,7 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk) if (parent == nullptr) parent = d.partitionTable(); - FileSystem* fs = FileSystemFactory::create(type, pedPartition->geom.start, pedPartition->geom.end); + FileSystem* fs = FileSystemFactory::create(type, pedPartition->geom.start, pedPartition->geom.end, d.logicalSize()); fs->scan(partitionNode); QString mountPoint; bool mounted; @@ -345,7 +345,7 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk) if (fs->type() == FileSystem::Luks) { r |= PartitionRole::Luks; FS::luks* luksFs = static_cast(fs); - luksFs->initLUKS(d.logicalSize()); + luksFs->initLUKS(); QString mapperNode = luksFs->mapperName(); mountPoint = FileSystem::detectMountPoint(fs, mapperNode); mounted = FileSystem::detectMountStatus(fs, mapperNode);