src/disk/pack.bend checks
raw source on the hub · import 0x2324e729258ea5021b37b97947af4c3f/src/disk/pack.bend as Pack
4 imports
import Base import ../lib/u64.bend as U import ../vmm/abi.bend as V import ./store.bend as S
Types
type PackId source · line 31 · raw
Data
Where a file sits on the host: what fstat says when it is opened.
PackId@dev:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @ino:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @size:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @mtime:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @mnsec:U32 -> PackId
type PackEntry source · line 36 · raw
Data
An entry: its number (in order of adding), offset in the pack, length (the file's), host path and identity, and whether it is still live.
PackEntry@n:U32 -> @off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @len:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @path:String -> @id:PackId -> @live:Bool -> PackEntry
type Pack source · line 41 · raw
Data
A pack: its name (the device's serial), entries in offset order, the end of the last slot, and how many entries were ever added.
Pack@name:String -> @entries:List<&2, PackEntry> -> @next:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @count:U32 -> Pack
type Piece source · line 46 · raw
Data
A part of a read: n bytes of an entry's file from offset foff, n bytes of zeros, n bytes of a dead slot, n bytes past the end.
PFile@entry:PackEntry -> @foff:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @n:U32 -> Piece
PZero@n:U32 -> Piece
PDead@n:U32 -> Piece
PPast@n:U32 -> Piece
type ReadNext source · line 53 · raw
Data
What follows a host read of want bytes that answered got.
RDoneReadNext
ROpenReadNext
RFailReadNext
Definitions
def Pack.align_bits source · line 59 · raw
Nat
1 MiB: every slot starts at a multiple of it.
def Pack.align source · line 62 · raw
0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
def Pack.slots source · line 68 · raw
U32
The host's descriptor slots: 32 of the 128 descriptors src/net/fds.bend keeps beside the guest's flows (macOS caps the process at 1024), which also hold the disks, the shares' open files, the vCPUs' pipes and the sockets.
def Pack.miss source · line 72 · raw
U32
A host read's answer: the slot holds another entry (or none).
def Pack.max_name source · line 76 · raw
Nat
The longest name: virtio-blk's id string is 20 bytes.
def Pack.new source · line 79 · raw
@name:String -> Pack
def Pack.name source · line 82 · raw
@p:Pack -> String
def Pack.entries source · line 87 · raw
@p:Pack -> List<&2, PackEntry>
def Pack.next source · line 93 · raw
@p:Pack -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
The end of the last slot: where the next file goes.
def Pack.count source · line 98 · raw
@p:Pack -> U32
def Pack.sectors source · line 104 · raw
@p:Pack -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
The device's capacity in 512-byte sectors.
def Pack.slot_len source · line 109 · raw
@+len:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
A file of len bytes takes this much of the pack: len rounded up to 1 MiB, and 1 MiB for an empty file (a slot is never empty: offsets stay apart).
def PackId.size source · line 113 · raw
@i:PackId -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
def PackEntry.n source · line 118 · raw
@e:PackEntry -> U32
def PackEntry.off source · line 123 · raw
@e:PackEntry -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
def PackEntry.len source · line 128 · raw
@e:PackEntry -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
def PackEntry.path source · line 133 · raw
@e:PackEntry -> String
def PackEntry.id source · line 138 · raw
@e:PackEntry -> PackId
def PackEntry.live source · line 143 · raw
@e:PackEntry -> Bool
def PackEntry.end source · line 149 · raw
@e:PackEntry -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
The end of an entry's slot.
def Pack.add source · line 156 · raw
@p:Pack -> @path:String -> @+id:PackId -> Pack
Adds the file at path (identity id, which says its length): it takes the slot at Pack.next.
def Pack.kill source · line 163 · raw
@es:List<&2, PackEntry> -> @+off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> List<&2, PackEntry>
The entries with the one at offset off dead (the others as they were).
def Pack.drop source · line 172 · raw
@p:Pack -> @off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> Pack
Drops the entry at offset off: it is dead from now on, and its slot is never given again (next does not move).
def Pack.has_live source · line 178 · raw
@es:List<&2, PackEntry> -> @+off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> Bool
Whether a live entry starts at offset off (what pack drop may drop).
def Pack.can_drop source · line 185 · raw
@p:Pack -> @off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> Bool
def Pack.n_at.go source · line 189 · raw
@es:List<&2, PackEntry> -> @+off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> U32
The number of the entry at offset off (0 when none: Pack.can_drop first).
def Pack.n_at source · line 196 · raw
@p:Pack -> @off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> U32
def Pack.ends source · line 201 · raw
@es:List<&2, PackEntry> -> @at:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
The end of the last slot (at when there is none).
def Pack.tiles.go source · line 210 · raw
@es:List<&2, PackEntry> -> @+at:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> Bool
Whether the entries tile from offset at on: each starts where the last slot ended (no two overlap, none is left out).
def Pack.tiles source · line 218 · raw
@p:Pack -> Bool
Whether the pack's slots tile [0, next).
def Pack.find source · line 224 · raw
@es:List<&2, PackEntry> -> @+x:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> Maybe<&2, PackEntry>
The entry whose slot holds offset x.
def Pack.min source · line 232 · raw
@+r:U32 -> @d:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> U32
min(r, d) for a U64 distance d.
def Piece.len source · line 237 · raw
@p:Piece -> U32
def Pack.piece.of source · line 249 · raw
@live:Bool -> @+e:PackEntry -> @+x:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+r:U32 -> Piece
The piece at x (at most r bytes) inside entry e's slot.
def Pack.piece source · line 259 · raw
@m:Maybe<&2, PackEntry> -> @+x:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+r:U32 -> Piece
The piece at x (at most r bytes): past the end when no slot holds x.
def Pack.split.go source · line 268 · raw
@fuel:Nat -> @done:Bool -> @+es:List<&2, PackEntry> -> @+x:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+r:U32 -> List<&2, Piece>
The pieces of r bytes from x on. Each piece ends at the read's end or at a slot's or a file's end, so 2 per entry and one more suffice (fuel).
def Pack.split source · line 283 · raw
@p:Pack -> @+off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+len:U32 -> List<&2, Piece>
A read of len bytes at byte offset off, as pieces in order; their lengths add up to len.
def Pack.slot_of source · line 289 · raw
@n:U32 -> U32
The descriptor slot of entry n, and its key there (0: an empty slot).
def Pack.key_of source · line 292 · raw
@n:U32 -> U32
def Pack.on_read source · line 298 · raw
@+got:U32 -> @+want:U32 -> ReadNext
After a host read of want bytes answered got: done when it moved them all, open the file again on a miss, else fail (an error, or a short read: the file changed).
def Pack.w source · line 303 · raw
@+ws:List<&2, U32> -> @i:Nat -> U32
The identity in what the host answered an open: [0, dev hi, lo, ino hi, lo, size hi, lo, mtime hi, lo, mtime ns]; anything else (an errno) is none.
def Pack.facts source · line 306 · raw
@+ws:List<&2, U32> -> Maybe<&2, PackId>
def Pack.errno source · line 312 · raw
@+ws:List<&2, U32> -> U32
The errno in what the host answered an open (0: it opened).
def PackId.is_eq source · line 315 · raw
@a:PackId -> @b:PackId -> Bool
def Pack.same source · line 323 · raw
@+id:PackId -> @m:Maybe<&2, PackId> -> Bool
Whether a reopened file is still the one that was added.
def Pack.reread source · line 334 · raw
@-R:Type -> @+got:U32 -> @+want:U32 -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, U32>
def Pack.read.reopened source · line 338 · raw
@-R:Type -> @same:Bool -> @+slot:U32 -> @+key:U32 -> @+foff:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+a:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Iov> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, U32>
After the reopen: read again when it is the same file, else let the slot go.
def Pack.read.next source · line 349 · raw
@-R:Type -> @nx:ReadNext -> @+slot:U32 -> @+key:U32 -> @+path:String -> @+id:PackId -> @+foff:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+a:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Iov> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, U32>
def Pack.read.file source · line 361 · raw
@-R:Type -> @e:PackEntry -> @+foff:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+a:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Iov> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, U32>
n bytes of an entry's file from foff into the pieces of memory a.
def Pack.read.piece source · line 371 · raw
@-R:Type -> @pc:Piece -> @+a:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Iov> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, U32>
One piece into the memory a.
def Pack.read.then source · line 385 · raw
@-R:Type -> @+s:U32 -> @more:0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, U32> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, U32>
The rest of the pieces, unless one failed.
def Pack.read.pieces source · line 389 · raw
@-R:Type -> @pcs:List<&2, Piece> -> @+iovs:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Iov> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, U32>
The pieces into the memory iovs, in order; stops at the first that fails.
def Pack.read source · line 401 · raw
@-R:Type -> @+p:Pack -> @+off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+iovs:List<&2, 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Iov> -> 0x2324e729258ea5021b37b97947af4c3f/src/vmm/abi.Op<R, U32>
A read of the device at byte offset off into the memory iovs: status 0 OK, 1 IOERR.
def Pack.div10 source · line 408 · raw
@x:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
x / 10 and x % 10, by long division in 16-bit steps (no U32 overflows).
def Pack.mod10 source · line 415 · raw
@x:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> U32
def Pack.dec.go source · line 421 · raw
@fuel:Nat -> @done:Bool -> @+x:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+acc:String -> String
def Pack.dec source · line 434 · raw
@x:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> String
A U64 in decimal (at most 20 digits).
def Pack.times10 source · line 438 · raw
@+x:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+d:U32 -> 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64
x * 10 + d.
def Pack.parse.go source · line 441 · raw
@cs:String -> @+acc:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+n:Nat -> Maybe<&2, 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64>
def Pack.parse source · line 450 · raw
@s:String -> Maybe<&2, 0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64>
A decimal number (1 to 19 digits, nothing else).
def Pack.name_char source · line 453 · raw
@+c:U32 -> Bool
def Pack.name_chars source · line 457 · raw
@s:String -> Bool
def Pack.name_ok source · line 465 · raw
@+s:String -> Bool
A pack's name (its serial): 1 to 20 of [A-Za-z0-9._-].
def Pack.hex1 source · line 471 · raw
@+d:U32 -> Char
def Pack.json_char source · line 476 · raw
@+c:U32 -> @+rest:String -> String
A character of a JSON string: quote and backslash escaped, control characters as \u00XX.
def Pack.json_chars source · line 481 · raw
@s:String -> String
def Pack.json_str source · line 488 · raw
@s:String -> String
def Pack.json_entry source · line 491 · raw
@e:PackEntry -> String
def Pack.json_entries source · line 496 · raw
@es:List<&2, PackEntry> -> @+first:Bool -> String
def Pack.json source · line 504 · raw
@p:Pack -> String
The pack for status json: {"name":..,"size":bytes,"entries":[..]}.
def Pack.no_pack source · line 510 · raw
String
Control replies (pack add, pack drop).
def Pack.added source · line 513 · raw
@+off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> @+len:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> String
def Pack.cannot_open source · line 516 · raw
@+path:String -> @+errno:U32 -> String
def Pack.no_entry source · line 519 · raw
@+off:0x2324e729258ea5021b37b97947af4c3f/src/lib/u64.U64 -> String