1 Star 0 Fork 0

lixiang / mbed-littlefs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Mbed OS API for the little filesystem

This is the Mbed OS API for littlefs, a little fail-safe filesystem designed for embedded systems.

   | | |     .---._____
  .-----.   |          |
--|o    |---| littlefs |
--|     |---|          |
  '-----'   '----------'
   | | |

Bounded RAM/ROM - The littlefs is designed to work with a limited amount of memory. Recursion is avoided, and dynamic memory is limited to configurable buffers that can be provided statically.

Power-loss resilient - The littlefs is designed for systems that may have random power failures. The littlefs has strong copy-on-write guarantees, and storage on disk is always kept in a valid state.

Wear leveling - Because the most common form of embedded storage is erodible flash memories, littlefs provides a form of dynamic wear leveling for systems that cannot fit a full flash translation layer.

Usage

If you are already using a filesystem in Mbed, adopting the littlefs should just require a name change to use the LittleFileSystem2 class.

Here is a simple example that updates a file named "boot_count" every time the application runs:

#include "LittleFileSystem2.h"
#include "SPIFBlockDevice.h"

// Physical block device, can be any device that supports the BlockDevice API
SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5);

// Storage for the littlefs
LittleFileSystem2 fs("fs");

// Entry point
int main() {
    // Mount the filesystem
    int err = fs.mount(&bd);
    if (err) {
        // Reformat if we can't mount the filesystem,
        // this should only happen on the first boot
        LittleFileSystem2::format(&bd);
        fs.mount(&bd);
    }

    // Read the boot count
    uint32_t boot_count = 0;
    FILE *f = fopen("/fs/boot_count", "r+");
    if (!f) {
        // Create the file if it doesn't exist
        f = fopen("/fs/boot_count", "w+");
    }
    fread(&boot_count, sizeof(boot_count), 1, f);

    // Update the boot count
    boot_count += 1;
    rewind(f);
    fwrite(&boot_count, sizeof(boot_count), 1, f);

    // Remember that storage may not be updated until the file
    // is closed successfully
    fclose(f);

    // Release any resources we were using
    fs.unmount();

    // Print the boot count
    printf("boot_count: %ld\n", boot_count);
}

Reference material

DESIGN.md - DESIGN.md contains a fully detailed dive into how littlefs actually works. We encourage you to read it because the solutions and tradeoffs at work here are quite interesting.

SPEC.md - SPEC.md contains the on-disk specification of littlefs with all the nitty-gritty details. This can be useful for developing tooling.

Related projects

littlefs - Where the core of littlefs currently lives.

littlefs-fuse - A FUSE wrapper for littlefs. The project allows you to mount littlefs directly in a Linux machine. This can be useful for debugging littlefs if you have an SD card handy.

littlefs-js - A JavaScript wrapper for littlefs. I'm not sure why you would want this, but it is handy for demos. You can see it in action here.

空文件

简介

littleFS from : https://github.com/armmbed/mbed-littlefs 展开 收起
C 等 4 种语言
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/lixiangQD/mbed-littlefs.git
git@gitee.com:lixiangQD/mbed-littlefs.git
lixiangQD
mbed-littlefs
mbed-littlefs
master

搜索帮助