blob: 2eb0cea38439b4f7e94e9079ec0885264b2e7708 [file] [log] [blame]
rscbe7cbb42005-07-12 15:24:18 +00001.TH VENTI-FCALL 3
2.SH NAME
3VtEntry, VtFcall, VtRoot,
4vtentrypack,
5vtentryunpack,
6vtfcallclear,
7vtfcallfmt,
8vtfcallpack,
9vtfcallunpack,
10vtfromdisktype,
11vttodisktype,
12vtgetstring,
13vtputstring,
14vtrootpack,
15vtrootunpack,
16vtparsescore,
rsc3aec33f2005-07-18 22:41:58 +000017vtscorefmt \- venti data formats
rscbe7cbb42005-07-12 15:24:18 +000018.SH SYNOPSIS
19.PP
20.ft L
21#include <u.h>
22.br
23#include <libc.h>
24.br
25#include <venti.h>
26.ta +\w'\fLxxxx'u
27.PP
28.ft L
29.nf
30enum
31{
32 VtEntrySize = 40,
33 VtRootSize = 300,
rscbe7cbb42005-07-12 15:24:18 +000034 VtScoreSize = 20,
35};
36.PP
37.ft L
38.nf
39typedef struct VtEntry
40{
rsc3aec33f2005-07-18 22:41:58 +000041 ulong gen; /* generation number */
42 ushort psize; /* pointer block size */
43 ushort dsize; /* data block size */
rscbe7cbb42005-07-12 15:24:18 +000044 uchar type;
45 uchar flags;
46 uvlong size;
47 uchar score[VtScoreSize];
48} VtEntry;
49.PP
50.ft L
51.nf
52typedef struct VtRoot
53{
54 char name[128];
55 char type[128];
rsc3aec33f2005-07-18 22:41:58 +000056 uchar score[VtScoreSize]; /* to a Dir block */
57 ushort blocksize; /* maximum block size */
58 uchar prev[VtScoreSize]; /* previous root block */
rscbe7cbb42005-07-12 15:24:18 +000059} VtRoot;
60.ta +\w'\fLPacket* 'u
61.PP
62.B
63void vtentrypack(VtEntry *e, uchar *buf, int index)
64.br
65.B
66int vtentryunpack(VtEntry *e, uchar *buf, int index)
67.PP
68.B
69Packet* vtfcallpack(VtFcall *f)
70.br
71.B
72int vtfcallunpack(VtFcall *f, Packet *p)
73.PP
74.B
75void vtfcallclear(VtFcall *f)
76.PP
77.B
78uint vttodisktype(uint type)
79.br
80.B
81uint vtfromdisktype(uint type)
82.PP
83.B
84int vtputstring(Packet *p, char *s)
85.br
86.B
87int vtgetstring(Packet *p, char **s)
88.PP
89.B
90void vtrootpack(VtRoot *r, uchar *buf)
91.br
92.B
93int vtrootunpack(VtRoot *r, uchar *buf)
94.PP
95.B
96int vtparsescore(char *s, char **prefix, uchar score[VtScoreSize])
97.PP
98.B
99int vtfcallfmt(Fmt *fmt)
100.B
101int vtscorefmt(Fmt *fmt)
102.SH DESCRIPTION
103These routines convert between C representations of Venti
104structures and serialized representations used on disk and
105on the network.
106.PP
107.I Vtentrypack
108converts a
109.B VtEntry
110structure describing a Venti file
111(see
rsc3aec33f2005-07-18 22:41:58 +0000112.IR venti (7))
rscbe7cbb42005-07-12 15:24:18 +0000113into a 40-byte
114.RB ( VtEntrySize )
115structure at
116.IB buf + index *40 \fR.
117Vtentryunpack
118does the reverse conversion.
119.PP
120.I Vtfcallpack
121converts a
122.B VtFcall
123structure describing a Venti protocol message
124(see
125.IR venti (7))
126into a packet.
127.I Vtfcallunpack
128does the reverse conversion.
129.PP
130The fields in a
131.B VtFcall
132are named after the protocol fields described in
133.IR venti (7),
134except that the
135.B type
136field is renamed
137.BR blocktype .
138The
139.B msgtype
140field holds the one-byte message type:
141.BR VtThello ,
142.BR VtRhello ,
143and so on.
144.PP
145.I Vtfcallclear
146frees the strings
147.IB f ->error \fR,
148.IB f ->version \fR,
149.IB f ->uid \fR,
150.IB f ->sid \fR,
151the buffers
rsc3aec33f2005-07-18 22:41:58 +0000152.IB f ->crypto
rscbe7cbb42005-07-12 15:24:18 +0000153and
154.IB f ->codec \fR,
155and the packet
156.IB f ->data \fR.
157.PP
158The block type enumeration defined in
159.B <venti.h>
160(presented in
rsc3aec33f2005-07-18 22:41:58 +0000161.IR venti (7))
rscbe7cbb42005-07-12 15:24:18 +0000162differs from the one used on disk and in the network
163protocol.
164The disk and network representation uses different
rsc3aec33f2005-07-18 22:41:58 +0000165constants and does not distinguish between
rscbe7cbb42005-07-12 15:24:18 +0000166.BI VtDataType+ n
167and
168.BI VtDirType+ n
169blocks.
170.I Vttodisktype
171converts a
172.B <venti.h>
173enumeration value to the disk value;
174.I vtfromdisktype
rsc3aec33f2005-07-18 22:41:58 +0000175converts a disk value to the enumeration value,
176always using the
177.B VtDataType
178pointers.
rscbe7cbb42005-07-12 15:24:18 +0000179The
180.B VtFcall
181field
182.B blocktype
183is an enumeration value
184.RI ( vtfcallpack
185and
186.I vtfcallunpack
187convert to and from the disk values used in packets
188automatically),
189so most programs will not need to call these functions.
190.PP
191.I Vtputstring
192appends the Venti protocol representation of the string
193.I s
194to the packet
195.IR p .
196.I Vtgetstring
197reads a string from the packet, returning a pointer to a copy
198of the string in
199.BI * s \fR.
200The copy must be freed by the caller.
201These functions are used by
202.I vtfcallpack
203and
204.IR vtfcallunpack ;
205most programs will not need to call them directly.
206.PP
207.I Vtrootpack
208converts a
209.B VtRoot
210structure describing a Venti file tree
211into the 300-byte
212.RB ( VtRootSize )
213buffer pointed to by
214.IR buf .
215.I Vtrootunpack does the reverse conversion.
216.PP
217.I Vtparsescore
218parses the 40-digit hexadecimal string
219.IR s ,
220writing its value
221into
222.IR score .
223If the hexadecimal string is prefixed with
224a text label followed by a colon, a copy of that
225label is returned in
226.BI * prefix \fR.
227If
228.I prefix
229is nil, the label is ignored.
230.PP
231.I Vtfcallfmt
232and
233.I vtscorefmt
234are
235.IR print (3)
236formatters to print
237.B VtFcall
238structures and scores.
239.I Vtfcallfmt
240assumes that
241.I vtscorefmt
242is installed as
243.BR %V .
244.SH SOURCE
245.B \*9/src/libventi
246.SH SEE ALSO
247.IR venti (1),
248.IR venti (3),
249.IR venti (7)
250.SH DIAGNOSTICS
251.IR Vtentrypack ,
252.IR vtfcallpack ,
253.IR vtrootpack ,
254and
255.I vtfcallclear
256cannot fail.
257.PP
258.IR Vtentryunpack ,
259.IR vtrootunpack ,
260.IR vtputstring ,
261.IR vtgetstring ,
262and
263.I vtparsescore
264return 0 on success, \-1 on error.
265.PP
266.I Vtfcallpack
267returns a packet on success, nil on error.
268.PP
269.I Vttodisktype
270and
271.I vtfromdisktype
272return
273.B VtCorruptType
274(255)
275when presented with invalid input.