Summary: | free size harddisk wrong metadata | ||
---|---|---|---|
Product: | [Unmaintained] kdesktop | Reporter: | christian <ch75> |
Component: | general | Assignee: | David Faure <faure> |
Status: | CLOSED FIXED | ||
Severity: | normal | CC: | finex |
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: | view the error |
Description
christian
2006-08-11 19:52:25 UTC
Created attachment 17341 [details]
view the error
here is the error:
Looking at the code I find the size information stored as unsigned long, which is too small for that sizes. I'm going to fix that. SVN commit 611855 by mkoller: BUG: 132269 Fix correct calculation of percent diskfree by using KIO::filesize_t instead int/uint, etc. M +39 -57 kfilemediaplugin.cpp M +4 -9 kfilemediaplugin.h --- branches/KDE/3.5/kdebase/kioslave/media/kfile-plugin/kfilemediaplugin.cpp #611854:611855 @@ -20,7 +20,6 @@ #include "kfilemediaplugin.h" #include <kgenericfactory.h> -#include <kdiskfreesp.h> #include <dcopref.h> @@ -28,8 +27,10 @@ #include <qpainter.h> #include <qstyle.h> #include <qapplication.h> -#include <qeventloop.h> +#include <qfile.h> +#include <sys/statvfs.h> + typedef KGenericFactory<KFileMediaPlugin> KFileMediaPluginFactory; K_EXPORT_COMPONENT_FACTORY(kfile_media, KFileMediaPluginFactory("kio_media")) @@ -93,75 +94,56 @@ } if (!mount_point.isEmpty() && medium.isMounted()) - { - KDiskFreeSp *df = new KDiskFreeSp(); - + { m_total = 0; m_used = 0; m_free = 0; - connect(df, SIGNAL( done() ), this, SLOT( slotDfDone() )); - connect(df, SIGNAL( foundMountPoint(const QString &, - unsigned long, - unsigned long, - unsigned long) ), - this, SLOT( slotFoundMountPoint(const QString &, - unsigned long, - unsigned long, - unsigned long)) ); - df->readDF(mount_point); + struct statvfs vfs; + memset(&vfs, 0, sizeof(vfs)); - qApp->eventLoop()->enterLoop(); + if ( ::statvfs(QFile::encodeName(mount_point), &vfs) != -1 ) + { + m_total = static_cast<KIO::filesize_t>(vfs.f_blocks) * static_cast<KIO::filesize_t>(vfs.f_frsize); + m_free = static_cast<KIO::filesize_t>(vfs.f_bavail) * static_cast<KIO::filesize_t>(vfs.f_frsize); + m_used = m_total - m_free; - int percent = 0; - int length = 0; + int percent = 0; + int length = 0; - if (m_total != 0) - { - percent = 100 * m_used / m_total; - length = 150 * m_used / m_total; - } + if (m_total != 0) + { + percent = 100 * m_used / m_total; + length = 150 * m_used / m_total; + } - appendItem(group, "free", (long long unsigned)m_free); - appendItem(group, "used", (long long unsigned)m_used); - appendItem(group, "total", (long long unsigned)m_total); + appendItem(group, "free", m_free); + appendItem(group, "used", m_used); + appendItem(group, "total", m_total); - group = appendGroup(info, "mediumSummary"); + group = appendGroup(info, "mediumSummary"); - appendItem(group, "percent", QString("%1%").arg(percent)); + appendItem(group, "percent", QString("%1%").arg(percent)); - QPixmap bar(150, 20); - QPainter p(&bar); + QPixmap bar(150, 20); + QPainter p(&bar); - p.fillRect(0, 0, length, 20, Qt::red); - p.fillRect(length, 0, 150-length, 20, Qt::green); + p.fillRect(0, 0, length, 20, Qt::red); + p.fillRect(length, 0, 150-length, 20, Qt::green); - QColorGroup cg = QApplication::palette().active(); + QColorGroup cg = QApplication::palette().active(); - QApplication::style().drawPrimitive(QStyle::PE_Panel, &p, - QRect(0, 0, 150, 20), cg, - QStyle::Style_Sunken); + QApplication::style().drawPrimitive(QStyle::PE_Panel, &p, + QRect(0, 0, 150, 20), cg, + QStyle::Style_Sunken); - appendItem( group, "thumbnail", bar ); + appendItem( group, "thumbnail", bar ); + } } return true; } -void KFileMediaPlugin::slotFoundMountPoint(const QString &/*mountPoint*/, - unsigned long total, unsigned long used, - unsigned long free) -{ - m_free = free; - m_used = used; - m_total = total; -} - -void KFileMediaPlugin::slotDfDone() -{ - qApp->eventLoop()->exitLoop(); -} - const Medium KFileMediaPlugin::askMedium(KFileMetaInfo &info) { DCOPRef mediamanager("kded", "mediamanager"); @@ -184,14 +166,14 @@ = addGroupInfo(info, "mediumInfo", i18n("Medium Information")); KFileMimeTypeInfo::ItemInfo *item - = addItemInfo(group, "free", i18n("Free"), QVariant::Int); - setUnit(item, KFileMimeTypeInfo::KiloBytes); + = addItemInfo(group, "free", i18n("Free"), QVariant::ULongLong); + setUnit(item, KFileMimeTypeInfo::Bytes); - item = addItemInfo(group, "used", i18n("Used"), QVariant::Int); - setUnit(item, KFileMimeTypeInfo::KiloBytes); + item = addItemInfo(group, "used", i18n("Used"), QVariant::ULongLong); + setUnit(item, KFileMimeTypeInfo::Bytes); - item = addItemInfo(group, "total", i18n("Total"), QVariant::Int); - setUnit(item, KFileMimeTypeInfo::KiloBytes); + item = addItemInfo(group, "total", i18n("Total"), QVariant::ULongLong); + setUnit(item, KFileMimeTypeInfo::Bytes); item = addItemInfo(group, "baseURL", i18n("Base URL"), QVariant::String); item = addItemInfo(group, "mountPoint", i18n("Mount Point"), QVariant::String); --- branches/KDE/3.5/kdebase/kioslave/media/kfile-plugin/kfilemediaplugin.h #611854:611855 @@ -22,6 +22,7 @@ #include <kfilemetainfo.h> #include <kurl.h> +#include <kio/global.h> #include "medium.h" @@ -38,15 +39,9 @@ void addMimeType(const char *mimeType); const Medium askMedium(KFileMetaInfo &info); - unsigned long m_total; - unsigned long m_used; - unsigned long m_free; - -private slots: - void slotFoundMountPoint(const QString &mountPoint, - unsigned long total, unsigned long used, - unsigned long available); - void slotDfDone(); + KIO::filesize_t m_total; + KIO::filesize_t m_used; + KIO::filesize_t m_free; }; #endif Bug closed. Kdesktop is no more mantained. |