{"action":"created","issue":{"url":"https://api.github.com/repos/adafruit/Adafruit_nRF52_Arduino/issues/227","repository_url":"https://api.github.com/repos/adafruit/Adafruit_nRF52_Arduino","labels_url":"https://api.github.com/repos/adafruit/Adafruit_nRF52_Arduino/issues/227/labels{/name}","comments_url":"https://api.github.com/repos/adafruit/Adafruit_nRF52_Arduino/issues/227/comments","events_url":"https://api.github.com/repos/adafruit/Adafruit_nRF52_Arduino/issues/227/events","html_url":"https://github.com/adafruit/Adafruit_nRF52_Arduino/issues/227","id":408815781,"node_id":"MDU6SXNzdWU0MDg4MTU3ODE=","number":227,"title":"InternalFS Corrupt Blocks","user":{"login":"czuvich","id":11586167,"node_id":"MDQ6VXNlcjExNTg2MTY3","avatar_url":"https://avatars1.githubusercontent.com/u/11586167?v=4","gravatar_id":"","url":"https://api.github.com/users/czuvich","html_url":"https://github.com/czuvich","followers_url":"https://api.github.com/users/czuvich/followers","following_url":"https://api.github.com/users/czuvich/following{/other_user}","gists_url":"https://api.github.com/users/czuvich/gists{/gist_id}","starred_url":"https://api.github.com/users/czuvich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/czuvich/subscriptions","organizations_url":"https://api.github.com/users/czuvich/orgs","repos_url":"https://api.github.com/users/czuvich/repos","events_url":"https://api.github.com/users/czuvich/events{/privacy}","received_events_url":"https://api.github.com/users/czuvich/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2019-02-11T14:46:49Z","updated_at":"2019-03-14T05:22:00Z","closed_at":null,"author_association":"NONE","body":"Board: nRF52840 Express\r\nMacOS\r\nBootloader 0.2.6\r\nArduino IDE 1.8.8\r\n\r\nI'm trying to write a string to the InternalFS, and I get the following error sporadically.\r\n```\r\n12:59:53.579 -> lfs error:494: Corrupted dir pair at 0 1\r\n12:59:53.579 -> lfs error:2222: Invalid superblock at 0 1\r\n12:59:53.579 -> [IFLASH] Format internal file system\r\n```\r\nThe only way to fix it is to InternalFS.format(true).  I can't quite pinpoint what is causing it, so I don't think posting code will help.  Having said that, I did some research and discovered the following which may/may not help:\r\n\r\n1) InternalFS File.write(buffer, size) does not overwrite the file. It appends to it.  I incremented a counter every 1s and read/write it to the same file and got the following output:\r\n```\r\n1\r\n12\r\n123\r\n```\r\nInstead, I would expect the following:\r\n```\r\n1\r\n2\r\n3\r\n```\r\nWhich takes me to 2). \r\n\r\n2)  In order to overwrite the file contents, I remove the file and create a new one. Removing a file takes a VERY long time (a few seconds).  I found the following article from Nordic that describes how internal flash is slow to remove:\r\n\r\nhttps://devzone.nordicsemi.com/f/nordic-q-a/20197/nrf52-flash-memory-vs-eeprom\r\n\r\nIt could be that since I'm running BLE and removing files, RTOS is switching tasks which is causing issues?  Anyways, right now I've created an RTOS queue to serialize my writes, and/or maybe I need to add a mutex.  I think once ExternalFS is up and running these kind of problems go away.. but I thought I'd post my findings here."},"comment":{"url":"https://api.github.com/repos/adafruit/Adafruit_nRF52_Arduino/issues/comments/472708422","html_url":"https://github.com/adafruit/Adafruit_nRF52_Arduino/issues/227#issuecomment-472708422","issue_url":"https://api.github.com/repos/adafruit/Adafruit_nRF52_Arduino/issues/227","id":472708422,"node_id":"MDEyOklzc3VlQ29tbWVudDQ3MjcwODQyMg==","user":{"login":"hathach","id":249515,"node_id":"MDQ6VXNlcjI0OTUxNQ==","avatar_url":"https://avatars3.githubusercontent.com/u/249515?v=4","gravatar_id":"","url":"https://api.github.com/users/hathach","html_url":"https://github.com/hathach","followers_url":"https://api.github.com/users/hathach/followers","following_url":"https://api.github.com/users/hathach/following{/other_user}","gists_url":"https://api.github.com/users/hathach/gists{/gist_id}","starred_url":"https://api.github.com/users/hathach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hathach/subscriptions","organizations_url":"https://api.github.com/users/hathach/orgs","repos_url":"https://api.github.com/users/hathach/repos","events_url":"https://api.github.com/users/hathach/events{/privacy}","received_events_url":"https://api.github.com/users/hathach/received_events","type":"User","site_admin":false},"created_at":"2019-03-14T05:22:00Z","updated_at":"2019-03-14T05:22:00Z","author_association":"MEMBER","body":"@jeremypoulter  @czuvich Ah thanks, I just realized I skim too fast and only think of the corruption issue. Yes the Arduino API FILE_WRITE is always in append mode. If you want overwrite, you could either remove or open then seek(0) to the beginning of the file and start writing."}}
{"actor":{"display_login":"hathach"}}