API Documentation¶
littlefs module¶
- class littlefs.FileHandle(fs, fh)¶
- close()¶
Flush and close the IO object.
This method has no effect if the file is already closed.
- flush()¶
Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
- readable()¶
Return whether object was opened for reading.
If False, read() will raise OSError.
- readall()¶
Read until EOF, using multiple read() call.
- readinto(b)¶
- seek(offset, whence=0)¶
Change the stream position to the given byte offset.
- offset
The stream position, relative to ‘whence’.
- whence
The relative position to seek from.
The offset is interpreted relative to the position indicated by whence. Values for whence are:
os.SEEK_SET or 0 – start of stream (the default); offset should be zero or positive
os.SEEK_CUR or 1 – current stream position; offset may be negative
os.SEEK_END or 2 – end of stream; offset is usually negative
Return the new absolute position.
- seekable()¶
Return whether object supports random access.
If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().
- tell()¶
Return current stream position.
- truncate(size=None) int ¶
Truncate file to size bytes.
File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.
- writable()¶
Return whether object was opened for writing.
If False, write() will raise OSError.
- write(data)¶
- class littlefs.LFSConfig(context=None, int block_size: int = 128, *, int block_count: int = 64, int read_size: int = 0, int prog_size: int = 0, int block_cycles: int = -1, int cache_size: int = 0, int lookahead_size: int = 8, int name_max: int = 255, int file_max: int = 0, int attr_max: int = 0, int metadata_max: int = 0, int disk_version: int = 0)¶
- attr_max¶
- block_count¶
- block_size¶
- cache_size¶
- disk_version¶
- file_max¶
- lookahead_size¶
- metadata_max¶
- name_max¶
- prog_size¶
- read_size¶
- class littlefs.LFSDirectory¶
- class littlefs.LFSFSStat(disk_version: int, name_max: int, file_max: int, attr_max: int, block_count: int, block_size: int)¶
Littlefs filesystem status.
- class littlefs.LFSFileFlag(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Littlefs file mode flags
- append = 2048¶
- creat = 256¶
- excl = 512¶
- rdonly = 1¶
- rdwr = 3¶
- trunc = 1024¶
- wronly = 2¶
- class littlefs.LFSStat(type: int, size: int, name: str)¶
Littlefs File / Directory status.
- TYPE_DIR = 2¶
- TYPE_REG = 1¶
- class littlefs.LittleFS(context: UserContext | None = None, mount=True, **kwargs)¶
Littlefs file system
- property context: UserContext¶
User context of the file system
- listdir(path='.') List[str] ¶
List directory content
List the content of a directory. This function uses
scandir()
internally. Usingscandir()
might be better if you are searching for a specific file or need access to thelittlefs.lfs.LFSStat
of the files.
- open(fname: str, mode='r', buffering: int = -1, encoding: str = None, errors: str = None, newline: str = None) IO ¶
Open a file.
mode
is an optional string that specifies the mode in which the file is opened and is analogous to the built-inio.open()
function. Files opened in text mode (default) will take and return str objects. Files opened in binary mode will take and return byte-like objects.- Parameters:
fname (str) – The path to the file to open.
mode (str) – Specifies the mode in which the file is opened.
buffering (int) – Specifies the buffering policy. Pass 0 to disable buffering in binary mode.
encoding (str) – Text encoding to use. (text mode only)
errors (str) – Specifies how encoding and decoding errors are to be handled. (text mode only)
newline (str) – Controls how universal newlines mode works. (text mode only)
- remove(path: str, recursive: bool = False) None ¶
Remove a file or directory
If the path to remove is a directory, the directory must be empty.
- removedirs(name)¶
Remove directories recursively
This works like
remove()
but if the leaf directory is empty after the successful removal ofname
, the function tries to recursively remove all parent directories which are also empty.
- walk(top: str) Iterator[Tuple[str, List[str], List[str]]] ¶
Generate the file names in a directory tree
Generate the file and directory names in a directory tree by walking the tree top-down. This functions closely resembels the behaviour of
os.walk()
.Each iteration yields a tuple containing three elements:
The root of the currently processed element
A list of directories located in the root
A list of filenames located in the root
- exception littlefs.LittleFSError(code: int)¶
- class Error(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
- LFS_ERR_BADF = -9¶
- LFS_ERR_CORRUPT = -84¶
- LFS_ERR_EXIST = -17¶
- LFS_ERR_FBIG = -27¶
- LFS_ERR_INVAL = -22¶
- LFS_ERR_IO = -5¶
- LFS_ERR_ISDIR = -21¶
- LFS_ERR_NAMETOOLONG = -36¶
- LFS_ERR_NOATTR = -61¶
- LFS_ERR_NOENT = -2¶
- LFS_ERR_NOMEM = -12¶
- LFS_ERR_NOSPC = -28¶
- LFS_ERR_NOTDIR = -20¶
- LFS_ERR_NOTEMPTY = -39¶
- LFS_ERR_OK = 0¶
- class littlefs.UserContext(buffsize: int)¶
Basic User Context Implementation
littlefs.context module¶
- class littlefs.context.UserContext(buffsize: int)¶
Basic User Context Implementation
littlefs.lfs module¶
- class littlefs.lfs.LFSConfig(context=None, int block_size: int = 128, *, int block_count: int = 64, int read_size: int = 0, int prog_size: int = 0, int block_cycles: int = -1, int cache_size: int = 0, int lookahead_size: int = 8, int name_max: int = 255, int file_max: int = 0, int attr_max: int = 0, int metadata_max: int = 0, int disk_version: int = 0)¶
- attr_max¶
- block_count¶
- block_size¶
- cache_size¶
- disk_version¶
- file_max¶
- lookahead_size¶
- metadata_max¶
- name_max¶
- prog_size¶
- read_size¶
- class littlefs.lfs.LFSDirectory¶
- class littlefs.lfs.LFSFSStat(disk_version: int, name_max: int, file_max: int, attr_max: int, block_count: int, block_size: int)¶
Littlefs filesystem status.
- class littlefs.lfs.LFSFileFlag(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Littlefs file mode flags
- append = 2048¶
- creat = 256¶
- excl = 512¶
- rdonly = 1¶
- rdwr = 3¶
- trunc = 1024¶
- wronly = 2¶
- class littlefs.lfs.LFSStat(type: int, size: int, name: str)¶
Littlefs File / Directory status.
- TYPE_DIR = 2¶
- TYPE_REG = 1¶
- 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_grow(LFSFilesystem fs, block_count) int ¶
Irreversibly grows the filesystem to a new size.
- Parameters:
fs (LFSFilesystem)
block_count (int) – Number of blocks in the new filesystem.
- littlefs.lfs.fs_mkconsistent(LFSFilesystem fs)¶
Attempt to make the filesystem consistent and ready for writing
- littlefs.lfs.fs_size(LFSFilesystem fs)¶
- littlefs.lfs.fs_stat(LFSFilesystem fs)¶
Get filesystem status
- littlefs.lfs.getattr(LFSFilesystem fs, path, typ)¶
- 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 directory, the directory must be empty.
- littlefs.lfs.removeattr(LFSFilesystem fs, path, typ)¶
- 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, typ, data)¶
- 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