1 #include <exec/types.h>
2 #include <dos/dosextens.h>
4 #include <proto/exec.h>
10 void hexdump(UBYTE
*buf
, int size
) {
14 for (i
= 0; i
< size
; i
+= CHUNK
) {
17 count
= ((size
-i
) > CHUNK
? CHUNK
: size
-i
);
19 for (j
= 0; j
< count
; j
++) {
20 if (j
== CHUNK
/ 2) fputc(' ', stdout
);
21 printf("%02x ", buf
[i
+j
]);
24 for (j
= count
; j
< CHUNK
; j
++) {
25 if (j
== CHUNK
/ 2) fputc(' ', stdout
);
33 int round1(char *filename
) {
39 fputs("\nround 1: 1024 buffers of 1024 bytes each\n\n", stdout
);
41 fh
= Open(filename
, MODE_NEWFILE
);
43 printf("couldn't open '%s' for write (%ld)\n", filename
, IoErr());
47 printf("opened '%s' for write\n", filename
);
49 fputs("writing... ", stdout
);
52 for (n
= 0; n
< 1024; n
++) {
53 for (i
= 0; i
< 1024; i
++)
54 buf
[i
] = (i
+ n
) & 0xff;
56 bytes
= Write(fh
, buf
, 1024);
58 printf("buffer %d: error (%ld)\n", n
, IoErr());
64 printf("buffer %d: short write! error is %ld\n", n
, IoErr());
70 fputs("1024 buffers written\n", stdout
);
74 fh
= Open(filename
, MODE_OLDFILE
);
76 printf("couldn't open '%s' for read (%ld)\n", filename
, IoErr());
80 printf("opened '%s' for read\n", filename
);
82 fputs("reading... ", stdout
);
85 for (n
= 0; n
< 1024; n
++) {
86 bytes
= Read(fh
, buf
, 1024);
88 printf("buffer %d: error (%ld)\n", n
, IoErr());
93 printf("buffer %d: short read! error is %ld\n", n
, IoErr());
98 for (i
= 0; i
< 1024; i
++)
99 if (buf
[i
] != ((i
+ n
) & 0xff)) {
100 printf("buffer %d: verify error!\n file pos %d, expected 0x%02x, got 0x%02x\n", n
, n
* 1024 + i
, ((i
+ n
) & 0xff), buf
[i
]);
101 printf("buffer dump (0x%02x bytes):\n", 1024);
108 fputs("1024 buffers read and verified\n", stdout
);
112 DeleteFile(filename
);
114 fputs("cleaned up\n", stdout
);
119 int round2(char *filename
) {
125 fputs("\nround 2: 8192 buffers, increasing length from 0-1023 bytes\n\n", stdout
);
127 fh
= Open(filename
, MODE_NEWFILE
);
129 printf("couldn't open '%s' for write (%ld)\n", filename
, IoErr());
133 printf("opened '%s' for write\n", filename
);
135 fputs("writing... ", stdout
);
138 for (n
= 0; n
< 8192; n
++) {
139 for (i
= 0; i
< (n
& 1023); i
++)
140 buf
[i
] = (i
+ n
) & 0xff;
142 bytes
= Write(fh
, buf
, (n
& 1023));
144 printf("buffer %d: error (%ld)\n", n
, IoErr());
149 if (bytes
< (n
& 1023)) {
150 printf("buffer %d: short write! error is %ld\n", n
, IoErr());
156 fputs("1024 buffers written\n", stdout
);
160 fh
= Open(filename
, MODE_OLDFILE
);
162 printf("couldn't open '%s' for read (%ld)\n", filename
, IoErr());
166 printf("opened '%s' for read\n", filename
);
168 fputs("reading... ", stdout
);
171 for (n
= 0; n
< 8192; n
++) {
172 bytes
= Read(fh
, buf
, (n
& 1023));
174 printf("buffer %d: error (%ld)\n", n
, IoErr());
178 if (bytes
< (n
& 1023)) {
179 printf("buffer %d: short read! error is %ld\n", n
, IoErr());
184 for (i
= 0; i
< (n
& 1023); i
++)
185 if (buf
[i
] != ((i
+ n
) & 0xff)) {
186 printf("buffer %d: verify error!\n file pos %d, expected 0x%02x, got 0x%02x\n", n
, n
* (n
& 1023) + i
, ((i
+ n
) & 0xff), buf
[i
]);
187 printf("buffer dump (0x%02x bytes):\n", (n
& 1023));
194 fputs("8192 buffers read and verified\n", stdout
);
198 //DeleteFile(filename);
200 fputs("cleaned up\n", stdout
);
205 int main(int argc
, char **argv
) {
207 printf("usage: %s filename\n", argv
[0]);
211 if (round1(argv
[1]) || round2(argv
[1]))