Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
22ad1c95
Commit
22ad1c95
authored
Oct 07, 2014
by
Martin Blix Grydeland
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
VFIL_fsinfo function to retrieve file system information
parent
3eeafa8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
vfil.h
include/vfil.h
+1
-0
vfil.c
lib/libvarnish/vfil.c
+51
-0
No files found.
include/vfil.h
View file @
22ad1c95
...
...
@@ -34,3 +34,4 @@ int VFIL_tmpfile(char *);
char
*
VFIL_readfile
(
const
char
*
pfx
,
const
char
*
fn
,
ssize_t
*
sz
);
char
*
VFIL_readfd
(
int
fd
,
ssize_t
*
sz
);
int
VFIL_nonblocking
(
int
fd
);
int
VFIL_fsinfo
(
int
fd
,
unsigned
*
pbs
,
uintmax_t
*
size
,
uintmax_t
*
space
);
lib/libvarnish/vfil.c
View file @
22ad1c95
...
...
@@ -38,6 +38,18 @@
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/types.h>
#ifdef HAVE_SYS_MOUNT_H
# include <sys/param.h>
# include <sys/mount.h>
#endif
#ifdef HAVE_SYS_STATVFS_H
# include <sys/statvfs.h>
#endif
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif
#include "vas.h"
#include "vdef.h"
...
...
@@ -136,3 +148,42 @@ VFIL_nonblocking(int fd)
assert
(
i
!=
-
1
);
return
(
i
);
}
/*
* Get file system information from an fd
* Returns block size, total size and space available in the passed pointers
* Returns 0 on success, or -1 on failure with errno set
*/
int
VFIL_fsinfo
(
int
fd
,
unsigned
*
pbs
,
uintmax_t
*
psize
,
uintmax_t
*
pspace
)
{
unsigned
bs
;
uintmax_t
size
,
space
;
#if defined(HAVE_SYS_STATVFS_H)
struct
statvfs
fsst
;
if
(
fstatvfs
(
fd
,
&
fsst
))
return
(
-
1
);
bs
=
fsst
.
f_frsize
;
size
=
fsst
.
f_blocks
*
fsst
.
f_frsize
;
space
=
fsst
.
f_bavail
*
fsst
.
f_frsize
;
#elif defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_VFS_H)
struct
statfs
fsst
;
if
(
fstatfs
(
fd
,
&
fsst
))
return
(
-
1
);
bs
=
fsst
.
f_bsize
;
size
=
fsst
.
f_blocks
*
fsst
.
f_bsize
;
space
=
fsst
.
f_bavail
*
fsst
.
f_bsize
;
#else
#error no struct statfs / struct statvfs
#endif
if
(
pbs
)
*
pbs
=
bs
;
if
(
psize
)
*
psize
=
size
;
if
(
pspace
)
*
pspace
=
space
;
return
(
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment