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