+static gboolean
+check_at_leom(VfsDevice *self, guint64 size)
+{
+ gboolean recheck = FALSE;
+ guint64 est_avail_now;
+ struct fs_usage fsusage;
+ guint64 block_size = DEVICE(self)->block_size;
+ guint64 eom_warning_buffer = EOM_EARLY_WARNING_ZONE_BLOCKS * block_size;
+
+ if (!self->leom || !self->monitor_free_space)
+ return FALSE;
+
+ /* handle VOLUME_LIMIT */
+ if (self->enforce_volume_limit && self->volume_limit &&
+ self->volume_bytes + size + eom_warning_buffer > self->volume_limit) {
+ return TRUE;
+ }
+
+ /* handle actual filesystem available space, using some heuristics to avoid polling this
+ * too frequently */
+ est_avail_now = 0;
+ if (self->checked_fs_free_bytes >= self->checked_bytes_used + size)
+ est_avail_now = self->checked_fs_free_bytes - self->checked_bytes_used - size;
+
+ /* is it time to check again? */
+ if (est_avail_now <= block_size * MONITOR_FREE_SPACE_CLOSELY_WITHIN_BLOCKS) {
+ recheck = TRUE;
+ } else if (self->checked_bytes_used > MONITOR_FREE_SPACE_EVERY_KB * 1024) {
+ recheck = TRUE;
+ } else if (self->checked_fs_free_time + MONITOR_FREE_SPACE_EVERY_SECONDS <= time(NULL)) {
+ recheck = TRUE;
+ }
+
+ if (!recheck)
+ return FALSE;
+
+ if (get_fs_usage(self->dir_name, NULL, &fsusage) < 0 || fsusage.fsu_bavail_top_bit_set) {
+ g_warning("Filesystem cannot provide free space: %s; setting MONITOR_FREE_SPACE false",
+ fsusage.fsu_bavail_top_bit_set? "no result" : strerror(errno));
+ self->monitor_free_space = FALSE;
+ return FALSE;
+ }
+
+ self->checked_fs_free_bytes = fsusage.fsu_bavail * fsusage.fsu_blocksize;
+ self->checked_bytes_used = 0;
+ self->checked_fs_free_time = time(NULL);
+
+ if (self->checked_fs_free_bytes - size <= eom_warning_buffer) {
+ g_debug("%s: at LEOM", DEVICE(self)->device_name);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+check_at_peom(VfsDevice *self, guint64 size)
+{
+ if (self->enforce_volume_limit && (self->volume_limit > 0)) {
+ guint64 newtotal = self->volume_bytes + size;
+ if (newtotal > self->volume_limit) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
+vfs_device_recycle_file (Device * dself, guint filenum) {
+ VfsDevice * self = VFS_DEVICE(dself);