API Documentation

littlefs module

class littlefs.FileHandle(fs, fh)

Bases: object

close()
read(size)
write(data)
class littlefs.LittleFS(context=None, **kwargs)

Bases: object

Littlefs file system

context
format()

Format the underlying buffer

listdir(path='.')

List directory content

makedirs(name, exist_ok=False)
mkdir(path)

Create a new directory

mount()

Mount the underlying buffer

open(fname, mode='r')

Open a file

remove(path)

Remove a file or directory

If the path to remove is a directory, the directory must be empty.

Parameters:path (str) – The path to the file or directory to remove.
removedirs(name)

Remove directories recursively

This works like remove() but if the leaf directory is empty after the successfull removal of name, the function tries to recursively remove all parent directories which are also empty.

rename(src, dst)
replace(src, dst)
rmdir(path)
scandir(path)
stat(path)
sync()
truncate(path, length)

Remove a file or directory

This function is an alias for remove().

walk(top)

littlefs.context module

class littlefs.context.UserContext(buffsize)

Bases: object

Basic User Context Implementation

erase(cfg, block)

Erase a block

Parameters:
  • cfg (LFSConfig) – Filesystem configuration object
  • block (int) – Block number to read
prog(cfg, block, off, data)

program data

Parameters:
  • cfg (LFSConfig) – Filesystem configuration object
  • block (int) – Block number to program
  • off (int) – Offset from start of block
  • data (bytes) – Data to write
read(cfg, block, off, size)

read data

Parameters:
  • cfg (LFSConfig) – Filesystem configuration object
  • block (int) – Block number to read
  • off (int) – Offset from start of block
  • size (int) – Number of bytes to read.
sync(cfg)

Sync cached data

Parameters:cfg (LFSConfig) – Filesystem configuration object

littlefs.lfs module

class littlefs.lfs.LFSConfig(context=None, **kwargs)
block_count
block_size
cache_size
lookahead_size
prog_size
read_size
class littlefs.lfs.LFSDirectory
class littlefs.lfs.LFSFile
class littlefs.lfs.LFSFilesystem
littlefs.lfs.dir_close(LFSFilesystem fs, LFSDirectory dh)
littlefs.lfs.dir_open(LFSFilesystem fs, path)
littlefs.lfs.dir_read(LFSFilesystem fs, LFSDirectory dh)
littlefs.lfs.dir_rewind(LFSFilesystem fs, LFSDirectory dh)
littlefs.lfs.dir_tell(LFSFilesystem fs, LFSDirectory dh)
littlefs.lfs.file_close(LFSFilesystem fs, LFSFile fh)
littlefs.lfs.file_open(LFSFilesystem fs, path, flags)
littlefs.lfs.file_open_cfg(self, path, flags, config)
littlefs.lfs.file_read(LFSFilesystem fs, LFSFile fh, size)
littlefs.lfs.file_rewind(LFSFilesystem fs, LFSFile fh)
littlefs.lfs.file_seek(LFSFilesystem fs, LFSFile fh, off, whence)
littlefs.lfs.file_size(LFSFilesystem fs, LFSFile fh)
littlefs.lfs.file_sync(LFSFilesystem fs, LFSFile fh)
littlefs.lfs.file_tell(LFSFilesystem fs, LFSFile fh)
littlefs.lfs.file_truncate(LFSFilesystem fs, LFSFile fh, size)
littlefs.lfs.file_write(LFSFilesystem fs, LFSFile fh, data)
littlefs.lfs.format(LFSFilesystem fs, LFSConfig cfg)

Format the filesystem

littlefs.lfs.fs_size(LFSFilesystem fs)
littlefs.lfs.getattr(LFSFilesystem fs, path, type, buffer, size)
littlefs.lfs.mkdir(LFSFilesystem fs, path)
littlefs.lfs.mount(LFSFilesystem fs, LFSConfig cfg)

Mount the filesystem

littlefs.lfs.remove(LFSFilesystem fs, path)

Remove a file or directory

If removing a direcotry, the directory must be empty.

littlefs.lfs.removeattr(LFSFilesystem fs, path, type)
littlefs.lfs.rename(LFSFilesystem fs, oldpath, newpath)

Rename or move a file or directory

If the destination exists, it must match the source in type. If the destination is a directory, the directory must be empty.

littlefs.lfs.setattr(LFSFilesystem fs, path, type, buffer, size)
littlefs.lfs.stat(LFSFilesystem fs, path)

Find info about a file or directory

littlefs.lfs.unmount(LFSFilesystem fs)

Unmount the filesystem

This does nothing beside releasing any allocated resources