VENTI-FILE(3)
π NAME π
okay bestie, this is VENTI-FILE(3) from the Library Functions Manual β the Venti files page. It stars VtFile plus all these functions: vtfileblock, vtfileblockscore, vtfileclose, vtfilecreate, vtfilecreateroot, vtfileflush, vtfileflushbefore, vtfilegetdirsize, vtfilegetentry, vtfilegetsize, vtfileincref, vtfilelock, vtfilelock2, vtfileopen, vtfileopenroot, vtfileread, vtfileremove, vtfilesetdirsize, vtfilesetentry, vtfilesetsize, vtfiletruncate, vtfileunlock, vtfilewrite. Theyβre the whole vibe for creating and manipulating Venti files β¨.
πΈ SYNOPSIS πΈ
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, uchar score[VtScoreSize]);
int vtfilelock(VtFile *f, int mode);
int vtfilelock2(VtFile *f, VtFile *f, int mode);
void vtfileunlock(VtFile *f);
π¦ DESCRIPTION π¦
These routines give you a simple interface to create and manipulate Venti file trees (see venti(7)). slay.
π creating + opening files
vtfilecreaterootβ creates a new Venti file.typemust be eitherVtDataTypeorVtDirType, specifying a data or directory file.dsizeis the block size to use for leaf (data or directory) blocks in the hash tree;psizeis the block size to use for internal (pointer) blocks.vtfileopenrootβ opens an existing Venti file described bye.vtfileopenβ opens the Venti file described by thenth entry in the directoryf.modeshould be one ofVtOREAD,VtOWRITE, orVtORDWR, indicating how the returned file is to be used. TheVtOWRITEandVtORDWRmodes can only be used iffis open with modeVtORDWR.vtfilecreateβ creates a new file in the directoryfwith block typetypeand block sizesdsizeandpsize(seevtfilecreaterootabove).
π reference counts + remove
vtfileincrefβ each file has an associated reference count and holds a reference to its parent in the file tree. This increments that reference count.vtfilecloseβ decrements the reference count. If there are no other references,vtfileclosereleases the reference tofβs parent and then frees the in-memory structuref. The data stored infis still accessible by reopening it.vtfileremoveβ removes the fileffrom its parent directory. It also acts asvtfileclose, releasing the reference tofand potentially freeing the structure.
π§ blocks, reading, writing, flushing
vtfileblockβ returns thenth block in the filef. If there are notnblocks in the file andmodeisVtOREAD,vtfileblockreturnsnil. If the mode isVtOWRITEorVtORDWR,vtfileblockgrows the file as needed and then returns the block.vtfilereadβ reads at mostnbytes at offsetoffsetfromfinto memory atbuf. It returns the number of bytes read.vtfilewriteβ writes thenbytes in memory atbufinto the filefat offsetn. It returns the number of bytes written, or-1on error. Writing fewer bytes than requested will only happen if an error is encountered. It writes to an in-memory copy of the data blocks (seeventi-cache(3)) instead of writing directly to Venti.vtfileflushβ writes all copied blocks associated withfto the Venti server.vtfileflushbeforeβ flushes only those blocks corresponding to data in the file before byteoffset. If youβre looping withvtfilewrite, callvtfileflushbeforeregularly so the block cache doesnβt fill up with unwritten blocks.
π sizes, entries, scores
vtfiletruncateβ changes the filefto have zero length.vtfilegetsizeβ returns the length (in bytes) of filef.vtfilesetsizeβ sets the length (in bytes) of filef.vtfilegetdirsizeβ returns the length (in directory entries) of the directoryf.vtfilesetdirsizeβ sets the length (in directory entries) of the directoryf.vtfilegetentryβ fillsewith an entry that can be passed tovtfileopenrootto reopenfat a later time.vtfilesetentryβ sets the entry associated withfto bee.vtfileblockscoreβ returns inscorethe score of thenth block in the filef.
π locking β read this part, bestie
Venti files are locked and unlocked via vtfilelock and vtfileunlock to moderate concurrent access. Only one thread at a time β the one that has the file locked β can read or modify the file. The functions that return files (vtfilecreateroot, vtfileopenroot, vtfilecreate, and 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.
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.
π SOURCE π
/src/libventi/file.c
π«Ά SEE ALSO π«Ά
venti-cache(3), venti-conn(3), venti-client(3), venti(7)
mwah π β thatβs VENTI-FILE(3) from the Library Functions Manual. source: /src/libventi/file.c; footer: literally just VENTI-FILE(3) (no date on this one, bestie). periodt.
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms