<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tech-pubs.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Kernel%3A_vfile</id>
	<title>Kernel: vfile - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://tech-pubs.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Kernel%3A_vfile"/>
	<link rel="alternate" type="text/html" href="https://tech-pubs.net/wiki/index.php?title=Kernel:_vfile&amp;action=history"/>
	<updated>2026-04-19T20:49:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://tech-pubs.net/wiki/index.php?title=Kernel:_vfile&amp;diff=466&amp;oldid=prev</id>
		<title>Raion at 23:54, 9 January 2026</title>
		<link rel="alternate" type="text/html" href="https://tech-pubs.net/wiki/index.php?title=Kernel:_vfile&amp;diff=466&amp;oldid=prev"/>
		<updated>2026-01-09T23:54:02Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 23:54, 9 January 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l87&quot;&gt;Line 87:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 87:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Porting: BSD struct file semantically similar to vfile. Main differences: no bhv chain, no explicit pfile layer, different lock strategy.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Porting: BSD struct file semantically similar to vfile. Main differences: no bhv chain, no explicit pfile layer, different lock strategy.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Overall, IRIX vfile is unique due to bhv_desc_t behavior chaining and pfile offset separation, designed for extensibility and Cellular IRIX distributed coherence. No direct equivalent in illumos/BSD for easy porting; closest analogs are struct file in both, but require adding behavior dispatch and double-close logic for fidelity.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Overall, IRIX vfile is unique due to bhv_desc_t behavior chaining and &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Kernel: &lt;/ins&gt;pfile&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]] &lt;/ins&gt;offset separation, designed for extensibility and Cellular IRIX distributed coherence. No direct equivalent in illumos/BSD for easy porting; closest analogs are struct file in both, but require adding behavior dispatch and double-close logic for fidelity.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category: Kernel Documentation]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Raion</name></author>
	</entry>
	<entry>
		<id>https://tech-pubs.net/wiki/index.php?title=Kernel:_vfile&amp;diff=457&amp;oldid=prev</id>
		<title>Raion: Created page with &quot;== Overview == The vfile (virtual file) object in the IRIX kernel represents an open file description — the kernel-side structure that corresponds to an open file shared across processes (via fork, dup, etc.). It holds per-open state such as reference count, open flags, credentials, associated vnode or vsocket, and a behavior chain head for stacked behaviors (notably the pfile behavior for offset management). The vfile layer sits between the per-process file descriptor...&quot;</title>
		<link rel="alternate" type="text/html" href="https://tech-pubs.net/wiki/index.php?title=Kernel:_vfile&amp;diff=457&amp;oldid=prev"/>
		<updated>2026-01-04T03:27:21Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Overview == The vfile (virtual file) object in the IRIX kernel represents an open file description — the kernel-side structure that corresponds to an open file shared across processes (via fork, dup, etc.). It holds per-open state such as reference count, open flags, credentials, associated vnode or vsocket, and a behavior chain head for stacked behaviors (notably the pfile behavior for offset management). The vfile layer sits between the per-process file descriptor...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Overview ==&lt;br /&gt;
The vfile (virtual file) object in the IRIX kernel represents an open file description — the kernel-side structure that corresponds to an open file shared across processes (via fork, dup, etc.). It holds per-open state such as reference count, open flags, credentials, associated vnode or vsocket, and a behavior chain head for stacked behaviors (notably the pfile behavior for offset management).&lt;br /&gt;
The vfile layer sits between the per-process file descriptor table (fdt) and lower-level objects (vnode for files, vsocket for sockets). It manages reference counting, close semantics (including double-close protocol for races), credential handling, and integration with distributed (Cellular IRIX) features. The implementation emphasizes thread/sproc safety via spinlocks and careful race avoidance during close.&lt;br /&gt;
== Key Functions ==&lt;br /&gt;
Initialization (vfile_init)&lt;br /&gt;
Initializes the file_zone for efficient allocation of vfile_t structures, sets up debugging lists/locks, calls vfile_cell_init() (distributed support) and pfile_init().&lt;br /&gt;
Creation (vfile_create)&lt;br /&gt;
Allocates a vfile_t from the zone, initializes:&lt;br /&gt;
&lt;br /&gt;
Spinlock (vf_lock)&lt;br /&gt;
Reference count = 1&lt;br /&gt;
Flags and credential hold&lt;br /&gt;
Behavior chain head (vf_bh)&lt;br /&gt;
Links into debug active list&lt;br /&gt;
Increments global SYSINFO.filecnt&lt;br /&gt;
&lt;br /&gt;
Allocation for Open (vfile_alloc)&lt;br /&gt;
Creates a vfile (with FINPROGRESS flag), allocates an fd via fdt_alloc, creates associated pfile behavior. Returns file pointer and fd; caller must call vfile_ready after successful VOP_OPEN.&lt;br /&gt;
Activation (vfile_ready)&lt;br /&gt;
Clears FINPROGRESS, sets associated vnode/vsocket pointer.&lt;br /&gt;
Undo on Failed Open (vfile_alloc_undo)&lt;br /&gt;
Reverses vfile_alloc when VOP_OPEN fails: removes fd, drops refcount, tears down pfile, destroys vfile.&lt;br /&gt;
Close Protocol (vfile_close, vfile_close_common, vfile_ref_release)&lt;br /&gt;
Implements a two-phase close to handle races between multiple threads/sprocs closing the same fd:&lt;br /&gt;
&lt;br /&gt;
vfile_close: Calls VFILE_CLOSE with VFILE_FIRSTCLOSE to probe if last reference.&lt;br /&gt;
vfile_close_common: Performs actual cleanup:&lt;br /&gt;
Cleans locks if present&lt;br /&gt;
Calls VOP_CLOSE (or VSOP_CLOSE) with appropriate lastclose flag&lt;br /&gt;
Handles double-call race by potentially issuing extra VOP_CLOSE&lt;br /&gt;
On true last close: flushes/invalidates if requested, releases vnode, removes GRIO reservations, tears down behaviors, destroys vfile&lt;br /&gt;
&lt;br /&gt;
vfile_ref_release: Used for non-close reference drops (e.g., rfork cleanup); only performs full close if last reference.&lt;br /&gt;
&lt;br /&gt;
Assignment Helper (vfile_assign)&lt;br /&gt;
Convenience wrapper: allocates vfile/fd, performs VOP_OPEN (updating vnode pointer if changed), readies vfile on success, undoes on failure.&lt;br /&gt;
== Undocumented or IRIX-Specific Interfaces and Behaviors ==&lt;br /&gt;
Critical Structures (from ksys/vfile.h)&lt;br /&gt;
&lt;br /&gt;
vfile_t:&lt;br /&gt;
int vf_count — reference count (shared opens)&lt;br /&gt;
int vf_flag — open flags (FREAD, FWRITE, etc.) + internal (FINPROGRESS, FLCINVAL, FLCFLUSH, FPRIORITY)&lt;br /&gt;
cred_t *vf_cred — held credentials of opener&lt;br /&gt;
spinlock_t vf_lock — protects structure&lt;br /&gt;
bhv_head_t vf_bh — head of behavior chain (pfile inserted here)&lt;br /&gt;
void *vf_data — pointer to vnode_t or vsock_t (via VF_TO_VNODE/VF_TO_VSOCK)&lt;br /&gt;
Debug links (vf_next, vf_prev) for active list&lt;br /&gt;
&lt;br /&gt;
Macros:&lt;br /&gt;
VFLOCK / VFUNLOCK — spinlock wrappers&lt;br /&gt;
VFILE_CLOSE(fp, phase, info) — behavior chain dispatch for close&lt;br /&gt;
VFILE_TEARDOWN(fp) — behavior chain teardown dispatch&lt;br /&gt;
VF_IS_VNODE, VF_SET_DATA&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Double-Close Protocol&lt;br /&gt;
IRIX uses a two-call close pattern (VFILE_FIRSTCLOSE, VFILE_SECONDCLOSE) via behavior chain to safely determine last close in multiprocessor/shared-process environments. Prevents race where one thread tears down structure while another assumes it still exists.&lt;br /&gt;
Flags and Special Handling&lt;br /&gt;
&lt;br /&gt;
FINPROGRESS: Set during open until vfile_ready&lt;br /&gt;
FLCINVAL / FLCFLUSH: Trigger VOP_FSYNC with invalidate or flush on last close&lt;br /&gt;
FPRIORITY: Indicates GRIO (Guaranteed Rate I/O) reservation&lt;br /&gt;
VFRLOCKS: Vnode has record locks → clean on close&lt;br /&gt;
&lt;br /&gt;
Distributed Support&lt;br /&gt;
References to DC/DS (Distributed Coordinator/Server) and VFILE_SKIPCLOSE indicate special handling in Cellular IRIX: last close may be deferred or coordinated remotely.&lt;br /&gt;
== Similarities to illumos and BSD Kernel Implementations ==&lt;br /&gt;
illumos (Solaris-derived)&lt;br /&gt;
Moderate similarity:&lt;br /&gt;
&lt;br /&gt;
Per-open state in struct file (referenced by filedesc table)&lt;br /&gt;
Reference counting and close races handled via closef()&lt;br /&gt;
Vnode ops with VOP_CLOSE(last)&lt;br /&gt;
Credential holding&lt;br /&gt;
No behavior chaining; vnode ops direct&lt;br /&gt;
No explicit pfile separation — offset in uio or per-read/write&lt;br /&gt;
&lt;br /&gt;
Porting: illumos file closer to vfile than BSD, but lacks behavior chain and double-close protocol.&lt;br /&gt;
BSD (FreeBSD, NetBSD, OpenBSD)&lt;br /&gt;
Closer in some aspects:&lt;br /&gt;
&lt;br /&gt;
struct file with reference count, flags, credential, pointer to fileops and data (vnode/socket)&lt;br /&gt;
Double-close avoidance via careful refcounting&lt;br /&gt;
closef() performs fdrop() → ops → free&lt;br /&gt;
No behavior chaining; direct fops dispatch&lt;br /&gt;
Offset not stored in file — managed per-I/O via uio&lt;br /&gt;
&lt;br /&gt;
Porting: BSD struct file semantically similar to vfile. Main differences: no bhv chain, no explicit pfile layer, different lock strategy.&lt;br /&gt;
Overall, IRIX vfile is unique due to bhv_desc_t behavior chaining and pfile offset separation, designed for extensibility and Cellular IRIX distributed coherence. No direct equivalent in illumos/BSD for easy porting; closest analogs are struct file in both, but require adding behavior dispatch and double-close logic for fidelity.&lt;/div&gt;</summary>
		<author><name>Raion</name></author>
	</entry>
</feed>