From 59061be1512a909481b620aa73f01b775936d5b3 Mon Sep 17 00:00:00 2001 From: L-diy Date: Mon, 6 Nov 2023 14:50:48 +0100 Subject: [PATCH] Add documentation for the llfs api --- docs/llfs.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 docs/llfs.md diff --git a/docs/llfs.md b/docs/llfs.md new file mode 100644 index 0000000..eac7c21 --- /dev/null +++ b/docs/llfs.md @@ -0,0 +1,57 @@ +# LLFS (Linked List File System) + +## Introduction +The llfs filesystem can be generated using the mkllfss utility. +It is a simple filesystem that uses a linked list to store files. +The filesystem is stored in a single c file (`llfs_data.c`), which can be compiled and read by the llfs library. +The llfs filesystem is a flat filesystem, meaning that it does not support directories. + +## Usage of the llfs API +### Getting a list of files +```c +#include "llfs.h" + +void main(void) { + // Allocate space for 10 files + llfs_file_t file_list[10]; + + // Get the file list + size_t file_count = llfs_file_list(file_list, 10, NULL); + + // Loop through the files and print their names and sizes + for (int i = 0; i < file_count; i++) { + LOG_INFO(TAG, "File: %s, size: %d", file_list[i].name, file_list[i].len); + } +} +``` +Result: +``` +[Info] (2009) [main]: File: image.bmp, size: 9270 +[Info] (2013) [main]: File: python_file.py, size: 645 +[Info] (2019) [main]: File: image2.bmp, size: 7738 +[Info] (2024) [main]: File: filename with a space.txt, size: 61 +[Info] (2031) [main]: File: file1.txt, size: 77 +``` + +### Reading a file +```c +#include "llfs.h" + +void main(void) { + // Get a file by name + llfs_file_t *file = llfs_file_open("filename with a space.txt"); + + if (file != NULL) { + // Print the file name, size and data + LOG_INFO(TAG, "File found: %s, size: %d", file->name, file->len); + LOG_INFO(TAG, "File data: %s", file->data); + } else { + LOG_WARN(TAG, "File not found"); + } +} +``` +Result: +``` +[Info] (2040) [main]: File found: filename with a space.txt, size: 61 +[Info] (2047) [main]: File data: This is a file with a space in it's filename. +```