| of[fd] = mkfile(m, mode, m0), files[m] = mkfile(m2, md0, # links(m, dirs), content0), buf-opt = none, dirs0 = dirs, err = ESUCCESS, ino = 0, ino0 = 0, inode = mkinode(m, md0, false, # links(m, dirs), 0, m2), n0 ≠ 0, afs-cons(dirs, files), of-cons(of, dirs, files), m ∈ files, fd ∈ of, n0 ≤ # buf ⊦ [afs_truncate_internal#(m2, m2 / VFS_PAGE_SIZE; inode, buf-opt, ino0, ino, isdir, err, dirs, files; asynced)] ( afs-cons(dirs, files) → ⟪ino3 := 0; if err = ESUCCESS then vfs_write_loop#(m0, inode, m0 + n0, buf, dirs; ino3, err, files, asynced); if ino3 ≠ 0 then err := ESUCCESS; if err = ESUCCESS then let ino = inode.size in {n0 := ino3, ino1 := m0 + ino3; if ino3 ≠ 0 ∧ ino < ino1 then {inode.size := ino1; afs_check_commit#(dirs, files; err; asynced); if err = ESUCCESS then afs_write_inode#(inode; err, dirs, files; asynced)}; if err ≠ ESUCCESS then n0 := (m0 ≤ ino ⊃ ino - m0;0), err := ESUCCESS; of[fd].pos := m0 + n0}⟫ (dirs0 = dirs)), mode ≠ MODE_W ∧ mode ≠ MODE_RW |
files[m] = mkfile(m2, md0, # links(m, dirs), content0), of[fd] = mkfile(m, mode, m0), buf-opt = none, dirs0 = dirs, err = ESUCCESS, ino = 0, ino0 = ino, ino1 = ino2, ino2 = 0, inode = mkinode(m, md0, false, # links(m, dirs), 0, m2), n = m2, pageno = m2 / VFS_PAGE_SIZE, afs-cons(dirs, files), of-cons(of, dirs, files), fd ∈ of, m ∈ files, n0 ≤ # buf ⊦ [ let ino = inode.ino, content = files[inode.ino].content, buf = ? in {ino1 := inode.size % VFS_PAGE_SIZE, ino0 := min(n, inode.size); isdir := inode.size ≤ n ∧ ino1 ≠ 0 ∧ (pageno ∈ content ∨ buf-opt.some?); if isdir then {if buf-opt.some? then buf := buf-opt.buf else buf := files[ino].content[pageno]; buf := fill(buf, zero, ino1, VFS_PAGE_SIZE - ino1); content[pageno] := buf; buf-opt := some(buf)}; files[ino].content := content upto ino0; let new_inode = inode in {new_inode.size := n; afs_inode_sync#(new_inode; dirs, files)}; inode := getinode(inode.ino, dirs, files); err := ESUCCESS} or fail#(; ; err); asynced := ?] ( afs-cons(dirs, files) → ⟪ino3 := 0; if err = ESUCCESS then vfs_write_loop#(m0, inode, m0 + n0, buf, dirs; ino3, err, files, asynced); if ino3 ≠ 0 then err := ESUCCESS; if err = ESUCCESS then let ino = inode.size in {n0 := ino3, ino1 := m0 + ino3; if ino3 ≠ 0 ∧ ino < ino1 then {inode.size := ino1; afs_check_commit#(dirs, files; err; asynced); if err = ESUCCESS then afs_write_inode#(inode; err, dirs, files; asynced)}; if err ≠ ESUCCESS then n0 := (m0 ≤ ino ⊃ ino - m0;0), err := ESUCCESS; of[fd].pos := m0 + n0}⟫ (dirs0 = dirs)), VFS_PAGE_SIZE = 0, n0 = 0, mode ≠ MODE_W ∧ mode ≠ MODE_RW
Used simplifier rules: afs_truncate_internal# (N, PAGENO ; INODE, PBUF-OPT, OFFSET, SIZE, MODIFIED, ERR, DIRS, FILES ; ASYNCED ) { let INO = INODE.ino, CONTENT = FILES[INODE.ino].content, PBUF = ? in {OFFSET := INODE.size % VFS_PAGE_SIZE, SIZE := min(N, INODE.size); MODIFIED := INODE.size ≤ N ∧ OFFSET ≠ 0 ∧ (PAGENO ∈ CONTENT ∨ PBUF-OPT.some?); if MODIFIED then {if PBUF-OPT.some? then PBUF := PBUF-OPT.buf else PBUF := FILES[INO].content[PAGENO]; PBUF := fill(PBUF, zero, OFFSET, VFS_PAGE_SIZE - OFFSET); CONTENT[PAGENO] := PBUF; PBUF-OPT := some(PBUF)}; FILES[INO].content := CONTENT upto SIZE; let NEW_INODE = INODE in {NEW_INODE.size := N; afs_inode_sync#(NEW_INODE; DIRS, FILES)}; INODE := getinode(INODE.ino, DIRS, FILES); ERR := ESUCCESS} or fail#(; ; ERR); ASYNCED := ? };