| 128 | } |
| 129 | |
| 130 | int FileSystem::mount() |
| 131 | { |
| 132 | if(!partition) { |
| 133 | return Error::NoPartition; |
| 134 | } |
| 135 | |
| 136 | if(!partition.verify(Storage::Partition::SubType::Data::spiffs)) { |
| 137 | return Error::BadPartition; |
| 138 | } |
| 139 | |
| 140 | auto partSize = partition.size(); |
| 141 | if(partSize > MAX_PARTITION_SIZE) { |
| 142 | debug_e("[SPIFFS] Partition too large"); |
| 143 | return Error::BadPartition; |
| 144 | } |
| 145 | |
| 146 | fs.user_data = this; |
| 147 | spiffs_config cfg{ |
| 148 | .hal_read_f = f_read, |
| 149 | .hal_write_f = f_write, |
| 150 | .hal_erase_f = f_erase, |
| 151 | .phys_size = uint32_t(partSize), |
| 152 | .phys_addr = 0, |
| 153 | .phys_erase_block = uint32_t(partition.getBlockSize()), |
| 154 | .log_block_size = logicalBlockSize, |
| 155 | .log_page_size = LOG_PAGE_SIZE, |
| 156 | }; |
| 157 | |
| 158 | // debug_i("FFS offset: 0x%08x, size: %u Kb, \n", cfg.phys_addr, cfg.phys_size / 1024); |
| 159 | |
| 160 | auto res = tryMount(cfg); |
| 161 | if(res < 0) { |
| 162 | /* |
| 163 | * Mount failed, so we either try to repair the system or format it. |
| 164 | * For now, just format it. |
| 165 | */ |
| 166 | res = format(); |
| 167 | } |
| 168 | |
| 169 | #if SPIFFS_TEST_VISUALISATION |
| 170 | if(res == SPIFFS_OK) { |
| 171 | SPIFFS_vis(handle()); |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | return res; |
| 176 | } |
| 177 | |
| 178 | int FileSystem::tryMount(spiffs_config& cfg) |
| 179 | { |
no test coverage detected