Bug 132269 - free size harddisk wrong metadata
Summary: free size harddisk wrong metadata
Status: CLOSED FIXED
Alias: None
Product: kdesktop
Classification: Unmaintained
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-11 19:52 UTC by christian
Modified: 2009-01-02 20:33 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
view the error (21.91 KB, image/png)
2006-08-11 19:53 UTC, christian
Details

Note You need to log in before you can comment on or make changes to this bug.
Description christian 2006-08-11 19:52:25 UTC
Version:            (using KDE KDE 3.5.4)
Installed from:    Compiled From Sources

The Metadata ist wrong , see screenshot 

to replay , insert USB Harddisk , view metadata of usb Stick Item.
see size is wrong.
Comment 1 christian 2006-08-11 19:53:45 UTC
Created attachment 17341 [details]
view the error

here is the error:
Comment 2 Martin Koller 2006-11-02 23:00:37 UTC
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.
Comment 3 Martin Koller 2006-12-09 20:01:37 UTC
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
Comment 4 FiNeX 2009-01-02 20:33:06 UTC
Bug closed. Kdesktop is no more mantained.