summaryrefslogtreecommitdiff
path: root/gio/glocalfile.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2012-01-09 21:49:08 -0500
committerMatthias Clasen <mclasen@redhat.com>2012-01-09 21:49:08 -0500
commit00c00e2f3f3194202877e54a2429bd1a4f9c5526 (patch)
tree1a625ef26f385fb62c146b8080452c79c2c72dba /gio/glocalfile.c
parent31960257a6f52a4ec92d70986969f3f7ce336c4c (diff)
downloadglib-00c00e2f3f3194202877e54a2429bd1a4f9c5526.tar.gz
Add G_FILE_ATTRIBUTE_FILESYSTEM_USED to get exact used space
This is implemented by with statfs_buffer.f_bavail (free blocks for unprivileged users) as a default way to retrieve real free space. Based on a patch by Marcus Carlson, bug 625751.
Diffstat (limited to 'gio/glocalfile.c')
-rw-r--r--gio/glocalfile.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index 7c1b05bfc..cfd805a1b 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -993,6 +993,25 @@ g_local_file_query_filesystem_info (GFile *file,
#endif /* G_OS_WIN32 */
}
+ if (!no_size &&
+ g_file_attribute_matcher_matches (attribute_matcher,
+ G_FILE_ATTRIBUTE_FILESYSTEM_USED))
+ {
+#ifdef G_OS_WIN32
+ gchar *localdir = g_path_get_dirname (local->filename);
+ wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
+ ULARGE_INTEGER li_free;
+ ULARGE_INTEGER li_total;
+
+ g_free (localdir);
+ if (GetDiskFreeSpaceExW (wdirname, &li_free, &li_total, NULL))
+ g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USED, (guint64)li_total.QuadPart - (guint64)li_free.QuadPart);
+ g_free (wdirname);
+#else
+ g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USED, block_size * (statfs_buffer.f_blocks - statfs_buffer.f_bfree));
+#endif /* G_OS_WIN32 */
+ }
+
#ifndef G_OS_WIN32
#ifdef USE_STATFS
#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)