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