Fat32 ctrl block

This commit is contained in:
Wiesner András 2023-09-30 06:37:35 +02:00
parent 8e30051824
commit ae3e1e07cf
2 changed files with 35 additions and 0 deletions

View File

@ -2,4 +2,24 @@
// Created by epagris on 2023.09.28.. // Created by epagris on 2023.09.28..
// //
#include <memory.h>
#include "fat32.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;
}

View File

@ -33,4 +33,19 @@ typedef struct {
uint8_t fs_type[8]; // file system type ("FAT32") uint8_t fs_type[8]; // file system type ("FAT32")
} __attribute__((packed)) Bpb_Fat32; } __attribute__((packed)) Bpb_Fat32;
typedef struct {
uint32_t bpb_s; // sector of bios parameter block
uint32_t fat_s; // first sector of the FAT area
uint32_t root_s; // first sector of root directory
uint32_t data_s; // first sector of the data area (~volume)
uint32_t serial_number; // serial number of the volume
uint32_t sectors_per_fat; // sectors per FAT table
uint16_t bytes_per_sector; // number of bytes creating a sector
uint16_t sectors_per_cluster; // number of sectors creating a cluster
uint8_t fat_copies; // number of FAT table copies
uint8_t volume_label[11]; // pointer to volume label
} Fat32_CtrlBlock;
int fat32_load(Fat32_CtrlBlock *ctrl, const uint8_t *bpb, uint32_t bpb_s);
#endif //EMBPART_FAT32_H #endif //EMBPART_FAT32_H