Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ (2) — Plan9 4th Edition

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

venti(1)

venti(2)

venti(6)

VENTI-FCALL(2)

NAME

VtEntry, VtFcall, VtRoot, vtentrypack, vtentryunpack, vtfcallclear, vtfcallfmt, vtfcallpack, vtfcallunpack, vtfromdisktype, vttodisktype, vtgetstring, vtputstring, vtrootpack, vtrootunpack, vtparsescore, vtscorefmt − venti data formats

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;

voidvtentrypack(VtEntry ∗e, uchar ∗buf, int index)
intvtentryunpack(VtEntry ∗e, uchar ∗buf, int index)

Packet∗vtfcallpack(VtFcall ∗f)
intvtfcallunpack(VtFcall ∗f, Packet ∗p)

void vtfcallclear(VtFcall ∗f)

uintvttodisktype(uint type)
uintvtfromdisktype(uint type)

intvtputstring(Packet ∗p, char ∗s)
intvtgetstring(Packet ∗p, char ∗∗s)

voidvtrootpack(VtRoot ∗r, uchar ∗buf)
intvtrootunpack(VtRoot ∗r, uchar ∗buf)

intvtparsescore(char ∗s, char ∗∗prefix, uchar score[VtScoreSize])

intvtfcallfmt(Fmt ∗fmt)
intvtscorefmt(Fmt ∗fmt)

DESCRIPTION

These routines convert between C representations of Venti structures and serialized representations used on disk and on the network. 

­Vtentrypack converts a ­VtEntry structure describing a Venti file (see venti(6)) into a 40-byte (VtEntrySize) structure at buf+index∗40.  Vtentryunpack does the reverse conversion. 

­Vtfcallpack converts a ­VtFcall structure describing a Venti protocol message (see venti(6)) into a packet. ­Vtfcallunpack does the reverse conversion. 

The fields in a ­VtFcall are named after the protocol fields described in venti(6), except that the ­type field is renamed blocktype.  The ­msgtype field holds the one-byte message type: VtThello, VtRhello, and so on. 

­Vtfcallclear frees the strings f->error, f->version, f->uid, f->sid, the buffers f->crypto and f->codec, and the packet f->data. 

The block type enumeration defined in ­<venti.h> (presented in venti(6)) 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.  ­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. 

­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. The copy must be freed by the caller. These functions are used by ­vtfcallpack and vtfcallunpack; most programs will not need to call them directly.

­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. 

­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. 

­Vtfcallfmt and ­vtscorefmt are print(2) formatters to print ­VtFcall structures and scores.  ­Vtfcallfmt assumes that ­vtscorefmt is installed as %V. 

SOURCE

­/sys/src/libventi

SEE ALSO

venti(1), venti(2), venti(6)

DIAGNOSTICS

Vtentrypack, vtfcallpack, vtrootpack, and ­vtfcallclear cannot fail. 

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. 

Plan 9  —  December 02, 2007

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026