Noodle
Loading...
Searching...
No Matches
Filesystem Backend Layer

Small compatibility layer over the storage backends used by Noodle. More...

Macros

#define NOODLE_FS_NEEDS_LEADING_SLASH   1
 Whether the selected backend expects normalized paths to start with '/'.
#define NOODLE_MAX_FILENAME   20
 Maximum filename length copied by noodle_norm_filename().

Functions

void noodle_copy_name (char *dst, size_t cap, const char *src)
 Copy a C string into a bounded buffer with NUL-termination.
const char * noodle_norm_filename (const char *name)
 Normalize a filename/path for the selected filesystem backend.
NDL_File noodle_fs_open_read (const char *path)
 Open a file for reading using the selected backend.
NDL_File noodle_fs_open_write (const char *path)
 Open a file for writing using the selected backend.
bool noodle_fs_remove (const char *path)
 Remove a file using the selected backend.
void noodle_rewind_file (NDL_File &fi)
 Rewind a file handle to position 0.

Detailed Description

Small compatibility layer over the storage backends used by Noodle.

Noodle reads and writes model tensors through a tiny common API so the same higher-level code can run on SdFat, SD_MMC, FFat, LittleFS, or with storage disabled. This header selects the backend-specific includes and exposes:

Define exactly one backend macro before this header is included:

  • NOODLE_USE_SDFAT
  • NOODLE_USE_SD_MMC
  • NOODLE_USE_FFAT
  • NOODLE_USE_LITTLEFS
  • NOODLE_USE_NONE

When using the main noodle.h entry point, noodle_config.h is included first and selects NOODLE_USE_SDFAT by default if no backend macro is set. If this header is included directly, the caller must define one backend macro first.

Path Normalization

Arduino filesystem APIs such as SD_MMC, FFat, and LittleFS expect paths with a leading slash, for example "/w01.txt". SdFat commonly uses bare names, for example "w01.txt". noodle_norm_filename() applies this policy before open/remove calls.

Warning
For slash-requiring backends, noodle_norm_filename() returns a pointer to a static buffer. It is not re-entrant or thread-safe. Use the returned pointer immediately and do not store it.

Macro Definition Documentation

◆ NOODLE_FS_NEEDS_LEADING_SLASH

#define NOODLE_FS_NEEDS_LEADING_SLASH   1

Whether the selected backend expects normalized paths to start with '/'.

SdFat is treated as accepting bare filenames. Other real Arduino filesystem backends are normalized to slash-prefixed paths.

◆ NOODLE_MAX_FILENAME

#define NOODLE_MAX_FILENAME   20

Maximum filename length copied by noodle_norm_filename().

The limit applies to the input name characters, excluding any added leading slash and trailing NUL. Longer names are truncated by noodle_copy_name().

Function Documentation

◆ noodle_copy_name()

void noodle_copy_name ( char * dst,
size_t cap,
const char * src )
inline

Copy a C string into a bounded buffer with NUL-termination.

If src is nullptr, dst is set to an empty string. If src is longer than the destination capacity, the result is truncated and still NUL-terminated.

Parameters
dstDestination buffer.
capDestination capacity in bytes, including the trailing NUL.
srcSource C string.

◆ noodle_fs_open_read()

NDL_File noodle_fs_open_read ( const char * path)
inline

Open a file for reading using the selected backend.

The path is normalized with noodle_norm_filename() before opening. In NOODLE_USE_NONE mode this returns an invalid NDL_File.

Parameters
pathFilename or path.
Returns
Open file handle, or an invalid handle on failure.

◆ noodle_fs_open_write()

NDL_File noodle_fs_open_write ( const char * path)
inline

Open a file for writing using the selected backend.

The path is normalized with noodle_norm_filename() before opening. Existing SdFat files are truncated. Other backends use their FILE_WRITE mode. In NOODLE_USE_NONE mode this returns an invalid NDL_File.

Parameters
pathFilename or path.
Returns
Open file handle, or an invalid handle on failure.

◆ noodle_fs_remove()

bool noodle_fs_remove ( const char * path)
inline

Remove a file using the selected backend.

The path is normalized with noodle_norm_filename() before removal.

Parameters
pathFilename or path.
Returns
true when the selected backend reports that the file was removed.

◆ noodle_norm_filename()

const char * noodle_norm_filename ( const char * name)
inline

Normalize a filename/path for the selected filesystem backend.

SdFat paths are returned unchanged. For backends that require a leading slash, this function prepends '/' unless name already starts with one.

Parameters
nameInput filename or path, for example "w01.txt" or "/w01.txt".
Returns
Pointer to the normalized path string.
Warning
For slash-requiring backends, the returned pointer refers to a static buffer. Use it immediately and do not store it.

◆ noodle_rewind_file()

void noodle_rewind_file ( NDL_File & fi)
inline

Rewind a file handle to position 0.

SdFat exposes seekSet(0), while Arduino File backends expose seek(0). In NOODLE_USE_NONE mode the handle is closed.

Parameters
fiOpen file handle to rewind.