Skip to content

implement generic attribute implementation #31

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

Closed
wants to merge 2 commits into from

Conversation

guillaumerems
Copy link

add example with timestamp attribute

@loboris
Copy link

loboris commented Mar 20, 2018

@guillaumerems

Could yo update this PR for the latest littlefs commits.

@luc-github
Copy link

@geky I see timestamp is part of this PR - which is very nice feature
Cannot see why travis failed
Do you think it can be integrated soon or is there any other plan for it ?
Thank you ^_^

@geky
Copy link
Member

geky commented Apr 11, 2019

Hi, sorry about late response (almost a year :( ). As I understand this is superseded by custom attributes in v2 (#85), which has been merged.

Here's how you might be able to create timestamps with a custom file wrapper:

#define ATTR_TIMESTAMP 0x74

typedef struct time_file {
    lfs_file_t file;
    uint32_t timestamp;
    struct lfs_attr attrs[1];
    struct lfs_file_config cfg;
} time_file_t;

int time_file_open(lfs_t *lfs, time_file_t *file, char *path, int flags) {
    // set up description of timestamp attribute
    file->attrs[0].type = ATTR_TIMESTAMP;
    file->attrs[0].buffer = &file->timestamp;
    file->attrs[0].size = sizeof(&file->timestamp);

    // set up config to indicate file has custom attributes
    memset(&file->cfg, 0, sizeof(file->cfg));
    file->cfg->attrs = &file->attrs;
    file->cfg->attr_count = 1;

    // attributes will be automatically populated during open call
    return lfs_file_opencfg(lfs, &file->file, path, flags, &file->cfg);
}

int time_file_write(lfs_t *lfs, struct time_file *file, void *buffer, size_t size) {
    // update timestamp
    file->timestamp = now(NULL);
    lfs_file_write(file->lfs, &file->file, buffer, size);

    // note that like file data, custom attributes are not actually written to disk until file sync or file close
}

Related #23.

I'm going to go ahead and close this. Feel free to create another issue if I've missed anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants