| # apebs = # wlar, avhdr0.leb = VTBL_LNUM, avhdr0.vol = VTBL_VOLID, wlar[n2] = wl-entry(m0, used), wlar[vtblpnum1] = wl-entry(m3, free), apebs[n2] = mkpeb(aehdr, avhdr0, buf1, m2, false), apebs1 = apebs, n4 = n2, q1 = q, vols1 = vols, wlar0 = wlar, vtblpnum1 ≠ n2, n2 < # wlar, vtblpnum1 < # wlar, bflipset-cons(bflipset0, wlar), is-aligned(LEB_SIZE, EB_PAGE_SIZE), ubi-io-inv(apebs), ubi-io-peb-inv(mkpeb(aehdr, avhdr0, buf1, m2, false)), unique-sqns(apebs), valid-ebatbl(apebs, wlar, vols, n2), valid-eraseq(q), valid-eraseq(wlar, q), valid-eraseq(apebs, q), valid-global-sqn(apebs, n1), valid-vtbl(apebs, vols, wlar, n2), valid-wl(apebs, wlar), m0 + WL_THRESHOLD ≤ m3, ¬ VTBL_VOLID ∈ vols ⊦ [ubi_atomic_leb_change# (avhdr0.vol, avhdr0.leb, vtblpnum1, LEB_SIZE, copy(apebs[n2].data, 0, mkbuf(LEB_SIZE), 0, LEB_SIZE), EB_PAGE_SIZE ; vols, wlar, q, bflipset0, n2, n1, apebs ; err0)] ( (err0 = ESUCCESS ∨ ⌊err0⌋ ) ∧ id○(apebs, apebs1, vtblpnum1) ∧ ubi-io-inv(apebs) ∧ # apebs = # wlar ∧ unique-sqns(apebs) ∧ valid-global-sqn(apebs, n1) ∧ valid-wl(apebs, wlar) ∧ valid-eraseq(q) ∧ valid-eraseq(wlar, q) ∧ valid-eraseq(apebs, q) ∧ ¬ VTBL_VOLID ∈ vols1 ∧ bflipset-cons(bflipset0, wlar) ∧ ( avhdr0.vol ∈ vols1 ∨ is-encoded(to-vtbl(vols1), buf1) ∨ err0 ≠ ESUCCESS → valid-ebatbl(apebs, wlar, vols1, n2) ∧ valid-vtbl(apebs, vols1, wlar, n2)) ∧ ( err0 = ESUCCESS → (∀ v, m. ¬ v ∈ vols1 ∧ is-encoded(to-vtbl(vols1)[v, m], buf1) → valid-ebatbl(apebs, wlar, vols1[v, fill(mkebatbl(m), unmapped)], n2) ∧ valid-vtbl(apebs, vols1[v, fill(mkebatbl(m), unmapped)], wlar, n2))) ∧ ( err0 = ESUCCESS ∧ avhdr0.vol ∈ vols1 ∧ vols1[avhdr0.vol][avhdr0.leb] ≠ unmapped → q = q1 + eq-entry(vols1[avhdr0.vol][avhdr0.leb].pnum, avhdr0.vol × avhdr0.leb) ') ∧ (err0 = ESUCCESS → q = q1 + eq-entry(n4, avhdr0.vol × avhdr0.leb) ') ∧ id(apebs, apebs1, mapped-pebs(vols1)) ∧ vols = vols1 ∧ (avhdr0.vol ∈ vols1 ∧ err0 = ESUCCESS → vols1 = vols1[avhdr0.vol, vols1[avhdr0.vol][avhdr0.leb, ⌜vtblpnum1⌝ ]]) ∧ ( err0 = ESUCCESS → apebs[vtblpnum1].fill = align↑(datasize(apebs[vtblpnum1].data, LEB_SIZE), EB_PAGE_SIZE) ∧ apebs[vtblpnum1].data = buf1 ∧ q.lebrefs ⊆ q1.lebrefs ++ (avhdr0.vol × avhdr0.leb)) ∧ (err0 ≠ ESUCCESS → q.lebrefs = q1.lebrefs) → Δ wlar = Δ wlar0 ∧ ecs(wlar) = ecs(wlar0) ∧ (err0 = ESUCCESS → wlar[vtblpnum1].ec = m3 ∧ wlar[n4].ec = m0) → [vtblpnum2 := n4; if err0 ≠ ESUCCESS then debug#("ubi: wear-leveling of PEB " + vtblpnum2.toString + " to PEB " + vtblpnum1.toString + " failed"); if err0 = ESUCCESS then {ubi_erase_worker_helper#(vtblpnum2; wlar, apebs; err0); if err0 = ESUCCESS then q := q.butlast}] ( # apebs = # wlar ∧ unique-sqns(apebs) ∧ valid-global-sqn(apebs, n1) ∧ valid-wl(apebs, wlar) ∧ valid-eraseq(q) ∧ valid-eraseq(wlar, q) ∧ valid-eraseq(apebs, q) ∧ bflipset-cons(bflipset0, wlar) ∧ valid-ebatbl(apebs, wlar, vols1, n2) ∧ valid-vtbl(apebs, vols1, wlar, n2) ∧ ubi-io-inv(apebs) ∧ ( id(apebs, apebs1, mapped-pebs(vols1)) ∧ q.lebrefs ⊆ q1.lebrefs ++ (VTBL_VOLID × VTBL_LNUM) ∨ (∃ v, m, n. v ∈ vols1 ∧ m < # vols1[v] ∧ vols1[v][m] ≠ unmapped ∧ vols1 = vols1[v, vols1[v][m, ⌜n⌝ ]] ∧ id(apebs, apebs1, mapped-pebs(vols1) -- vols1[v][m].pnum) ∧ apebs[n].data = apebs1[vols1[v][m].pnum].data ∧ apebs[n].fill ≤ apebs1[vols1[v][m].pnum].fill ∧ q.lebrefs ⊆ q1.lebrefs ++ (v × m))) → err0 = ESUCCESS → Δ wlar < Δ wlar0)) |
# apebs = # wlar, avhdr0.leb = VTBL_LNUM, avhdr0.vol = VTBL_VOLID, apebs[n2] = mkpeb(aehdr, avhdr0, buf1, m2, false), wlar[vtblpnum1] = wl-entry(m3, free), wlar[n2] = wl-entry(m0, used), apebs1 = apebs, n4 = n2, q1 = q, vols1 = vols, wlar0 = wlar, vtblpnum1 < # wlar, n2 < # wlar, bflipset-cons(bflipset0, wlar), is-aligned(LEB_SIZE, EB_PAGE_SIZE), ubi-io-inv(apebs), ubi-io-peb-inv(mkpeb(aehdr, avhdr0, buf1, m2, false)), unique-sqns(apebs), valid-ebatbl(apebs, wlar, vols, n2), valid-eraseq(apebs, q), valid-eraseq(wlar, q), valid-eraseq(q), valid-global-sqn(apebs, n1), valid-vtbl(apebs, vols, wlar, n2), valid-wl(apebs, wlar), m0 + WL_THRESHOLD ≤ m3 ⊦ ∀ vols, wlar, q, bflipset0, n2, n1, apebs, err0. (err0 = ESUCCESS ∨ ⌊err0⌋ ) ∧ id○(apebs, apebs1, vtblpnum1) ∧ ubi-io-inv(apebs) ∧ # apebs = # wlar ∧ unique-sqns(apebs) ∧ valid-global-sqn(apebs, n1) ∧ valid-wl(apebs, wlar) ∧ valid-eraseq(q) ∧ valid-eraseq(wlar, q) ∧ valid-eraseq(apebs, q) ∧ ¬ VTBL_VOLID ∈ vols1 ∧ bflipset-cons(bflipset0, wlar) ∧ ( avhdr0.vol ∈ vols1 ∨ is-encoded(to-vtbl(vols1), buf1) ∨ err0 ≠ ESUCCESS → valid-ebatbl(apebs, wlar, vols1, n2) ∧ valid-vtbl(apebs, vols1, wlar, n2)) ∧ ( err0 = ESUCCESS → (∀ v, m. ¬ v ∈ vols1 ∧ is-encoded(to-vtbl(vols1)[v, m], buf1) → valid-ebatbl(apebs, wlar, vols1[v, fill(mkebatbl(m), unmapped)], n2) ∧ valid-vtbl(apebs, vols1[v, fill(mkebatbl(m), unmapped)], wlar, n2))) ∧ ( err0 = ESUCCESS ∧ avhdr0.vol ∈ vols1 ∧ vols1[avhdr0.vol][avhdr0.leb] ≠ unmapped → q = q1 + eq-entry(vols1[avhdr0.vol][avhdr0.leb].pnum, avhdr0.vol × avhdr0.leb) ') ∧ (err0 = ESUCCESS → q = q1 + eq-entry(n4, avhdr0.vol × avhdr0.leb) ') ∧ id(apebs, apebs1, mapped-pebs(vols1)) ∧ vols = vols1 ∧ (avhdr0.vol ∈ vols1 ∧ err0 = ESUCCESS → vols1 = vols1[avhdr0.vol, vols1[avhdr0.vol][avhdr0.leb, ⌜vtblpnum1⌝ ]]) ∧ ( err0 = ESUCCESS → apebs[vtblpnum1].fill = align↑(datasize(apebs[vtblpnum1].data, LEB_SIZE), EB_PAGE_SIZE) ∧ apebs[vtblpnum1].data = buf1 ∧ q.lebrefs ⊆ q1.lebrefs ++ (avhdr0.vol × avhdr0.leb)) ∧ (err0 ≠ ESUCCESS → q.lebrefs = q1.lebrefs) → Δ wlar = Δ wlar0 ∧ ecs(wlar) = ecs(wlar0) ∧ (err0 = ESUCCESS → wlar[vtblpnum1].ec = m3 ∧ wlar[n4].ec = m0) → [vtblpnum2 := n4; if err0 ≠ ESUCCESS then debug#("ubi: wear-leveling of PEB " + vtblpnum2.toString + " to PEB " + vtblpnum1.toString + " failed"); if err0 = ESUCCESS then {ubi_erase_worker_helper#(vtblpnum2; wlar, apebs; err0); if err0 = ESUCCESS then q := q.butlast}] ( # apebs = # wlar ∧ unique-sqns(apebs) ∧ valid-global-sqn(apebs, n1) ∧ valid-wl(apebs, wlar) ∧ valid-eraseq(q) ∧ valid-eraseq(wlar, q) ∧ valid-eraseq(apebs, q) ∧ bflipset-cons(bflipset0, wlar) ∧ valid-ebatbl(apebs, wlar, vols1, n2) ∧ valid-vtbl(apebs, vols1, wlar, n2) ∧ ubi-io-inv(apebs) ∧ ( id(apebs, apebs1, mapped-pebs(vols1)) ∧ q.lebrefs ⊆ q1.lebrefs ++ (VTBL_VOLID × VTBL_LNUM) ∨ (∃ v, m, n. v ∈ vols1 ∧ m < # vols1[v] ∧ vols1[v][m] ≠ unmapped ∧ vols1 = vols1[v, vols1[v][m, ⌜n⌝ ]] ∧ id(apebs, apebs1, mapped-pebs(vols1) -- vols1[v][m].pnum) ∧ apebs[n].data = apebs1[vols1[v][m].pnum].data ∧ apebs[n].fill ≤ apebs1[vols1[v][m].pnum].fill ∧ q.lebrefs ⊆ q1.lebrefs ++ (v × m))) → err0 = ESUCCESS → Δ wlar < Δ wlar0), vtblpnum1 = n2, VTBL_VOLID ∈ vols