Make attribute writing be dependent on attr_count upon close/sync and not upon open
Current user attributes behavior given upon open to write is bit complicated: If attribute count is not 0 upon open: At the first sync (or close) after the open things will be written to the disk (in cost of wear etc.) even if user decided not to write attributes and changed attribute count to 0 (maybe wanted to read attributes upon open and according that decided not to update them?). at next syncs (or close) will write user attributes will be re-written (and changed if user changed them in the buffer) just if the file changed till then. If attribute count is 0 upon open: syncs (or close) user attributes will be re-written (and changed if user changed them in the buffer) just if the file changed till then.
This is complex behave, and in cases for example that user opened file with READ-WRITE and wanted to read attributes it will cause write to flash even if he decided not to change anything.
Solution in this fix The write of the user attributes will be done if and just if file was opened to write and attribute count is greater than 0 upon the close/sync.
tests that added (and will fail without this PR):
- if upon open attribute count was 1 and upon sync it was 0 and no change done to the file - there was no write to the file metadata (file position stay same)
- changing attribute count to 1 before sync cause write of the user attributes to the file, even if the file wasn't change (before the fix it happened just in first sync after opening if the attribute count was bigger than 0 upon opening).
- if multiple syncs happen when attribute count is bigger than 1, each time attributes will be written. (this is reasonable behavior, but user need to be aware of it if fore some reason it calls lots of syncs without any change and the attribute count is bigger than 0 each sync will cause write to the disk)