Skip to content

File syn_fat.c

FileList > src > syntropic > storage > syn_fat.c

Go to the source code of this file

  • #include "../log/syn_log.h"
  • #include "../util/syn_assert.h"
  • #include "../util/syn_pack.h"
  • #include "syn_fat.h"
  • #include <string.h>

Classes

Type Name
struct DirEntryLoc
Result of a directory scan — location of a matching entry.
struct FAT_Volume
Internal FAT volume metadata parsed from the boot sector.
struct SYN_FatFileCtx
Open file tracking context (pooled).

Public Attributes

Type Name
SYN_SD g_sd

Public Static Attributes

Type Name
SYN_FatFileCtx g_fat_files
const SYN_VfsOps g_fat_vfs_ops = /* multi line expression */
FAT_Volume g_vol

Public Functions

Type Name
const SYN_VfsOps * syn_fat_get_ops (void)
Get the VFS operations structure for the custom FAT filesystem.
SYN_Status syn_fat_init (uint8_t spi_bus, SYN_GPIO_Pin cs)
Initialize the SD card and mount the FAT filesystem in VFS at /sd.

Public Static Functions

Type Name
uint32_t cluster_to_sector (const FAT_Volume * vol, uint32_t cluster)
bool fat_parse_bpb (FAT_Volume * vol, const uint8_t * bpb, uint32_t volume_start)
uint32_t find_free_cluster (const FAT_Volume * vol)
uint32_t find_partition_start (const uint8_t * sector0)
uint32_t get_cluster_for_offset (const FAT_Volume * vol, uint32_t start_cluster, uint32_t offset)
void path_to_fat_name (const char * path, char * fat_name)
uint32_t read_fat_entry (const FAT_Volume * vol, uint32_t cluster)
bool scan_root_dir (const FAT_Volume * vol, const char * fat_name, DirEntryLoc * loc, bool find_empty_slot)
int syn_fat_vfs_close (SYN_VfsFile * file)
int syn_fat_vfs_open (SYN_VfsFile * file, const char * path, int flags, void * fs_data)
int syn_fat_vfs_read (SYN_VfsFile * file, void * buf, size_t len)
int32_t syn_fat_vfs_seek (SYN_VfsFile * file, int32_t offset, int whence)
int32_t syn_fat_vfs_tell (SYN_VfsFile * file)
int syn_fat_vfs_unlink (const char * path, void * fs_data)
int syn_fat_vfs_write (SYN_VfsFile * file, const void * buf, size_t len)
bool write_fat_entry (const FAT_Volume * vol, uint32_t cluster, uint32_t value)

Macros

Type Name
define TAG "syn\_fat"

Public Attributes Documentation

variable g_sd

SYN_SD g_sd;

Public Static Attributes Documentation

variable g_fat_files

SYN_FatFileCtx g_fat_files[SYN_VFS_MAX_OPEN_FILES];

variable g_fat_vfs_ops

const SYN_VfsOps g_fat_vfs_ops;

variable g_vol

FAT_Volume g_vol;

Public Functions Documentation

function syn_fat_get_ops

Get the VFS operations structure for the custom FAT filesystem.

const SYN_VfsOps * syn_fat_get_ops (
    void
) 

Returns:

Pointer to the static SYN_VfsOps vtable.


function syn_fat_init

Initialize the SD card and mount the FAT filesystem in VFS at /sd.

SYN_Status syn_fat_init (
    uint8_t spi_bus,
    SYN_GPIO_Pin cs
) 

Parameters:

  • spi_bus SPI bus index.
  • cs GPIO CS pin index.

Returns:

SYN_OK on success, SYN_ERROR on failure.


Public Static Functions Documentation

function cluster_to_sector

static uint32_t cluster_to_sector (
    const FAT_Volume * vol,
    uint32_t cluster
) 

function fat_parse_bpb

static bool fat_parse_bpb (
    FAT_Volume * vol,
    const uint8_t * bpb,
    uint32_t volume_start
) 

function find_free_cluster

static uint32_t find_free_cluster (
    const FAT_Volume * vol
) 

function find_partition_start

static uint32_t find_partition_start (
    const uint8_t * sector0
) 

function get_cluster_for_offset

static uint32_t get_cluster_for_offset (
    const FAT_Volume * vol,
    uint32_t start_cluster,
    uint32_t offset
) 

function path_to_fat_name

static void path_to_fat_name (
    const char * path,
    char * fat_name
) 

function read_fat_entry

static uint32_t read_fat_entry (
    const FAT_Volume * vol,
    uint32_t cluster
) 

function scan_root_dir

static bool scan_root_dir (
    const FAT_Volume * vol,
    const char * fat_name,
    DirEntryLoc * loc,
    bool find_empty_slot
) 

function syn_fat_vfs_close

static int syn_fat_vfs_close (
    SYN_VfsFile * file
) 

function syn_fat_vfs_open

static int syn_fat_vfs_open (
    SYN_VfsFile * file,
    const char * path,
    int flags,
    void * fs_data
) 

function syn_fat_vfs_read

static int syn_fat_vfs_read (
    SYN_VfsFile * file,
    void * buf,
    size_t len
) 

function syn_fat_vfs_seek

static int32_t syn_fat_vfs_seek (
    SYN_VfsFile * file,
    int32_t offset,
    int whence
) 

function syn_fat_vfs_tell

static int32_t syn_fat_vfs_tell (
    SYN_VfsFile * file
) 

static int syn_fat_vfs_unlink (
    const char * path,
    void * fs_data
) 

function syn_fat_vfs_write

static int syn_fat_vfs_write (
    SYN_VfsFile * file,
    const void * buf,
    size_t len
) 

function write_fat_entry

static bool write_fat_entry (
    const FAT_Volume * vol,
    uint32_t cluster,
    uint32_t value
) 

Macro Definition Documentation

define TAG

#define TAG `"syn_fat"`


The documentation for this class was generated from the following file src/syntropic/storage/syn_fat.c