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;

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

Copyright © 2024 Alcatel-Lucent. All rights reserved.