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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
.TH VENTI-FILE 3
.SH NAME
VtFile,
vtfileblock,
vtfileblockscore,
vtfileclose,
vtfilecreate,
vtfilecreateroot,
vtfileflush,
vtfileflushbefore,
vtfilegetdirsize,
vtfilegetentry,
vtfilegetsize,
vtfileincref,
vtfilelock,
vtfilelock2,
vtfileopen,
vtfileopenroot,
vtfileread,
vtfileremove,
vtfilesetdirsize,
vtfilesetentry,
vtfilesetsize,
vtfiletruncate,
vtfileunlock,
vtfilewrite \- Venti files
.SH SYNOPSIS
.ta +\w'\fLVtBlock* 'u
.PP
.B
VtFile* vtfilecreateroot(VtCache *c, int psize, int dsize, int type);
.PP
.B
VtFile* vtfileopenroot(VtCache *c, VtEntry *e);
.PP
.B
VtFile* vtfileopen(VtFile *f, u32int n, int mode);
.PP
.B
VtFile* vtfilecreate(VtFile *f, int psize, int dsize, int type);
.PP
.B
void vtfileincref(VtFile *f);
.PP
.B
void vtfileclose(VtFile *f);
.PP
.B
int vtfileremove(VtFile *f);
.PP
.B
VtBlock* vtfileblock(VtFile *f, u32int n, int mode);
.PP
.B
long vtfileread(VtFile *f, void *buf, long n, vlong offset);
.PP
.B
long vtfilewrite(VtFile *f, void *buf, long n, vlong offset);
.PP
.B
int vtfileflush(VtFile *f);
.PP
.B
int vtfileflushbefore(VtFile *f, vlong offset);
.PP
.B
int vtfiletruncate(VtFile *f);
.PP
.B
uvlong vtfilegetsize(VtFile *f);
.PP
.B
int vtfilesetsize(VtFile *f, vlong size);
.PP
.B
u32int vtfilegetdirsize(VtFile *f);
.PP
.B
int vtfilesetdirsize(VtFile *f, u32int size);
.PP
.B
int vtfilegetentry(VtFile *f, VtEntry *e);
.PP
.B
int vtfilesetentry(VtFile *f, VtEntry *e);
.PP
.B
int vtfileblockscore(VtFile *f, u32int n,
uchar score[VtScoreSize]);
.PP
.B
int vtfilelock(VtFile *f, int mode);
.PP
.B
int vtfilelock2(VtFile *f, VtFile *f, int mode);
.PP
.B
void vtfileunlock(VtFile *f);
.SH DESCRIPTION
These routines provide a simple interface to create and
manipulate Venti file trees (see
.MR venti (7) ).
.PP
.I Vtfilecreateroot
creates a new Venti file.
.I Type
must be either
.B VtDataType
or
.BR VtDirType ,
specifying a data or directory file.
.I Dsize
is the block size to use for leaf (data or directory) blocks in the hash tree;
.I psize
is the block size to use for internal (pointer) blocks.
.PP
.I Vtfileopenroot
opens an existing Venti file described by
.IR e .
.PP
.I Vtfileopen
opens the Venti file described by the
.IR n th
entry in the directory
.IR f .
.I Mode
should be one of
.BR VtOREAD ,
.BR VtOWRITE ,
or
.BR VtORDWR ,
indicating how the returned file is to be used.
The
.BR VtOWRITE
and
.BR VtORDWR
modes can only be used if
.IR f
is open with mode
.BR VtORDWR .
.PP
.I Vtfilecreate
creates a new file in the directory
.I f
with block type
.I type
and block sizes
.I dsize
and
.I psize
(see
.I vtfilecreateroot
above).
.PP
Each file has an associated reference count
and holds a reference to its parent in the file tree.
.I Vtfileincref
increments this reference count.
.I Vtfileclose
decrements the reference count.
If there are no other references,
.I vtfileclose
releases the reference to
.IR f 's
parent and then frees the in-memory structure
.IR f .
The data stored in
.I f
is still accessible by reopening it.
.PP
.I Vtfileremove
removes the file
.I f
from its parent directory.
It also acts as
.IR vtfileclose ,
releasing the reference to
.I f
and potentially freeing the structure.
.PP
.I Vtfileblock
returns the
.IR n th
block in the file
.IR f .
If there are not
.I n
blocks in the file and
.I mode
is
.BR VtOREAD ,
.I vtfileblock
returns nil.
If the mode is
.B VtOWRITE
or
.BR VtORDWR ,
.I vtfileblock
grows the file as needed and then returns the block.
.PP
.I Vtfileread
reads at most
.I n
bytes at offset
.I offset
from
.I f
into memory at
.IR buf .
It returns the number of bytes read.
.PP
.I Vtfilewrite
writes the
.I n
bytes in memory at
.I buf
into the file
.I f
at offset
.IR n .
It returns the number of bytes written,
or \-1 on error.
Writing fewer bytes than requested will only happen
if an error is encountered.
.PP
.I Vtfilewrite
writes to an in-memory copy of the data blocks
(see
.MR venti-cache (3) )
instead of writing directly to Venti.
.I Vtfileflush
writes all copied blocks associated with
.I f
to the Venti server.
.I Vtfileflushbefore
flushes only those blocks corresponding to data in the file before
byte
.IR offset .
Loops that
.I vtfilewrite
should call
.I vtfileflushbefore
regularly to avoid filling the block cache with unwritten blocks.
.PP
.I Vtfiletruncate
changes the file
.I f
to have zero length.
.PP
.I Vtfilegetsize
returns the length (in bytes) of file
.IR f .
.PP
.I Vtfilesetsize
sets the length (in bytes) of file
.IR f .
.PP
.I Vtfilegetdirsize
returns the length (in directory entries)
of the directory
.IR f .
.PP
.I Vtfilesetdirsize
sets the length (in directory entries)
of the directory
.IR f .
.PP
.I Vtfilegetentry
fills
.I e
with an entry that can be passed to
.IR vtfileopenroot
to reopen
.I f
at a later time.
.PP
.I Vtfilesetentry
sets the entry associated with
.I f
to be
.IR e .
.PP
.I Vtfileblockscore
returns in
.I score
the score of the
.IR n th
block in the file
.IR f .
.PP
Venti files are locked and unlocked
via
.I vtfilelock
and
.I vtfileunlock
to moderate concurrent access.
Only one thread at a time\(emthe one that has the file locked\(emcan
read or modify the file.
The functions that return files
.RI ( vtfilecreateroot ,
.IR vtfileopenroot ,
.IR vtfilecreate ,
and
.IR vtfileopen )
return them unlocked.
When files are passed to any of the functions documented in
this manual page, it is the caller's responsibility to ensure that
they are already locked.
.PP
Internally, a file is locked by locking the
block that contains its directory entry.
When two files in the same
directory both need to be locked,
.I vtfilelock2
must be used.
It locks both its arguments, taking special care
not to deadlock if their entries are stored
in the same directory block.
.SH SOURCE
.B \*9/src/libventi/file.c
.SH SEE ALSO
.MR venti-cache (3) ,
.MR venti-conn (3) ,
.MR venti-client (3) ,
.MR venti (7)
|