Add documentation for the llfs api
This commit is contained in:
57
docs/llfs.md
Normal file
57
docs/llfs.md
Normal file
@@ -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.
|
||||
```
|
||||
Reference in New Issue
Block a user