[mythtv-users] Disk Space Way Wrong

Mark Lord mythtv at rtr.ca
Fri Apr 20 16:20:19 UTC 2012


On 12-04-20 11:58 AM, Mark Lord wrote:
> On 12-04-20 09:02 AM, Raymond Wagner wrote:
>> On 4/19/2012 22:35, Mark Lord wrote:
>>> On 12-04-19 10:04 PM, Gavin Hurlbut wrote:
>>>> On Thu, Apr 19, 2012 at 9:59 AM, Mark Lord<mythtv at rtr.ca>  wrote:
>>>>> Most likely it's the old bug whereby Mythtv shows the space free
>>>>> on the root filesystem rather than on the filesystem where
>>>>> recordings are kept.
>>>> What old bug is that?  I do not recall ever having seen this.  Got a
>>>> trac ticket number?
>>> Nope.  It just reports wrong on every system I've set up,
>>> always showing the root partition free space instead of
>>> where the recordings are kept.
>>>
>>> I think perhaps it trips up on symlinks or something.
>>
>> Here is the code in question.
>>
>> https://github.com/MythTV/mythtv/blob/master/mythtv/libs/libmythbase/mythcoreutil.cpp#L39
>>
>> It's not doing anything fancy, it just runs statfs on the path you give it.
> 
> There's the bug.  It should open the path, and then use fstatfs(fd, ..).
> Doing it that way would make symlinks transparent to it, as they should be.

Like this, but undoubtedly prettier than this:  :)

--- mythtv/libs/libmythdb/mythcoreutil.cpp.orig	2012-04-18 18:29:45.000000000 -0400
+++ mythtv/libs/libmythdb/mythcoreutil.cpp	2012-04-20 12:15:58.688776954 -0400
@@ -31,6 +31,19 @@
 #include "mythverbose.h"
 #include "unzip.h"

+int statfs_wrapper(const char *path, struct statfs *st)
+{
+	int ret, fd = open(path, O_RDONLY);
+
+	if (fd != -1) {
+		ret = fstatfs(fd, st);
+		close(fd);
+		if (ret != -1)
+			return ret;
+	}
+	return statfs(path, st);
+}
+
 /** \fn getDiskSpace(const QString&,long long&,long long&)
  *  \brief Returns free space on disk containing file in KiB,
  *          or -1 if it does not succeed.
@@ -50,7 +63,7 @@
     // others are invalid and set to 0 (such as when an automounted directory
     // is not mounted but still visible because --ghost was used),
     // so check to make sure we can have a total size > 0
-    if ((statfs(cstr.constData(), &statbuf) == 0) &&
+    if ((statfs_wrapper(cstr.constData(), &statbuf) == 0) &&
         (statbuf.f_blocks > 0) &&
         (statbuf.f_bsize > 0))
     {
--- mythtv/programs/mythbackend/mainserver.cpp.orig	2012-04-18 18:29:45.000000000 -0400
+++ mythtv/programs/mythbackend/mainserver.cpp	2012-04-20 12:15:46.298844076 -0400
@@ -4117,6 +4117,8 @@
     return totalKBperMin;
 }

+extern int statfs_wrapper(const char *path, struct statfs *buf);  // libs/libmythdb/mythcoreutil.cpp
+
 void MainServer::BackendQueryDiskSpace(QStringList &strlist, bool consolidated,
                                        bool allHosts)
 {
@@ -4179,7 +4181,7 @@
                     localStr = "1"; // Assume local
                     bSize = 0;

-                    if (!statfs(currentDir.toLocal8Bit().constData(), &statbuf))
+                    if (!statfs_wrapper(currentDir.toLocal8Bit().constData(), &statbuf))
                     {
 #if CONFIG_DARWIN
                         char *fstypename = statbuf.f_fstypename;


More information about the mythtv-users mailing list