#ifndef FAT12_H
#define FAT12_H

#include <stdint.h>

#define FAT12_SIGNATURE 0xAA55
#define ROOT_DIR_ENTRIES 224

typedef struct {
    uint8_t  jmp_boot[3];  // Jump instruction
    char     oem_name[8];  // OEM Name
    uint16_t bytes_per_sector;
    uint8_t  sectors_per_cluster;
    uint16_t reserved_sectors;
    uint8_t  num_fats;
    uint16_t root_entry_count;
    uint16_t total_sectors_16;
    uint8_t  media;
    uint16_t fat_size_16;
    uint16_t sectors_per_track;
    uint16_t num_heads;
    uint32_t hidden_sectors;
    uint32_t total_sectors_32;
    uint8_t  boot_signature;
    uint32_t volume_id;
    char     volume_label[11];
    char     fs_type[8];
} __attribute__((packed)) fat12_boot_sector_t;

typedef struct {
    char     filename[8];
    char     extension[3];
    uint8_t  attributes;
    uint8_t  reserved;
    uint8_t  creation_time_tenths;
    uint16_t creation_time;
    uint16_t creation_date;
    uint16_t last_access_date;
    uint16_t first_cluster_high;
    uint16_t last_mod_time;
    uint16_t last_mod_date;
    uint16_t first_cluster_low;
    uint32_t file_size;
} __attribute__((packed)) fat12_dir_entry_t;

// FAT12 Filesystem initialization
int fat12_init(void);

// Read the root directory
int fat12_read_root_directory(void);

// Find a file in the root directory
int fat12_find_file(const char *filename, fat12_dir_entry_t *entry);

// Read a file (to be implemented)
int fat12_read_file(fat12_dir_entry_t *entry, void *buffer);

#endif // FAT12_H
