Lecture 13: VFS presentations

File systems three ways

Why focus on the virtual file system?

Virtual file system terms

Vnodes in 1986

Vnodes in 1986

Virtual file system and physical file system

File operations

Meaning of inheritance

OS/161 vnode_ops

struct vnode {
	int vn_refcount;                /* Reference count */
	struct spinlock vn_countlock;   /* Lock for vn_refcount */
	struct fs *vn_fs;               /* Filesystem vnode belongs to */
	void *vn_data;                  /* Filesystem-specific data */
	const struct vnode_ops *vn_ops; /* Functions on this vnode */

struct vnode_ops {
	int (*vop_eachopen)(struct vnode *object, int flags_from_open);
	int (*vop_reclaim)(struct vnode *vnode);
	int (*vop_read)(struct vnode *file, struct uio *uio);
	int (*vop_write)(struct vnode *file, struct uio *uio);

const struct vnode_operations sfs_fileops, sfs_dirops, semfs_dirops, semfs_semops;

Linux file_operations

struct file {
	/* Protects f_ep, f_flags. Must not be taken from IRQ context. */
	spinlock_t f_lock;
	fmode_t f_mode;
	loff_t f_pos;
	struct fown_struct f_owner;
	struct inode *f_inode;
	const struct file_operations *f_op;
	void *private_data;

struct file_operations {
	struct module *owner;
	ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
	ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
	int (*release) (struct inode *, struct file *);

const struct file_operations v9fs_file_operations, v9fs_file_operations_dotl, adfs_file_operations,
	ext4_file_operations, omg so many wtf;

Virtual functions

class file {
	virtual ssize_t read(char* buf, size_t sz, loff_t* fpos) = 0;
	virtual ssize_t write(const char* buf, size_t sz, loff_t* fpos) = 0;

Framing questions