2010-06-24 02:06:40 +02:00
|
|
|
#include <sys/statvfs.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#define TRIALS 10
|
|
|
|
#define SIZE 65536
|
|
|
|
|
2013-04-16 18:04:46 +02:00
|
|
|
int max_error = 3;
|
|
|
|
#include "common.h"
|
|
|
|
|
2010-06-24 02:27:26 +02:00
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
int subtest;
|
2013-09-27 14:07:37 +02:00
|
|
|
char filename[] = "statvfs_test_XXXXXX";
|
2011-11-14 11:07:49 +01:00
|
|
|
|
2013-08-14 14:29:26 +02:00
|
|
|
static void create_file(void)
|
2010-06-24 02:06:40 +02:00
|
|
|
{
|
|
|
|
char buf[SIZE]={0};
|
|
|
|
char *p;
|
2010-06-24 02:27:26 +02:00
|
|
|
ssize_t ntowrite, nwritten;
|
2010-06-24 02:06:40 +02:00
|
|
|
int fd;
|
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
subtest = 2;
|
|
|
|
if ((fd = mkstemp(filename)) < 0) e(1);
|
2010-06-24 02:06:40 +02:00
|
|
|
|
|
|
|
ntowrite = SIZE;
|
|
|
|
p = &buf[0];
|
2011-11-14 11:07:49 +01:00
|
|
|
while (ntowrite > 0) {
|
|
|
|
if ((nwritten = write(fd, p, ntowrite)) < 0) e(2);
|
2010-06-24 02:06:40 +02:00
|
|
|
p += nwritten;
|
|
|
|
ntowrite -= nwritten;
|
|
|
|
}
|
2010-06-24 02:27:26 +02:00
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
if (close(fd) < 0) e(3);
|
2010-06-24 02:06:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct statvfs stats;
|
|
|
|
unsigned long f_bsize, f_bsize_new;
|
|
|
|
unsigned long f_frsize, f_frsize_new;
|
|
|
|
fsblkcnt_t f_blocks, f_blocks_new;
|
|
|
|
fsblkcnt_t f_bfree, f_bfree_new;
|
|
|
|
fsblkcnt_t f_bavail, f_bavail_new;
|
|
|
|
fsfilcnt_t f_files, f_files_new;
|
|
|
|
fsfilcnt_t f_ffree, f_ffree_new;
|
|
|
|
fsfilcnt_t f_favail, f_favail_new;
|
|
|
|
unsigned long f_fsid, f_fsid_new;
|
|
|
|
unsigned long f_flag, f_flag_new;
|
|
|
|
unsigned long f_namemax, f_namemax_new;
|
|
|
|
int i;
|
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
start(55);
|
2010-06-24 02:27:26 +02:00
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
subtest = 1;
|
|
|
|
for(i = 0; i < TRIALS; i++) {
|
|
|
|
if (statvfs(".", &stats) < 0) e(1);
|
2010-06-24 02:06:40 +02:00
|
|
|
|
|
|
|
f_bsize = stats.f_bsize ;
|
|
|
|
f_frsize = stats.f_frsize ;
|
|
|
|
f_blocks = stats.f_blocks ;
|
|
|
|
f_bfree = stats.f_bfree ;
|
|
|
|
f_bavail = stats.f_bavail ;
|
|
|
|
f_files = stats.f_files ;
|
|
|
|
f_ffree = stats.f_ffree ;
|
|
|
|
f_favail = stats.f_favail ;
|
|
|
|
f_fsid = stats.f_fsid ;
|
|
|
|
f_flag = stats.f_flag ;
|
|
|
|
f_namemax = stats.f_namemax;
|
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
create_file();
|
2010-06-24 02:27:26 +02:00
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
if (statvfs(".", &stats) < 0) e(2);
|
|
|
|
if (unlink(filename) < 0) e(3);
|
2010-06-24 02:06:40 +02:00
|
|
|
|
|
|
|
f_bsize_new = stats.f_bsize ;
|
2011-11-14 11:07:49 +01:00
|
|
|
f_frsize_new = stats.f_frsize ;
|
|
|
|
f_blocks_new = stats.f_blocks ;
|
|
|
|
f_bfree_new = stats.f_bfree ;
|
|
|
|
f_bavail_new = stats.f_bavail ;
|
|
|
|
f_files_new = stats.f_files ;
|
|
|
|
f_ffree_new = stats.f_ffree ;
|
|
|
|
f_favail_new = stats.f_favail ;
|
|
|
|
f_fsid_new = stats.f_fsid ;
|
|
|
|
f_flag_new = stats.f_flag ;
|
|
|
|
f_namemax_new = stats.f_namemax;
|
|
|
|
|
|
|
|
if (!((f_bsize == f_bsize_new) &&
|
|
|
|
(f_frsize == f_frsize_new) &&
|
|
|
|
(f_blocks == f_blocks_new) &&
|
|
|
|
(f_bfree > f_bfree_new) &&
|
|
|
|
(f_bavail > f_bavail_new) &&
|
|
|
|
(f_files == f_files_new) &&
|
|
|
|
(f_ffree == f_ffree_new + 1) &&
|
|
|
|
(f_favail == f_favail_new + 1) &&
|
|
|
|
(f_fsid == f_fsid_new) &&
|
|
|
|
(f_flag == f_flag_new) &&
|
|
|
|
(f_namemax == f_namemax_new))) {
|
|
|
|
e(4);
|
2010-06-24 02:06:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
quit();
|
|
|
|
return(-1);
|
2010-06-24 02:06:40 +02:00
|
|
|
}
|