Add some write-verification tools [copy seems to work]
This commit is contained in:
parent
327523aabf
commit
f2d729aee2
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,6 +11,7 @@ initrd/etc
|
||||
hdd/boot
|
||||
hdd/bin/*
|
||||
hdd/etc/hostname
|
||||
hdd/lib
|
||||
.gdb_history
|
||||
bootdisk.img
|
||||
util/toaru-toolchain/*
|
||||
|
56
userspace/compare.c
Normal file
56
userspace/compare.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CHUNK_SIZE 1024
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Need two files to compare.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
FILE * a = fopen(argv[1], "r");
|
||||
FILE * b = fopen(argv[2], "r");
|
||||
size_t lengtha, lengthb;
|
||||
|
||||
fseek(a, 0, SEEK_END);
|
||||
lengtha = ftell(a);
|
||||
fseek(a, 0, SEEK_SET);
|
||||
|
||||
fseek(b, 0, SEEK_END);
|
||||
lengthb = ftell(b);
|
||||
fseek(b, 0, SEEK_SET);
|
||||
|
||||
fprintf(stderr,"[%d bytes and %d bytes]\n", lengtha, lengthb);
|
||||
|
||||
char bufa[CHUNK_SIZE];
|
||||
char bufb[CHUNK_SIZE];
|
||||
|
||||
int chunk = 0;
|
||||
size_t read = 0;
|
||||
|
||||
while (read < lengtha) {
|
||||
memset(bufa, 0x0, CHUNK_SIZE);
|
||||
memset(bufb, 0x0, CHUNK_SIZE);
|
||||
fread(bufa, 1, CHUNK_SIZE, a);
|
||||
fread(bufb, 1, CHUNK_SIZE, b);
|
||||
size_t different = 0;
|
||||
for (int i = 0; i < CHUNK_SIZE; ++i) {
|
||||
if (bufa[i] != bufb[i])
|
||||
different++;
|
||||
}
|
||||
|
||||
if (different > 0) {
|
||||
printf("Chunk %d has %d differing bytes.\n", chunk, different);
|
||||
}
|
||||
|
||||
read += CHUNK_SIZE;
|
||||
chunk++;
|
||||
}
|
||||
|
||||
fclose(a);
|
||||
fclose(b);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
39
userspace/verify-write.c
Normal file
39
userspace/verify-write.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define CHUNK_SIZE 1024
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
if (argc < 3) {
|
||||
printf("Expected two arguments, the file to read, and the filename to write out to.\nTry again, maybe?\n");
|
||||
return -1;
|
||||
}
|
||||
FILE * input = fopen(argv[1], "r");
|
||||
FILE * output = fopen(argv[2], "w");
|
||||
size_t length;
|
||||
|
||||
fseek(input, 0, SEEK_END);
|
||||
length = ftell(input);
|
||||
fseek(input, 0, SEEK_SET);
|
||||
|
||||
char buf[CHUNK_SIZE];
|
||||
while (length > CHUNK_SIZE) {
|
||||
fread( buf, 1, CHUNK_SIZE, input);
|
||||
fwrite(buf, 1, CHUNK_SIZE, output);
|
||||
fflush(output);
|
||||
length -= CHUNK_SIZE;
|
||||
}
|
||||
if (length > 0) {
|
||||
fread( buf, 1, length, input);
|
||||
fwrite(buf, 1, length, output);
|
||||
fflush(output);
|
||||
}
|
||||
|
||||
fclose(output);
|
||||
fclose(input);
|
||||
|
||||
char * args[] = {"/bin/compare", argv[1], argv[2], NULL };
|
||||
execve(args[0], args, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user