- Update to follow statvfs change.

- Add expected results.
This commit is contained in:
enami 2004-07-07 01:57:35 +00:00
parent cc559c8583
commit 7f914da132
4 changed files with 115 additions and 22 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.1 2004/03/26 14:53:39 enami Exp $
# $NetBSD: Makefile,v 1.2 2004/07/07 01:57:35 enami Exp $
NOMAN= # defined
@ -10,5 +10,7 @@ PROG= df
SRCS= df.c strpct.c getmntinfo.c
regress:
./df | cmp ${.CURDIR}/df.out -
./df -h | cmp ${.CURDIR}/df-h.out -
.include <bsd.prog.mk>

43
regress/bin/df/df-h.out Normal file
View File

@ -0,0 +1,43 @@
Filesystem Size Used Avail Capacity Mounted on
filer:/ 1.1T 132M 1.1T 0% /filer
filer:/ 1.1T 0B 1.1T 0% /filer
filer:/ 1.1T 229G 918G 20% /filer
filer:/ 1.1T 688G 459G 60% /filer
filer:/ 1.1T 1.1T 57G 95% /filer
filer:/ 1.1T 1.1T 0B 100% /filer
filer:/ 1.1T 0B 1.1T 0% /filer
filer:/ 1.1T 229G 860G 21% /filer
filer:/ 1.1T 688G 401G 63% /filer
filer:/ 1.1T 1.1T 0B 100% /filer
filer:/ 1.1T 1.1T -57G 105% /filer
filer:/ 1.1T 0B 1.0T 0% /filer
filer:/ 1.1T 229G 803G 22% /filer
filer:/ 1.1T 688G 344G 66% /filer
filer:/ 1.1T 1.1T -57G 105% /filer
filer:/ 1.1T 1.1T -115G 111% /filer
filer:/ 1.1T 0B 975G 0% /filer
filer:/ 1.1T 229G 746G 23% /filer
filer:/ 1.1T 688G 287G 70% /filer
filer:/ 1.1T 1.1T -115G 111% /filer
filer:/ 1.1T 1.1T -172G 117% /filer
/dev/ld0g 1.2T 17G 1.1T 1% /anon-root
/dev/ld0g 1.2T 0B 1.2T 0% /anon-root
/dev/ld0g 1.2T 250G 998G 20% /anon-root
/dev/ld0g 1.2T 749G 499G 60% /anon-root
/dev/ld0g 1.2T 1.2T 62G 95% /anon-root
/dev/ld0g 1.2T 1.2T 0B 100% /anon-root
/dev/ld0g 1.2T 0B 1.2T 0% /anon-root
/dev/ld0g 1.2T 250G 936G 21% /anon-root
/dev/ld0g 1.2T 749G 437G 63% /anon-root
/dev/ld0g 1.2T 1.2T 0B 100% /anon-root
/dev/ld0g 1.2T 1.2T -62G 105% /anon-root
/dev/ld0g 1.2T 0B 1.1T 0% /anon-root
/dev/ld0g 1.2T 250G 874G 22% /anon-root
/dev/ld0g 1.2T 749G 374G 66% /anon-root
/dev/ld0g 1.2T 1.2T -62G 105% /anon-root
/dev/ld0g 1.2T 1.2T -125G 111% /anon-root
/dev/ld0g 1.2T 0B 1.0T 0% /anon-root
/dev/ld0g 1.2T 250G 811G 23% /anon-root
/dev/ld0g 1.2T 749G 312G 70% /anon-root
/dev/ld0g 1.2T 1.2T -125G 111% /anon-root
/dev/ld0g 1.2T 1.2T -187G 117% /anon-root

43
regress/bin/df/df.out Normal file
View File

@ -0,0 +1,43 @@
Filesystem 1K-blocks Used Avail Capacity Mounted on
filer:/ 1202716672 135168 1202581504 0% /filer
filer:/ 1202716672 0 1202716672 0% /filer
filer:/ 1202716672 240543334 962173337 20% /filer
filer:/ 1202716672 721630003 481086668 60% /filer
filer:/ 1202716672 1142580838 60135833 95% /filer
filer:/ 1202716672 1202716672 0 100% /filer
filer:/ 1202716672 0 1142580838 0% /filer
filer:/ 1202716672 240543334 902037504 21% /filer
filer:/ 1202716672 721630003 420950835 63% /filer
filer:/ 1202716672 1142580838 0 100% /filer
filer:/ 1202716672 1202716672 -60135833 105% /filer
filer:/ 1202716672 0 1082445004 0% /filer
filer:/ 1202716672 240543334 841901670 22% /filer
filer:/ 1202716672 721630003 360815001 66% /filer
filer:/ 1202716672 1142580838 -60135833 105% /filer
filer:/ 1202716672 1202716672 -120271667 111% /filer
filer:/ 1202716672 0 1022309171 0% /filer
filer:/ 1202716672 240543334 781765836 23% /filer
filer:/ 1202716672 721630003 300679168 70% /filer
filer:/ 1202716672 1142580838 -120271667 111% /filer
filer:/ 1202716672 1202716672 -180407500 117% /filer
/dev/ld0g 1308726116 17901268 1225388540 1% /anon-root
/dev/ld0g 1308726116 0 1308726116 0% /anon-root
/dev/ld0g 1308726116 261745224 1046980892 20% /anon-root
/dev/ld0g 1308726116 785235672 523490444 60% /anon-root
/dev/ld0g 1308726116 1243289812 65436304 95% /anon-root
/dev/ld0g 1308726116 1308726116 0 100% /anon-root
/dev/ld0g 1308726116 0 1243289808 0% /anon-root
/dev/ld0g 1308726116 261745224 981544584 21% /anon-root
/dev/ld0g 1308726116 785235672 458054140 63% /anon-root
/dev/ld0g 1308726116 1243289812 0 100% /anon-root
/dev/ld0g 1308726116 1308726116 -65436304 105% /anon-root
/dev/ld0g 1308726116 0 1177853504 0% /anon-root
/dev/ld0g 1308726116 261745224 916108280 22% /anon-root
/dev/ld0g 1308726116 785235672 392617832 66% /anon-root
/dev/ld0g 1308726116 1243289812 -65436304 105% /anon-root
/dev/ld0g 1308726116 1308726116 -130872608 111% /anon-root
/dev/ld0g 1308726116 0 1112417196 0% /anon-root
/dev/ld0g 1308726116 261745224 850671972 23% /anon-root
/dev/ld0g 1308726116 785235672 327181528 70% /anon-root
/dev/ld0g 1308726116 1243289812 -130872608 111% /anon-root
/dev/ld0g 1308726116 1308726116 -196308916 117% /anon-root

View File

@ -1,4 +1,4 @@
/* $NetBSD: getmntinfo.c,v 1.1 2004/03/26 14:53:39 enami Exp $ */
/* $NetBSD: getmntinfo.c,v 1.2 2004/07/07 01:57:35 enami Exp $ */
#include <sys/param.h>
#include <sys/ucred.h>
@ -12,47 +12,48 @@
#define MB * 1024 KB
#define GB * 1024 MB
static struct statfs *getnewstatfs(void);
static void other_variants(const struct statfs *, const int *, int,
static struct statvfs *getnewstatvfs(void);
static void other_variants(const struct statvfs *, const int *, int,
const int *, int);
static void setup_filer(void);
static void setup_ld0g(void);
static struct statfs *allstatfs;
static struct statvfs *allstatvfs;
static int sftotal, sfused;
struct statfs *
getnewstatfs(void)
struct statvfs *
getnewstatvfs(void)
{
if (sftotal == sfused) {
sftotal = sftotal ? sftotal * 2 : 1;
allstatfs = realloc(allstatfs,
sftotal * sizeof(struct statfs));
if (allstatfs == NULL)
allstatvfs = realloc(allstatvfs,
sftotal * sizeof(struct statvfs));
if (allstatvfs == NULL)
err(EXIT_FAILURE, "realloc");
}
return (&allstatfs[sfused++]);
return (&allstatvfs[sfused++]);
}
void
other_variants(const struct statfs *tmpl, const int *minfree, int minfreecnt,
other_variants(const struct statvfs *tmpl, const int *minfree, int minfreecnt,
const int *consumed, int consumedcnt)
{
int64_t total, used;
struct statfs *sf;
struct statvfs *sf;
int i, j;
for (i = 0; i < minfreecnt; i++)
for (j = 0; j < consumedcnt; j++) {
sf = getnewstatfs();
sf = getnewstatvfs();
*sf = *tmpl;
total = (int64_t)(u_long)sf->f_blocks * sf->f_bsize;
used = total * consumed[j] / 100;
sf->f_bfree = (total - used) / sf->f_bsize;
sf->f_bavail = (total * (100 - minfree[i]) / 100 -
used) / sf->f_bsize;
sf->f_bresvd = sf->f_bfree - sf->f_bavail;
}
}
@ -63,14 +64,16 @@ other_variants(const struct statfs *tmpl, const int *minfree, int minfreecnt,
void
setup_filer(void)
{
static const struct statfs tmpl = {
static const struct statvfs tmpl = {
#define BSIZE 512
#define TOTAL 1147ULL GB
#define USED 132ULL MB
.f_bsize = BSIZE,
.f_frsize = BSIZE,
.f_blocks = TOTAL / BSIZE,
.f_bfree = (TOTAL - USED) / BSIZE,
.f_bavail = (TOTAL - USED) / BSIZE,
.f_bresvd = 0,
.f_mntfromname = "filer:/",
.f_mntonname = "/filer",
#undef USED
@ -79,9 +82,9 @@ setup_filer(void)
};
static const int minfree[] = { 0, 5, 10, 15, };
static const int consumed[] = { 0, 20, 60, 95, 100 };
struct statfs *sf;
struct statvfs *sf;
sf = getnewstatfs();
sf = getnewstatvfs();
*sf = tmpl;
other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]),
consumed, sizeof(consumed) / sizeof(consumed[0]));
@ -94,15 +97,17 @@ setup_filer(void)
void
setup_ld0g(void)
{
static const struct statfs tmpl = {
static const struct statvfs tmpl = {
#define BSIZE 4096 /* Guess */
#define TOTAL 1308726116ULL KB
#define USED 17901268ULL KB
#define AVAIL 1225388540ULL KB
.f_bsize = BSIZE,
.f_frsize = BSIZE,
.f_blocks = TOTAL / BSIZE,
.f_bfree = (TOTAL - USED) / BSIZE,
.f_bavail = AVAIL / BSIZE,
.f_bresvd = (TOTAL - USED) / BSIZE - AVAIL / BSIZE,
.f_mntfromname = "/dev/ld0g",
.f_mntonname = "/anon-root",
#undef AVAIL
@ -112,21 +117,21 @@ setup_ld0g(void)
};
static const int minfree[] = { 0, 5, 10, 15, };
static const int consumed[] = { 0, 20, 60, 95, 100 };
struct statfs *sf;
struct statvfs *sf;
sf = getnewstatfs();
sf = getnewstatvfs();
*sf = tmpl;
other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]),
consumed, sizeof(consumed) / sizeof(consumed[0]));
}
int
getmntinfo(struct statfs **mntbuf, int flags)
getmntinfo(struct statvfs **mntbuf, int flags)
{
setup_filer();
setup_ld0g();
*mntbuf = allstatfs;
*mntbuf = allstatvfs;
return (sfused);
}