mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 08:48:31 +01:00
Compare commits
39 Commits
thread-saf
...
open-file-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7820e653e | ||
|
|
deeaa17317 | ||
|
|
026833214a | ||
|
|
b19a51c044 | ||
|
|
d97d66adf5 | ||
|
|
1a59954ec6 | ||
|
|
6a7012774d | ||
|
|
288a5cbc8d | ||
|
|
5783eea0de | ||
|
|
2bb523421e | ||
|
|
7388b2938a | ||
|
|
ce425a56c3 | ||
|
|
a99a93fb27 | ||
|
|
45afded784 | ||
|
|
00a9ba7826 | ||
|
|
fc6988c7c3 | ||
|
|
d0f055d321 | ||
|
|
b9fa33f9bc | ||
|
|
2efebf8e9b | ||
|
|
754b4c3cda | ||
|
|
584eb26efc | ||
|
|
008ebc37df | ||
|
|
66272067ab | ||
|
|
e273a82679 | ||
|
|
1dc6ae94b9 | ||
|
|
817ef02d24 | ||
|
|
b8dcf10974 | ||
|
|
0aba71d0d6 | ||
|
|
0ea2871e24 | ||
|
|
d04c1392c0 | ||
|
|
f215027fd4 | ||
|
|
1ae4b36f2a | ||
|
|
480cdd9f81 | ||
|
|
6303558aee | ||
|
|
4bd653dd00 | ||
|
|
8e6826c4e2 | ||
|
|
87a2cb0e41 | ||
|
|
6d0ec5e851 | ||
|
|
64f70f51b0 |
32
.travis.yml
32
.travis.yml
@@ -208,6 +208,38 @@ jobs:
|
||||
script:
|
||||
- make test TFLAGS+="-k --valgrind"
|
||||
|
||||
# test compilation in read-only mode
|
||||
- stage: test
|
||||
env:
|
||||
- NAME=littlefs-readonly
|
||||
- CC="arm-linux-gnueabi-gcc --static -mthumb"
|
||||
- CFLAGS="-Werror -DLFS_READONLY"
|
||||
if: branch !~ -prefix$
|
||||
install:
|
||||
- *install-common
|
||||
- sudo apt-get install
|
||||
gcc-arm-linux-gnueabi
|
||||
libc6-dev-armel-cross
|
||||
- arm-linux-gnueabi-gcc --version
|
||||
# report-size will compile littlefs and report the size
|
||||
script: [*report-size]
|
||||
|
||||
# test compilation in thread-safe mode
|
||||
- stage: test
|
||||
env:
|
||||
- NAME=littlefs-threadsafe
|
||||
- CC="arm-linux-gnueabi-gcc --static -mthumb"
|
||||
- CFLAGS="-Werror -DLFS_THREADSAFE"
|
||||
if: branch !~ -prefix$
|
||||
install:
|
||||
- *install-common
|
||||
- sudo apt-get install
|
||||
gcc-arm-linux-gnueabi
|
||||
libc6-dev-armel-cross
|
||||
- arm-linux-gnueabi-gcc --version
|
||||
# report-size will compile littlefs and report the size
|
||||
script: [*report-size]
|
||||
|
||||
# self-host with littlefs-fuse for fuzz test
|
||||
- stage: test
|
||||
env:
|
||||
|
||||
@@ -222,6 +222,11 @@ License Identifiers that are here available: http://spdx.org/licenses/
|
||||
want this, but it is handy for demos. You can see it in action
|
||||
[here][littlefs-js-demo].
|
||||
|
||||
- [littlefs-python] - A Python wrapper for littlefs. The project allows you
|
||||
to create images of the filesystem on your PC. Check if littlefs will fit
|
||||
your needs, create images for a later download to the target memory or
|
||||
inspect the content of a binary image of the target memory.
|
||||
|
||||
- [mklfs] - A command line tool built by the [Lua RTOS] guys for making
|
||||
littlefs images from a host PC. Supports Windows, Mac OS, and Linux.
|
||||
|
||||
@@ -250,3 +255,4 @@ License Identifiers that are here available: http://spdx.org/licenses/
|
||||
[LittleFileSystem]: https://os.mbed.com/docs/mbed-os/v5.12/apis/littlefilesystem.html
|
||||
[SPIFFS]: https://github.com/pellepl/spiffs
|
||||
[Dhara]: https://github.com/dlbeer/dhara
|
||||
[littlefs-python]: https://pypi.org/project/littlefs-python/
|
||||
|
||||
@@ -207,7 +207,7 @@ int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block,
|
||||
bd->power_cycles -= 1;
|
||||
if (bd->power_cycles == 0) {
|
||||
// sync to make sure we persist the last changes
|
||||
assert(lfs_testbd_rawsync(cfg) == 0);
|
||||
LFS_ASSERT(lfs_testbd_rawsync(cfg) == 0);
|
||||
// simulate power loss
|
||||
exit(33);
|
||||
}
|
||||
@@ -254,7 +254,7 @@ int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block) {
|
||||
bd->power_cycles -= 1;
|
||||
if (bd->power_cycles == 0) {
|
||||
// sync to make sure we persist the last changes
|
||||
assert(lfs_testbd_rawsync(cfg) == 0);
|
||||
LFS_ASSERT(lfs_testbd_rawsync(cfg) == 0);
|
||||
// simulate power loss
|
||||
exit(33);
|
||||
}
|
||||
|
||||
233
lfs.h
233
lfs.h
@@ -22,7 +22,7 @@ extern "C"
|
||||
// Software library version
|
||||
// Major (top-nibble), incremented on backwards incompatible changes
|
||||
// Minor (bottom-nibble), incremented on feature additions
|
||||
#define LFS_VERSION 0x00020002
|
||||
#define LFS_VERSION 0x00020003
|
||||
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
|
||||
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
|
||||
|
||||
@@ -54,7 +54,7 @@ typedef uint32_t lfs_block_t;
|
||||
|
||||
// Maximum size of a file in bytes, may be redefined to limit to support other
|
||||
// drivers. Limited on disk to <= 4294967296. However, above 2147483647 the
|
||||
// functions _lfs_file_seek, _lfs_file_size, and _lfs_file_tell will return
|
||||
// functions lfs_file_seek, lfs_file_size, and lfs_file_tell will return
|
||||
// incorrect values due to using signed integers. Stored in superblock and
|
||||
// must be respected by other littlefs drivers.
|
||||
#ifndef LFS_FILE_MAX
|
||||
@@ -85,9 +85,6 @@ enum lfs_error {
|
||||
LFS_ERR_NOMEM = -12, // No more memory available
|
||||
LFS_ERR_NOATTR = -61, // No data/attr available
|
||||
LFS_ERR_NAMETOOLONG = -36, // File name too long
|
||||
#if LFS_THREAD_SAFE
|
||||
LFS_ERR_LOCK = -23, // Failed to aquire lock
|
||||
#endif
|
||||
};
|
||||
|
||||
// File types
|
||||
@@ -127,20 +124,29 @@ enum lfs_type {
|
||||
enum lfs_open_flags {
|
||||
// open flags
|
||||
LFS_O_RDONLY = 1, // Open a file as read only
|
||||
#ifndef LFS_READONLY
|
||||
LFS_O_WRONLY = 2, // Open a file as write only
|
||||
LFS_O_RDWR = 3, // Open a file as read and write
|
||||
#endif
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
LFS_O_CREAT = 0x0100, // Create a file if it does not exist
|
||||
LFS_O_EXCL = 0x0200, // Fail if a file already exists
|
||||
LFS_O_TRUNC = 0x0400, // Truncate the existing file to zero size
|
||||
LFS_O_APPEND = 0x0800, // Move to end of file on every write
|
||||
LFS_O_SNAPSHOT = 0x1000, // Open a temporary snapshot, ignore changes
|
||||
#endif
|
||||
|
||||
// internally used flags
|
||||
#ifndef LFS_READONLY
|
||||
LFS_F_DIRTY = 0x010000, // File does not match storage
|
||||
LFS_F_WRITING = 0x020000, // File has been written since last flush
|
||||
LFS_F_READING = 0x040000, // File has been read since last flush
|
||||
LFS_F_ERRED = 0x080000, // An error occured during write
|
||||
#endif
|
||||
LFS_F_READING = 0x020000, // File has been read since last flush
|
||||
#ifndef LFS_READONLY
|
||||
LFS_F_WRITING = 0x040000, // File has been written since last flush
|
||||
LFS_F_ZOMBIE = 0x080000, // An error occurred during write
|
||||
#endif
|
||||
LFS_F_INLINE = 0x100000, // Currently inlined in directory entry
|
||||
LFS_F_OPENED = 0x200000, // File has been opened
|
||||
};
|
||||
|
||||
// File seek flags
|
||||
@@ -178,7 +184,7 @@ struct lfs_config {
|
||||
// are propogated to the user.
|
||||
int (*sync)(const struct lfs_config *c);
|
||||
|
||||
#if LFS_THREAD_SAFE
|
||||
#ifdef LFS_THREADSAFE
|
||||
// Lock the underlying block device. Negative error codes
|
||||
// are propogated to the user.
|
||||
int (*lock)(const struct lfs_config *c);
|
||||
@@ -186,7 +192,7 @@ struct lfs_config {
|
||||
// Unlock the underlying block device. Negative error codes
|
||||
// are propogated to the user.
|
||||
int (*unlock)(const struct lfs_config *c);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Minimum size of a block read. All read operations will be a
|
||||
// multiple of this value.
|
||||
@@ -292,16 +298,15 @@ struct lfs_file_config {
|
||||
void *buffer;
|
||||
|
||||
// Optional list of custom attributes related to the file. If the file
|
||||
// is opened with read access, these attributes will be read from disk
|
||||
// during the open call. If the file is opened with write access, the
|
||||
// attributes will be written to disk every file sync or close. This
|
||||
// write occurs atomically with update to the file's contents.
|
||||
// is opened for reading, these attributes will be read from disk during
|
||||
// open. If the file is open for writing, these attribute will be atomically
|
||||
// written to disk when the file is written to disk. Note that these
|
||||
// attributes are not written unless the file is modified.
|
||||
//
|
||||
// Custom attributes are uniquely identified by an 8-bit type and limited
|
||||
// to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller
|
||||
// than the buffer, it will be padded with zeros. If the stored attribute
|
||||
// is larger, then it will be silently truncated. If the attribute is not
|
||||
// found, it will be created implicitly.
|
||||
// to LFS_ATTR_MAX bytes. If the stored attribute is larger than the
|
||||
// provided buffer, it will be silently truncated. If no attribute is
|
||||
// found, and the file is open for writing, it will be created implicitly.
|
||||
struct lfs_attr *attrs;
|
||||
|
||||
// Number of custom attributes in the list
|
||||
@@ -413,6 +418,7 @@ typedef struct lfs {
|
||||
|
||||
/// Filesystem functions ///
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Format a block device with the littlefs
|
||||
//
|
||||
// Requires a littlefs object and config struct. This clobbers the littlefs
|
||||
@@ -420,7 +426,8 @@ typedef struct lfs {
|
||||
// be zeroed for defaults and backwards compatibility.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_format(lfs_t *lfs, const struct lfs_config *config);
|
||||
int lfs_format(lfs_t *lfs, const struct lfs_config *config);
|
||||
#endif
|
||||
|
||||
// Mounts a littlefs
|
||||
//
|
||||
@@ -430,51 +437,55 @@ int _lfs_format(lfs_t *lfs, const struct lfs_config *config);
|
||||
// be zeroed for defaults and backwards compatibility.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_mount(lfs_t *lfs, const struct lfs_config *config);
|
||||
int lfs_mount(lfs_t *lfs, const struct lfs_config *config);
|
||||
|
||||
// Unmounts a littlefs
|
||||
//
|
||||
// Does nothing besides releasing any allocated resources.
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_unmount(lfs_t *lfs);
|
||||
int lfs_unmount(lfs_t *lfs);
|
||||
|
||||
/// General operations ///
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Removes a file or directory
|
||||
//
|
||||
// If removing a directory, the directory must be empty.
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_remove(lfs_t *lfs, const char *path);
|
||||
int lfs_remove(lfs_t *lfs, const char *path);
|
||||
#endif
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// 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.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath);
|
||||
int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath);
|
||||
#endif
|
||||
|
||||
// Find info about a file or directory
|
||||
//
|
||||
// Fills out the info structure, based on the specified file or directory.
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
|
||||
int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
|
||||
|
||||
// Get a custom attribute
|
||||
//
|
||||
// Custom attributes are uniquely identified by an 8-bit type and limited
|
||||
// to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller than
|
||||
// the buffer, it will be padded with zeros. If the stored attribute is larger,
|
||||
// then it will be silently truncated. If no attribute is found, the error
|
||||
// LFS_ERR_NOATTR is returned and the buffer is filled with zeros.
|
||||
// to LFS_ATTR_MAX bytes. If the stored attribute is larger than the
|
||||
// provided buffer, it will be silently truncated. If no attribute is found,
|
||||
// the error LFS_ERR_NOATTR is returned and the buffer is filled with zeros.
|
||||
//
|
||||
// Returns the size of the attribute, or a negative error code on failure.
|
||||
// Note, the returned size is the size of the attribute on disk, irrespective
|
||||
// of the size of the buffer. This can be used to dynamically allocate a buffer
|
||||
// or check for existance.
|
||||
lfs_ssize_t _lfs_getattr(lfs_t *lfs, const char *path,
|
||||
lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path,
|
||||
uint8_t type, void *buffer, lfs_size_t size);
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Set custom attributes
|
||||
//
|
||||
// Custom attributes are uniquely identified by an 8-bit type and limited
|
||||
@@ -482,15 +493,18 @@ lfs_ssize_t _lfs_getattr(lfs_t *lfs, const char *path,
|
||||
// implicitly created.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_setattr(lfs_t *lfs, const char *path,
|
||||
int lfs_setattr(lfs_t *lfs, const char *path,
|
||||
uint8_t type, const void *buffer, lfs_size_t size);
|
||||
#endif
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Removes a custom attribute
|
||||
//
|
||||
// If an attribute is not found, nothing happens.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type);
|
||||
int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type);
|
||||
#endif
|
||||
|
||||
|
||||
/// File operations ///
|
||||
@@ -501,7 +515,7 @@ int _lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type);
|
||||
// are values from the enum lfs_open_flags that are bitwise-ored together.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_file_open(lfs_t *lfs, lfs_file_t *file,
|
||||
int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
|
||||
const char *path, int flags);
|
||||
|
||||
// Open a file with extra configuration
|
||||
@@ -514,7 +528,7 @@ int _lfs_file_open(lfs_t *lfs, lfs_file_t *file,
|
||||
// config struct must be zeroed for defaults and backwards compatibility.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
const char *path, int flags,
|
||||
const struct lfs_file_config *config);
|
||||
|
||||
@@ -524,86 +538,92 @@ int _lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
// sync had been called and releases any allocated resources.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_file_close(lfs_t *lfs, lfs_file_t *file);
|
||||
int lfs_file_close(lfs_t *lfs, lfs_file_t *file);
|
||||
|
||||
// Synchronize a file on storage
|
||||
//
|
||||
// Any pending writes are written out to storage.
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_file_sync(lfs_t *lfs, lfs_file_t *file);
|
||||
int lfs_file_sync(lfs_t *lfs, lfs_file_t *file);
|
||||
|
||||
// Read data from file
|
||||
//
|
||||
// Takes a buffer and size indicating where to store the read data.
|
||||
// Returns the number of bytes read, or a negative error code on failure.
|
||||
lfs_ssize_t _lfs_file_read(lfs_t *lfs, lfs_file_t *file,
|
||||
lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file,
|
||||
void *buffer, lfs_size_t size);
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Write data to file
|
||||
//
|
||||
// Takes a buffer and size indicating the data to write. The file will not
|
||||
// actually be updated on the storage until either sync or close is called.
|
||||
//
|
||||
// Returns the number of bytes written, or a negative error code on failure.
|
||||
lfs_ssize_t _lfs_file_write(lfs_t *lfs, lfs_file_t *file,
|
||||
lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
|
||||
const void *buffer, lfs_size_t size);
|
||||
#endif
|
||||
|
||||
// Change the position of the file
|
||||
//
|
||||
// The change in position is determined by the offset and whence flag.
|
||||
// Returns the new position of the file, or a negative error code on failure.
|
||||
lfs_soff_t _lfs_file_seek(lfs_t *lfs, lfs_file_t *file,
|
||||
lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file,
|
||||
lfs_soff_t off, int whence);
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Truncates the size of the file to the specified size
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size);
|
||||
int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size);
|
||||
#endif
|
||||
|
||||
// Return the position of the file
|
||||
//
|
||||
// Equivalent to _lfs_file_seek(lfs, file, 0, LFS_SEEK_CUR)
|
||||
// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_CUR)
|
||||
// Returns the position of the file, or a negative error code on failure.
|
||||
lfs_soff_t _lfs_file_tell(lfs_t *lfs, lfs_file_t *file);
|
||||
lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file);
|
||||
|
||||
// Change the position of the file to the beginning of the file
|
||||
//
|
||||
// Equivalent to _lfs_file_seek(lfs, file, 0, LFS_SEEK_SET)
|
||||
// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_SET)
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_file_rewind(lfs_t *lfs, lfs_file_t *file);
|
||||
int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file);
|
||||
|
||||
// Return the size of the file
|
||||
//
|
||||
// Similar to _lfs_file_seek(lfs, file, 0, LFS_SEEK_END)
|
||||
// Similar to lfs_file_seek(lfs, file, 0, LFS_SEEK_END)
|
||||
// Returns the size of the file, or a negative error code on failure.
|
||||
lfs_soff_t _lfs_file_size(lfs_t *lfs, lfs_file_t *file);
|
||||
lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file);
|
||||
|
||||
|
||||
/// Directory operations ///
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Create a directory
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_mkdir(lfs_t *lfs, const char *path);
|
||||
int lfs_mkdir(lfs_t *lfs, const char *path);
|
||||
#endif
|
||||
|
||||
// Open a directory
|
||||
//
|
||||
// Once open a directory can be used with read to iterate over files.
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path);
|
||||
int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path);
|
||||
|
||||
// Close a directory
|
||||
//
|
||||
// Releases any allocated resources.
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir);
|
||||
int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir);
|
||||
|
||||
// Read an entry in the directory
|
||||
//
|
||||
// Fills out the info structure, based on the specified file or directory.
|
||||
// Returns a positive value on success, 0 at the end of directory,
|
||||
// or a negative error code on failure.
|
||||
int _lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info);
|
||||
int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info);
|
||||
|
||||
// Change the position of the directory
|
||||
//
|
||||
@@ -611,7 +631,7 @@ int _lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info);
|
||||
// an absolute offset in the directory seek.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off);
|
||||
int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off);
|
||||
|
||||
// Return the position of the directory
|
||||
//
|
||||
@@ -619,12 +639,12 @@ int _lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off);
|
||||
// sense, but does indicate the current position in the directory iteration.
|
||||
//
|
||||
// Returns the position of the directory, or a negative error code on failure.
|
||||
lfs_soff_t _lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir);
|
||||
lfs_soff_t lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir);
|
||||
|
||||
// Change the position of the directory to the beginning of the directory
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir);
|
||||
int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir);
|
||||
|
||||
|
||||
/// Filesystem-level filesystem operations
|
||||
@@ -635,7 +655,7 @@ int _lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir);
|
||||
// size may be larger than the filesystem actually is.
|
||||
//
|
||||
// Returns the number of allocated blocks, or a negative error code on failure.
|
||||
lfs_ssize_t _lfs_fs_size(lfs_t *lfs);
|
||||
lfs_ssize_t lfs_fs_size(lfs_t *lfs);
|
||||
|
||||
// Traverse through all blocks in use by the filesystem
|
||||
//
|
||||
@@ -644,12 +664,13 @@ lfs_ssize_t _lfs_fs_size(lfs_t *lfs);
|
||||
// blocks are in use or how much of the storage is available.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
|
||||
int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
#ifdef LFS_MIGRATE
|
||||
// Attempts to migrate a previous version of littlefs
|
||||
//
|
||||
// Behaves similarly to the _lfs_format function. Attempts to mount
|
||||
// Behaves similarly to the lfs_format function. Attempts to mount
|
||||
// the previous version of littlefs and update the filesystem so it can be
|
||||
// mounted with the current version of littlefs.
|
||||
//
|
||||
@@ -658,106 +679,8 @@ int _lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
|
||||
// be zeroed for defaults and backwards compatibility.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int _lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg);
|
||||
int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg);
|
||||
#endif
|
||||
|
||||
#if LFS_THREAD_SAFE
|
||||
|
||||
int _ts_lfs_format(lfs_t *lfs, const struct lfs_config *config);
|
||||
int _ts_lfs_mount(lfs_t *lfs, const struct lfs_config *config);
|
||||
int _ts_lfs_unmount(lfs_t *lfs);
|
||||
int _ts_lfs_remove(lfs_t *lfs, const char *path);
|
||||
int _ts_lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath);
|
||||
int _ts_lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
|
||||
lfs_ssize_t _ts_lfs_getattr(lfs_t *lfs, const char *path, uint8_t type, void *buffer, lfs_size_t size);
|
||||
int _ts_lfs_setattr(lfs_t *lfs, const char *path, uint8_t type, const void *buffer, lfs_size_t size);
|
||||
int _ts_lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type);
|
||||
int _ts_lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags);
|
||||
int _ts_lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, const char *path, int flags, const struct lfs_file_config *config);
|
||||
int _ts_lfs_file_close(lfs_t *lfs, lfs_file_t *file);
|
||||
int _ts_lfs_file_sync(lfs_t *lfs, lfs_file_t *file);
|
||||
lfs_ssize_t _ts_lfs_file_read(lfs_t *lfs, lfs_file_t *file, void *buffer, lfs_size_t size);
|
||||
lfs_ssize_t _ts_lfs_file_write(lfs_t *lfs, lfs_file_t *file, const void *buffer, lfs_size_t size);
|
||||
lfs_soff_t _ts_lfs_file_seek(lfs_t *lfs, lfs_file_t *file, lfs_soff_t off, int whence);
|
||||
int _ts_lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size);
|
||||
lfs_soff_t _ts_lfs_file_tell(lfs_t *lfs, lfs_file_t *file);
|
||||
int _ts_lfs_file_rewind(lfs_t *lfs, lfs_file_t *file);
|
||||
lfs_soff_t _ts_lfs_file_size(lfs_t *lfs, lfs_file_t *file);
|
||||
int _ts_lfs_mkdir(lfs_t *lfs, const char *path);
|
||||
int _ts_lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path);
|
||||
int _ts_lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir);
|
||||
int _ts_lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info);
|
||||
int _ts_lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off);
|
||||
lfs_soff_t _ts_lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir);
|
||||
int _ts_lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir);
|
||||
lfs_ssize_t _ts_lfs_fs_size(lfs_t *lfs);
|
||||
int _ts_lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
|
||||
int _ts_lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg);
|
||||
|
||||
#define lfs_format _ts_lfs_format
|
||||
#define lfs_mount _ts_lfs_mount
|
||||
#define lfs_unmount _ts_lfs_unmount
|
||||
#define lfs_remove _ts_lfs_remove
|
||||
#define lfs_rename _ts_lfs_rename
|
||||
#define lfs_stat _ts_lfs_stat
|
||||
#define lfs_getattr _ts_lfs_getattr
|
||||
#define lfs_setattr _ts_lfs_setattr
|
||||
#define lfs_removeattr _ts_lfs_removeattr
|
||||
#define lfs_file_open _ts_lfs_file_open
|
||||
#define lfs_file_opencfg _ts_lfs_file_opencfg
|
||||
#define lfs_file_close _ts_lfs_file_close
|
||||
#define lfs_file_sync _ts_lfs_file_sync
|
||||
#define lfs_file_read _ts_lfs_file_read
|
||||
#define lfs_file_write _ts_lfs_file_write
|
||||
#define lfs_file_seek _ts_lfs_file_seek
|
||||
#define lfs_file_truncate _ts_lfs_file_truncate
|
||||
#define lfs_file_tell _ts_lfs_file_tell
|
||||
#define lfs_file_rewind _ts_lfs_file_rewind
|
||||
#define lfs_file_size _ts_lfs_file_size
|
||||
#define lfs_mkdir _ts_lfs_mkdir
|
||||
#define lfs_dir_open _ts_lfs_dir_open
|
||||
#define lfs_dir_close _ts_lfs_dir_close
|
||||
#define lfs_dir_read _ts_lfs_dir_read
|
||||
#define lfs_dir_seek _ts_lfs_dir_seek
|
||||
#define lfs_dir_tell _ts_lfs_dir_tell
|
||||
#define lfs_dir_rewind _ts_lfs_dir_rewind
|
||||
#define lfs_fs_size _ts_lfs_fs_size
|
||||
#define lfs_fs_traverse _ts_lfs_fs_traverse
|
||||
#define lfs_migrate _ts_lfs_migrate
|
||||
|
||||
#else
|
||||
|
||||
#define lfs_format _lfs_format
|
||||
#define lfs_mount _lfs_mount
|
||||
#define lfs_unmount _lfs_unmount
|
||||
#define lfs_remove _lfs_remove
|
||||
#define lfs_rename _lfs_rename
|
||||
#define lfs_stat _lfs_stat
|
||||
#define lfs_getattr _lfs_getattr
|
||||
#define lfs_setattr _lfs_setattr
|
||||
#define lfs_removeattr _lfs_removeattr
|
||||
#define lfs_file_open _lfs_file_open
|
||||
#define lfs_file_opencfg _lfs_file_opencfg
|
||||
#define lfs_file_close _lfs_file_close
|
||||
#define lfs_file_sync _lfs_file_sync
|
||||
#define lfs_file_read _lfs_file_read
|
||||
#define lfs_file_write _lfs_file_write
|
||||
#define lfs_file_seek _lfs_file_seek
|
||||
#define lfs_file_truncate _lfs_file_truncate
|
||||
#define lfs_file_tell _lfs_file_tell
|
||||
#define lfs_file_rewind _lfs_file_rewind
|
||||
#define lfs_file_size _lfs_file_size
|
||||
#define lfs_mkdir _lfs_mkdir
|
||||
#define lfs_dir_open _lfs_dir_open
|
||||
#define lfs_dir_close _lfs_dir_close
|
||||
#define lfs_dir_read _lfs_dir_read
|
||||
#define lfs_dir_seek _lfs_dir_seek
|
||||
#define lfs_dir_tell _lfs_dir_tell
|
||||
#define lfs_dir_rewind _lfs_dir_rewind
|
||||
#define lfs_fs_size _lfs_fs_size
|
||||
#define lfs_fs_traverse _lfs_fs_traverse
|
||||
#define lfs_migrate _lfs_migrate
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -43,9 +43,6 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LFS_THREAD_SAFE
|
||||
#define LFS_THREAD_SAFE 0
|
||||
#endif
|
||||
|
||||
// Macros, may be replaced by system specific wrappers. Arguments to these
|
||||
// macros must not have side-effects as the macros can be removed for a smaller
|
||||
|
||||
@@ -106,7 +106,7 @@ def main(args):
|
||||
struct.unpack('<HH', superblock[1].data[0:4].ljust(4, b'\xff'))))
|
||||
print("%-47s%s" % ("littlefs v%s.%s" % version,
|
||||
"data (truncated, if it fits)"
|
||||
if not any([args.no_truncate, args.tags, args.log, args.all]) else ""))
|
||||
if not any([args.no_truncate, args.log, args.all]) else ""))
|
||||
|
||||
# print gstate
|
||||
print("gstate 0x%s" % ''.join('%02x' % c for c in gstate))
|
||||
|
||||
@@ -16,41 +16,39 @@ code = '''
|
||||
lfs_getattr(&lfs, "hello", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "hello", 'B', buffer+4, 6) => 6;
|
||||
lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "bbbbbb", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "bbbbbb", 6) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_setattr(&lfs, "hello", 'B', "", 0) => 0;
|
||||
lfs_getattr(&lfs, "hello", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "hello", 'B', buffer+4, 6) => 0;
|
||||
lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "\0\0\0\0\0\0", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_removeattr(&lfs, "hello", 'B') => 0;
|
||||
lfs_getattr(&lfs, "hello", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "hello", 'B', buffer+4, 6) => LFS_ERR_NOATTR;
|
||||
lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "\0\0\0\0\0\0", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_setattr(&lfs, "hello", 'B', "dddddd", 6) => 0;
|
||||
lfs_getattr(&lfs, "hello", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "hello", 'B', buffer+4, 6) => 6;
|
||||
lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "dddddd", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "dddddd", 6) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_setattr(&lfs, "hello", 'B', "eee", 3) => 0;
|
||||
lfs_getattr(&lfs, "hello", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "hello", 'B', buffer+4, 6) => 3;
|
||||
lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "eee\0\0\0", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "eee", 3) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_setattr(&lfs, "hello", 'A', buffer, LFS_ATTR_MAX+1) => LFS_ERR_NOSPC;
|
||||
lfs_setattr(&lfs, "hello", 'B', "fffffffff", 9) => 0;
|
||||
@@ -65,13 +63,13 @@ code = '''
|
||||
lfs_getattr(&lfs, "hello", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "hello", 'B', buffer+4, 9) => 9;
|
||||
lfs_getattr(&lfs, "hello", 'C', buffer+13, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "fffffffff", 9) => 0;
|
||||
memcmp(buffer+13, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "fffffffff", 9) == 0);
|
||||
assert(memcmp(buffer+13, "ccccc", 5) == 0);
|
||||
|
||||
lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0;
|
||||
lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello");
|
||||
memcmp(buffer, "hello", strlen("hello")) => 0;
|
||||
assert(memcmp(buffer, "hello", strlen("hello")) == 0);
|
||||
lfs_file_close(&lfs, &file);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
@@ -94,41 +92,39 @@ code = '''
|
||||
lfs_getattr(&lfs, "/", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "/", 'B', buffer+4, 6) => 6;
|
||||
lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "bbbbbb", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "bbbbbb", 6) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_setattr(&lfs, "/", 'B', "", 0) => 0;
|
||||
lfs_getattr(&lfs, "/", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "/", 'B', buffer+4, 6) => 0;
|
||||
lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "\0\0\0\0\0\0", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_removeattr(&lfs, "/", 'B') => 0;
|
||||
lfs_getattr(&lfs, "/", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "/", 'B', buffer+4, 6) => LFS_ERR_NOATTR;
|
||||
lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "\0\0\0\0\0\0", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_setattr(&lfs, "/", 'B', "dddddd", 6) => 0;
|
||||
lfs_getattr(&lfs, "/", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "/", 'B', buffer+4, 6) => 6;
|
||||
lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "dddddd", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "dddddd", 6) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_setattr(&lfs, "/", 'B', "eee", 3) => 0;
|
||||
lfs_getattr(&lfs, "/", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "/", 'B', buffer+4, 6) => 3;
|
||||
lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "eee\0\0\0", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "eee", 3) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
lfs_setattr(&lfs, "/", 'A', buffer, LFS_ATTR_MAX+1) => LFS_ERR_NOSPC;
|
||||
lfs_setattr(&lfs, "/", 'B', "fffffffff", 9) => 0;
|
||||
@@ -142,13 +138,13 @@ code = '''
|
||||
lfs_getattr(&lfs, "/", 'A', buffer, 4) => 4;
|
||||
lfs_getattr(&lfs, "/", 'B', buffer+4, 9) => 9;
|
||||
lfs_getattr(&lfs, "/", 'C', buffer+13, 5) => 5;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "fffffffff", 9) => 0;
|
||||
memcmp(buffer+13, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "fffffffff", 9) == 0);
|
||||
assert(memcmp(buffer+13, "ccccc", 5) == 0);
|
||||
|
||||
lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0;
|
||||
lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello");
|
||||
memcmp(buffer, "hello", strlen("hello")) => 0;
|
||||
assert(memcmp(buffer, "hello", strlen("hello")) == 0);
|
||||
lfs_file_close(&lfs, &file);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
@@ -176,52 +172,55 @@ code = '''
|
||||
memcpy(buffer, "aaaa", 4);
|
||||
memcpy(buffer+4, "bbbbbb", 6);
|
||||
memcpy(buffer+10, "ccccc", 5);
|
||||
lfs_file_write(&lfs, &file, "hi", 2) => 2;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
memset(buffer, 0, 15);
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "bbbbbb", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "bbbbbb", 6) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
attrs1[1].size = 0;
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0;
|
||||
lfs_file_write(&lfs, &file, "hi", 2) => 2;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
memset(buffer, 0, 15);
|
||||
attrs1[1].size = 6;
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "\0\0\0\0\0\0", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
attrs1[1].size = 6;
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0;
|
||||
memcpy(buffer+4, "dddddd", 6);
|
||||
lfs_file_write(&lfs, &file, "hi", 2) => 2;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
memset(buffer, 0, 15);
|
||||
attrs1[1].size = 6;
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "dddddd", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "dddddd", 6) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
attrs1[1].size = 3;
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0;
|
||||
memcpy(buffer+4, "eee", 3);
|
||||
lfs_file_write(&lfs, &file, "hi", 2) => 2;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
memset(buffer, 0, 15);
|
||||
attrs1[1].size = 6;
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "eee\0\0\0", 6) => 0;
|
||||
memcmp(buffer+10, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "eee", 3) == 0);
|
||||
assert(memcmp(buffer+10, "ccccc", 5) == 0);
|
||||
|
||||
attrs1[0].size = LFS_ATTR_MAX+1;
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1)
|
||||
=> LFS_ERR_NOSPC;
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello2",
|
||||
LFS_O_WRONLY | LFS_O_CREAT, &cfg1) => LFS_ERR_NOSPC;
|
||||
|
||||
struct lfs_attr attrs2[] = {
|
||||
{'A', buffer, 4},
|
||||
@@ -231,6 +230,7 @@ code = '''
|
||||
struct lfs_file_config cfg2 = {.attrs=attrs2, .attr_count=3};
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDWR, &cfg2) => 0;
|
||||
memcpy(buffer+4, "fffffffff", 9);
|
||||
lfs_file_write(&lfs, &file, "hi", 2) => 2;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
attrs1[0].size = 4;
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
|
||||
@@ -249,13 +249,13 @@ code = '''
|
||||
|
||||
lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg3) => 0;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
memcmp(buffer, "aaaa", 4) => 0;
|
||||
memcmp(buffer+4, "fffffffff", 9) => 0;
|
||||
memcmp(buffer+13, "ccccc", 5) => 0;
|
||||
assert(memcmp(buffer, "aaaa", 4) == 0);
|
||||
assert(memcmp(buffer+4, "fffffffff", 9) == 0);
|
||||
assert(memcmp(buffer+13, "ccccc", 5) == 0);
|
||||
|
||||
lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0;
|
||||
lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello");
|
||||
memcmp(buffer, "hello", strlen("hello")) => 0;
|
||||
assert(memcmp(buffer, "hillo", strlen("hello")) == 0);
|
||||
lfs_file_close(&lfs, &file);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
@@ -287,17 +287,16 @@ code = '''
|
||||
lfs_getattr(&lfs, "hello/hello", 'B', buffer, 9) => 9;
|
||||
lfs_getattr(&lfs, "hello/hello", 'C', buffer+9, 9) => 5;
|
||||
lfs_getattr(&lfs, "hello/hello", 'D', buffer+18, 9) => LFS_ERR_NOATTR;
|
||||
memcmp(buffer, "fffffffff", 9) => 0;
|
||||
memcmp(buffer+9, "ccccc\0\0\0\0", 9) => 0;
|
||||
memcmp(buffer+18, "\0\0\0\0\0\0\0\0\0", 9) => 0;
|
||||
assert(memcmp(buffer, "fffffffff", 9) == 0);
|
||||
assert(memcmp(buffer+9, "ccccc", 5) == 0);
|
||||
|
||||
lfs_file_write(&lfs, &file, "hi", 2) => 2;
|
||||
lfs_file_sync(&lfs, &file) => 0;
|
||||
lfs_getattr(&lfs, "hello/hello", 'B', buffer, 9) => 4;
|
||||
lfs_getattr(&lfs, "hello/hello", 'C', buffer+9, 9) => 0;
|
||||
lfs_getattr(&lfs, "hello/hello", 'D', buffer+18, 9) => 4;
|
||||
memcmp(buffer, "gggg\0\0\0\0\0", 9) => 0;
|
||||
memcmp(buffer+9, "\0\0\0\0\0\0\0\0\0", 9) => 0;
|
||||
memcmp(buffer+18, "hhhh\0\0\0\0\0", 9) => 0;
|
||||
assert(memcmp(buffer, "gggg", 4) == 0);
|
||||
assert(memcmp(buffer+18, "hhhh", 4) == 0);
|
||||
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
@@ -242,3 +242,695 @@ code = '''
|
||||
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # open same file reading from separate file handles
|
||||
define.READERS = 3
|
||||
define.SIZE = [10, 100, 1000, 10000]
|
||||
define.RDMODE = ['LFS_O_RDONLY', 'LFS_O_RDWR']
|
||||
code = '''
|
||||
const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "shared", LFS_O_CREAT | LFS_O_WRONLY) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &file, &alphas[j % 26], 1) => 1;
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// open all files
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_t readers[READERS];
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
lfs_file_open(&lfs, &readers[i], "shared", RDMODE) => 0;
|
||||
}
|
||||
|
||||
// perform operations while all readers are open
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &readers[i], buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
lfs_file_close(&lfs, &readers[i]) => 0;
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # open same file reading and writing from separate file handles
|
||||
define.READERS = 3
|
||||
define.SIZE = [10, 100, 1000, 10000]
|
||||
define.RDMODE = ['LFS_O_RDONLY', 'LFS_O_RDWR']
|
||||
define.WRMODE = ['LFS_O_WRONLY', 'LFS_O_RDWR']
|
||||
code = '''
|
||||
const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
const char nums[] = "0123456789";
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "shared", LFS_O_CREAT | LFS_O_WRONLY) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &file, &alphas[j % 26], 1) => 1;
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// open all files
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_t writer;
|
||||
lfs_file_t readers[READERS];
|
||||
lfs_file_open(&lfs, &writer, "shared", WRMODE) => 0;
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
lfs_file_open(&lfs, &readers[i], "shared", RDMODE) => 0;
|
||||
}
|
||||
|
||||
// perform operations while all readers are open
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &writer, &nums[j % 10], 1) => 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
for (int j = 0; j < SIZE/2; j++) {
|
||||
lfs_file_read(&lfs, &readers[i], buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
}
|
||||
|
||||
// sync, now write should reflect in all open files
|
||||
lfs_file_sync(&lfs, &writer) => 0;
|
||||
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
for (int j = SIZE/2; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &readers[i], buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
}
|
||||
|
||||
// double check our writer reflects its own changes
|
||||
if (WRMODE == LFS_O_RDWR) {
|
||||
lfs_file_rewind(&lfs, &writer) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &writer, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
lfs_file_close(&lfs, &readers[i]) => 0;
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # check that attributes are updated in open files
|
||||
define.READERS = 3
|
||||
define.SIZE = 10
|
||||
define.RDMODE = ['LFS_O_RDONLY', 'LFS_O_RDWR']
|
||||
define.WRMODE = ['LFS_O_WRONLY', 'LFS_O_RDWR']
|
||||
code = '''
|
||||
const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
const char nums[] = "0123456789";
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
const struct lfs_file_config filecfg = {
|
||||
.attr_count = 3,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', "a", 1},
|
||||
{'B', "bb", 2},
|
||||
{'C', "ccc", 3},
|
||||
},
|
||||
};
|
||||
lfs_file_opencfg(&lfs, &file, "shared",
|
||||
LFS_O_CREAT | LFS_O_WRONLY, &filecfg) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &file, &alphas[j % 26], 1) => 1;
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// open all files
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_t writer;
|
||||
const struct lfs_file_config writercfg = {
|
||||
.attr_count = 3,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[1]){0}, 1},
|
||||
{'B', &(uint8_t[2]){0}, 2},
|
||||
{'C', &(uint8_t[3]){0}, 3}}};
|
||||
lfs_file_t readers[READERS];
|
||||
const struct lfs_file_config readercfgs[READERS] = {
|
||||
{ .attr_count = 3,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[1]){0}, 1},
|
||||
{'B', &(uint8_t[2]){0}, 2},
|
||||
{'C', &(uint8_t[3]){0}, 3}}},
|
||||
{ .attr_count = 3,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[1]){0}, 1},
|
||||
{'B', &(uint8_t[2]){0}, 2},
|
||||
{'C', &(uint8_t[3]){0}, 3}}},
|
||||
{ .attr_count = 3,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[1]){0}, 1},
|
||||
{'B', &(uint8_t[2]){0}, 2},
|
||||
{'C', &(uint8_t[3]){0}, 3}}}};
|
||||
lfs_file_opencfg(&lfs, &writer, "shared",
|
||||
WRMODE, &writercfg) => 0;
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
lfs_file_opencfg(&lfs, &readers[i], "shared",
|
||||
RDMODE, &readercfgs[i]) => 0;
|
||||
}
|
||||
|
||||
// perform operations while all readers are open
|
||||
writercfg.attrs[0].size = 1;
|
||||
memcpy(writercfg.attrs[0].buffer, "0", 1);
|
||||
writercfg.attrs[1].size = 2;
|
||||
memcpy(writercfg.attrs[1].buffer, "11", 2);
|
||||
writercfg.attrs[2].size = 3;
|
||||
memcpy(writercfg.attrs[2].buffer, "222", 3);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &writer, &nums[j % 10], 1) => 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
assert(readercfgs[i].attrs[0].size == 1);
|
||||
assert(memcmp(readercfgs[i].attrs[0].buffer, "a", 1) == 0);
|
||||
assert(readercfgs[i].attrs[1].size == 2);
|
||||
assert(memcmp(readercfgs[i].attrs[1].buffer, "bb", 2) == 0);
|
||||
assert(readercfgs[i].attrs[2].size == 3);
|
||||
assert(memcmp(readercfgs[i].attrs[2].buffer, "ccc", 3) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &readers[i], buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
}
|
||||
|
||||
// sync, now write should reflect in all open files
|
||||
lfs_file_sync(&lfs, &writer) => 0;
|
||||
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
assert(readercfgs[i].attrs[0].size == 1);
|
||||
assert(memcmp(readercfgs[i].attrs[0].buffer, "0", 1) == 0);
|
||||
assert(readercfgs[i].attrs[1].size == 2);
|
||||
assert(memcmp(readercfgs[i].attrs[1].buffer, "11", 2) == 0);
|
||||
assert(readercfgs[i].attrs[2].size == 3);
|
||||
assert(memcmp(readercfgs[i].attrs[2].buffer, "222", 3) == 0);
|
||||
lfs_file_rewind(&lfs, &readers[i]) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &readers[i], buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
}
|
||||
|
||||
// double check our writer reflects its own changes
|
||||
if (WRMODE == LFS_O_RDWR) {
|
||||
assert(writercfg.attrs[0].size == 1);
|
||||
assert(memcmp(writercfg.attrs[0].buffer, "0", 1) == 0);
|
||||
assert(writercfg.attrs[1].size == 2);
|
||||
assert(memcmp(writercfg.attrs[1].buffer, "11", 2) == 0);
|
||||
assert(writercfg.attrs[2].size == 3);
|
||||
assert(memcmp(writercfg.attrs[2].buffer, "222", 3) == 0);
|
||||
lfs_file_rewind(&lfs, &writer) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &writer, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
}
|
||||
|
||||
// now try explicit lfs_setattr calls, this should still update open files
|
||||
lfs_setattr(&lfs, "shared", 'A', "A", 1) => 0;
|
||||
lfs_setattr(&lfs, "shared", 'B', "BB", 2) => 0;
|
||||
lfs_setattr(&lfs, "shared", 'C', "CCC", 3) => 0;
|
||||
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
assert(readercfgs[i].attrs[0].size == 1);
|
||||
assert(memcmp(readercfgs[i].attrs[0].buffer, "A", 1) == 0);
|
||||
assert(readercfgs[i].attrs[1].size == 2);
|
||||
assert(memcmp(readercfgs[i].attrs[1].buffer, "BB", 2) == 0);
|
||||
assert(readercfgs[i].attrs[2].size == 3);
|
||||
assert(memcmp(readercfgs[i].attrs[2].buffer, "CCC", 3) == 0);
|
||||
lfs_file_rewind(&lfs, &readers[i]) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &readers[i], buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
}
|
||||
|
||||
if (WRMODE == LFS_O_RDWR) {
|
||||
assert(writercfg.attrs[0].size == 1);
|
||||
assert(memcmp(writercfg.attrs[0].buffer, "A", 1) == 0);
|
||||
assert(writercfg.attrs[1].size == 2);
|
||||
assert(memcmp(writercfg.attrs[1].buffer, "BB", 2) == 0);
|
||||
assert(writercfg.attrs[2].size == 3);
|
||||
assert(memcmp(writercfg.attrs[2].buffer, "CCC", 3) == 0);
|
||||
lfs_file_rewind(&lfs, &writer) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &writer, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
} else if (WRMODE == LFS_O_WRONLY) {
|
||||
// this should NOT update wronly attributes, these may be
|
||||
// stored in read-only memory
|
||||
assert(writercfg.attrs[0].size == 1);
|
||||
assert(memcmp(writercfg.attrs[0].buffer, "0", 1) == 0);
|
||||
assert(writercfg.attrs[1].size == 2);
|
||||
assert(memcmp(writercfg.attrs[1].buffer, "11", 2) == 0);
|
||||
assert(writercfg.attrs[2].size == 3);
|
||||
assert(memcmp(writercfg.attrs[2].buffer, "222", 3) == 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < READERS; i++) {
|
||||
lfs_file_close(&lfs, &readers[i]) => 0;
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # simple snapshot for reading
|
||||
define.SIZE = [10, 100, 1000, 10000]
|
||||
code = '''
|
||||
const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
const char nums[] = "0123456789";
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
const struct lfs_file_config filecfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', "abcd", 4},
|
||||
},
|
||||
};
|
||||
lfs_file_opencfg(&lfs, &file, "open_me",
|
||||
LFS_O_CREAT | LFS_O_WRONLY, &filecfg) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &file, &alphas[j % 26], 1) => 1;
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// open reader/writer/snapshot
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_t reader;
|
||||
const struct lfs_file_config readercfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[4]){0}, 4}
|
||||
},
|
||||
};
|
||||
lfs_file_t writer;
|
||||
const struct lfs_file_config writercfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[4]){0}, 4}
|
||||
},
|
||||
};
|
||||
lfs_file_t snapshot;
|
||||
const struct lfs_file_config snapshotcfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[4]){0}, 4}
|
||||
},
|
||||
};
|
||||
lfs_file_opencfg(&lfs, &reader, "open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
lfs_file_opencfg(&lfs, &writer, "open_me",
|
||||
LFS_O_WRONLY, &writercfg) => 0;
|
||||
lfs_file_opencfg(&lfs, &snapshot, "open_me",
|
||||
LFS_O_RDONLY | LFS_O_SNAPSHOT, &snapshotcfg) => 0;
|
||||
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = 0; j < SIZE/2; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
|
||||
assert(memcmp(snapshotcfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = 0; j < SIZE/2; j++) {
|
||||
lfs_file_read(&lfs, &snapshot, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
|
||||
// write file
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &writer, &nums[j % 10], 1) => 1;
|
||||
}
|
||||
memcpy(writercfg.attrs[0].buffer, "0123", 4);
|
||||
lfs_file_sync(&lfs, &writer) => 0;
|
||||
|
||||
// reader should change
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "0123", 4) == 0);
|
||||
for (int j = SIZE/2; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
|
||||
// snapshot should remain unchanged
|
||||
assert(memcmp(snapshotcfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = SIZE/2; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &snapshot, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_file_close(&lfs, &writer) => 0;
|
||||
lfs_file_close(&lfs, &snapshot) => 0;
|
||||
|
||||
// disk should change
|
||||
lfs_file_opencfg(&lfs, &reader, "open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "0123", 4) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_opencfg(&lfs, &reader, "open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "0123", 4) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # simple snapshot for writing
|
||||
define.SIZE = [10, 100, 1000, 10000]
|
||||
code = '''
|
||||
const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
const char nums[] = "0123456789";
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
const struct lfs_file_config filecfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', "abcd", 4},
|
||||
},
|
||||
};
|
||||
lfs_file_opencfg(&lfs, &file, "open_me",
|
||||
LFS_O_CREAT | LFS_O_WRONLY, &filecfg) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &file, &alphas[j % 26], 1) => 1;
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// open reader/snapshot
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_t reader;
|
||||
const struct lfs_file_config readercfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[4]){0}, 4}
|
||||
},
|
||||
};
|
||||
lfs_file_t snapshot;
|
||||
const struct lfs_file_config snapshotcfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[4]){0}, 4}
|
||||
},
|
||||
};
|
||||
lfs_file_opencfg(&lfs, &reader, "open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
lfs_file_opencfg(&lfs, &snapshot, "open_me",
|
||||
LFS_O_RDWR | LFS_O_SNAPSHOT, &snapshotcfg) => 0;
|
||||
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = 0; j < SIZE/2; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
|
||||
assert(memcmp(snapshotcfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &snapshot, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
|
||||
// modify snapshot
|
||||
lfs_file_rewind(&lfs, &snapshot) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &snapshot, &nums[j % 10], 1) => 1;
|
||||
}
|
||||
memcpy(snapshotcfg.attrs[0].buffer, "0123", 4);
|
||||
|
||||
lfs_file_rewind(&lfs, &snapshot) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &snapshot, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
|
||||
lfs_file_sync(&lfs, &snapshot) => 0;
|
||||
|
||||
// reader should not change
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = SIZE/2; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
|
||||
// snapshot should changed
|
||||
assert(memcmp(snapshotcfg.attrs[0].buffer, "0123", 4) == 0);
|
||||
lfs_file_rewind(&lfs, &snapshot) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &snapshot, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_file_close(&lfs, &snapshot) => 0;
|
||||
|
||||
// disk should not change
|
||||
lfs_file_opencfg(&lfs, &reader, "open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_opencfg(&lfs, &reader, "open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # temporary files
|
||||
define.SIZE = [10, 100, 1000, 10000]
|
||||
define.TMP_PATH = 'range(4)'
|
||||
code = '''
|
||||
const char alphas[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
const char nums[] = "0123456789";
|
||||
const char caps[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
const struct lfs_file_config filecfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', "abcd", 4},
|
||||
},
|
||||
};
|
||||
lfs_file_opencfg(&lfs, &file, "open_me",
|
||||
LFS_O_CREAT | LFS_O_WRONLY, &filecfg) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &file, &alphas[j % 26], 1) => 1;
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_file_opencfg(&lfs, &file, "dont_open_me",
|
||||
LFS_O_CREAT | LFS_O_WRONLY, &filecfg) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &file, &alphas[j % 26], 1) => 1;
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// open reader/writer/temp
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_t reader;
|
||||
const struct lfs_file_config readercfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[4]){0}, 4}
|
||||
},
|
||||
};
|
||||
lfs_file_t writer;
|
||||
const struct lfs_file_config writercfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[4]){0}, 4}
|
||||
},
|
||||
};
|
||||
lfs_file_t tmp;
|
||||
const struct lfs_file_config tmpcfg = {
|
||||
.attr_count = 1,
|
||||
.attrs = (struct lfs_attr[]){
|
||||
{'A', &(uint8_t[4]){0}, 4}
|
||||
},
|
||||
};
|
||||
lfs_file_opencfg(&lfs, &reader, "open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
lfs_file_opencfg(&lfs, &writer, "open_me",
|
||||
LFS_O_WRONLY, &writercfg) => 0;
|
||||
const char *tmp_paths[] = {NULL, "/", "/tmp", "/open_me.tmp"};
|
||||
lfs_file_opencfg(&lfs, &tmp, tmp_paths[TMP_PATH],
|
||||
LFS_O_RDWR | LFS_O_CREAT | LFS_O_SNAPSHOT, &tmpcfg) => 0;
|
||||
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = 0; j < SIZE/3; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
|
||||
assert(memcmp(tmpcfg.attrs[0].buffer, "\0\0\0\0", 4) == 0);
|
||||
assert(lfs_file_size(&lfs, &tmp) == 0);
|
||||
|
||||
// write to tmp
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &tmp, &nums[j % 10], 1) => 1;
|
||||
}
|
||||
memcpy(tmpcfg.attrs[0].buffer, "0123", 4);
|
||||
|
||||
lfs_file_rewind(&lfs, &tmp) => 0;
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &tmp, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
|
||||
lfs_file_sync(&lfs, &tmp) => 0;
|
||||
|
||||
// reader should not change
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = SIZE/3; j < 2*SIZE/3; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
|
||||
// tmp should change
|
||||
assert(memcmp(tmpcfg.attrs[0].buffer, "0123", 4) == 0);
|
||||
lfs_file_rewind(&lfs, &tmp) => 0;
|
||||
for (int j = 0; j < SIZE/2; j++) {
|
||||
lfs_file_read(&lfs, &tmp, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
|
||||
// write to file
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_write(&lfs, &writer, &caps[j % 26], 1) => 1;
|
||||
}
|
||||
memcpy(writercfg.attrs[0].buffer, "ABCD", 4);
|
||||
lfs_file_sync(&lfs, &writer) => 0;
|
||||
|
||||
// reader should change
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "ABCD", 4) == 0);
|
||||
for (int j = 2*SIZE/3; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == caps[j % 26]);
|
||||
}
|
||||
|
||||
// tmp should not change
|
||||
assert(memcmp(tmpcfg.attrs[0].buffer, "0123", 4) == 0);
|
||||
for (int j = SIZE/2; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &tmp, buffer, 1) => 1;
|
||||
assert(buffer[0] == nums[j % 10]);
|
||||
}
|
||||
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_file_close(&lfs, &writer) => 0;
|
||||
lfs_file_close(&lfs, &tmp) => 0;
|
||||
|
||||
// tmp should not appear on disk
|
||||
lfs_dir_open(&lfs, &dir, "/") => 0;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, ".") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, "..") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_REG);
|
||||
assert(strcmp(info.name, "dont_open_me") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_REG);
|
||||
assert(strcmp(info.name, "open_me") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 0;
|
||||
lfs_dir_close(&lfs, &dir) => 0;
|
||||
lfs_file_opencfg(&lfs, &reader, "open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "ABCD", 4) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == caps[j % 26]);
|
||||
}
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_file_opencfg(&lfs, &reader, "dont_open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_dir_open(&lfs, &dir, "/") => 0;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, ".") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, "..") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_REG);
|
||||
assert(strcmp(info.name, "dont_open_me") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_REG);
|
||||
assert(strcmp(info.name, "open_me") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 0;
|
||||
lfs_dir_close(&lfs, &dir) => 0;
|
||||
lfs_file_opencfg(&lfs, &reader, "open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "ABCD", 4) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == caps[j % 26]);
|
||||
}
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_file_opencfg(&lfs, &reader, "dont_open_me",
|
||||
LFS_O_RDONLY, &readercfg) => 0;
|
||||
assert(memcmp(readercfg.attrs[0].buffer, "abcd", 4) == 0);
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
lfs_file_read(&lfs, &reader, buffer, 1) => 1;
|
||||
assert(buffer[0] == alphas[j % 26]);
|
||||
}
|
||||
lfs_file_close(&lfs, &reader) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # test snapshot open errors
|
||||
code = '''
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, NULL,
|
||||
LFS_O_RDWR | LFS_O_SNAPSHOT) => LFS_ERR_ISDIR;
|
||||
lfs_file_open(&lfs, &file, "/",
|
||||
LFS_O_RDWR | LFS_O_SNAPSHOT) => LFS_ERR_ISDIR;
|
||||
lfs_file_open(&lfs, &file, "/tmp",
|
||||
LFS_O_RDWR | LFS_O_SNAPSHOT) => LFS_ERR_NOENT;
|
||||
lfs_file_open(&lfs, &file, "/tmp/",
|
||||
LFS_O_RDWR | LFS_O_CREAT | LFS_O_SNAPSHOT) => LFS_ERR_NOENT;
|
||||
lfs_file_open(&lfs, &file, "/tmp/tmp",
|
||||
LFS_O_RDWR | LFS_O_CREAT | LFS_O_SNAPSHOT) => LFS_ERR_NOENT;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
@@ -95,9 +95,9 @@ code = '''
|
||||
|
||||
lfs_mkdir(&lfs, "coffee/../milk") => 0;
|
||||
lfs_stat(&lfs, "coffee/../milk", &info) => 0;
|
||||
strcmp(info.name, "milk") => 0;
|
||||
assert(strcmp(info.name, "milk") == 0);
|
||||
lfs_stat(&lfs, "milk", &info) => 0;
|
||||
strcmp(info.name, "milk") => 0;
|
||||
assert(strcmp(info.name, "milk") == 0);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
@@ -129,9 +129,9 @@ code = '''
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mkdir(&lfs, ".milk") => 0;
|
||||
lfs_stat(&lfs, ".milk", &info) => 0;
|
||||
strcmp(info.name, ".milk") => 0;
|
||||
assert(strcmp(info.name, ".milk") == 0);
|
||||
lfs_stat(&lfs, "tea/.././.milk", &info) => 0;
|
||||
strcmp(info.name, ".milk") => 0;
|
||||
assert(strcmp(info.name, ".milk") == 0);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
@@ -149,13 +149,13 @@ code = '''
|
||||
lfs_mkdir(&lfs, "coffee/coldcoffee") => 0;
|
||||
|
||||
lfs_stat(&lfs, "coffee/../../../../../../tea/hottea", &info) => 0;
|
||||
strcmp(info.name, "hottea") => 0;
|
||||
assert(strcmp(info.name, "hottea") == 0);
|
||||
|
||||
lfs_mkdir(&lfs, "coffee/../../../../../../milk") => 0;
|
||||
lfs_stat(&lfs, "coffee/../../../../../../milk", &info) => 0;
|
||||
strcmp(info.name, "milk") => 0;
|
||||
assert(strcmp(info.name, "milk") == 0);
|
||||
lfs_stat(&lfs, "milk", &info) => 0;
|
||||
strcmp(info.name, "milk") => 0;
|
||||
assert(strcmp(info.name, "milk") == 0);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user