Record sector size in FileSystem class.
This commit is contained in:
parent
d797a47229
commit
7dba4b8245
|
@ -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::luks*>(fs);
|
||||
luksFs->initLUKS(logicalSize());
|
||||
luksFs->initLUKS();
|
||||
|
||||
QString mapperNode = luksFs->mapperName();
|
||||
mountPoint = FileSystem::detectMountPoint(fs, mapperNode);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<float>(m_logicalSectorSize) ));
|
||||
setSectorsUsed(std::ceil((m_innerFs->readUsedCapacity(mapperNode) + payloadOffset()) / static_cast<float>(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 <filename>%1</filename>.", 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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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::luks*>(fs);
|
||||
luksFs->initLUKS(d.logicalSize());
|
||||
luksFs->initLUKS();
|
||||
QString mapperNode = luksFs->mapperName();
|
||||
mountPoint = FileSystem::detectMountPoint(fs, mapperNode);
|
||||
mounted = FileSystem::detectMountStatus(fs, mapperNode);
|
||||
|
|
Loading…
Reference in New Issue