Initial (probably final) checkin.
[fat-rescue] / dirsearch.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <fcntl.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 #define CLUSTER_SIZE 16384
8 #define OFFSET 0x2800
9
10 int main(int argc, char **argv)
11 {
12         int fd = open("/home/sesse/minnekort.img", O_RDONLY);
13         int offset = OFFSET;
14         char rd[32];
15         
16         for ( ;; ) {
17                 if (lseek(fd, offset, SEEK_SET) != offset) {
18                         break;
19                 }
20                 read(fd, rd, 32);
21                 if (memcmp(rd, ".          ", 11) == 0) {
22                         int i;
23                         
24                         printf("Possible directory found at 0x%x\n", offset);
25                         for (i = 0; i < 128; ++i) {
26                                 read(fd, rd, 32);
27                                 printf("%c%c%c%c%c%c%c%c.%c%c%c\n",
28                                         rd[0], rd[1], rd[2], rd[3],
29                                         rd[4], rd[5], rd[6], rd[7],
30                                         rd[8], rd[9], rd[10]);
31                         }
32                 }
33                 offset += CLUSTER_SIZE;
34                 printf("0x%x\r", offset);
35                 fflush(stdout);
36         }
37         return 0;
38 }