fs/hostfs/hostfs_kern.c

Source file repositories/reference/linux-study-clean/fs/hostfs/hostfs_kern.c

File Facts

System
Linux kernel
Corpus path
fs/hostfs/hostfs_kern.c
Extension
.c
Size
24367 bytes
Lines
1097
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations hostfs_file_fops = {
	.llseek		= generic_file_llseek,
	.splice_read	= filemap_splice_read,
	.splice_write	= iter_file_splice_write,
	.read_iter	= generic_file_read_iter,
	.write_iter	= generic_file_write_iter,
	.mmap_prepare	= generic_file_mmap_prepare,
	.open		= hostfs_open,
	.release	= hostfs_file_release,
	.fsync		= hostfs_fsync,
};

static const struct file_operations hostfs_dir_fops = {
	.llseek		= generic_file_llseek,
	.iterate_shared	= hostfs_readdir,
	.read		= generic_read_dir,
	.open		= hostfs_open,
	.fsync		= hostfs_fsync,
};

static int hostfs_writepages(struct address_space *mapping,
		struct writeback_control *wbc)
{
	struct inode *inode = mapping->host;
	struct folio *folio = NULL;
	loff_t i_size = i_size_read(inode);
	int err = 0;

	while ((folio = writeback_iter(mapping, wbc, folio, &err))) {
		loff_t pos = folio_pos(folio);
		size_t count = folio_size(folio);
		char *buffer;
		int ret;

		if (count > i_size - pos)
			count = i_size - pos;

		buffer = kmap_local_folio(folio, 0);
		ret = write_file(HOSTFS_I(inode)->fd, &pos, buffer, count);
		kunmap_local(buffer);
		folio_unlock(folio);
		if (ret != count) {
			err = ret < 0 ? ret : -EIO;
			mapping_set_error(mapping, err);
		}
	}

	return err;
}

static int hostfs_read_folio(struct file *file, struct folio *folio)
{
	char *buffer;
	loff_t start = folio_pos(folio);
	int bytes_read, ret = 0;

	buffer = kmap_local_folio(folio, 0);
	bytes_read = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer,
			PAGE_SIZE);
	if (bytes_read < 0)
		ret = bytes_read;
	else
		buffer = folio_zero_tail(folio, bytes_read, buffer + bytes_read);
	kunmap_local(buffer);

	folio_end_read(folio, ret == 0);
	return ret;
}

static int hostfs_write_begin(const struct kiocb *iocb,
			      struct address_space *mapping,
			      loff_t pos, unsigned len,
			      struct folio **foliop, void **fsdata)
{
	pgoff_t index = pos >> PAGE_SHIFT;

	*foliop = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
			mapping_gfp_mask(mapping));
	if (IS_ERR(*foliop))
		return PTR_ERR(*foliop);
	return 0;
}

static int hostfs_write_end(const struct kiocb *iocb,
			    struct address_space *mapping,
			    loff_t pos, unsigned len, unsigned copied,
			    struct folio *folio, void *fsdata)
{
	struct inode *inode = mapping->host;
	void *buffer;

Annotation

Implementation Notes