attrs: Dropped lfsr_setattr flags
After running into issues with LFS_A_CREAT/EXCL in file-attached custom
attributes, we're left in a really weird place:
- None of lfs_setattr's flags are valid in lfs_attr
- None of lfs_attr's flags are valid in lfs_setattr
I also started thinking about the actual use case for LFS_A_CREAT/EXCL,
and it's really not clear.
littlefs really doesn't care about interprocess communication the same
way POSIX/other filesystem APIs do. We can always rely on integration
layers wrapping up multiple operations in a single mutex, so offering
flexible creation semantics has diminished value. LFS_A_CREAT and
LFS_A_EXCL can both be emulated by calling lfsr_getattr first and
checking its return value.
Thinking ahead to the hypothetical lfsr_set API. The main purpose of
lfsr_set is to provide an API that's easier to use but less powerful
than lfsr_file_open. And adding a flags argument seems to run counter to
that.
For example, if you saw this code with no knowledge of littlefs:
lfsr_setattr(&lfs, "cat", 'a', "meow", 4, 0);
You would probably be surprised that it returns LFS_ERR_NOENT without
additional flags.
I realize Linux sidesteps this with XATTR_CREATE/REPLACE by making 0
default to implicitly creating, but I didn't want to introduce
inconsistent flag behavior like this unless I had to.
---
So for now dropping LFS_A_CREAT/EXCL and flags argument to lfsr_setattr.
Code savings minimal, this was mostly for API ergonomics:
code stack
before: 38104 2624
after: 38084 (-0.1%) 2624 (+0.0%)
This commit is contained in:
@@ -155,9 +155,7 @@ enum lfs_type {
|
||||
#define LFS_A_RDONLY 0 // Open an attr as read only
|
||||
#define LFS_A_WRONLY 1 // Open an attr as write only
|
||||
#define LFS_A_RDWR 2 // Open an attr as read and write
|
||||
#define LFS_A_CREAT 0x04 // Create an attr if it does not exist
|
||||
#define LFS_A_EXCL 0x08 // Fail if an attr already exists
|
||||
#define LFS_A_LAZY 0x10 // Only write attr if file changed
|
||||
#define LFS_A_LAZY 0x04 // Only write attr if file changed
|
||||
|
||||
// Filesystem format flags
|
||||
#define LFS_F_RDWR 0 // Format the filesystem as read and write
|
||||
@@ -951,17 +949,13 @@ lfs_ssize_t lfsr_getattr(lfs_t *lfs, const char *path, uint8_t type,
|
||||
lfs_ssize_t lfsr_sizeattr(lfs_t *lfs, const char *path, uint8_t type);
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Set custom attributes
|
||||
//
|
||||
// The flags field controls the exact behavior if the attribute is or
|
||||
// isn't found.
|
||||
// Set a custom attributes
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
//int lfs_setattr(lfs_t *lfs, const char *path,
|
||||
// uint8_t type, const void *buffer, lfs_size_t size);
|
||||
int lfsr_setattr(lfs_t *lfs, const char *path, uint8_t type,
|
||||
const void *buffer, lfs_size_t size,
|
||||
uint32_t flags);
|
||||
const void *buffer, lfs_size_t size);
|
||||
#endif
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
|
||||
Reference in New Issue
Block a user