CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
lfs.h
Go to the documentation of this file.
1/*
2 * The little filesystem
3 *
4 * Copyright (c) 2022, The littlefs authors.
5 * Copyright (c) 2017, Arm Limited. All rights reserved.
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8#ifndef LFS_H
9#define LFS_H
10
11// #include "lfs_util.h"
12
13#include <stdint.h>
14#include <stdbool.h>
15
16#ifdef __cplusplus
17extern "C"
18{
19#endif
20
21
23
24// Software library version
25// Major (top-nibble), incremented on backwards incompatible changes
26// Minor (bottom-nibble), incremented on feature additions
27#define LFS_VERSION 0x0002000a
28#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
29#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
30
31// Version of On-disk data structures
32// Major (top-nibble), incremented on backwards incompatible changes
33// Minor (bottom-nibble), incremented on feature additions
34#define LFS_DISK_VERSION 0x00020001
35#define LFS_DISK_VERSION_MAJOR (0xffff & (LFS_DISK_VERSION >> 16))
36#define LFS_DISK_VERSION_MINOR (0xffff & (LFS_DISK_VERSION >> 0))
37
38
40
41// Type definitions
42typedef uint32_t lfs_size_t;
43typedef uint32_t lfs_off_t;
44
45typedef int32_t lfs_ssize_t;
46typedef int32_t lfs_soff_t;
47
48typedef uint32_t lfs_block_t;
49
50// Maximum name size in bytes, may be redefined to reduce the size of the
51// info struct. Limited to <= 1022. Stored in superblock and must be
52// respected by other littlefs drivers.
53#ifndef LFS_NAME_MAX
54#define LFS_NAME_MAX 255
55#endif
56
57// Maximum size of a file in bytes, may be redefined to limit to support other
58// drivers. Limited on disk to <= 2147483647. Stored in superblock and must be
59// respected by other littlefs drivers.
60#ifndef LFS_FILE_MAX
61#define LFS_FILE_MAX 2147483647
62#endif
63
64// Maximum size of custom attributes in bytes, may be redefined, but there is
65// no real benefit to using a smaller LFS_ATTR_MAX. Limited to <= 1022. Stored
66// in superblock and must be respected by other littlefs drivers.
67#ifndef LFS_ATTR_MAX
68#define LFS_ATTR_MAX 1022
69#endif
70
71// Possible error codes, these are negative to allow
72// valid positive return values
74 LFS_ERR_OK = 0, // No error
75 LFS_ERR_IO = -5, // Error during device operation
76 LFS_ERR_CORRUPT = -84, // Corrupted
77 LFS_ERR_NOENT = -2, // No directory entry
78 LFS_ERR_EXIST = -17, // Entry already exists
79 LFS_ERR_NOTDIR = -20, // Entry is not a dir
80 LFS_ERR_ISDIR = -21, // Entry is a dir
81 LFS_ERR_NOTEMPTY = -39, // Dir is not empty
82 LFS_ERR_BADF = -9, // Bad file number
83 LFS_ERR_FBIG = -27, // File too large
84 LFS_ERR_INVAL = -22, // Invalid parameter
85 LFS_ERR_NOSPC = -28, // No space left on device
86 LFS_ERR_NOMEM = -12, // No more memory available
87 LFS_ERR_NOATTR = -61, // No data/attr available
88 LFS_ERR_NAMETOOLONG = -36, // File name too long
89};
90
91// File types
93 // file types
94 LFS_TYPE_REG = 0x001,
95 LFS_TYPE_DIR = 0x002,
96
97 // internally used types
106
107 // internally used type specializations
119
120 // internal chip sources
124};
125
126// File open flags
128 // open flags
129 LFS_O_RDONLY = 1, // Open a file as read only
130#ifndef LFS_READONLY
131 LFS_O_WRONLY = 2, // Open a file as write only
132 LFS_O_RDWR = 3, // Open a file as read and write
133 LFS_O_CREAT = 0x0100, // Create a file if it does not exist
134 LFS_O_EXCL = 0x0200, // Fail if a file already exists
135 LFS_O_TRUNC = 0x0400, // Truncate the existing file to zero size
136 LFS_O_APPEND = 0x0800, // Move to end of file on every write
137#endif
138
139 // internally used flags
140#ifndef LFS_READONLY
141 LFS_F_DIRTY = 0x010000, // File does not match storage
142 LFS_F_WRITING = 0x020000, // File has been written since last flush
143#endif
144 LFS_F_READING = 0x040000, // File has been read since last flush
145#ifndef LFS_READONLY
146 LFS_F_ERRED = 0x080000, // An error occurred during write
147#endif
148 LFS_F_INLINE = 0x100000, // Currently inlined in directory entry
149};
150
151// File seek flags
153 LFS_SEEK_SET = 0, // Seek relative to an absolute position
154 LFS_SEEK_CUR = 1, // Seek relative to the current file position
155 LFS_SEEK_END = 2, // Seek relative to the end of the file
156};
157
158
159// Configuration provided during initialization of the littlefs
160struct lfs_config {
161 // Opaque user provided context that can be used to pass
162 // information to the block device operations
163 void *context;
164
165 // Read a region in a block. Negative error codes are propagated
166 // to the user.
167 int (*read)(const struct lfs_config *c, lfs_block_t block,
168 lfs_off_t off, void *buffer, lfs_size_t size);
169
170 // Program a region in a block. The block must have previously
171 // been erased. Negative error codes are propagated to the user.
172 // May return LFS_ERR_CORRUPT if the block should be considered bad.
173 int (*prog)(const struct lfs_config *c, lfs_block_t block,
174 lfs_off_t off, const void *buffer, lfs_size_t size);
175
176 // Erase a block. A block must be erased before being programmed.
177 // The state of an erased block is undefined. Negative error codes
178 // are propagated to the user.
179 // May return LFS_ERR_CORRUPT if the block should be considered bad.
180 int (*erase)(const struct lfs_config *c, lfs_block_t block);
181
182 // Sync the state of the underlying block device. Negative error codes
183 // are propagated to the user.
184 int (*sync)(const struct lfs_config *c);
185
186#ifdef LFS_THREADSAFE
187 // Lock the underlying block device. Negative error codes
188 // are propagated to the user.
189 int (*lock)(const struct lfs_config *c);
190
191 // Unlock the underlying block device. Negative error codes
192 // are propagated to the user.
193 int (*unlock)(const struct lfs_config *c);
194#endif
195
196 // Minimum size of a block read in bytes. All read operations will be a
197 // multiple of this value.
199
200 // Minimum size of a block program in bytes. All program operations will be
201 // a multiple of this value.
203
204 // Size of an erasable block in bytes. This does not impact ram consumption
205 // and may be larger than the physical erase size. However, non-inlined
206 // files take up at minimum one block. Must be a multiple of the read and
207 // program sizes.
209
210 // Number of erasable blocks on the device. Defaults to block_count stored
211 // on disk when zero.
213
214 // Number of erase cycles before littlefs evicts metadata logs and moves
215 // the metadata to another block. Suggested values are in the
216 // range 100-1000, with large values having better performance at the cost
217 // of less consistent wear distribution.
218 //
219 // Set to -1 to disable block-level wear-leveling.
220 int32_t block_cycles;
221
222 // Size of block caches in bytes. Each cache buffers a portion of a block in
223 // RAM. The littlefs needs a read cache, a program cache, and one additional
224 // cache per file. Larger caches can improve performance by storing more
225 // data and reducing the number of disk accesses. Must be a multiple of the
226 // read and program sizes, and a factor of the block size.
228
229 // Size of the lookahead buffer in bytes. A larger lookahead buffer
230 // increases the number of blocks found during an allocation pass. The
231 // lookahead buffer is stored as a compact bitmap, so each byte of RAM
232 // can track 8 blocks.
234
235 // Threshold for metadata compaction during lfs_fs_gc in bytes. Metadata
236 // pairs that exceed this threshold will be compacted during lfs_fs_gc.
237 // Defaults to ~88% block_size when zero, though the default may change
238 // in the future.
239 //
240 // Note this only affects lfs_fs_gc. Normal compactions still only occur
241 // when full.
242 //
243 // Set to -1 to disable metadata compaction during lfs_fs_gc.
245
246 // Optional statically allocated read buffer. Must be cache_size.
247 // By default lfs_malloc is used to allocate this buffer.
248 void *read_buffer;
249
250 // Optional statically allocated program buffer. Must be cache_size.
251 // By default lfs_malloc is used to allocate this buffer.
252 void *prog_buffer;
253
254 // Optional statically allocated lookahead buffer. Must be lookahead_size.
255 // By default lfs_malloc is used to allocate this buffer.
256 void *lookahead_buffer;
257
258 // Optional upper limit on length of file names in bytes. No downside for
259 // larger names except the size of the info struct which is controlled by
260 // the LFS_NAME_MAX define. Defaults to LFS_NAME_MAX or name_max stored on
261 // disk when zero.
263
264 // Optional upper limit on files in bytes. No downside for larger files
265 // but must be <= LFS_FILE_MAX. Defaults to LFS_FILE_MAX or file_max stored
266 // on disk when zero.
268
269 // Optional upper limit on custom attributes in bytes. No downside for
270 // larger attributes size but must be <= LFS_ATTR_MAX. Defaults to
271 // LFS_ATTR_MAX or attr_max stored on disk when zero.
273
274 // Optional upper limit on total space given to metadata pairs in bytes. On
275 // devices with large blocks (e.g. 128kB) setting this to a low size (2-8kB)
276 // can help bound the metadata compaction time. Must be <= block_size.
277 // Defaults to block_size when zero.
279
280 // Optional upper limit on inlined files in bytes. Inlined files live in
281 // metadata and decrease storage requirements, but may be limited to
282 // improve metadata-related performance. Must be <= cache_size, <=
283 // attr_max, and <= block_size/8. Defaults to the largest possible
284 // inline_max when zero.
285 //
286 // Set to -1 to disable inlined files.
288
289#ifdef LFS_MULTIVERSION
290 // On-disk version to use when writing in the form of 16-bit major version
291 // + 16-bit minor version. This limiting metadata to what is supported by
292 // older minor versions. Note that some features will be lost. Defaults to
293 // to the most recent minor version when zero.
294 uint32_t disk_version;
295#endif
296};
297
298// File info structure
299struct lfs_info {
300 // Type of the file, either LFS_TYPE_REG or LFS_TYPE_DIR
301 uint8_t type;
302
303 // Size of the file, only valid for REG files. Limited to 32-bits.
305
306 // Name of the file stored as a null-terminated string. Limited to
307 // LFS_NAME_MAX+1, which can be changed by redefining LFS_NAME_MAX to
308 // reduce RAM. LFS_NAME_MAX is stored in superblock and must be
309 // respected by other littlefs drivers.
310 char name[LFS_NAME_MAX+1];
311};
312
313// Filesystem info structure
314struct lfs_fsinfo {
315 // On-disk version.
316 uint32_t disk_version;
317
318 // Size of a logical block in bytes.
320
321 // Number of logical blocks in filesystem.
323
324 // Upper limit on the length of file names in bytes.
326
327 // Upper limit on the size of files in bytes.
329
330 // Upper limit on the size of custom attributes in bytes.
332};
333
334// Custom attribute structure, used to describe custom attributes
335// committed atomically during file writes.
336struct lfs_attr {
337 // 8-bit type of attribute, provided by user and used to
338 // identify the attribute
339 uint8_t type;
340
341 // Pointer to buffer containing the attribute
342 void *buffer;
343
344 // Size of attribute in bytes, limited to LFS_ATTR_MAX
346};
347
348// Optional configuration provided during lfs_file_opencfg
349struct lfs_file_config {
350 // Optional statically allocated file buffer. Must be cache_size.
351 // By default lfs_malloc is used to allocate this buffer.
352 void *buffer;
353
354 // Optional list of custom attributes related to the file. If the file
355 // is opened with read access, these attributes will be read from disk
356 // during the open call. If the file is opened with write access, the
357 // attributes will be written to disk every file sync or close. This
358 // write occurs atomically with update to the file's contents.
359 //
360 // Custom attributes are uniquely identified by an 8-bit type and limited
361 // to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller
362 // than the buffer, it will be padded with zeros. If the stored attribute
363 // is larger, then it will be silently truncated. If the attribute is not
364 // found, it will be created implicitly.
365 struct lfs_attr *attrs;
366
367 // Number of custom attributes in the list
369};
370
371
373typedef struct lfs_cache {
377 uint8_t *buffer;
379
380typedef struct lfs_mdir {
381 lfs_block_t pair[2];
382 uint32_t rev;
384 uint32_t etag;
385 uint16_t count;
386 bool erased;
387 bool split;
388 lfs_block_t tail[2];
390
391// littlefs directory type
392typedef struct lfs_dir {
393 struct lfs_dir *next;
394 uint16_t id;
395 uint8_t type;
397
399 lfs_block_t head[2];
401
402// littlefs file type
403typedef struct lfs_file {
404 struct lfs_file *next;
405 uint16_t id;
406 uint8_t type;
408
409 struct lfs_ctz {
412 } ctz;
413
414 uint32_t flags;
419
420 const struct lfs_file_config *cfg;
422
423typedef struct lfs_superblock {
424 uint32_t version;
431
432typedef struct lfs_gstate {
433 uint32_t tag;
434 lfs_block_t pair[2];
436
437// The littlefs filesystem type
438typedef struct lfs {
441
442 lfs_block_t root[2];
443 struct lfs_mlist {
444 struct lfs_mlist *next;
445 uint16_t id;
446 uint8_t type;
448 } *mlist;
449 uint32_t seed;
450
454
455 struct lfs_lookahead {
460 uint8_t *buffer;
461 } lookahead;
462
463 const struct lfs_config *cfg;
469
470#ifdef LFS_MIGRATE
471 struct lfs1 *lfs1;
472#endif
474
475
477
478#ifndef LFS_READONLY
479// Format a block device with the littlefs
480//
481// Requires a littlefs object and config struct. This clobbers the littlefs
482// object, and does not leave the filesystem mounted. The config struct must
483// be zeroed for defaults and backwards compatibility.
484//
485// Returns a negative error code on failure.
486int lfs_format(lfs_t *lfs, const struct lfs_config *config);
487#endif
488
489// Mounts a littlefs
490//
491// Requires a littlefs object and config struct. Multiple filesystems
492// may be mounted simultaneously with multiple littlefs objects. Both
493// lfs and config must be allocated while mounted. The config struct must
494// be zeroed for defaults and backwards compatibility.
495//
496// Returns a negative error code on failure.
497int lfs_mount(lfs_t *lfs, const struct lfs_config *config);
498
499// Unmounts a littlefs
500//
501// Does nothing besides releasing any allocated resources.
502// Returns a negative error code on failure.
503int lfs_unmount(lfs_t *lfs);
504
506
507#ifndef LFS_READONLY
508// Removes a file or directory
509//
510// If removing a directory, the directory must be empty.
511// Returns a negative error code on failure.
512int lfs_remove(lfs_t *lfs, const char *path);
513#endif
514
515#ifndef LFS_READONLY
516// Rename or move a file or directory
517//
518// If the destination exists, it must match the source in type.
519// If the destination is a directory, the directory must be empty.
520//
521// Returns a negative error code on failure.
522int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath);
523#endif
524
525// Find info about a file or directory
526//
527// Fills out the info structure, based on the specified file or directory.
528// Returns a negative error code on failure.
529int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
530
531// Get a custom attribute
532//
533// Custom attributes are uniquely identified by an 8-bit type and limited
534// to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller than
535// the buffer, it will be padded with zeros. If the stored attribute is larger,
536// then it will be silently truncated. If no attribute is found, the error
537// LFS_ERR_NOATTR is returned and the buffer is filled with zeros.
538//
539// Returns the size of the attribute, or a negative error code on failure.
540// Note, the returned size is the size of the attribute on disk, irrespective
541// of the size of the buffer. This can be used to dynamically allocate a buffer
542// or check for existence.
543lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path,
544 uint8_t type, void *buffer, lfs_size_t size);
545
546#ifndef LFS_READONLY
547// Set custom attributes
548//
549// Custom attributes are uniquely identified by an 8-bit type and limited
550// to LFS_ATTR_MAX bytes. If an attribute is not found, it will be
551// implicitly created.
552//
553// Returns a negative error code on failure.
554int lfs_setattr(lfs_t *lfs, const char *path,
555 uint8_t type, const void *buffer, lfs_size_t size);
556#endif
557
558#ifndef LFS_READONLY
559// Removes a custom attribute
560//
561// If an attribute is not found, nothing happens.
562//
563// Returns a negative error code on failure.
564int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type);
565#endif
566
567
569
570#ifndef LFS_NO_MALLOC
571// Open a file
572//
573// The mode that the file is opened in is determined by the flags, which
574// are values from the enum lfs_open_flags that are bitwise-ored together.
575//
576// Returns a negative error code on failure.
578 const char *path, int flags);
579
580// if LFS_NO_MALLOC is defined, lfs_file_open() will fail with LFS_ERR_NOMEM
581// thus use lfs_file_opencfg() with config.buffer set.
582#endif
583
584// Open a file with extra configuration
585//
586// The mode that the file is opened in is determined by the flags, which
587// are values from the enum lfs_open_flags that are bitwise-ored together.
588//
589// The config struct provides additional config options per file as described
590// above. The config struct must remain allocated while the file is open, and
591// the config struct must be zeroed for defaults and backwards compatibility.
592//
593// Returns a negative error code on failure.
595 const char *path, int flags,
596 const struct lfs_file_config *config);
597
598// Close a file
599//
600// Any pending writes are written out to storage as though
601// sync had been called and releases any allocated resources.
602//
603// Returns a negative error code on failure.
605
606// Synchronize a file on storage
607//
608// Any pending writes are written out to storage.
609// Returns a negative error code on failure.
610int lfs_file_sync(lfs_t *lfs, lfs_file_t *file);
611
612// Read data from file
613//
614// Takes a buffer and size indicating where to store the read data.
615// Returns the number of bytes read, or a negative error code on failure.
617 void *buffer, lfs_size_t size);
618
619#ifndef LFS_READONLY
620// Write data to file
621//
622// Takes a buffer and size indicating the data to write. The file will not
623// actually be updated on the storage until either sync or close is called.
624//
625// Returns the number of bytes written, or a negative error code on failure.
627 const void *buffer, lfs_size_t size);
628#endif
629
630// Change the position of the file
631//
632// The change in position is determined by the offset and whence flag.
633// Returns the new position of the file, or a negative error code on failure.
635 lfs_soff_t off, int whence);
636
637#ifndef LFS_READONLY
638// Truncates the size of the file to the specified size
639//
640// Returns a negative error code on failure.
642#endif
643
644// Return the position of the file
645//
646// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_CUR)
647// Returns the position of the file, or a negative error code on failure.
649
650// Change the position of the file to the beginning of the file
651//
652// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_SET)
653// Returns a negative error code on failure.
655
656// Return the size of the file
657//
658// Similar to lfs_file_seek(lfs, file, 0, LFS_SEEK_END)
659// Returns the size of the file, or a negative error code on failure.
661
662
664
665#ifndef LFS_READONLY
666// Create a directory
667//
668// Returns a negative error code on failure.
669int lfs_mkdir(lfs_t *lfs, const char *path);
670#endif
671
672// Open a directory
673//
674// Once open a directory can be used with read to iterate over files.
675// Returns a negative error code on failure.
676int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path);
677
678// Close a directory
679//
680// Releases any allocated resources.
681// Returns a negative error code on failure.
682int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir);
683
684// Read an entry in the directory
685//
686// Fills out the info structure, based on the specified file or directory.
687// Returns a positive value on success, 0 at the end of directory,
688// or a negative error code on failure.
689int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info);
690
691// Change the position of the directory
692//
693// The new off must be a value previous returned from tell and specifies
694// an absolute offset in the directory seek.
695//
696// Returns a negative error code on failure.
697int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off);
698
699// Return the position of the directory
700//
701// The returned offset is only meant to be consumed by seek and may not make
702// sense, but does indicate the current position in the directory iteration.
703//
704// Returns the position of the directory, or a negative error code on failure.
706
707// Change the position of the directory to the beginning of the directory
708//
709// Returns a negative error code on failure.
711
712
714
715// Find on-disk info about the filesystem
716//
717// Fills out the fsinfo structure based on the filesystem found on-disk.
718// Returns a negative error code on failure.
719int lfs_fs_stat(lfs_t *lfs, struct lfs_fsinfo *fsinfo);
720
721// Finds the current size of the filesystem
722//
723// Note: Result is best effort. If files share COW structures, the returned
724// size may be larger than the filesystem actually is.
725//
726// Returns the number of allocated blocks, or a negative error code on failure.
728
729// Traverse through all blocks in use by the filesystem
730//
731// The provided callback will be called with each block address that is
732// currently in use by the filesystem. This can be used to determine which
733// blocks are in use or how much of the storage is available.
734//
735// Returns a negative error code on failure.
736int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
737
738#ifndef LFS_READONLY
739// Attempt to make the filesystem consistent and ready for writing
740//
741// Calling this function is not required, consistency will be implicitly
742// enforced on the first operation that writes to the filesystem, but this
743// function allows the work to be performed earlier and without other
744// filesystem changes.
745//
746// Returns a negative error code on failure.
748#endif
749
750#ifndef LFS_READONLY
751// Attempt any janitorial work
752//
753// This currently:
754// 1. Calls mkconsistent if not already consistent
755// 2. Compacts metadata > compact_thresh
756// 3. Populates the block allocator
757//
758// Though additional janitorial work may be added in the future.
759//
760// Calling this function is not required, but may allow the offloading of
761// expensive janitorial work to a less time-critical code path.
762//
763// Returns a negative error code on failure. Accomplishing nothing is not
764// an error.
765int lfs_fs_gc(lfs_t *lfs);
766#endif
767
768#ifndef LFS_READONLY
769// Grows the filesystem to a new size, updating the superblock with the new
770// block count.
771//
772// Note: This is irreversible.
773//
774// Returns a negative error code on failure.
775int lfs_fs_grow(lfs_t *lfs, lfs_size_t block_count);
776#endif
777
778#ifndef LFS_READONLY
779#ifdef LFS_MIGRATE
780// Attempts to migrate a previous version of littlefs
781//
782// Behaves similarly to the lfs_format function. Attempts to mount
783// the previous version of littlefs and update the filesystem so it can be
784// mounted with the current version of littlefs.
785//
786// Requires a littlefs object and config struct. This clobbers the littlefs
787// object, and does not leave the filesystem mounted. The config struct must
788// be zeroed for defaults and backwards compatibility.
789//
790// Returns a negative error code on failure.
791int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg);
792#endif
793#endif
794
795
796#ifdef __cplusplus
797} /* extern "C" */
798#endif
799
800#endif
int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags)
File operations ///.
Definition lfs.c:6112
int lfs_fs_grow(lfs_t *lfs, lfs_size_t block_count)
Definition lfs.c:6475
int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info)
Definition lfs.c:6341
lfs_open_flags
Definition lfs.h:124
@ LFS_O_CREAT
Definition lfs.h:130
@ LFS_F_DIRTY
Definition lfs.h:138
@ LFS_F_ERRED
Definition lfs.h:143
@ LFS_F_READING
Definition lfs.h:141
@ LFS_O_EXCL
Definition lfs.h:131
@ LFS_O_APPEND
Definition lfs.h:133
@ LFS_F_WRITING
Definition lfs.h:139
@ LFS_O_TRUNC
Definition lfs.h:132
@ LFS_O_RDWR
Definition lfs.h:129
@ LFS_O_WRONLY
Definition lfs.h:128
@ LFS_O_RDONLY
Definition lfs.h:126
@ LFS_F_INLINE
Definition lfs.h:145
uint32_t lfs_block_t
Definition lfs.h:45
int lfs_unmount(lfs_t *lfs)
Definition lfs.c:6001
lfs_ssize_t lfs_fs_size(lfs_t *lfs)
Definition lfs.c:6413
lfs_error
Definition lfs.h:70
@ LFS_ERR_NOMEM
Definition lfs.h:83
@ LFS_ERR_NOTDIR
Definition lfs.h:76
@ LFS_ERR_NAMETOOLONG
Definition lfs.h:85
@ LFS_ERR_NOTEMPTY
Definition lfs.h:78
@ LFS_ERR_ISDIR
Definition lfs.h:77
@ LFS_ERR_IO
Definition lfs.h:72
@ LFS_ERR_NOATTR
Definition lfs.h:84
@ LFS_ERR_NOSPC
Definition lfs.h:82
@ LFS_ERR_INVAL
Definition lfs.h:81
@ LFS_ERR_FBIG
Definition lfs.h:80
@ LFS_ERR_BADF
Definition lfs.h:79
@ LFS_ERR_CORRUPT
Definition lfs.h:73
@ LFS_ERR_OK
Definition lfs.h:71
@ LFS_ERR_NOENT
Definition lfs.h:74
@ LFS_ERR_EXIST
Definition lfs.h:75
int lfs_setattr(lfs_t *lfs, const char *path, uint8_t type, const void *buffer, lfs_size_t size)
Definition lfs.c:6078
int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type)
Definition lfs.c:6096
lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, void *buffer, lfs_size_t size)
Definition lfs.c:6181
lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, const void *buffer, lfs_size_t size)
Definition lfs.c:6199
lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file)
Definition lfs.c:6252
struct lfs_mdir lfs_mdir_t
int32_t lfs_ssize_t
Definition lfs.h:42
int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file)
Definition lfs.c:6267
int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off)
Definition lfs.c:6356
struct lfs_file lfs_file_t
struct lfs_gstate lfs_gstate_t
int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir)
Definition lfs.c:6327
int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info)
Definition lfs.c:6047
int lfs_fs_stat(lfs_t *lfs, struct lfs_fsinfo *fsinfo)
Filesystem-level filesystem operations.
Definition lfs.c:6399
struct lfs_cache lfs_cache_t
internal littlefs data structures ///
lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path, uint8_t type, void *buffer, lfs_size_t size)
Definition lfs.c:6061
lfs_soff_t lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir)
Definition lfs.c:6371
int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir)
Definition lfs.c:6385
int lfs_fs_mkconsistent(lfs_t *lfs)
Definition lfs.c:6443
int lfs_fs_gc(lfs_t *lfs)
Definition lfs.c:6459
struct lfs lfs_t
lfs_type
Definition lfs.h:89
@ LFS_TYPE_FCRC
Definition lfs.h:115
@ LFS_TYPE_REG
Definition lfs.h:91
@ LFS_TYPE_DIRSTRUCT
Definition lfs.h:108
@ LFS_TYPE_SUPERBLOCK
Definition lfs.h:107
@ LFS_TYPE_MOVESTATE
Definition lfs.h:113
@ LFS_TYPE_CTZSTRUCT
Definition lfs.h:109
@ LFS_TYPE_TAIL
Definition lfs.h:100
@ LFS_FROM_MOVE
Definition lfs.h:119
@ LFS_TYPE_GLOBALS
Definition lfs.h:101
@ LFS_TYPE_USERATTR
Definition lfs.h:98
@ LFS_FROM_NOOP
Definition lfs.h:118
@ LFS_TYPE_DIR
Definition lfs.h:92
@ LFS_TYPE_INLINESTRUCT
Definition lfs.h:110
@ LFS_TYPE_CRC
Definition lfs.h:102
@ LFS_TYPE_STRUCT
Definition lfs.h:97
@ LFS_TYPE_SPLICE
Definition lfs.h:95
@ LFS_TYPE_SOFTTAIL
Definition lfs.h:111
@ LFS_TYPE_HARDTAIL
Definition lfs.h:112
@ LFS_TYPE_NAME
Definition lfs.h:96
@ LFS_TYPE_CREATE
Definition lfs.h:105
@ LFS_TYPE_DELETE
Definition lfs.h:106
@ LFS_TYPE_CCRC
Definition lfs.h:114
@ LFS_TYPE_FROM
Definition lfs.h:99
@ LFS_FROM_USERATTRS
Definition lfs.h:120
int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path)
Definition lfs.c:6312
struct lfs_dir lfs_dir_t
struct lfs_superblock lfs_superblock_t
int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, const char *path, int flags, const struct lfs_file_config *config)
Definition lfs.c:6129
int lfs_remove(lfs_t *lfs, const char *path)
General operations ///.
Definition lfs.c:6016
int lfs_file_close(lfs_t *lfs, lfs_file_t *file)
Definition lfs.c:6149
int lfs_mkdir(lfs_t *lfs, const char *path)
Directory operations ///.
Definition lfs.c:6297
int lfs_file_sync(lfs_t *lfs, lfs_file_t *file)
Definition lfs.c:6165
int lfs_fs_traverse(lfs_t *lfs, int(*cb)(void *, lfs_block_t), void *data)
Definition lfs.c:6427
int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size)
Definition lfs.c:6235
lfs_whence_flags
Definition lfs.h:149
@ LFS_SEEK_END
Definition lfs.h:152
@ LFS_SEEK_CUR
Definition lfs.h:151
@ LFS_SEEK_SET
Definition lfs.h:150
int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath)
Definition lfs.c:6032
lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, lfs_soff_t off, int whence)
Definition lfs.c:6217
int32_t lfs_soff_t
Definition lfs.h:43
lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file)
Definition lfs.c:6281
int lfs_format(lfs_t *lfs, const struct lfs_config *config)
Filesystem functions ///.
Definition lfs.c:5942
int lfs_mount(lfs_t *lfs, const struct lfs_config *config)
Definition lfs.c:5972
uint32_t lfs_off_t
Definition lfs.h:40
uint32_t lfs_size_t
Definitions ///.
Definition lfs.h:39
struct lfs_mdir lfs_mdir_t
#define LFS_NAME_MAX
Definition lfs.h:54
struct lfs_gstate lfs_gstate_t
struct lfs_cache lfs_cache_t
internal littlefs data structures ///
Definition lfs.h:452
lfs_block_t ckpoint
Definition lfs.h:456
uint8_t * buffer
Definition lfs.h:457
lfs_block_t size
Definition lfs.h:454
lfs_block_t next
Definition lfs.h:455
lfs_block_t start
Definition lfs.h:453
Definition lfs.h:440
struct lfs_mlist * next
Definition lfs.h:441
lfs_mdir_t m
Definition lfs.h:444
uint16_t id
Definition lfs.h:442
uint8_t type
Definition lfs.h:443
Definition lfs.h:333
void * buffer
Definition lfs.h:339
lfs_size_t size
Definition lfs.h:342
uint8_t type
Definition lfs.h:336
internal littlefs data structures ///
Definition lfs.h:370
uint8_t * buffer
Definition lfs.h:374
lfs_off_t off
Definition lfs.h:372
lfs_size_t size
Definition lfs.h:373
lfs_block_t block
Definition lfs.h:371
Definition lfs.h:157
lfs_size_t lookahead_size
Definition lfs.h:230
int(* sync)(const struct lfs_config *c)
Definition lfs.h:181
void * context
Definition lfs.h:160
lfs_size_t attr_max
Definition lfs.h:269
lfs_size_t block_count
Definition lfs.h:209
void * prog_buffer
Definition lfs.h:249
void * lookahead_buffer
Definition lfs.h:253
lfs_size_t file_max
Definition lfs.h:264
lfs_size_t prog_size
Definition lfs.h:199
lfs_size_t cache_size
Definition lfs.h:224
void * read_buffer
Definition lfs.h:245
int(* prog)(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
Definition lfs.h:170
lfs_size_t read_size
Definition lfs.h:195
lfs_size_t metadata_max
Definition lfs.h:275
lfs_size_t inline_max
Definition lfs.h:284
int(* read)(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
Definition lfs.h:164
lfs_size_t block_size
Definition lfs.h:205
int(* erase)(const struct lfs_config *c, lfs_block_t block)
Definition lfs.h:177
lfs_size_t compact_thresh
Definition lfs.h:241
lfs_size_t name_max
Definition lfs.h:259
int32_t block_cycles
Definition lfs.h:217
Definition lfs.h:389
struct lfs_dir * next
Definition lfs.h:390
lfs_block_t head[2]
Definition lfs.h:396
lfs_off_t pos
Definition lfs.h:395
uint8_t type
Definition lfs.h:392
lfs_mdir_t m
Definition lfs.h:393
uint16_t id
Definition lfs.h:391
Definition lfs.h:406
lfs_size_t size
Definition lfs.h:408
lfs_block_t head
Definition lfs.h:407
Definition lfs.h:346
void * buffer
Definition lfs.h:349
lfs_size_t attr_count
Definition lfs.h:365
struct lfs_attr * attrs
Definition lfs.h:362
Definition lfs.h:400
lfs_cache_t cache
Definition lfs.h:415
const struct lfs_file_config * cfg
Definition lfs.h:417
struct lfs_file::lfs_ctz ctz
struct lfs_file * next
Definition lfs.h:401
lfs_off_t off
Definition lfs.h:414
lfs_off_t pos
Definition lfs.h:412
lfs_block_t block
Definition lfs.h:413
lfs_mdir_t m
Definition lfs.h:404
uint8_t type
Definition lfs.h:403
uint16_t id
Definition lfs.h:402
uint32_t flags
Definition lfs.h:411
Definition lfs.h:311
lfs_size_t file_max
Definition lfs.h:325
lfs_size_t attr_max
Definition lfs.h:328
lfs_size_t block_count
Definition lfs.h:319
lfs_size_t name_max
Definition lfs.h:322
lfs_size_t block_size
Definition lfs.h:316
uint32_t disk_version
Definition lfs.h:313
Definition lfs.h:429
uint32_t tag
Definition lfs.h:430
lfs_block_t pair[2]
Definition lfs.h:431
Definition lfs.h:296
char name[LFS_NAME_MAX+1]
Definition lfs.h:307
uint8_t type
Definition lfs.h:298
lfs_size_t size
Definition lfs.h:301
Definition lfs.h:377
bool split
Definition lfs.h:384
uint32_t etag
Definition lfs.h:381
uint16_t count
Definition lfs.h:382
lfs_block_t pair[2]
Definition lfs.h:378
lfs_block_t tail[2]
Definition lfs.h:385
bool erased
Definition lfs.h:383
uint32_t rev
Definition lfs.h:379
lfs_off_t off
Definition lfs.h:380
Definition lfs.h:420
uint32_t version
Definition lfs.h:421
lfs_size_t attr_max
Definition lfs.h:426
lfs_size_t block_count
Definition lfs.h:423
lfs_size_t file_max
Definition lfs.h:425
lfs_size_t block_size
Definition lfs.h:422
lfs_size_t name_max
Definition lfs.h:424
Definition lfs.h:435
lfs_size_t inline_max
Definition lfs.h:465
lfs_block_t root[2]
Definition lfs.h:439
lfs_cache_t pcache
Definition lfs.h:437
lfs_size_t file_max
Definition lfs.h:463
const struct lfs_config * cfg
Definition lfs.h:460
lfs_size_t name_max
Definition lfs.h:462
uint32_t seed
Definition lfs.h:446
lfs_size_t block_count
Definition lfs.h:461
lfs_cache_t rcache
Definition lfs.h:436
lfs_gstate_t gstate
Definition lfs.h:448
struct lfs::lfs_mlist * mlist
lfs_gstate_t gdelta
Definition lfs.h:450
lfs_gstate_t gdisk
Definition lfs.h:449
lfs_size_t attr_max
Definition lfs.h:464
struct lfs::lfs_lookahead lookahead