int init_fs(struct v7 *v7) { struct fs_info fs0, fs1; int r, r0, r1; r0 = fs_get_info(0, &fs0); r1 = fs_get_info(1, &fs1); dprintf(("r0 = %d, r1 = %d\n", r0, r1)); if (r0 == 0 && r1 == 0) { if (fs0.seq < fs1.seq) { r1 = -1; } else { r0 = -1; } } if (r0 == 0) { r = fs_mount(0, &s_fsm); } else if (r1 == 0) { r = fs_mount(1, &s_fsm); } else { r = fs_format(0); if (r != 0) return r; r = fs_mount(0, &s_fsm); } return r; }
static int fs_get_active_idx(const char *cpfx) { struct fs_container_info fs0, fs1; int r0 = fs_get_info(cpfx, 0, &fs0); int r1 = fs_get_info(cpfx, 1, &fs1); DBG(("r0 = %d %llx, r1 = %d %llx", r0, fs0.seq, r1, fs1.seq)); if (r0 == 0 && r1 == 0) { if (fs0.seq < fs1.seq) { r1 = -1; } else { r0 = -1; } } if (r0 == 0) return 0; if (r1 == 0) return 1; return -1; }
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; }