Update fat12.h

This commit is contained in:
2025-12-19 15:43:24 -08:00
committed by GitHub
parent 0a396c58c2
commit f9980c2e68

View File

@@ -2,31 +2,29 @@
#define FAT12_H #define FAT12_H
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
// --- Configuration ---
#define FAT12_SECTOR_SIZE 512 #define FAT12_SECTOR_SIZE 512
// --- On-Disk Structures (Must be Packed) --- /* --- On-Disk Structures --- */
// BIOS Parameter Block (Start of Boot Sector)
typedef struct { typedef struct {
uint8_t jump[3]; uint8_t jump[3];
char oem[8]; char oem[8];
uint16_t bytes_per_sector; // 512 uint16_t bytes_per_sector;
uint8_t sectors_per_cluster; // 1 uint8_t sectors_per_cluster;
uint16_t reserved_sectors; // 1 (Boot sector) uint16_t reserved_sectors;
uint8_t fat_count; // 2 uint8_t fat_count;
uint16_t dir_entries_count; // 224 uint16_t dir_entries_count;
uint16_t total_sectors; // 2880 uint16_t total_sectors;
uint8_t media_descriptor; // 0xF0 uint8_t media_descriptor;
uint16_t sectors_per_fat; // 9 uint16_t sectors_per_fat;
uint16_t sectors_per_track; // 18 uint16_t sectors_per_track;
uint16_t heads; // 2 uint16_t heads;
uint32_t hidden_sectors; uint32_t hidden_sectors;
uint32_t total_sectors_large; uint32_t total_sectors_large;
} __attribute__((packed)) fat12_bpb_t; } __attribute__((packed)) fat12_bpb_t;
// Directory Entry (32 bytes)
typedef struct { typedef struct {
char filename[8]; char filename[8];
char ext[3]; char ext[3];
@@ -39,29 +37,24 @@ typedef struct {
uint16_t high_cluster_num; // Always 0 in FAT12 uint16_t high_cluster_num; // Always 0 in FAT12
uint16_t last_mod_time; uint16_t last_mod_time;
uint16_t last_mod_date; uint16_t last_mod_date;
uint16_t low_cluster_num; // The starting cluster uint16_t low_cluster_num;
uint32_t file_size; // Size in bytes uint32_t file_size;
} __attribute__((packed)) fat12_entry_t; } __attribute__((packed)) fat12_entry_t;
// --- Kernel File Handle --- /* --- Kernel File Handle --- */
// This is what your kernel uses to track an open file
typedef struct { typedef struct {
char name[11];
uint32_t size; uint32_t size;
uint16_t start_cluster; uint16_t start_cluster;
uint16_t current_cluster; uint16_t current_cluster;
uint32_t current_sector_in_cluster;
uint32_t bytes_read; uint32_t bytes_read;
bool valid;
} file_t; } file_t;
// --- Public API --- /* --- API --- */
// You must implement this in your disk driver (e.g., floppy.c) void fat12_init(void);
// Returns 0 on success, non-zero on error.
extern int disk_read_sector(uint32_t lba, uint8_t *buffer);
void fat12_init();
file_t fat12_open(const char *filename); file_t fat12_open(const char *filename);
uint32_t fat12_read(file_t *file, uint8_t *buffer, uint32_t bytes_to_read); uint32_t fat12_read(file_t *file, uint8_t *buffer, uint32_t bytes_to_read);
#endif // FAT12_H #endif