VtFile* vtfilecreateroot(VtCache *c, int psize, int dsize, int type);
VtFile* vtfileopenroot(VtCache *c, VtEntry *e);
VtFile* vtfileopen(VtFile *f, u32int n, int mode);
VtFile* vtfilecreate(VtFile *f, int psize, int dsize, int type);
void vtfileincref(VtFile *f);
void vtfileclose(VtFile *f);
int vtfileremove(VtFile *f);
VtBlock*vtfileblock(VtFile *f, u32int n, int mode);
long vtfileread(VtFile *f, void *buf, long n, vlong offset);
long vtfilewrite(VtFile *f, void *buf, long n, vlong offset);
int vtfileflush(VtFile *f);
int vtfileflushbefore(VtFile *f, vlong offset);
int vtfiletruncate(VtFile *f);
uvlong vtfilegetsize(VtFile *f);
int vtfilesetsize(VtFile *f, vlong size);
u32int vtfilegetdirsize(VtFile *f);
int vtfilesetdirsize(VtFile *f, u32int size);
int vtfilegetentry(VtFile *f, VtEntry *e);
int vtfilesetentry(VtFile *f, VtEntry *e);
int vtfileblockscore(VtFile *f, u32int n,
int vtfilelock(VtFile *f, int mode);
int vtfilelock2(VtFile *f, VtFile *f, int mode);
void vtfileunlock(VtFile *f);
These routines provide a simple interface to create and
manipulate Venti file trees (see
Vtfilecreateroot creates a new Venti file.
Type must be either
VtDirType, specifying a data or directory file.
Dsize is the block size to use for leaf (data or directory) blocks in the hash tree;
psize is the block size to use for internal (pointer) blocks.
Vtfileopenroot opens an existing Venti file described by
Vtfileopen opens the Venti file described by the
nth entry in the directory
Mode should be one of
VtORDWR, indicating how the returned file is to be used.
VtORDWR modes can only be used if
f is open with mode
Vtfilecreate creates a new file in the directory
f with block type
type and block sizes
Each file has an associated reference count
and holds a reference to its parent in the file tree.
Vtfileincref increments this reference count.
Vtfileclose decrements the reference count.
If there are no other references,
vtfileclose releases the reference to
fs parent and then frees the in-memory structure
f. The data stored in
f is still accessible by reopening it.
Vtfileremove removes the file
f from its parent directory.
It also acts as
vtfileclose, releasing the reference to
f and potentially freeing the structure.
Vtfileblock returns the
nth block in the file
f. If there are not
n blocks in the file and
vtfileblock returns nil.
If the mode is
vtfileblock grows the file as needed and then returns the block.
Vtfileread reads at most
n bytes at offset
f into memory at
buf. It returns the number of bytes read.
Vtfilewrite writes the
n bytes in memory at
buf into the file
f at offset
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.
Vtfilewrite writes to an in-memory copy of the data blocks
instead of writing directly to Venti.
Vtfileflush writes all copied blocks associated with
f to the Venti server.
Vtfileflushbefore flushes only those blocks corresponding to data in the file before
offset. Loops that
vtfilewrite should call
vtfileflushbefore regularly to avoid filling the block cache with unwritten blocks.
Vtfiletruncate changes the file
f to have zero length.
Vtfilegetsize returns the length (in bytes) of file
Vtfilesetsize sets the length (in bytes) of file
Vtfilegetdirsize returns the length (in directory entries)
of the directory
Vtfilesetdirsize sets the length (in directory entries)
of the directory
e with an entry that can be passed to
vtfileopenroot to reopen
f at a later time.
Vtfilesetentry sets the entry associated with
f to be
Vtfileblockscore returns in
score the score of the
nth block in the file
Venti files are locked and unlocked
vtfileunlock to moderate concurrent access.
Only one thread at a timethe one that has the file lockedcan
read or modify the file.
The functions that return files
vtfileopen) return them unlocked.
When files are passed to any of the functions documented in
this manual page, it is the callers responsibility to ensure that
they are already locked.
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,
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.