static int fs_format(int cidx) { s32_t r; struct mount_info *m = &s_fsm; _u32 fsc_size = FS_CONTAINER_SIZE(FS_SIZE); dprintf(("formatting %d s=%u, cs=%d\n", cidx, FS_SIZE, (int) fsc_size)); m->cidx = cidx; r = fs_create_container(cidx, FS_SIZE); if (r < 0) goto out; m->fh = r; m->valid = m->rw = m->formatting = 1; /* Touch a byte at the end to open a "hole". */ r = sl_FsWrite(m->fh, fsc_size - 1, (_u8 *) "\xff", 1); dprintf(("write 1 @ %d %d\n", (int) (fsc_size - 1), (int) r)); if (r != 1) goto out_close; /* There must be a mount attempt before format. It'll fail and that's ok. */ r = fs_mount_spiffs(m, FS_SIZE, FS_BLOCK_SIZE, FS_PAGE_SIZE); dprintf(("mount: %d\n", (int) r)); r = SPIFFS_format(&m->fs); dprintf(("format: %d\n", (int) r)); if (r != SPIFFS_OK) goto out_close; m->seq = INITIAL_SEQ; r = fs_write_meta(m); out_close: sl_FsClose(m->fh, NULL, NULL, 0); out: m->fh = -1; m->valid = m->formatting = m->rw = 0; return r; }
static int fs_mount(int cidx, struct mount_info *m) { int r; struct fs_info fsi; memset(m, 0, sizeof(*m)); m->fh = -1; dprintf(("mounting %d\n", cidx)); m->cidx = cidx; r = fs_get_info(cidx, &fsi); if (r != 0) return r; m->seq = fsi.seq; m->valid = 1; r = fs_mount_spiffs(m, FS_SIZE, FS_BLOCK_SIZE, FS_PAGE_SIZE); dprintf(("mount %d: %d\n", cidx, r)); return r; }
static int fs_mount_idx(const char *cpfx, int cidx, struct mount_info *m) { int r; struct fs_container_info fsi; memset(m, 0, sizeof(*m)); m->fh = -1; m->cidx = cidx; r = fs_get_info(cpfx, cidx, &fsi); if (r != 0) return r; m->cpfx = strdup(cpfx); m->seq = fsi.seq; m->valid = 1; LOG(LL_INFO, ("Mounting %s.%d 0x%llx", cpfx, cidx, fsi.seq)); r = fs_mount_spiffs(m, fsi.fs_size, fsi.fs_block_size, fsi.fs_page_size, fsi.fs_erase_size); DBG(("mount %d: %d %d", cidx, (int) r, (int) SPIFFS_errno(&m->fs))); if (r < 0) { LOG(LL_ERROR, ("Mount failed: %d", r)); } return r; }