Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lfs_file_getattr and lfs_file_setattr #580

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DS-LK
Copy link

@DS-LK DS-LK commented Jul 13, 2021

I found that in the process of using littlefs, sometimes the save path is not obtained or obtained, and the custom attribute cannot be used at this time. I think it is better to add a file parameter, it allows us to apply more scenarios, and can also save memory usage in some cases.

Signed-off-by: zhouliang3 <zhouliang3@xiaomi.com>
Signed-off-by: zhouliang3 <zhouliang3@xiaomi.com>
@DS-LK DS-LK changed the title Add attribute operation, use file parameter Add lfs_file_getattr and lfs_file_setattr Oct 19, 2021
@DS-LK
Copy link
Author

DS-LK commented Oct 19, 2021

Add a function to get the path

@DS-LK
Copy link
Author

DS-LK commented Oct 19, 2021

@geky Hello, can you take some time to review it, thank you very much.

@dpkristensen
Copy link

Would love for this feature to be merged.

@geky
Copy link
Member

geky commented May 1, 2023

Hi @DS-LK, thanks for creating a PR, sorry about the extremely late response. I should have commented on this earlier.

This functionality is a great idea, but unfortunately I don't think it fits into how littlefs currently models open files.

Consider:

// attr in RAM
struct lfs_attr example_attrs[1] = {
    {.type=1, .buffer=&(uint8_t[1]){}, .size=1}
};
struct lfs_file_config file_config = {.attrs=example_attrs, .attr_count=1};

lfs_file_t file;
lfs_file_opencfg(lfs, &file, "example_file", LFS_O_RDWR, &file_config);

// write RAM attr
memset(example_attrs[0].buffer, "a", 1);

// write file attr
lfs_file_setattr(lfs, &file, "b", 1);

// close file 
lfs_file_close(lfs, &file);

With this implementation the file attr will be set to "a".

A bit less clear is that this implementation also immediately writes the attrs to disk, where as other lfs_file_* functions stage changes to be written until the next lfs_file_sync.

There may be ways of making this work where lfs_file_setattr only updates RAM-backed attrs or errors, but I think a better solution would be to address the core problem @dpkristensen highlighted in #759. i.e. make it so RAM-backed attrs are always fetched during lfs_file_open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs minor version new functionality only allowed in minor versions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants