76 lines
1.8 KiB
C
76 lines
1.8 KiB
C
#pragma once
|
|
|
|
#include "stdint.h"
|
|
#include "stdbool.h"
|
|
#include "stddef.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef struct __attribute__((packed)) fat32_bpb {
|
|
uint8_t jmp[3];
|
|
char oem[8];
|
|
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_type;
|
|
uint16_t fat_size_16;
|
|
uint16_t sectors_per_track;
|
|
uint16_t num_heads;
|
|
uint32_t hidden_sectors;
|
|
uint32_t total_sectors_32;
|
|
uint32_t fat_size_32;
|
|
uint16_t ext_flags;
|
|
uint16_t fs_version;
|
|
uint32_t root_cluster;
|
|
uint16_t fs_info;
|
|
uint16_t backup_boot_sector;
|
|
uint8_t reserved[12];
|
|
uint8_t drive_number;
|
|
uint8_t reserved1;
|
|
uint8_t boot_signature;
|
|
uint32_t volume_id;
|
|
char volume_label[11];
|
|
char fs_type[8];
|
|
} fat32_bpb_t;
|
|
|
|
typedef struct __attribute__((packed)) fat32_dir_entry {
|
|
char name[11];
|
|
uint8_t attr;
|
|
uint8_t nt_reserved;
|
|
uint8_t creation_time_tenth;
|
|
uint16_t creation_time;
|
|
uint16_t creation_date;
|
|
uint16_t last_access_date;
|
|
uint16_t first_cluster_high;
|
|
uint16_t write_time;
|
|
uint16_t write_date;
|
|
uint16_t first_cluster_low;
|
|
uint32_t file_size;
|
|
} fat32_dir_entry_t;
|
|
|
|
typedef struct fat32_fs {
|
|
uint32_t partition_lba;
|
|
uint32_t fat_start_lba;
|
|
uint32_t cluster_start_lba;
|
|
uint32_t sectors_per_cluster;
|
|
uint32_t bytes_per_cluster;
|
|
uint32_t root_cluster;
|
|
bool mounted;
|
|
} fat32_fs_t;
|
|
|
|
extern fat32_fs_t g_fat32;
|
|
|
|
int fat32_mount(void);
|
|
int fat32_list(const char *dir_path, char *out_buf, size_t buf_size);
|
|
int fat32_read_file(const char *path, void *buffer, size_t max_len);
|
|
int fat32_write_file(const char *path, const void *buffer, size_t len);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|