|
|
```c
|
|
|
int sys_mount()
|
|
|
{
|
|
|
// 1. 读取引导分区数据
|
|
|
uint32_t N = fat32_read_N();
|
|
|
struct fat_boot_sector *boot_sector_data = fat32_read_boot_sector(N);
|
|
|
if (boot_sector_data == NULL)
|
|
|
{
|
|
|
// 处理错误
|
|
|
fprintf(stderr, "Failed to read boot sector.\n");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
// 2. 从引导分区读取数据到 BPB
|
|
|
struct fat_bios_param_block *bpb = fat32_read_bpb(boot_sector_data);
|
|
|
if (bpb == NULL)
|
|
|
{
|
|
|
// 处理错误
|
|
|
fprintf(stderr, "Failed to read BPB.\n");
|
|
|
free(boot_sector_data);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
// 3. 将 FAT 读入内存
|
|
|
uint32_t *fat = fat32_read_fat(bpb, file_allocation_table);
|
|
|
if (fat == NULL)
|
|
|
{
|
|
|
// 处理错误
|
|
|
fprintf(stderr, "Failed to read FAT.\n");
|
|
|
free(boot_sector_data);
|
|
|
free(bpb);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
// 4. 将根目录读入内存
|
|
|
fat32_read_root_dir(fat, bpb);
|
|
|
|
|
|
// 清理分配的内存
|
|
|
free(boot_sector_data);
|
|
|
free(bpb);
|
|
|
free(fat);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
``` |
|
|
\ No newline at end of file |