Change enums to u32 for stored fields
[yaffs2.git] / linux-tests / verifybigsparse.c
1 #define _LARGEFILE64_SOURCE
2 #include<stdio.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include <string.h>
9
10
11 #define N_WRITES 16
12 #define STRIDE   250000
13
14 #define BUFFER_N 1100
15 unsigned  xxbuffer[BUFFER_N];
16
17
18 void set_buffer(int n)
19 {
20         int i;
21         for(i = 0; i < BUFFER_N; i++)
22                 xxbuffer[i] = i + n;
23 }
24
25
26 void verify_big_sparse_file(int h)
27 {
28         unsigned check_buffer[BUFFER_N];
29         int i;
30         loff_t offset = 0;
31         loff_t pos;
32         int n = sizeof(check_buffer);
33         int result;
34         const char * check_type;
35         int checks_failed = 0;
36         int checks_passed = 0;
37
38         for(i = 0; i < N_WRITES * STRIDE; i++) {
39                 if(i % STRIDE) {
40                         check_type = "zero";
41                         memset(xxbuffer,0, n);
42                 } else {
43                         check_type = "buffer";
44                         set_buffer(i/STRIDE);
45                 }
46                 //printf("%s checking %lld\n", check_type, offset);
47                 pos = lseek64(h, offset, SEEK_SET);
48                 if(pos != offset) {
49                         printf("mismatched seek pos %lld offset %lld\n",
50                                 pos, offset);
51                         perror("lseek64");
52                         exit(1);
53                 }
54                 result = read(h, check_buffer, n);
55
56                 if(result != n) {
57                         printf("mismatched read result %d n %d\n", result, n);
58                         exit(1);
59                 }
60
61
62
63
64                 if(memcmp(xxbuffer, check_buffer, n)) {
65                         int j;
66
67                         printf("buffer at %lld mismatches\n", pos);
68                         printf("xxbuffer ");
69                         for(j = 0; j < 20; j++)
70                                 printf(" %d",xxbuffer[j]);
71                         printf("\n");
72                         printf("check_buffer ");
73                         for(j = 0; j < 20; j++)
74                                 printf(" %d",check_buffer[j]);
75                         printf("\n");
76
77                         checks_failed++;
78                 } else {
79                         checks_passed++;
80                 }
81
82                 offset += sizeof(xxbuffer);
83         }
84
85         printf("%d checks passed, %d checks failed\n", checks_passed, checks_failed);
86
87 }
88
89
90 int main(int argc, char *argv[])
91 {
92         int handle;
93
94         if(argc < 2) {
95                 printf("Gimme a file name!\n");
96                 exit(1);
97         }
98
99         handle = open(argv[1], O_RDONLY);
100
101         if(handle < 0) {
102                 perror("opening file");
103                 exit(1);
104         }
105
106         verify_big_sparse_file(handle);
107
108         printf("Job done\n");
109         return 0;
110 }