From: Nathan Scott Date: Tue, 18 Jun 2002 04:37:18 +0000 (+0000) Subject: add fstest.c and mmapcat.c - keep a copy of these here so they don't get X-Git-Tag: v1.1.0~1078 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=eafc89f616f3dd7d0ce43aad75893561f4807c92;p=users%2Fhch%2Fxfstests-dev.git add fstest.c and mmapcat.c - keep a copy of these here so they don't get lost and so that I can write some QA tests which make use of em. authors are listed at the head of each file, minor mods made to fix warnings, etc. --- diff --git a/src/Makefile b/src/Makefile index 64fb18de7..e3c31baaa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -35,7 +35,8 @@ include $(TOPDIR)/include/builddefs TARGETS = alloc acl_get bstat devzero dirstress fault feature \ fsstress fill fill2 getpagesize holes ioctl loggen lstat64 \ - nametest permname randholes runas truncfile usemem + nametest permname randholes runas truncfile usemem \ + fstest mmapcat ifeq ($(HAVE_DB), true) TARGETS += dbtest endif diff --git a/src/fstest.c b/src/fstest.c new file mode 100644 index 000000000..a0078bc52 --- /dev/null +++ b/src/fstest.c @@ -0,0 +1,340 @@ +/* Verification tool, designed to detect data corruption on a filesystem + + tridge@samba.org, March 2002 + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* variables settable on the command line */ +static int loop_count = 100; +static int num_files = 1; +static int file_size = 1024*1024; +static int block_size = 1024; +static char *base_dir = "."; +static int use_mmap; +static int use_sync; +static int do_frags = 1; + +typedef unsigned char uchar; + +#ifndef MIN +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif + +static void *x_malloc(int size) +{ + void *ret = malloc(size); + if (!ret) { + fprintf(stderr,"Out of memory for size %d!\n", size); + exit(1); + } + return ret; +} + + +/* generate a buffer for a particular child, fnum etc. Just use a simple buffer + to make debugging easy +*/ +static void gen_buffer(uchar *buf, int loop, int child, int fnum, int ofs) +{ + uchar v = (loop+child+fnum+(ofs/block_size)) % 256; + memset(buf, v, block_size); +} + +/* + check if a buffer from disk is correct +*/ +static void check_buffer(uchar *buf, int loop, int child, int fnum, int ofs) +{ + uchar *buf2; + + buf2 = x_malloc(block_size); + + gen_buffer(buf2, loop, child, fnum, ofs); + + if (memcmp(buf, buf2, block_size) != 0) { + int i, j; + for (i=0;buf[i] == buf2[i] && id_name,".") == 0) continue; + if (strcmp(de->d_name,"..") == 0) continue; + + sprintf(fname, "%s/%s", dir, de->d_name); + if (lstat(fname, &st)) { + perror(fname); + continue; + } + + if (S_ISDIR(st.st_mode)) { + traverse(fname, fn); + } + + fn(fname); + } + + closedir(d); +} + +/* the main child function - this creates/checks the file for one child */ +static void run_child(int child) +{ + int i, loop; + char dir[1024]; + + sprintf(dir, "%s/child%d", base_dir, child); + + /* cleanup any old files */ + if (remove(dir) != 0 && errno != ENOENT) { + printf("Child %d cleaning %s\n", child, dir); + traverse(dir, remove); + remove(dir); + } + + if (mkdir(dir, 0755) != 0) { + perror(dir); + exit(1); + } + + for (loop = 0; loop < loop_count; loop++) { + printf("Child %d loop %d\n", child, loop); + for (i=0;i +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int fd; + char *ptr; + struct stat64 st; + + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + perror(argv[1]); + exit(1); + } + fstat64(fd, &st); + ptr = mmap64(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + while (*ptr != 0) + write(1, ptr++, 1); + exit(0); +}