On Sat, 2014-10-18 at 10:42 +0200, Petter Reinholdtsen wrote:
> > I don't see the point of doing this in DVswitch.  There are applets
> > for this and a stock GNOME installation will warn on low disk space.
> 
> I believe it would be nice to see the amount of disk free where I look
> to check if the dvsink is working, and made a untested draft patch to
> do so.
> 
> Something along these lines would help me a bit when doing video
> recordings:
> 
> Index: src/dvsink-files.c
> ===================================================================
> --- src/dvsink-files.c  (revision 414)
> +++ src/dvsink-files.c  (working copy)
> @@ -17,6 +17,7 @@
>  #include <sys/types.h>
>  #include <sys/stat.h>
>  #include <unistd.h>
> +#include <sys/statfs.h>
>  
>  #include "config.h"
>  #include "dif.h"
> @@ -162,6 +163,19 @@
>      return total;
>  }
>  
> +/* Return the amount of megabyte free on the disk of the file descriptor */
> +static long freespace(int fd)
> +{
> +    struct statfs stat;
> +    long free;
> +    if (0 == fstatfs(fd, &stat))

From statfs(2):
>        Linux-specific.  The Linux statfs() was inspired by the 4.4BSD one (but
>        they do not use the same structure).
[...]
>        LSB  has  deprecated the library calls statfs() and fstatfs() and tells
>        us to use statvfs(2) and fstatvfs(2) instead.

> +    {
> +        free = stat.f_bsize * stat.f_bavail / (1024*1024) ;
> +    } else {
> +        free = -1;
> +    }
> +}

This is not even self-consistent in brace placement!

>  static void transfer_frames(struct transfer_params * params)
>  {
>      static uint8_t buf[SINK_FRAME_HEADER_SIZE + DIF_MAX_FRAME_SIZE];
> @@ -207,7 +221,8 @@
>             file = create_file(output_name_format, &name);
>             if (starting)
>                 printf("INFO: Started recording\n");
> -           printf("INFO: Created file %s\n", name);
> +           long free = freespace(file);

Local variable free hides global function free().

> +           printf("INFO: Created file %s - free space $ld MiB\n", name, 
> free);

So it prints "free space -1 MiB" in case of error??

Ben.

>             fflush(stdout);
>         }
>  
> Perhaps something to include?
> 

-- 
Ben Hutchings
Life is what happens to you while you're busy making other plans.
                                                               - John Lennon

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to