blob: 5378bf5c22a5b17b2cedcf8847c75a055124e8c3 [file] [log] [blame]
rscbe7cbb42005-07-12 15:24:18 +00001.TH VENTI-FILE 3
2.SH NAME
3VtFile,
rscbe7cbb42005-07-12 15:24:18 +00004vtfileblock,
rscbe7cbb42005-07-12 15:24:18 +00005vtfileblockscore,
rsc3aec33f2005-07-18 22:41:58 +00006vtfileclose,
7vtfilecreate,
8vtfilecreateroot,
9vtfileflush,
10vtfileflushbefore,
rscbe7cbb42005-07-12 15:24:18 +000011vtfilegetdirsize,
rsc3aec33f2005-07-18 22:41:58 +000012vtfilegetentry,
13vtfilegetsize,
14vtfileincref,
rscbe7cbb42005-07-12 15:24:18 +000015vtfilelock,
16vtfilelock2,
rsc3aec33f2005-07-18 22:41:58 +000017vtfileopen,
18vtfileopenroot,
19vtfileread,
20vtfileremove,
21vtfilesetdirsize,
22vtfilesetentry,
rscbe7cbb42005-07-12 15:24:18 +000023vtfilesetsize,
rsc3aec33f2005-07-18 22:41:58 +000024vtfiletruncate,
25vtfileunlock,
26vtfilewrite \- Venti files
rscbe7cbb42005-07-12 15:24:18 +000027.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
rsc86a1a5e2005-07-19 17:58:26 +000040VtFile* vtfilecreate(VtFile *f, int psize, int dsize, int type);
rscbe7cbb42005-07-12 15:24:18 +000041.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
rsc3aec33f2005-07-18 22:41:58 +000088int vtfileblockscore(VtFile *f, u32int n,
89 uchar score[VtScoreSize]);
rscbe7cbb42005-07-12 15:24:18 +000090.PP
91.B
92int vtfilelock(VtFile *f, int mode);
93.PP
94.B
95int vtfilelock2(VtFile *f, VtFile *f, int mode);
96.PP
97.B
98void vtfileunlock(VtFile *f);
99.SH DESCRIPTION
100These routines provide a simple interface to create and
101manipulate Venti file trees (see
rsc3aec33f2005-07-18 22:41:58 +0000102.IR venti (7)).
rscbe7cbb42005-07-12 15:24:18 +0000103.PP
104.I Vtfilecreateroot
105creates a new Venti file.
rsc3aec33f2005-07-18 22:41:58 +0000106.I Type
rscbe7cbb42005-07-12 15:24:18 +0000107must be either
108.B VtDataType
109or
110.BR VtDirType ,
111specifying a data or directory file.
112.I Dsize
113is the block size to use for leaf (data or directory) blocks in the hash tree;
114.I psize
rsc3aec33f2005-07-18 22:41:58 +0000115is the block size to use for internal (pointer) blocks.
rscbe7cbb42005-07-12 15:24:18 +0000116.PP
117.I Vtfileopenroot
118opens an existing Venti file described by
119.IR e .
120.PP
121.I Vtfileopen
122opens the Venti file described by the
123.IR n th
124entry in the directory
125.IR f .
126.I Mode
127should be one of
rsc3aec33f2005-07-18 22:41:58 +0000128.BR VtOREAD ,
129.BR VtOWRITE ,
rscbe7cbb42005-07-12 15:24:18 +0000130or
rsc3aec33f2005-07-18 22:41:58 +0000131.BR VtORDWR ,
rscbe7cbb42005-07-12 15:24:18 +0000132indicating how the returned file is to be used.
133The
rsc3aec33f2005-07-18 22:41:58 +0000134.BR VtOWRITE
rscbe7cbb42005-07-12 15:24:18 +0000135and
rsc3aec33f2005-07-18 22:41:58 +0000136.BR VtORDWR
rscbe7cbb42005-07-12 15:24:18 +0000137modes can only be used if
138.IR f
139is open with mode
rsc3aec33f2005-07-18 22:41:58 +0000140.BR VtORDWR .
rscbe7cbb42005-07-12 15:24:18 +0000141.PP
142.I Vtfilecreate
143creates a new file in the directory
144.I f
145with block type
146.I type
147and block sizes
148.I dsize
149and
150.I psize
151(see
152.I vtfilecreateroot
153above).
154.PP
155Each file has an associated reference count
156and holds a reference to its parent in the file tree.
157.I Vtfileincref
158increments this reference count.
159.I Vtfileclose
160decrements the reference count.
161If there are no other references,
162.I vtfileclose
163releases the reference to
164.IR f 's
165parent and then frees the in-memory structure
166.IR f .
167The data stored in
168.I f
169is still accessible by reopening it.
170.PP
171.I Vtfileremove
172removes the file
173.I f
174from its parent directory.
175It also acts as
176.IR vtfileclose ,
177releasing the reference to
178.I f
179and potentially freeing the structure.
180.PP
181.I Vtfileblock
182returns the
183.IR n th
184block in the file
185.IR f .
186If there are not
187.I n
188blocks in the file and
189.I mode
190is
191.BR VtOREAD ,
192.I vtfileblock
193returns nil.
194If the mode is
195.B VtOWRITE
196or
197.BR VtORDWR ,
198.I vtfileblock
199grows the file as needed and then returns the block.
200.PP
201.I Vtfileread
202reads at most
203.I n
204bytes at offset
205.I offset
206from
207.I f
208into memory at
209.IR buf .
210It returns the number of bytes read.
211.PP
212.I Vtfilewrite
213writes the
214.I n
215bytes in memory at
216.I buf
217into the file
218.I f
219at offset
220.IR n .
221It returns the number of bytes written,
222or \-1 on error.
223Writing fewer bytes than requested will only happen
224if an error is encountered.
225.PP
226.I Vtfilewrite
227writes to an in-memory copy of the data blocks
228(see
229.IR venti-cache (3))
230instead of writing directly to Venti.
231.I Vtfileflush
232writes all copied blocks associated with
233.I f
234to the Venti server.
235.I Vtfileflushbefore
236flushes only those blocks corresponding to data in the file before
237byte
238.IR offset .
239Loops that
240.I vtfilewrite
241should call
242.I vtfileflushbefore
rsc3aec33f2005-07-18 22:41:58 +0000243regularly to avoid filling the block cache with unwritten blocks.
rscbe7cbb42005-07-12 15:24:18 +0000244.PP
245.I Vtfiletruncate
246changes the file
247.I f
248to have zero length.
249.PP
250.I Vtfilegetsize
251returns the length (in bytes) of file
252.IR f .
253.PP
254.I Vtfilesetsize
255sets the length (in bytes) of file
256.IR f .
257.PP
258.I Vtfilegetdirsize
259returns the length (in directory entries)
260of the directory
261.IR f .
262.PP
263.I Vtfilesetdirsize
264sets the length (in directory entries)
265of the directory
266.IR f .
267.PP
268.I Vtfilegetentry
269fills
270.I e
271with an entry that can be passed to
272.IR vtfileopenroot
273to reopen
274.I f
275at a later time.
276.PP
277.I Vtfilesetentry
278sets the entry associated with
279.I f
280to be
281.IR e .
282.PP
283.I Vtfileblockscore
284returns in
285.I score
286the score of the
rsc3aec33f2005-07-18 22:41:58 +0000287.IR n th
rscbe7cbb42005-07-12 15:24:18 +0000288block in the file
289.IR f .
290.PP
291Venti files are locked and unlocked
292via
293.I vtfilelock
294and
295.I vtfileunlock
296to moderate concurrent access.
297Only one thread at a time\(emthe one that has the file locked\(emcan
298read or modify the file.
299The functions that return files
300.RI ( vtfilecreateroot ,
301.IR vtfileopenroot ,
302.IR vtfilecreate ,
303and
304.IR vtfileopen )
305return them unlocked.
306When files are passed to any of the functions documented in
307this manual page, it is the caller's responsibility to ensure that
308they are already locked.
309.PP
310Internally, a file is locked by locking the
311block that contains its directory entry.
312When two files in the same
313directory both need to be locked,
314.I vtfilelock2
315must be used.
316It locks both its arguments, taking special care
317not to deadlock if their entries are stored
318in the same directory block.
319.SH SOURCE
320.B \*9/src/libventi/file.c
321.SH SEE ALSO
rscbe7cbb42005-07-12 15:24:18 +0000322.IR venti-cache (3),
323.IR venti-conn (3),
rsc3aec33f2005-07-18 22:41:58 +0000324.IR venti-client (3),
325.IR venti (7)