{"action":"created","issue":{"url":"https://api.github.com/repos/ARMmbed/littlefs/issues/58","repository_url":"https://api.github.com/repos/ARMmbed/littlefs","labels_url":"https://api.github.com/repos/ARMmbed/littlefs/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/ARMmbed/littlefs/issues/58/comments","events_url":"https://api.github.com/repos/ARMmbed/littlefs/issues/58/events","html_url":"https://github.com/ARMmbed/littlefs/pull/58","id":330490370,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzNDg4NDQ5","number":58,"title":"Added possibility to open multiple files with LFS_NO_MALLOC enabled","user":{"login":"dpgeorge","id":6187689,"node_id":"MDQ6VXNlcjYxODc2ODk=","avatar_url":"https://avatars1.githubusercontent.com/u/6187689?v=4","gravatar_id":"","url":"https://api.github.com/users/dpgeorge","html_url":"https://github.com/dpgeorge","followers_url":"https://api.github.com/users/dpgeorge/followers","following_url":"https://api.github.com/users/dpgeorge/following{/other_user}","gists_url":"https://api.github.com/users/dpgeorge/gists{/gist_id}","starred_url":"https://api.github.com/users/dpgeorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpgeorge/subscriptions","organizations_url":"https://api.github.com/users/dpgeorge/orgs","repos_url":"https://api.github.com/users/dpgeorge/repos","events_url":"https://api.github.com/users/dpgeorge/events{/privacy}","received_events_url":"https://api.github.com/users/dpgeorge/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-08T01:39:26Z","updated_at":"2018-06-27T20:55:52Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/ARMmbed/littlefs/pulls/58","html_url":"https://github.com/ARMmbed/littlefs/pull/58","diff_url":"https://github.com/ARMmbed/littlefs/pull/58.diff","patch_url":"https://github.com/ARMmbed/littlefs/pull/58.patch"},"body":"The `LFS_NO_MALLOC` option is very useful, because some systems have very particular memory allocation needs.  But enabled this option doesn't allow to have multiple files open at the same time.  This PR adds a quick fix for this by allowing to pass in the `file_buffer` directly to `lfs_file_open()`, so the latter doesn't need to call `lfs_malloc()`.\r\n\r\nI don't expect this to be merged as-is because it breaks the existing API.  But a feature along these lines would be very useful because it gives full functionality of littlefs without the need for any `malloc()` or `free()` functions.\r\n\r\nAlternatives to this PR would be:\r\n- a new function, eg `lfs_file_open_using()` which accepts the 5th parameter added here\r\n- allow to set the global `lfs->cfg->file_buffer` pointer before each call to `lfs_file_open()` so the latter could pick up a new buffer each time\r\n\r\n( Background: we are looking to integrate littlefs in MicroPython: https://github.com/micropython/micropython/pull/3847 )"},"comment":{"url":"https://api.github.com/repos/ARMmbed/littlefs/issues/comments/400826151","html_url":"https://github.com/ARMmbed/littlefs/pull/58#issuecomment-400826151","issue_url":"https://api.github.com/repos/ARMmbed/littlefs/issues/58","id":400826151,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMDgyNjE1MQ==","user":{"login":"geky","id":1075160,"node_id":"MDQ6VXNlcjEwNzUxNjA=","avatar_url":"https://avatars3.githubusercontent.com/u/1075160?v=4","gravatar_id":"","url":"https://api.github.com/users/geky","html_url":"https://github.com/geky","followers_url":"https://api.github.com/users/geky/followers","following_url":"https://api.github.com/users/geky/following{/other_user}","gists_url":"https://api.github.com/users/geky/gists{/gist_id}","starred_url":"https://api.github.com/users/geky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geky/subscriptions","organizations_url":"https://api.github.com/users/geky/orgs","repos_url":"https://api.github.com/users/geky/repos","events_url":"https://api.github.com/users/geky/events{/privacy}","received_events_url":"https://api.github.com/users/geky/received_events","type":"User","site_admin":false},"created_at":"2018-06-27T20:55:52Z","updated_at":"2018-06-27T20:55:52Z","author_association":"MEMBER","body":"Hi @dpgeorge, thanks for the pr (and rebasing). I think you're right passing a buffer into open would be a better API.\r\n\r\nTossing ideas around, one idea to make this future compatible would be to take in a sort of config struct. Similar to the lfs_mount/lfs_format functions:\r\n``` cpp\r\nstruct lfs_file_config {\r\n    void *buffer;\r\n};\r\n\r\nint lfs_file_open(lfs_t *lfs, lfs_file_t *file,\r\n        const char *path, int flags,\r\n        const struct lfs_file_config *cfg);\r\n```\r\n\r\nThis would let us add additional configuration to the config structure in the future without breaking compatibility or having to come up with additional function names. Thoughts?"}}
{"actor":{"display_login":"geky"}}