Commit a5bdd5a4 authored by Andrius Štikonas's avatar Andrius Štikonas
Browse files

Switch to ntfsinfo to read NTFS usage.

BUG: 447248
parent 31921c59
Pipeline #113693 passed with stage
in 1 minute and 3 seconds
......@@ -47,7 +47,8 @@ ntfs::ntfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QStr
void ntfs::init()
{
m_Shrink = m_Grow = m_Check = m_GetUsed = findExternal(QStringLiteral("ntfsresize")) ? cmdSupportFileSystem : cmdSupportNone;
m_Shrink = m_Grow = m_Check = findExternal(QStringLiteral("ntfsresize")) ? cmdSupportFileSystem : cmdSupportNone;
m_GetUsed = findExternal(QStringLiteral("ntfsinfo")) ? cmdSupportFileSystem : cmdSupportNone;
m_GetLabel = cmdSupportCore;
m_SetLabel = findExternal(QStringLiteral("ntfslabel")) ? cmdSupportFileSystem : cmdSupportNone;
m_Create = findExternal(QStringLiteral("mkfs.ntfs")) ? cmdSupportFileSystem : cmdSupportNone;
......@@ -97,18 +98,27 @@ int ntfs::maxLabelLength() const
qint64 ntfs::readUsedCapacity(const QString& deviceNode) const
{
ExternalCommand cmd(QStringLiteral("ntfsresize"), { QStringLiteral("--info"), QStringLiteral("--force"), QStringLiteral("--no-progress-bar"), deviceNode });
ExternalCommand cmd(QStringLiteral("ntfsinfo"), { QStringLiteral("--mft"), QStringLiteral("--force"), deviceNode });
if (cmd.run(-1) && cmd.exitCode() == 0) {
qint64 usedBytes = -1;
QRegularExpression re(QStringLiteral("resize at (\\d+) bytes"));
QRegularExpressionMatch reUsedBytes = re.match(cmd.output());
QRegularExpression re(QStringLiteral("Cluster Size: (\\d+)"));
QRegularExpressionMatch reClusterSize = re.match(cmd.output());
qint64 clusterSize = reClusterSize.hasMatch() ? reClusterSize.captured(1).toLongLong() : -1;
QRegularExpression re2(QStringLiteral("Free Clusters: (\\d+)"));
QRegularExpressionMatch reFreeClusters = re2.match(cmd.output());
qint64 freeClusters = reFreeClusters.hasMatch() ? reFreeClusters.captured(1).toLongLong() : -1;
if (reUsedBytes.hasMatch())
usedBytes = reUsedBytes.captured(1).toLongLong();
QRegularExpression re3(QStringLiteral("Volume Size in Clusters: (\\d+)"));
QRegularExpressionMatch reVolumeSize = re3.match(cmd.output());
qint64 volumeSize = reVolumeSize.hasMatch() ? reVolumeSize.captured(1).toLongLong() : -1;
if (usedBytes > -1)
return usedBytes;
qint64 usedBytes = -1;
qDebug () << volumeSize << freeClusters << clusterSize;
if (clusterSize > -1 && freeClusters > -1 && volumeSize > -1) {
usedBytes = (volumeSize - freeClusters) * clusterSize;
}
return usedBytes;
}
return -1;
......
......@@ -74,6 +74,7 @@ QStringLiteral("nilfs-resize"),
QStringLiteral("ntfsresize"),
QStringLiteral("mkfs.ntfs"),
QStringLiteral("ntfsclone"),
QStringLiteral("ntfsinfo"),
QStringLiteral("ntfslabel"),
QStringLiteral("fsck.ocfs2"),
QStringLiteral("mkfs.ocfs2"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment