VENTI-FCALL(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ¦‹ NAME (aka who's who in this fic)

Bestie, gather round, because this page is the whole cast of venti data formats: VtEntry, VtFcall, VtRoot, vtentrypack, vtentryunpack, vtfcallclear, vtfcallfmt, vtfcallpack, vtfcallunpack, vtfromdisktype, vttodisktype, vtgetstring, vtputstring, vtrootpack, vtrootunpack, vtparsescore, vtscorefmt β€” literally all of them, under one roof.

This is VENTI-FCALL(3), from the Library Functions Manual, and it's giving "backstage pass to the venti lore." πŸ’…


✨ SYNOPSIS ✨

#include <u.h>
#include <libc.h>
#include <venti.h>

enum
{
    VtEntrySize = 40,
    VtRootSize = 300,
    VtScoreSize = 20,
};

typedef struct VtEntry
{
    ulong gen;    /* generation number */
    ushort psize;   /* pointer block size */
    ushort dsize;   /* data block size */
    uchar type;
    uchar flags;
    uvlong size;
    uchar score[VtScoreSize];
} VtEntry;

typedef struct VtRoot
{
    char name[128];
    char type[128];
    uchar score[VtScoreSize];  /* to a Dir block */
    ushort blocksize;          /* maximum block size */
    uchar prev[VtScoreSize];   /* previous root block */
} VtRoot;

void    vtentrypack(VtEntry *e, uchar *buf, int index)
int     vtentryunpack(VtEntry *e, uchar *buf, int index)

Packet* vtfcallpack(VtFcall *f)
int     vtfcallunpack(VtFcall *f, Packet *p)

void vtfcallclear(VtFcall *f)

uint    vttodisktype(uint type)
uint    vtfromdisktype(uint type)

int     vtputstring(Packet *p, char *s)
int     vtgetstring(Packet *p, char **s)

void    vtrootpack(VtRoot *r, uchar *buf)
int     vtrootunpack(VtRoot *r, uchar *buf)

int     vtparsescore(char *s, char **prefix, uchar score[VtScoreSize])

int     vtfcallfmt(Fmt *fmt)
int     vtscorefmt(Fmt *fmt)

πŸ’– DESCRIPTION πŸ’–

Okay so the whole vibe of these routines: they're the translators between the C version of Venti structures and the serialized version β€” the one that lives on disk and the one that travels over the network. Glow-up AND passport control, honestly. πŸ›‚βœ¨

πŸŽ€ Entry packing, the iconique original

vtentrypack takes a VtEntry structure describing a Venti file (peep venti(7)) and converts it into a 40-byte (VtEntrySize) structure written at buf+index*40. vtentryunpack is the reverse conversion β€” same energy, opposite direction. πŸ’«

🧚 Fcall packing, protocol edition

vtfcallpack takes a VtFcall structure describing a Venti protocol message (again, venti(7)) and converts it into a packet. vtfcallunpack does the reverse conversion.

The fields in a VtFcall are named after the protocol fields described in venti(7), with one single plot twist: the type field is renamed blocktype. The msgtype field holds the one-byte message type: VtThello, VtRhello, and so on. Not me memorizing the whole cast list 😭

πŸ’… vtfcallclear, the cleanup fairy

vtfcallclear frees the strings f->error, f->version, f->uid, f->sid, the buffers f->crypto and f->codec, and the packet f->data. It's the "okay bestie, time to go home" of the group chat. 🫢

πŸ”₯ Block types, the disk-vs-network drama

So the block type enumeration defined in <venti.h> (presented in venti(7)) differs from the one used on disk and in the network protocol. The disk and network representation uses different constants and does not distinguish between VtDataType+n and VtDirType+n blocks β€” lowkey shady of it, but okay.

vttodisktype converts a <venti.h> enumeration value to the disk value; vtfromdisktype converts a disk value to the enumeration value, always using the VtDirType pointers. The VtFcall field blocktype is an enumeration value (vtfcallpack and vtfcallunpack convert to and from the disk values used in packets automatically), so most programs will not need to call these functions. Convenience ate, honestly. πŸ‘‘

πŸ“ Strings, packed and unpacked

vtputstring appends the Venti protocol representation of the string s to the packet p. vtgetstring reads a string from the packet, returning a pointer to a copy of the string in *s.

Heads up bestie: the copy must be freed by the caller. That's a you problem, not a vtgetstring problem. 🫑

These functions are used by vtfcallpack and vtfcallunpack; most programs will not need to call them directly.

🌸 Root packing, tree edition

vtrootpack converts a VtRoot structure describing a Venti file tree into the 300-byte (VtRootSize) buffer pointed to by buf. vtrootunpack does the reverse conversion. Main character energy for the whole tree πŸŽ„

⭐ vtparsescore, hex decoder era

vtparsescore parses the 40-digit hexadecimal string s, writing its value into score. If the hexadecimal string is prefixed with a text label followed by a colon, a copy of that label is returned in *prefix. If prefix is nil, the label is ignored. Slay, flexible queen. πŸ’œ

vtfcallfmt and vtscorefmt are print(3) formatters to print VtFcall structures and scores. vtfcallfmt assumes that vtscorefmt is installed as %V. It's giving friendship bracelet, they come as a set πŸŽ€


πŸ’€ SOURCE

/src/libventi β€” that's the home address, no cap.


πŸ¦‹ SEE ALSO

venti(1), venti(3), venti(7) β€” the rest of the reading list, iykyk.


πŸ™ˆ DIAGNOSTICS

  • vtentrypack, vtfcallpack, vtrootpack, and vtfcallclear cannot fail. Literally built different. ✨
  • vtentryunpack, vtrootunpack, vtputstring, vtgetstring, and vtparsescore return 0 on success, -1 on error.
  • vtfcallpack returns a packet on success, nil on error.
  • vttodisktype and vtfromdisktype return VtCorruptType (255) when presented with invalid input. Garbage in, 255 out, periodt. πŸ’…

Okay that's the whole page bestie!! You just read VENTI-FCALL(3) from the Library Functions Manual, living in /src/libventi, and honestly? She ate. πŸŽ€πŸ«Άβ­ Remember: pack responsibly, free your strings, and never confuse your block types. Mwah πŸ’–