Show free space on HD if possible (without waking HDD)

Alles rund um das grafische Benutzerinterface Enigma
oudeis
Beiträge: 2
Registriert: Sonntag 23. Januar 2005, 01:37

Show free space on HD if possible (without waking HDD)

Beitrag von oudeis »

Dear all,

My apologies for posting in English. I do read German (and write a bit), so feel free to answer in German :)

I noticed that Enigma only shows free space on the HDD if it is recording, and I also noticed that the function call showHDDSpaceLeft was commented out, with the comment 'i don't like always running HDD !!'. I completely agree with that comment, but I do like to see the amount of free space.

Below is a patch which fixes this. I modified the function freeRecordSpace to check if the drive is sleeping, before accessing the disk. If the drive is in standby or sleeping, it is not woken up, unless we want it to (for example, when starting a recording). The code to check if the drive is sleeping is taken from hdparm.

Comments and suggestions welcome :)

Best regards,
Ruud

Patch is available here.

Edit: Added link to patch

Code: Alles auswählen

Index: src/enigma_dyn.cpp
===================================================================
RCS file: /cvs/tuxbox/apps/tuxbox/enigma/src/enigma_dyn.cpp,v
retrieving revision 1.430
diff -u -r1.430 enigma_dyn.cpp
--- a/src/enigma_dyn.cpp 21 Jan 2005 20:52:15 -0000 1.430
+++ b/src/enigma_dyn.cpp 22 Jan 2005 22:17:08 -0000
@@ -4576,7 +4576,7 @@
 }
 
 #ifndef DISABLE_FILE
-extern int freeRecordSpace(void);  // implemented in enigma_main.cpp
+extern int freeRecordSpace(bool);  // implemented in enigma_main.cpp
 #endif
 
 static eString data(eString request, eString dirpath, eString opt, eHTTPConnection *content)
@@ -4615,7 +4615,7 @@
 
  // free recording space on disk
 #ifndef DISABLE_FILE
- int fds = freeRecordSpace();
+ int fds = freeRecordSpace(false);
 #else
  int fds = 0;
 #endif
Index: src/enigma_main.cpp
===================================================================
RCS file: /cvs/tuxbox/apps/tuxbox/enigma/src/enigma_main.cpp,v
retrieving revision 1.248
diff -u -r1.248 enigma_main.cpp
--- a/src/enigma_main.cpp 21 Jan 2005 09:58:11 -0000 1.248
+++ b/src/enigma_main.cpp 22 Jan 2005 22:17:09 -0000
@@ -10,6 +10,7 @@
 #include <sys/vfs.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
+#include <linux/hdreg.h>
 
 #include <streaminfo.h>
 #include <parentallock.h>
@@ -2988,14 +2989,53 @@
   recordDVR(1, 1);
 }
 
-int freeRecordSpace()
+int freeRecordSpace(bool wakeup)
 {
+static int free = -1;
+ bool drive_sleeping = false;
+#ifdef HDIO_DRIVE_CMD
+#ifndef WIN_CHECKPOWERMODE1
+#define WIN_CHECKPOWERMODE1 0xE5
+#endif
+#ifndef WIN_CHECKPOWERMODE2
+#define WIN_CHECKPOWERMODE2 0x98
+#endif
+ //Open drive
+ if (!wakeup) {
+  int fd;
+
+  fd = open ("/dev/ide/host0/bus0/target0/lun0/disc", O_RDONLY|O_NONBLOCK); //hardcoded for now
+  if (fd >= 0) {
+   unsigned char args[4] = {WIN_CHECKPOWERMODE1,0,0,0};
+
+  
+   if (ioctl(fd, HDIO_DRIVE_CMD, &args)
+     && (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */
+     && ioctl(fd, HDIO_DRIVE_CMD, &args)) {
+    drive_sleeping = true;//sleeping or unknown, don't wake drive if unknown;
+   } else {
+    drive_sleeping = (args[2] == 255) ? false : true;
+   }
+   close(fd);
+  }
+ }
+#endif //HDIO_DRIVE_CMD
  struct statfs s;
- int free;
- if (statfs(MOVIEDIR, &s)<0)
-  free=-1;
- else
-  free=s.f_bfree/1000*s.f_bsize/1000;
+#ifdef HDIO_DRIVE_CMD 
+ if (!drive_sleeping || wakeup) {
+#endif
+  if (statfs(MOVIEDIR, &s)<0)
+   free=-1;
+  else
+   free=s.f_bfree/1000*s.f_bsize/1000;
+#ifdef HDIO_DRIVE_CMD
+ }
+#endif
  return free;
 }
 
@@ -3010,7 +3050,7 @@
 
  if (onoff) //  start recording
  {
-  if ( freeRecordSpace() < 10) // less than 10MB free (or directory not found)
+  if ( freeRecordSpace(true) < 10) // less than 10MB free (or directory not found)
   {
    handleServiceEvent(eServiceEvent(eServiceEvent::evtRecordFailed));
    return -3;
@@ -5038,7 +5078,7 @@
 
    static int cnt=0;
    static int swp=0;
-   int fds=freeRecordSpace();
+   int fds=freeRecordSpace(true);
    if (fds)
    {
     if (!(cnt++ % 7))
@@ -5714,7 +5754,7 @@
 #ifndef DISABLE_FILE
  case eServiceEvent::evtRecordFailed:
  {
-  int freespace = freeRecordSpace();
+  int freespace = freeRecordSpace(false);
 
   if ( state&stateInTimerMode )
   {
@@ -6694,7 +6734,7 @@
 {
  static int swp;
 
- int fds = freeRecordSpace();
+ int fds = freeRecordSpace(false);
  if (fds != -1)
  {
   swp^=1;
@@ -6730,7 +6770,9 @@
   dvrInfoBar->show();
 #ifndef DISABLE_FILE
 //  i don't like always running HDD !!
-// showHDDSpaceLeft(DVRSpaceLeft);
+#ifdef HDIO_DRIVE_CMD
+ showHDDSpaceLeft(DVRSpaceLeft);
+#endif
 #endif
   prepareDVRHelp();
  } else

digi_casi

Beitrag von digi_casi »

yes, that would be nice... but there are some problems with that...
1. if the drive is sleeping you don't see how much space is left, so it's basically worthless
2. if you keep the amount of free space from the last time the drive was not sleeping, you might miss some file actions (e.g. when somebody is deleting files thru webif), and you might have wrong information.

so, all in all it would be very complex to insure that you have accurate information about the free space.

why is it so bad to wake up the drive at all? a quality disk should not care about that *fg*
mirakels
Neugieriger
Neugieriger
Beiträge: 17
Registriert: Montag 8. November 2004, 23:48

Beitrag von mirakels »

Maybe waking up the drive to just get its freespace could be a configurable option. If wakup is not allowed, take the last freespace calculation but tag it with a marker so we know it may be a bit out of date.
digi_casi

Beitrag von digi_casi »

i don't think a configuration option is worth the effort.
oudeis
Beiträge: 2
Registriert: Sonntag 23. Januar 2005, 01:37

Beitrag von oudeis »

@digi_casi:
I haven't tested the patch very thoroughly, but it _does_ show the amount of free space if the drive is sleeping. It simply uses the last value before the drive went to sleep, for most cases this is good enough. You have a point though: the free space is only available from the first time it is queried while the drive is not asleep.

Also, the web interface uses the same function to retrieve the free space, so deleting from the web interface updates the counter as well.

There are other problems though, for example with an NFS mount. I didn't bother to check if /hdd is mounted on a NFS share or not. If it is NFS, then the query will very likely fail.

Anyway, for my personal use it is good enough ;)