mirror of
https://gitee.com/openharmony/third_party_littlefs
synced 2025-02-17 06:08:16 +00:00
Bumped versions, cleaned up some TODOs and missing comments
This commit is contained in:
parent
6774276124
commit
65ea6b3d0f
14
lfs.c
14
lfs.c
@ -722,7 +722,6 @@ relocate:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO zeros?
|
||||
static int lfs_dir_get(lfs_t *lfs, const lfs_dir_t *dir,
|
||||
lfs_off_t off, void *buffer, lfs_size_t size) {
|
||||
return lfs_bd_read(lfs, dir->pair[0], off, buffer, size);
|
||||
@ -1180,8 +1179,6 @@ int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) {
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO common info constructor?
|
||||
// TODO also used in lfs_stat
|
||||
info->type = 0xf & entry.d.type;
|
||||
if (entry.d.type == (LFS_STRUCT_CTZ | LFS_TYPE_REG)) {
|
||||
info->size = entry.d.u.file.size;
|
||||
@ -1707,7 +1704,6 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// TODO entry read function?
|
||||
lfs_entry_t entry = {.off = file->poff};
|
||||
err = lfs_dir_get(lfs, &cwd, entry.off, &entry.d, sizeof(entry.d));
|
||||
lfs_entry_fromle32(&entry.d);
|
||||
@ -1778,7 +1774,6 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file,
|
||||
nsize = size;
|
||||
|
||||
while (nsize > 0) {
|
||||
// TODO can this be collapsed?
|
||||
// check if we need a new block
|
||||
if (!(file->flags & LFS_F_READING) ||
|
||||
file->off == lfs->cfg->block_size) {
|
||||
@ -1848,12 +1843,9 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO combine with block allocation?
|
||||
// TODO need to move out if no longer fits in block also
|
||||
// TODO store INLINE_MAX in superblock?
|
||||
// TODO what if inline files is > block size (ie 128)
|
||||
if ((file->flags & LFS_F_INLINE) &&
|
||||
file->pos + nsize >= file->inline_size) {
|
||||
// inline file doesn't fit anymore
|
||||
file->block = 0xfffffffe;
|
||||
file->off = file->pos;
|
||||
|
||||
@ -1869,9 +1861,6 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
|
||||
}
|
||||
|
||||
while (nsize > 0) {
|
||||
// TODO can this be collapsed?
|
||||
// TODO can we reduce this now that block 0 is never allocated?
|
||||
// TODO actually, how does this behave if inline max == 0?
|
||||
// check if we need a new block
|
||||
if (!(file->flags & LFS_F_WRITING) ||
|
||||
file->off == lfs->cfg->block_size) {
|
||||
@ -1969,7 +1958,6 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file,
|
||||
return file->pos;
|
||||
}
|
||||
|
||||
// TODO handle inlining?
|
||||
int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) {
|
||||
if ((file->flags & 3) == LFS_O_RDONLY) {
|
||||
return LFS_ERR_BADF;
|
||||
|
36
lfs.h
36
lfs.h
@ -27,14 +27,14 @@
|
||||
// Software library version
|
||||
// Major (top-nibble), incremented on backwards incompatible changes
|
||||
// Minor (bottom-nibble), incremented on feature additions
|
||||
#define LFS_VERSION 0x00010003
|
||||
#define LFS_VERSION 0x00010004
|
||||
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
|
||||
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
|
||||
|
||||
// Version of On-disk data structures
|
||||
// Major (top-nibble), incremented on backwards incompatible changes
|
||||
// Minor (bottom-nibble), incremented on feature additions
|
||||
#define LFS_DISK_VERSION 0x00010001
|
||||
#define LFS_DISK_VERSION 0x00010002
|
||||
#define LFS_DISK_VERSION_MAJOR (0xffff & (LFS_DISK_VERSION >> 16))
|
||||
#define LFS_DISK_VERSION_MINOR (0xffff & (LFS_DISK_VERSION >> 0))
|
||||
|
||||
@ -50,17 +50,25 @@ typedef int32_t lfs_soff_t;
|
||||
|
||||
typedef uint32_t lfs_block_t;
|
||||
|
||||
// Maximum inline file size in bytes
|
||||
// Maximum inline file size in bytes. Large inline files require a larger
|
||||
// read and prog cache, but if a file can be inline it does not need its own
|
||||
// data block. LFS_ATTRS_MAX + LFS_INLINE_MAX must be <= 0xffff. Stored in
|
||||
// superblock and must be respected by other littlefs drivers.
|
||||
#ifndef LFS_INLINE_MAX
|
||||
#define LFS_INLINE_MAX 0x3ff
|
||||
#endif
|
||||
|
||||
// Maximum size of all attributes per file in bytes
|
||||
// Maximum size of all attributes per file in bytes, may be redefined but a
|
||||
// a smaller LFS_ATTRS_MAX has no benefit. LFS_ATTRS_MAX + LFS_INLINE_MAX
|
||||
// must be <= 0xffff. Stored in superblock and must be respected by other
|
||||
// littlefs drivers.
|
||||
#ifndef LFS_ATTRS_MAX
|
||||
#define LFS_ATTRS_MAX 0x3f
|
||||
#endif
|
||||
|
||||
// Max name size in bytes
|
||||
// Max name size in bytes, may be redefined to reduce the size of the
|
||||
// info struct. Stored in superblock and must be respected by other
|
||||
// littlefs drivers.
|
||||
#ifndef LFS_NAME_MAX
|
||||
#define LFS_NAME_MAX 0xff
|
||||
#endif
|
||||
@ -191,11 +199,23 @@ struct lfs_config {
|
||||
// If enabled, only one file may be opened at a time.
|
||||
void *file_buffer;
|
||||
|
||||
// Optional,
|
||||
// Optional upper limit on inlined files in bytes. Large inline files
|
||||
// require a larger read and prog cache, but if a file can be inlined it
|
||||
// does not need its own data block. Must be smaller than the read size
|
||||
// and prog size. Defaults to min(LFS_INLINE_MAX, read_size) when zero.
|
||||
// Stored in superblock and must be respected by other littlefs drivers.
|
||||
lfs_size_t inline_size;
|
||||
// Optional,
|
||||
|
||||
// Optional upper limit on attributes per file in bytes. No downside for
|
||||
// larger attributes size but must be less than LFS_ATTRS_MAX. Defaults to
|
||||
// LFS_ATTRS_MAX when zero.Stored in superblock and must be respected by
|
||||
// other littlefs drivers.
|
||||
lfs_size_t attrs_size;
|
||||
// Optional,
|
||||
|
||||
// Optional upper limit on length of file names in bytes. No downside for
|
||||
// larger names except the size of the info struct which is controlled by
|
||||
// the LFS_NAME_MAX define. Defaults to LFS_NAME_MAX when zero. Stored in
|
||||
// superblock and must be respected by other littlefs drivers.
|
||||
lfs_size_t name_size;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user