[mythtv] [PATCH] fix calculation of free disk space
Marc Slemko
marcs at znep.com
Sun Aug 17 13:23:52 EDT 2003
in a struct statfs, there are two fields related to free blocks:
long f_bfree; /* free blocks in fs */
long f_bavail; /* free blocks avail to non-superuser */
currently, mythtv uses f_bfree everywhere. Since mythtv should normally
not be running as root, this means its calculations are off, especially
with a large partition with the ext2fs default of 5% space reserved for
the superuser. This is a bigger deal now that there is autoexpiration
code.
This patch just changes the calculations to use f_bavail instead, which is
the space actually available to a user.
Index: programs/mythbackend/autoexpire.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/autoexpire.cpp,v
retrieving revision 1.3
diff -u -r1.3 autoexpire.cpp
--- programs/mythbackend/autoexpire.cpp 17 Jul 2003 01:04:13 -0000 1.3
+++ programs/mythbackend/autoexpire.cpp 17 Aug 2003 19:17:38 -0000
@@ -57,7 +57,7 @@
struct statfs statbuf;
int freespace = -1;
if (statfs(recordfileprefix.ascii(), &statbuf) == 0) {
- freespace = statbuf.f_bfree / (1024*1024*1024/statbuf.f_bsize);
+ freespace = statbuf.f_bavail / (1024*1024*1024/statbuf.f_bsize);
}
int minFree = gContext->GetNumSetting("AutoExpireDiskThreshold", 0);
@@ -95,7 +95,7 @@
if (statfs(recordfileprefix.ascii(), &statbuf) == 0)
{
freespace =
- statbuf.f_bfree / (1024*1024*1024/statbuf.f_bsize);
+ statbuf.f_bavail / (1024*1024*1024/statbuf.f_bsize);
}
}
Index: programs/mythbackend/encoderlink.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/encoderlink.cpp,v
retrieving revision 1.24
diff -u -r1.24 encoderlink.cpp
--- programs/mythbackend/encoderlink.cpp 7 Aug 2003 21:23:59 -0000 1.24
+++ programs/mythbackend/encoderlink.cpp 17 Aug 2003 19:17:39 -0000
@@ -172,7 +172,7 @@
struct statfs statbuf;
if (statfs(recordfileprefix.ascii(), &statbuf) == 0)
{
- freeSpace = statbuf.f_bfree / (1024*1024/statbuf.f_bsize);
+ freeSpace = statbuf.f_bavail / (1024*1024/statbuf.f_bsize);
}
}
else if (sock)
@@ -191,7 +191,7 @@
struct statfs statbuf;
if (statfs(recordfileprefix.ascii(), &statbuf) == 0)
{
- freeSpace = statbuf.f_bfree / (1024*1024/statbuf.f_bsize);
+ freeSpace = statbuf.f_bavail / (1024*1024/statbuf.f_bsize);
}
}
}
Index: programs/mythbackend/mainserver.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/mainserver.cpp,v
retrieving revision 1.73
diff -u -r1.73 mainserver.cpp
--- programs/mythbackend/mainserver.cpp 11 Aug 2003 20:44:38 -0000 1.73
+++ programs/mythbackend/mainserver.cpp 17 Aug 2003 19:17:46 -0000
@@ -912,8 +912,10 @@
int totalspace = -1, usedspace = -1;
if (statfs(recordfileprefix.ascii(), &statbuf) == 0)
{
- totalspace = statbuf.f_blocks / (1024*1024/statbuf.f_bsize);
- usedspace = (statbuf.f_blocks - statbuf.f_bfree) /
+ // total space available to user is total blocks - reserved blocks
+ totalspace = (statbuf.f_blocks - (statbuf.f_bfree - statbuf.f_bavail)) /
+ (1024*1024/statbuf.f_bsize);
+ usedspace = (statbuf.f_blocks - statbuf.f_bavail) /
(1024*1024/statbuf.f_bsize);
}
More information about the mythtv-dev
mailing list