fs/vboxsf/file.c
Source file repositories/reference/linux-study-clean/fs/vboxsf/file.c
File Facts
- System
- Linux kernel
- Corpus path
fs/vboxsf/file.c- Extension
.c- Size
- 10804 bytes
- Lines
- 396
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/page-flags.hlinux/pagemap.hlinux/highmem.hlinux/sizes.hvfsmod.h
Detected Declarations
struct vboxsf_handlefunction vboxsf_file_openfunction vboxsf_handle_releasefunction vboxsf_release_sf_handlefunction vboxsf_file_releasefunction vboxsf_vma_closefunction vboxsf_file_mmap_preparefunction vboxsf_read_foliofunction vboxsf_writepagesfunction vboxsf_write_end
Annotated Snippet
const struct file_operations vboxsf_reg_fops = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
.mmap_prepare = vboxsf_file_mmap_prepare,
.open = vboxsf_file_open,
.release = vboxsf_file_release,
.fsync = noop_fsync,
.splice_read = filemap_splice_read,
};
const struct inode_operations vboxsf_reg_iops = {
.getattr = vboxsf_getattr,
.setattr = vboxsf_setattr,
.fileattr_get = vboxsf_fileattr_get,
};
static int vboxsf_read_folio(struct file *file, struct folio *folio)
{
struct vboxsf_handle *sf_handle = file->private_data;
loff_t off = folio_pos(folio);
u32 nread = PAGE_SIZE;
u8 *buf;
int err;
buf = kmap_local_folio(folio, 0);
err = vboxsf_read(sf_handle->root, sf_handle->handle, off, &nread, buf);
buf = folio_zero_tail(folio, nread, buf + nread);
kunmap_local(buf);
folio_end_read(folio, err == 0);
return err;
}
static struct vboxsf_handle *vboxsf_get_write_handle(struct vboxsf_inode *sf_i)
{
struct vboxsf_handle *h, *sf_handle = NULL;
mutex_lock(&sf_i->handle_list_mutex);
list_for_each_entry(h, &sf_i->handle_list, head) {
if (h->access_flags == SHFL_CF_ACCESS_WRITE ||
h->access_flags == SHFL_CF_ACCESS_READWRITE) {
kref_get(&h->refcount);
sf_handle = h;
break;
}
}
mutex_unlock(&sf_i->handle_list_mutex);
return sf_handle;
}
static int vboxsf_writepages(struct address_space *mapping,
struct writeback_control *wbc)
{
struct inode *inode = mapping->host;
struct folio *folio = NULL;
struct vboxsf_inode *sf_i = VBOXSF_I(inode);
struct vboxsf_handle *sf_handle;
loff_t size = i_size_read(inode);
int error;
sf_handle = vboxsf_get_write_handle(sf_i);
if (!sf_handle)
return -EBADF;
while ((folio = writeback_iter(mapping, wbc, folio, &error))) {
loff_t off = folio_pos(folio);
u32 nwrite = folio_size(folio);
u8 *buf;
if (nwrite > size - off)
nwrite = size - off;
buf = kmap_local_folio(folio, 0);
error = vboxsf_write(sf_handle->root, sf_handle->handle,
off, &nwrite, buf);
kunmap_local(buf);
folio_unlock(folio);
}
kref_put(&sf_handle->refcount, vboxsf_handle_release);
/* mtime changed */
if (error == 0)
sf_i->force_restat = 1;
return error;
}
Annotation
- Immediate include surface: `linux/mm.h`, `linux/page-flags.h`, `linux/pagemap.h`, `linux/highmem.h`, `linux/sizes.h`, `vfsmod.h`.
- Detected declarations: `struct vboxsf_handle`, `function vboxsf_file_open`, `function vboxsf_handle_release`, `function vboxsf_release_sf_handle`, `function vboxsf_file_release`, `function vboxsf_vma_close`, `function vboxsf_file_mmap_prepare`, `function vboxsf_read_folio`, `function vboxsf_writepages`, `function vboxsf_write_end`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.