1
0
Fork 0
forked from len0rd/rockbox

rbutil: Replace sysinfo filesystem cluster size with type.

The cluster size isn't too useful. Show the filesystem type instead,
since that makes it easier to identify a device not showing up because
of its filesystem type.

Change-Id: I8f58ea23ab90808ab0c37978b211a5470ed8bb8e
This commit is contained in:
Dominik Riebeling 2020-10-04 11:26:40 +02:00
parent 1aa739e3c3
commit 74258fca31
4 changed files with 52 additions and 14 deletions

View file

@ -135,6 +135,51 @@ QString Utils::resolvePathCase(QString path)
}
QString Utils::filesystemType(QString path)
{
#if defined(Q_OS_LINUX)
FILE *mn = setmntent("/etc/mtab", "r");
if(!mn)
return QString("");
struct mntent *ent;
while((ent = getmntent(mn))) {
if(QString(ent->mnt_dir) == path) {
endmntent(mn);
LOG_INFO() << "device type is" << ent->mnt_type;
return QString(ent->mnt_type);
}
}
endmntent(mn);
#endif
#if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
int num;
struct statfs *mntinf;
num = getmntinfo(&mntinf, MNT_WAIT);
while(num--) {
if(QString(mntinf->f_mntonname) == path) {
LOG_INFO() << "device type is" << mntinf->f_fstypename;
return QString(mntinf->f_fstypename);
}
mntinf++;
}
#endif
#if defined(Q_OS_WIN32)
wchar_t t[64];
memset(t, 0, 32);
if(GetVolumeInformationW((LPCWSTR)path.utf16(),
NULL, 0, NULL, NULL, NULL, t, 64)) {
LOG_INFO() << "device type is" << t;
return QString::fromWCharArray(t);
}
#endif
return QString("-");
}
QString Utils::filesystemName(QString path)
{
QString name;
@ -218,18 +263,10 @@ qulonglong Utils::filesystemTotal(QString path)
}
qulonglong Utils::filesystemClusterSize(QString path)
{
qulonglong size = filesystemSize(path, FilesystemClusterSize);
LOG_INFO() << "cluster size for" << path << size;
return size;
}
qulonglong Utils::filesystemSize(QString path, enum Utils::Size type)
{
qulonglong size = 0;
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
// the usage of statfs() is deprecated by the LSB so use statvfs().
struct statvfs fs;
int ret;
@ -281,7 +318,7 @@ qulonglong Utils::filesystemSize(QString path, enum Utils::Size type)
//! \brief searches for a Executable in the Environement Path
QString Utils::findExecutable(QString name)
{
//try autodetect tts
//try autodetect tts
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
#if QT_VERSION >= 0x050e00
QStringList path = QString(getenv("PATH")).split(":", Qt::SkipEmptyParts);

View file

@ -44,8 +44,8 @@ public:
static QString resolvePathCase(QString path);
static qulonglong filesystemFree(QString path);
static qulonglong filesystemTotal(QString path);
static qulonglong filesystemClusterSize(QString path);
static qulonglong filesystemSize(QString path, enum Size type);
static QString filesystemType(QString path);
static QString findExecutable(QString name);
static QString checkEnvironment(bool permission);
static int compareVersionStrings(QString s1, QString s2);

View file

@ -139,7 +139,8 @@ void ZipInstaller::downloadDone(bool error)
// some room for operating (also includes calculation mistakes due to
// cluster sizes on the player).
if((qint64)Utils::filesystemFree(m_mountpoint)
< (zip.totalUncompressedSize(Utils::filesystemClusterSize(m_mountpoint))
< (zip.totalUncompressedSize(
Utils::filesystemSize(m_mountpoint, Utils::FilesystemClusterSize))
+ 1000000)) {
emit logItem(tr("Not enough disk space! Aborting."), LOGERROR);
emit logProgress(1, 1);

View file

@ -65,14 +65,14 @@ QString Sysinfo::getInfo(Sysinfo::InfoType type)
info += "<table>";
info += "<tr><td>" + tr("Mountpoint") + "</td><td>" + tr("Label")
+ "</td><td>" + tr("Free") + "</td><td>" + tr("Total") + "</td><td>"
+ tr("Cluster Size") + "</td></tr>";
+ tr("Type") + "</td><td></tr>";
for(int i = 0; i < drives.size(); i++) {
info += tr("<tr><td>%1</td><td>%4</td><td>%2 GiB</td><td>%3 GiB</td><td>%5</td></tr>")
.arg(QDir::toNativeSeparators(drives.at(i)))
.arg((double)Utils::filesystemFree(drives.at(i)) / (1<<30), 0, 'f', 2)
.arg((double)Utils::filesystemTotal(drives.at(i)) / (1<<30), 0, 'f', 2)
.arg(Utils::filesystemName(drives.at(i)))
.arg(Utils::filesystemClusterSize(drives.at(i)));
.arg(Utils::filesystemType(drives.at(i)));
}
info += "</table>";
info += "<hr/>";