blob: dfb7bf4118cb5b352204d8cd3f18f8758a15a1c1 [file] [log] [blame]
rscbe7cbb42005-07-12 15:24:18 +00001.TH VENTI-FILE 3
2.SH NAME
3VtFile,
4vtfileopenroot,
5vtfilecreateroot,
6vtfileopen,
7vtfilecreate,
8vtfileblock,
9vtfileread,
10vtfilewrite,
11vtfileflush,
12vtfileincref,
13vtfileclose,
14vtfilegetentry,
15vtfilesetentry,
16vtfileblockscore,
17vtfilegetdirsize,
18vtfilesetdirsize,
19vtfileunlock,
20vtfilelock,
21vtfilelock2,
22vtfileflushbefore,
23vtfiletruncate,
24vtfilegetsize,
25vtfilesetsize,
26vtfileremove \- Venti files
27.SH SYNOPSIS
28.ta +\w'\fLVtBlock* 'u
29.PP
30.B
31VtFile* vtfilecreateroot(VtCache *c, int psize, int dsize, int type);
32.PP
33.B
34VtFile* vtfileopenroot(VtCache *c, VtEntry *e);
35.PP
36.B
37VtFile* vtfileopen(VtFile *f, u32int n, int mode);
38.PP
39.B
40VtFile* vtfilecreate(VtFile *f, int psize, int dsize, int dir);
41.PP
42.B
43void vtfileincref(VtFile *f);
44.PP
45.B
46void vtfileclose(VtFile *f);
47.PP
48.B
49int vtfileremove(VtFile *f);
50.PP
51.B
52VtBlock* vtfileblock(VtFile *f, u32int n, int mode);
53.PP
54.B
55long vtfileread(VtFile *f, void *buf, long n, vlong offset);
56.PP
57.B
58long vtfilewrite(VtFile *f, void *buf, long n, vlong offset);
59.PP
60.B
61int vtfileflush(VtFile *f);
62.PP
63.B
64int vtfileflushbefore(VtFile *f, vlong offset);
65.PP
66.B
67int vtfiletruncate(VtFile *f);
68.PP
69.B
70uvlong vtfilegetsize(VtFile *f);
71.PP
72.B
73int vtfilesetsize(VtFile *f, vlong size);
74.PP
75.B
76u32int vtfilegetdirsize(VtFile *f);
77.PP
78.B
79int vtfilesetdirsize(VtFile *f, u32int size);
80.PP
81.B
82int vtfilegetentry(VtFile *f, VtEntry *e);
83.PP
84.B
85int vtfilesetentry(VtFile *f, VtEntry *e);
86.PP
87.B
88int vtfileblockscore(VtFile *f, u32int n, uchar score[VtScoreSize]);
89.PP
90.B
91int vtfilelock(VtFile *f, int mode);
92.PP
93.B
94int vtfilelock2(VtFile *f, VtFile *f, int mode);
95.PP
96.B
97void vtfileunlock(VtFile *f);
98.SH DESCRIPTION
99These routines provide a simple interface to create and
100manipulate Venti file trees (see
101.IR venti (1)).
102.PP
103.I Vtfilecreateroot
104creates a new Venti file.
105.I Btype
106must be either
107.B VtDataType
108or
109.BR VtDirType ,
110specifying a data or directory file.
111.I Dsize
112is the block size to use for leaf (data or directory) blocks in the hash tree;
113.I psize
114is the block size to use for intermediate (pointer) blocks.
115.PP
116.I Vtfileopenroot
117opens an existing Venti file described by
118.IR e .
119.PP
120.I Vtfileopen
121opens the Venti file described by the
122.IR n th
123entry in the directory
124.IR f .
125.I Mode
126should be one of
127.IR VtOREAD ,
128.IR VtOWRITE ,
129or
130.IR VtORDWR ,
131indicating how the returned file is to be used.
132The
133.IR VtOWRITE
134and
135.IR VtORDWR
136modes can only be used if
137.IR f
138is open with mode
139.IR VtORDWR .
140.PP
141.I Vtfilecreate
142creates a new file in the directory
143.I f
144with block type
145.I type
146and block sizes
147.I dsize
148and
149.I psize
150(see
151.I vtfilecreateroot
152above).
153.PP
154Each file has an associated reference count
155and holds a reference to its parent in the file tree.
156.I Vtfileincref
157increments this reference count.
158.I Vtfileclose
159decrements the reference count.
160If there are no other references,
161.I vtfileclose
162releases the reference to
163.IR f 's
164parent and then frees the in-memory structure
165.IR f .
166The data stored in
167.I f
168is still accessible by reopening it.
169.PP
170.I Vtfileremove
171removes the file
172.I f
173from its parent directory.
174It also acts as
175.IR vtfileclose ,
176releasing the reference to
177.I f
178and potentially freeing the structure.
179.PP
180.I Vtfileblock
181returns the
182.IR n th
183block in the file
184.IR f .
185If there are not
186.I n
187blocks in the file and
188.I mode
189is
190.BR VtOREAD ,
191.I vtfileblock
192returns nil.
193If the mode is
194.B VtOWRITE
195or
196.BR VtORDWR ,
197.I vtfileblock
198grows the file as needed and then returns the block.
199.PP
200.I Vtfileread
201reads at most
202.I n
203bytes at offset
204.I offset
205from
206.I f
207into memory at
208.IR buf .
209It returns the number of bytes read.
210.PP
211.I Vtfilewrite
212writes the
213.I n
214bytes in memory at
215.I buf
216into the file
217.I f
218at offset
219.IR n .
220It returns the number of bytes written,
221or \-1 on error.
222Writing fewer bytes than requested will only happen
223if an error is encountered.
224.PP
225.I Vtfilewrite
226writes to an in-memory copy of the data blocks
227(see
228.IR venti-cache (3))
229instead of writing directly to Venti.
230.I Vtfileflush
231writes all copied blocks associated with
232.I f
233to the Venti server.
234.I Vtfileflushbefore
235flushes only those blocks corresponding to data in the file before
236byte
237.IR offset .
238Loops that
239.I vtfilewrite
240should call
241.I vtfileflushbefore
242regularly to avoid filling the block cache with dirty blocks.
243.PP
244.I Vtfiletruncate
245changes the file
246.I f
247to have zero length.
248.PP
249.I Vtfilegetsize
250returns the length (in bytes) of file
251.IR f .
252.PP
253.I Vtfilesetsize
254sets the length (in bytes) of file
255.IR f .
256.PP
257.I Vtfilegetdirsize
258returns the length (in directory entries)
259of the directory
260.IR f .
261.PP
262.I Vtfilesetdirsize
263sets the length (in directory entries)
264of the directory
265.IR f .
266.PP
267.I Vtfilegetentry
268fills
269.I e
270with an entry that can be passed to
271.IR vtfileopenroot
272to reopen
273.I f
274at a later time.
275.PP
276.I Vtfilesetentry
277sets the entry associated with
278.I f
279to be
280.IR e .
281.PP
282.I Vtfileblockscore
283returns in
284.I score
285the score of the
286.I n th
287block in the file
288.IR f .
289.PP
290Venti files are locked and unlocked
291via
292.I vtfilelock
293and
294.I vtfileunlock
295to moderate concurrent access.
296Only one thread at a time\(emthe one that has the file locked\(emcan
297read or modify the file.
298The functions that return files
299.RI ( vtfilecreateroot ,
300.IR vtfileopenroot ,
301.IR vtfilecreate ,
302and
303.IR vtfileopen )
304return them unlocked.
305When files are passed to any of the functions documented in
306this manual page, it is the caller's responsibility to ensure that
307they are already locked.
308.PP
309Internally, a file is locked by locking the
310block that contains its directory entry.
311When two files in the same
312directory both need to be locked,
313.I vtfilelock2
314must be used.
315It locks both its arguments, taking special care
316not to deadlock if their entries are stored
317in the same directory block.
318.SH SOURCE
319.B \*9/src/libventi/file.c
320.SH SEE ALSO
321.IR venti (1),
322.IR venti-cache (3),
323.IR venti-conn (3),
324.IR venti-client (3)