I have a project for a class in which we're supposed to read each block into a buffer and compare the bytes to look for a mp3 file signature.
We are supposed to start with a zeroed out drive (I had an ext3 filesystem which I zeroed out using dd if=/dev/zero of=/dev/sdc1
) and print out that there are no matching bytes to the file signature.
Currently, using the code shown below:
int main (int argc, char* argv[]) {
printf("argc : %d \nargv %s \n", argc, argv[1]);
ReadDataBlockTest(argv[1]);
return 0;
}
void ReadDataBlockTest(char* arg) {
int fd;
int *pointList;
int bytes;
int buffer;
if((fd = open(arg, O_RDONLY)) < 0){ //check if disk can be read
perror(arg);
exit(1);
}
for (int i = 1; i < 5; i++)
{
lseek(fd, (i * 134217728), SEEK_SET);
read(fd, &buffer, 1);
printf("C: %02X\n", buffer);
}
}
I am getting an output of
argc : 2
argv /dev/sdc1
C: 5500
C: 5500
C: 5500
C: 5500
but also sometimes the number is 5600.
My issue is that I am not sure that I am reading in the bytes correctly, or if I am, why does the output oscillate?
If I am wrong, what should I do in order to fix it? Any help is appreciated.