26 lines
1019 B
C
26 lines
1019 B
C
//
|
|
// Created by epagris on 2023.09.28..
|
|
//
|
|
|
|
#include <memory.h>
|
|
#include "fat32.h"
|
|
|
|
int fat32_load(Fat32_CtrlBlock *ctrl, const uint8_t *bpb, uint32_t bpb_s) {
|
|
ctrl->bpb_s = bpb_s;
|
|
|
|
const Bpb_Fat32 * bpb_obj = (Bpb_Fat32 *)bpb;
|
|
|
|
ctrl->bytes_per_sector = bpb_obj->bytes_per_sector;
|
|
ctrl->sectors_per_cluster = bpb_obj->sectors_per_cluster;
|
|
ctrl->sectors_per_fat = bpb_obj->n_sectors_per_fat;
|
|
memcpy(ctrl->volume_label, bpb_obj->volume_label, 11);
|
|
ctrl->serial_number = bpb_obj->volume_serial_number;
|
|
ctrl->fat_copies = bpb_obj->n_fats;
|
|
|
|
ctrl->fat_s = ctrl->bpb_s + bpb_obj->n_reserved_sectors; // FATs are stored on the hidden area right after the reserved sectors
|
|
ctrl->data_s = ctrl->fat_s + ctrl->fat_copies * ctrl->sectors_per_fat; // data region begins right after the FAT copies
|
|
ctrl->root_s = bpb_obj->root_first_cluster * ctrl->sectors_per_cluster + ctrl->data_s; // first sector of root directory is determined using the cluster number as an offset
|
|
|
|
return 0;
|
|
}
|