Index: gstfilesink.c
===================================================================
--- gstfilesink.c	(revision 27702)
+++ gstfilesink.c	(working copy)
@@ -43,6 +43,8 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/stat.h> 
+#include <sys/statfs.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -85,6 +87,7 @@
   PROP_LOCATION,
   PROP_BUFFER_MODE,
   PROP_BUFFER_SIZE,
+  PROP_RESERVED_SPACE,
   PROP_LAST
 };
 
@@ -172,6 +175,14 @@
           G_MAXUINT, DEFAULT_BUFFER_SIZE,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (gobject_class, PROP_RESERVED_SPACE,
+      g_param_spec_uint ("reserved-space", "Reserved Storage Space",
+          "Send no space left warning when fewer than reserved-space bytes "
+            "remain",
+          0,
+          G_MAXUINT, DEFAULT_BUFFER_SIZE,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   gstbasesink_class->get_times = NULL;
   gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_file_sink_start);
   gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_file_sink_stop);
@@ -216,6 +227,7 @@
   g_free (sink->buffer);
   sink->buffer = NULL;
   sink->buffer_size = 0;
+  sink->reserved_space = 0;
 }
 
 static gboolean
@@ -262,6 +274,12 @@
     case PROP_BUFFER_SIZE:
       sink->buffer_size = g_value_get_uint (value);
       break;
+    case PROP_RESERVED_SPACE:
+      if(G_VALUE_HOLDS_UINT64(value))
+        sink->reserved_space = g_value_get_uint64 (value);
+      else
+        sink->reserved_space = g_value_get_uint (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -284,6 +302,9 @@
     case PROP_BUFFER_SIZE:
       g_value_set_uint (value, sink->buffer_size);
       break;
+    case PROP_RESERVED_SPACE:
+      g_value_set_uint64 (value, sink->reserved_space);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -336,6 +357,7 @@
   }
 
   sink->current_pos = 0;
+  sink->next_space_check = 0;
   /* try to seek in the file to figure out if it is seekable */
   sink->seekable = gst_file_sink_do_seek (sink, 0);
 
@@ -571,8 +593,30 @@
       goto handle_error;
 
     filesink->current_pos += size;
+    filesink->next_space_check -= size;
   }
 
+  /* Each time the reserved check halfs, update and possibly send an error, the
+   * current buffer was written, so return flow ok. */
+  if(filesink->reserved_space && filesink->next_space_check < 0) {
+    struct statfs fs;
+    struct stat file;
+    int fd=fileno(filesink->file);
+    if(fstatfs(fd, &fs) == 0 && fstat(fd, &file) == 0) {
+      gint64 left=file.st_blksize*fs.f_bavail - filesink->reserved_space;
+      GST_LOG("remaining storage %lld", left);
+      if(left<0) {
+        GST_ELEMENT_WARNING (filesink, RESOURCE, NO_SPACE_LEFT, (NULL),
+          (g_strdup_printf("Remaining space %lld, "
+          "less than reserved space %lld", file.st_blksize*fs.f_bavail,
+          filesink->reserved_space)));
+      }
+      filesink->next_space_check = left/2;
+    } else {
+      perror("fstatvfs error");
+    }
+  }
+
   return GST_FLOW_OK;
 
 handle_error:
Index: gstfilesink.h
===================================================================
--- gstfilesink.h	(revision 27702)
+++ gstfilesink.h	(working copy)
@@ -59,6 +59,13 @@
   gboolean seekable;
   guint64 current_pos;
 
+  /* Send the error message no space left when the disk has less than
+   * reserved_space free.
+   * Check the disk space when next_space_check gets zero or negative.
+   */
+  guint64 reserved_space;
+  gint64 next_space_check;
+
   gint    buffer_mode;
   guint   buffer_size;
   gchar  *buffer;
