This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_boot.c
61 lines (52 loc) · 1.72 KB
/
read_boot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
typedef struct {
unsigned char first_byte;
unsigned char start_chs[3];
unsigned char partition_type;
unsigned char end_chs[3];
char start_sector[4];
char length_sectors[4];
} __attribute((packed)) PartitionTable;
typedef struct {
unsigned char jmp[3];
char oem[8];
unsigned short sector_size; // 2 bytes
// {...} COMPLETAR
char volume_id[4];
char volume_label[11];
char fs_type[8]; // Type en ascii
char boot_code[448];
unsigned short boot_sector_signature;
} __attribute((packed)) Fat12BootSector;
int main() {
FILE * in = fopen("test.img", "rb");
int i;
PartitionTable pt[4];
Fat12BootSector bs;
fseek(in, 0x1BE, SEEK_SET); // Ir al inicio de la tabla de particiones
fread(pt, sizeof(PartitionTable), 4, in); // leo entradas
for(i=0; i<4; i++) {
printf("Partition type: %d\n", pt[i].partition_type);
if(pt[i].partition_type == 1) {
printf("Encontrado FAT12 %d\n", i);
break;
}
}
if(i == 4) {
printf("No se encontró filesystem FAT12, saliendo ...\n");
return -1;
}
fseek(in, 0, SEEK_SET);
fread(&bs, sizeof(Fat12BootSector), 1, in);
printf(" Jump code: %02X:%02X:%02X\n", bs.jmp[0], bs.jmp[1], bs.jmp[2]);
printf(" OEM code: [%.8s]\n", bs.oem);
printf(" sector_size: %d\n", bs.sector_size);
// {...} COMPLETAR
printf(" volume_id: 0x%08X\n", (unsigned int)bs.volume_id);
printf(" Volume label: [%.11s]\n", bs.volume_label);
printf(" Filesystem type: [%.8s]\n", bs.fs_type);
printf(" Boot sector signature: 0x%04X\n", bs.boot_sector_signature);
fclose(in);
return 0;
}