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