[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Move tor_get_avail_disk_space() to lib/fs
commit 973afcc40b52d71bfb1a1285806977fee9b843f6
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Fri Jun 29 09:34:37 2018 -0400
Move tor_get_avail_disk_space() to lib/fs
---
src/common/compat.c | 40 ------------------------------------
src/lib/fs/freespace.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/lib/fs/include.am | 1 +
3 files changed, 57 insertions(+), 40 deletions(-)
diff --git a/src/common/compat.c b/src/common/compat.c
index 63bf99de6..b0a0a302c 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -547,43 +547,3 @@ tor_getpass(const char *prompt, char *output, size_t buflen)
#error "No implementation for tor_getpass found!"
#endif /* defined(HAVE_READPASSPHRASE) || ... */
}
-
-/** Return the amount of free disk space we have permission to use, in
- * bytes. Return -1 if the amount of free space can't be determined. */
-int64_t
-tor_get_avail_disk_space(const char *path)
-{
-#ifdef HAVE_STATVFS
- struct statvfs st;
- int r;
- memset(&st, 0, sizeof(st));
-
- r = statvfs(path, &st);
- if (r < 0)
- return -1;
-
- int64_t result = st.f_bavail;
- if (st.f_frsize) {
- result *= st.f_frsize;
- } else if (st.f_bsize) {
- result *= st.f_bsize;
- } else {
- return -1;
- }
-
- return result;
-#elif defined(_WIN32)
- ULARGE_INTEGER freeBytesAvail;
- BOOL ok;
-
- ok = GetDiskFreeSpaceEx(path, &freeBytesAvail, NULL, NULL);
- if (!ok) {
- return -1;
- }
- return (int64_t)freeBytesAvail.QuadPart;
-#else
- (void)path;
- errno = ENOSYS;
- return -1;
-#endif /* defined(HAVE_STATVFS) || ... */
-}
diff --git a/src/lib/fs/freespace.c b/src/lib/fs/freespace.c
new file mode 100644
index 000000000..926b17dbd
--- /dev/null
+++ b/src/lib/fs/freespace.c
@@ -0,0 +1,56 @@
+/* Copyright (c) 2003-2004, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "lib/fs/files.h"
+#include "lib/cc/torint.h"
+
+#ifdef HAVE_SYS_STATVFS_H
+#include <sys/statvfs.h>
+#endif
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#include <string.h>
+
+/** Return the amount of free disk space we have permission to use, in
+ * bytes. Return -1 if the amount of free space can't be determined. */
+int64_t
+tor_get_avail_disk_space(const char *path)
+{
+#ifdef HAVE_STATVFS
+ struct statvfs st;
+ int r;
+ memset(&st, 0, sizeof(st));
+
+ r = statvfs(path, &st);
+ if (r < 0)
+ return -1;
+
+ int64_t result = st.f_bavail;
+ if (st.f_frsize) {
+ result *= st.f_frsize;
+ } else if (st.f_bsize) {
+ result *= st.f_bsize;
+ } else {
+ return -1;
+ }
+
+ return result;
+#elif defined(_WIN32)
+ ULARGE_INTEGER freeBytesAvail;
+ BOOL ok;
+
+ ok = GetDiskFreeSpaceEx(path, &freeBytesAvail, NULL, NULL);
+ if (!ok) {
+ return -1;
+ }
+ return (int64_t)freeBytesAvail.QuadPart;
+#else
+ (void)path;
+ errno = ENOSYS;
+ return -1;
+#endif /* defined(HAVE_STATVFS) || ... */
+}
diff --git a/src/lib/fs/include.am b/src/lib/fs/include.am
index a025eb81c..f33e4d643 100644
--- a/src/lib/fs/include.am
+++ b/src/lib/fs/include.am
@@ -9,6 +9,7 @@ src_lib_libtor_fs_a_SOURCES = \
src/lib/fs/conffile.c \
src/lib/fs/dir.c \
src/lib/fs/files.c \
+ src/lib/fs/freespace.c \
src/lib/fs/lockfile.c \
src/lib/fs/mmap.c \
src/lib/fs/path.c \
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits