Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
973afcc4
Commit
973afcc4
authored
6 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Move tor_get_avail_disk_space() to lib/fs
parent
f0319fcb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/common/compat.c
+0
-40
0 additions, 40 deletions
src/common/compat.c
src/lib/fs/freespace.c
+56
-0
56 additions, 0 deletions
src/lib/fs/freespace.c
src/lib/fs/include.am
+1
-0
1 addition, 0 deletions
src/lib/fs/include.am
with
57 additions
and
40 deletions
src/common/compat.c
+
0
−
40
View file @
973afcc4
...
...
@@ -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) || ... */
}
This diff is collapsed.
Click to expand it.
src/lib/fs/freespace.c
0 → 100644
+
56
−
0
View file @
973afcc4
/* 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) || ... */
}
This diff is collapsed.
Click to expand it.
src/lib/fs/include.am
+
1
−
0
View file @
973afcc4
...
...
@@ -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 \
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment