8 #define FAT_START 0x27400
9 #define DATA_START 0x42800
10 #define CLUSTER_SIZE 16384
11 unsigned short fat[FAT_SIZE];
13 int main(int argc, char **argv)
15 int fd = open("/home/sesse/minnekort.img", O_RDONLY);
21 char filename[8 + 1 + 3 + 1];
22 char data[CLUSTER_SIZE];
25 perror("/home/sesse/minnekort.img");
30 lseek(fd, FAT_START, SEEK_SET);
31 read(fd, fat, FAT_SIZE * sizeof(unsigned short));
33 // read the directory structure in question
34 sscanf(argv[1], "%i", &offset);
35 lseek(fd, offset, SEEK_SET);
38 memcpy(filename, de, 8);
40 memcpy(filename + 9, de + 8, 3);
43 printf("Filename = %s\n", filename);
44 ofd = open(filename, O_WRONLY | O_CREAT, 0644);
46 left = *((unsigned int *)(de + 0x1c));
47 printf("Size = %u\n", left);
49 printf("Recovering:");
50 cluster = *((unsigned short *)(de + 0x1a));
51 // printf(" %u(0x%x)", cluster, cluster * CLUSTER_SIZE + DATA_START);
55 int towrite = (CLUSTER_SIZE < left) ? CLUSTER_SIZE : left;
57 lseek(fd, cluster * CLUSTER_SIZE + DATA_START, SEEK_SET);
58 read(fd, data, CLUSTER_SIZE);
59 write(ofd, data, towrite);
61 // read the next entry in the FAT
62 cluster = fat[cluster];
64 /* if (towrite < CLUSTER_SIZE)
66 printf(" %u", cluster);
69 if (cluster < 0x0002) {
73 if (cluster >= 0xfff0 && cluster < 0xfff8) {
77 if (cluster >= 0xfff8) {
81 if (towrite < CLUSTER_SIZE) {
82 printf(" (EXPECTED EOF)\n");
85 // printf("(0x%x)", cluster * CLUSTER_SIZE + DATA_START);