git-annex/Utility/libdiskfree.c
Joey Hess e213ef310f git-annex (5.20140717) unstable; urgency=high
* Fix minor FD leak in journal code. Closes: #754608
  * direct: Fix handling of case where a work tree subdirectory cannot
    be written to due to permissions.
  * migrate: Avoid re-checksumming when migrating from hashE to hash backend.
  * uninit: Avoid failing final removal in some direct mode repositories
    due to file modes.
  * S3: Deal with AWS ACL configurations that do not allow creating or
    checking the location of a bucket, but only reading and writing content to
    it.
  * resolvemerge: New plumbing command that runs the automatic merge conflict
    resolver.
  * Deal with change in git 2.0 that made indirect mode merge conflict
    resolution leave behind old files.
  * sync: Fix git sync with local git remotes even when they don't have an
    annex.uuid set. (The assistant already did so.)
  * Set gcrypt-publish-participants when setting up a gcrypt repository,
    to avoid unncessary passphrase prompts.
    This is a security/usability tradeoff. To avoid exposing the gpg key
    ids who can decrypt the repository, users can unset
    gcrypt-publish-participants.
  * Install nautilus hooks even when ~/.local/share/nautilus/ does not yet
    exist, since it is not automatically created for Gnome 3 users.
  * Windows: Move .vbs files out of git\bin, to avoid that being in the
    PATH, which caused some weird breakage. (Thanks, divB)
  * Windows: Fix locking issue that prevented the webapp starting
    (since 5.20140707).

# imported from the archive
2014-07-17 11:27:25 -04:00

92 lines
2 KiB
C

/* disk free space checking, C mini-library
*
* Copyright 2012, 2014 Joey Hess <joey@kitenet.net>
*
* License: BSD-2-clause
*/
/* Include appropriate headers for the OS, and define what will be used to
* check the free space. */
#if defined(__APPLE__)
# include <sys/param.h>
# include <sys/mount.h>
/* In newer OSX versions, statfs64 is deprecated, in favor of statfs,
* which is 64 bit only with a build option -- but statfs64 still works,
* and this keeps older OSX also supported. */
# define STATCALL statfs64
# define STATSTRUCT statfs64
#else
#if defined (__FreeBSD__)
# include <sys/param.h>
# include <sys/mount.h>
# define STATCALL statfs /* statfs64 not yet tested on a real FreeBSD machine */
# define STATSTRUCT statfs
#else
#if defined __ANDROID__
# warning free space checking code not available for Android
# define UNKNOWN
#else
#if defined (__linux__) || defined (__FreeBSD_kernel__)
/* Linux or Debian kFreeBSD */
/* This is a POSIX standard, so might also work elsewhere too. */
# include <sys/statvfs.h>
# define STATCALL statvfs
# define STATSTRUCT statvfs
#else
# warning free space checking code not available for this OS
# define UNKNOWN
#endif
#endif
#endif
#endif
#include <errno.h>
#include <stdio.h>
unsigned long long int get(const char *path, int req) {
#ifdef UNKNOWN
errno = 1;
return 0;
#else
unsigned long long int v, blocksize;
struct STATSTRUCT buf;
if (STATCALL(path, &buf) != 0)
return 0; /* errno is set */
else
errno = 0;
switch (req) {
case 0:
v = buf.f_blocks;
break;
case 1:
v = buf.f_bavail;
break;
default:
v = 0;
}
blocksize = buf.f_bsize;
return v * blocksize;
#endif
}
/* Checks the amount of disk that is available to regular (non-root) users.
* (If there's an error, or this is not supported,
* returns 0 and sets errno to nonzero.)
*/
unsigned long long int diskfree(const char *path) {
return get(path, 1);
}
/* Gets the total size of the disk. */
unsigned long long int disksize(const char *path) {
return get(path, 0);
}
/*
main () {
printf("%lli\n", diskfree("."));
}
*/