diff options
author | Christophe Fergeau <teuf@gnome.org> | 2008-07-06 14:04:46 +0000 |
---|---|---|
committer | Christophe Fergeau <teuf@gnome.org> | 2008-07-06 14:04:46 +0000 |
commit | fce629575441fbc5ec5bb13f5b01aa011f7beefa (patch) | |
tree | 020cc9b46576e4188f7c0b479c385bf1df519ec1 /src/itdb_device.c | |
parent | c41ab5991769d2c19202e470084ed5727a7ee294 (diff) | |
download | libgpod-fce629575441fbc5ec5bb13f5b01aa011f7beefa.tar.gz libgpod-fce629575441fbc5ec5bb13f5b01aa011f7beefa.tar.xz libgpod-fce629575441fbc5ec5bb13f5b01aa011f7beefa.zip |
Pick itdb_device_get_storage_info from songbird
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@2041 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src/itdb_device.c')
-rw-r--r-- | src/itdb_device.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/itdb_device.c b/src/itdb_device.c index d15375d..f1c403b 100644 --- a/src/itdb_device.c +++ b/src/itdb_device.c @@ -1413,3 +1413,57 @@ G_GNUC_INTERNAL gboolean itdb_device_requires_checksum (Itdb_Device *device) return FALSE; } + +#ifdef WIN32 +#include <windows.h> +#else +#include <sys/statvfs.h> +#endif + +/** + * itdb_device_get_storage_info: + * + * @device: an #Itdb_Device + * @capacity: returned capacity in bytes + * @free: returned free space in bytes + * + * Return the storage info for this iPod + * + * Return value: TRUE if storage info could be obtained, FALSE otherwise + **/ +gboolean itdb_device_get_storage_info (Itdb_Device *device, guint64 *capacity, guint64 *free) +{ +#ifdef WIN32 + ULARGE_INTEGER u_free, u_capacity; +#else + struct statvfs info; + guint64 block_size; +#endif + + g_return_val_if_fail (device, FALSE); + g_return_val_if_fail (capacity, FALSE); + g_return_val_if_fail (free, FALSE); + +#ifdef WIN32 + if (GetDiskFreeSpaceEx(device->mountpoint, &u_free, &u_capacity, NULL) == 0) { + return FALSE; + } + *free = u_free.QuadPart; + *capacity = u_capacity.QuadPart; + return TRUE; +#else + if (statvfs(device->mountpoint, &info)) + return FALSE; + + if (info.f_frsize > 0) + block_size = info.f_frsize; + else + block_size = info.f_bsize; + + *capacity = info.f_blocks * block_size; + *free = info.f_bfree * block_size; + + return TRUE; +#endif +} + |