-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathfat32.cpp
More file actions
52 lines (49 loc) · 2.75 KB
/
fat32.cpp
File metadata and controls
52 lines (49 loc) · 2.75 KB
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
#include <kernel/fat32.h>
#include <kernel/sdhost.h>
#include <kernel/memory_func.h>
#include <kernel/mini_uart.h>
#include <kernel/string.h>
void get_mbr(struct mbr *mbr, char *buffer) {
readblock(0, buffer);
char buffer2[20];
for (int i = 0 ;i < 4; i++) {
memcpy(&mbr->entry[i].first_sector_addr, &buffer[446 + i * 16 + 8], 4);
memcpy(&mbr->entry[i].total_sectors, &buffer[446 + i * 16 + 12], 4);
io() << i << " first_sector_addr: " << u64tohex(mbr->entry[i].first_sector_addr, buffer2, sizeof(buffer2)) << "\r\n";
io() << i << " total_sectors: " << u64tohex(mbr->entry[i].total_sectors, buffer2, sizeof(buffer2)) << "\r\n";
}
}
void get_fat(struct fat32 *fat, char *sector_buffer) {
struct mbr mbr;
char buffer2[20];
io() << "Checkpoint 1\r\n";
get_mbr(&mbr, sector_buffer);
io() << "Checkpoint 2\r\n";
int fat32_start_sector = mbr.entry[0].first_sector_addr;
io() << "Checkpoint 3\r\n";
readblock(fat32_start_sector, sector_buffer);
io() << "Checkpoint 4\r\n";
memcpy(&fat->bytes_pre_logical_sector, §or_buffer[0xb], 2);
memcpy(&fat->logical_sector_per_cluster, §or_buffer[0xd], 1);
memcpy(&fat->reserved_logical_sector_size, §or_buffer[0xe], 2);
memcpy(&fat->fat_count, §or_buffer[0x10], 1);
memcpy(&fat->fat_size, §or_buffer[0x24], 4);
memcpy(&fat->root_dir_start, §or_buffer[0x2c], 4);
memcpy(&fat->fs_info_size, §or_buffer[0x30], 2);
fat->fat_start_block = fat32_start_sector + fat->reserved_logical_sector_size;
fat->data_start_block = fat->fat_start_block + fat->fat_count * fat->fat_size;
io() << "bytes_pre_logical_sector: " << u64tohex(fat->bytes_pre_logical_sector, buffer2, sizeof(buffer2)) << "\r\n";
io() << "logical_sector_per_cluster: " << u64tohex(fat->logical_sector_per_cluster, buffer2, sizeof(buffer2)) << "\r\n";
io() << "reserved_logical_sector_size: " << u64tohex(fat->reserved_logical_sector_size, buffer2, sizeof(buffer2)) << "\r\n";
io() << "fat_count: " << u64tohex(fat->fat_count, buffer2, sizeof(buffer2)) << "\r\n";
io() << "fat_size: " << u64tohex(fat->fat_size, buffer2, sizeof(buffer2)) << "\r\n";
io() << "root_dir_start: " << u64tohex(fat->root_dir_start, buffer2, sizeof(buffer2)) << "\r\n";
io() << "fs_info_size: " << u64tohex(fat->fs_info_size, buffer2, sizeof(buffer2)) << "\r\n";
io() << "fat_start_block: " << u64tohex(fat->fat_start_block, buffer2, sizeof(buffer2)) << "\r\n";
io() << "data_start_block: " << u64tohex(fat->data_start_block, buffer2, sizeof(buffer2)) << "\r\n";
io() << "Checkpoint 5\r\n";
readblock(fat->fat_start_block, sector_buffer);
io() << "Checkpoint 6\r\n";
readblock(fat->data_start_block, sector_buffer);
io() << "Checkpoint 7\r\n";
}