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:
@@ -11210,13 +11210,7 @@ lfs_ssize_t lfsr_sizeattr(lfs_t *lfs, const char *path, uint8_t type) {
|
||||
}
|
||||
|
||||
int lfsr_setattr(lfs_t *lfs, const char *path, uint8_t type,
|
||||
const void *buffer, lfs_size_t size,
|
||||
uint32_t flags) {
|
||||
// unknown flags?
|
||||
LFS_ASSERT((flags & ~(
|
||||
LFS_A_CREAT
|
||||
| LFS_O_EXCL)) == 0);
|
||||
|
||||
const void *buffer, lfs_size_t size) {
|
||||
// prepare our filesystem for writing
|
||||
int err = lfsr_fs_mkconsistent(lfs);
|
||||
if (err) {
|
||||
@@ -11232,18 +11226,6 @@ int lfsr_setattr(lfs_t *lfs, const char *path, uint8_t type,
|
||||
return err;
|
||||
}
|
||||
|
||||
// doesn't exist?
|
||||
if (!lfsr_o_iscreat(flags)
|
||||
&& err == LFS_ERR_NOATTR) {
|
||||
return LFS_ERR_NOATTR;
|
||||
|
||||
// does exist?
|
||||
} else if (lfsr_o_iscreat(flags)
|
||||
&& lfsr_o_isexcl(flags)
|
||||
&& err != LFS_ERR_NOATTR) {
|
||||
return LFS_ERR_EXIST;
|
||||
}
|
||||
|
||||
// commit our attr
|
||||
lfs_alloc_ckpoint(lfs);
|
||||
err = lfsr_mdir_commit(lfs, &mdir, LFSR_ATTRS(
|
||||
|
||||
Reference in New Issue
Block a user