| # apebs = # wlar, bflipset = ∅, ubi-io-inv(apebs), unique-sqns(apebs), valid-ebatbl(apebs, wlar, vols, n0), valid-eraseq(q), valid-eraseq(wlar, q), valid-eraseq(apebs, q), valid-global-sqn(apebs, n1), valid-vtbl(apebs, vols, wlar, n0), valid-wl(apebs, wlar), ¬ VTBL_VOLID ∈ vols ⊦ [ubi_get_pebs_for_wl#(wlar; vtblpnum0, vtblpnum, bflipset; boolvar)] ( bflipset-cons(bflipset, wlar) ∧ ( boolvar → vtblpnum0 < # wlar ∧ wlar[vtblpnum0].status = free ∧ vtblpnum < # wlar ∧ wlar[vtblpnum].status = used ∧ wlar[vtblpnum].ec + WL_THRESHOLD ≤ wlar[vtblpnum0].ec) → [wlar0 := wlar; vols1 := vols; q1 := q; apebs1 := apebs; if boolvar then let avhdr = ?, bitflips = ? in {aubi_io_read_vidhdr#(vtblpnum, apebs; avhdr; bitflips, err); if err = ESUCCESS then let buf = mkbuf(LEB_SIZE) in {aubi_io_read_data#(vtblpnum, 0, 0, LEB_SIZE, apebs; buf; bitflips, err); if err = ESUCCESS then ubi_atomic_leb_change# (avhdr.vol, avhdr.leb, vtblpnum0, LEB_SIZE, buf, EB_PAGE_SIZE; vols, wlar, q, bflipset, n0, n1, apebs; err); if err ≠ ESUCCESS then debug#("ubi: wear-leveling of PEB " + vtblpnum.toString + " to PEB " + vtblpnum0.toString + " failed"); if err = ESUCCESS then {ubi_erase_worker_helper#(vtblpnum; wlar, apebs; err); if err = ESUCCESS then q := q.butlast}}} else err := ENOSPC] ( # 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 ∈ vols ∧ bflipset-cons(bflipset, wlar) ∧ valid-ebatbl(apebs, wlar, vols, n0) ∧ valid-vtbl(apebs, vols, wlar, n0) ∧ ubi-io-inv(apebs) ∧ ( vols1 = vols ∧ id(apebs, apebs1, mapped-pebs(vols)) ∧ q.lebrefs ⊆ q1.lebrefs ++ (VTBL_VOLID × VTBL_LNUM) ∨ (∃ v, m, n. v ∈ vols1 ∧ m < # vols1[v] ∧ vols1[v][m] ≠ unmapped ∧ vols = 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))) → err = ESUCCESS → Δ wlar < Δ wlar0)) |
# apebs = # wlar, bflipset = ∅, ubi-io-inv(apebs), unique-sqns(apebs), valid-ebatbl(apebs, wlar, vols, n0), valid-eraseq(apebs, q), valid-eraseq(wlar, q), valid-eraseq(q), valid-global-sqn(apebs, n1), valid-vtbl(apebs, vols, wlar, n0), valid-wl(apebs, wlar) ⊦ ∀ vtblpnum0, vtblpnum, bflipset, boolvar. bflipset-cons(bflipset, wlar) ∧ ( boolvar → vtblpnum0 < # wlar ∧ wlar[vtblpnum0].status = free ∧ vtblpnum < # wlar ∧ wlar[vtblpnum].status = used ∧ wlar[vtblpnum].ec + WL_THRESHOLD ≤ wlar[vtblpnum0].ec) → [wlar0 := wlar; vols1 := vols; q1 := q; apebs1 := apebs; if boolvar then let avhdr = ?, bitflips = ? in {aubi_io_read_vidhdr#(vtblpnum, apebs; avhdr; bitflips, err); if err = ESUCCESS then let buf = mkbuf(LEB_SIZE) in {aubi_io_read_data#(vtblpnum, 0, 0, LEB_SIZE, apebs; buf; bitflips, err); if err = ESUCCESS then ubi_atomic_leb_change# (avhdr.vol, avhdr.leb, vtblpnum0, LEB_SIZE, buf, EB_PAGE_SIZE; vols, wlar, q, bflipset, n0, n1, apebs; err); if err ≠ ESUCCESS then debug#("ubi: wear-leveling of PEB " + vtblpnum.toString + " to PEB " + vtblpnum0.toString + " failed"); if err = ESUCCESS then {ubi_erase_worker_helper#(vtblpnum; wlar, apebs; err); if err = ESUCCESS then q := q.butlast}}} else err := ENOSPC] ( # 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 ∈ vols ∧ bflipset-cons(bflipset, wlar) ∧ valid-ebatbl(apebs, wlar, vols, n0) ∧ valid-vtbl(apebs, vols, wlar, n0) ∧ ubi-io-inv(apebs) ∧ ( vols1 = vols ∧ id(apebs, apebs1, mapped-pebs(vols)) ∧ q.lebrefs ⊆ q1.lebrefs ++ (VTBL_VOLID × VTBL_LNUM) ∨ (∃ v, m, n. v ∈ vols1 ∧ m < # vols1[v] ∧ vols1[v][m] ≠ unmapped ∧ vols = 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))) → err = ESUCCESS → Δ wlar < Δ wlar0), VTBL_VOLID ∈ vols