summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2010-08-01 12:18:46 +0000
committerCharlie <root@a5.ams.npubs.net>2010-08-01 12:18:46 +0000
commitf96d190facbbd33b09163b77ba4e681ca48a5d17 (patch)
tree5caa69634eef6ce17d2bca4b17db0f1a23980e97
parente43bf99d505c280c694da7ccd0ab68b5deec187b (diff)
Lookup jail size from file system if directory matches a mount.
-rw-r--r--tools/jail-measure.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/tools/jail-measure.c b/tools/jail-measure.c
index 9c57ded..55a34b1 100644
--- a/tools/jail-measure.c
+++ b/tools/jail-measure.c
@@ -35,8 +35,12 @@
* Stef Walter <stef@memberwebs.com>
*/
+#include "config.h"
+
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/mount.h>
#include <err.h>
#include <errno.h>
@@ -97,7 +101,7 @@ check_skip_link (FTSENT *f)
}
static void
-measure_jail (const char *path)
+iterate_jail_fs (const char *path)
{
const char *paths[2] = { path, NULL };
FTS *fts;
@@ -105,6 +109,7 @@ measure_jail (const char *path)
jail_blocks = 0;
jail_bytes = 0;
+
hsh_clear (jail_inodes);
fts = fts_open ((char**)paths, FTS_COMFOLLOW | FTS_PHYSICAL | FTS_XDEV, NULL);
@@ -141,6 +146,21 @@ measure_jail (const char *path)
}
fts_close (fts);
+}
+
+static void
+measure_jail (const char *path)
+{
+ struct statfs sf;
+
+ /* See if this is a mount point, and if not iterate all files */
+ if (statfs (path, &sf) != 0 || strcmp (path, sf.f_mntonname) != 0) {
+ iterate_jail_fs (path);
+
+ } else {
+ jail_files = sf.f_files - sf.f_ffree;
+ jail_blocks = sf.f_blocks - sf.f_bfree;
+ }
printf ("jail-space: %llu %s\n", (long long unsigned)(jail_blocks * 512), path);
printf ("jail-files: %llu %s\n", (long long unsigned)jail_files, path);